Error::Helper - Provides some easy error related methods.
Version 0.1.0
Below is a example module using this.
package Foo; use warnings; use strict; use base 'Error::Helper'; sub new{ my $arg=$_[1]; my $self = { perror=>undef, error=>undef, errorString=>"", }; bless $self; #error if $arg is set to "test" if( $arg eq "test" ){ $self->{perror}=1; $self->{error}=2; $self->{errorString}='A value of "test" has been set'; $self->warn; return $self; } return undef; } sub foo{ my $self=$_[0]; my $a=$_[1]; if( ! $self->errorblank ){ return undef; } if( !defined( $a ) ){ $self->{error}=1; $self->{errorString}='No value specified'; $self->warn; return undef; } return 1; }
Below is a example script.
use Foo; my $foo=Foo->new( $ARGV[0] ); if( $foo->error ){ warn('error:'.$foo->error.': '.$foo->errorString); exit $foo->error; } $foo->foo($ARGV[1]); if( $foo->error ){ warn('error:'.$foo->error.': '.$foo->errorString); exit $foo->error; }
There are three required variables in the blessed hash.
$self->{error}
This contains the current error code.
$self->{errorString}
This contains a description of the current error.
$self->{perror}
This is set to true is a permanent error is present. If note, it needs set to false.
Returns the current error code and true if there is an error.
If there is no error, undef is returned.
if($self->error){ warn('error: '.$foo->error.":".$foo->errorString); }
This blanks the error storage and is only meant for internal usage.
It does the following.
If $self->{perror} is set, it will not be able to blank any current errors.
$self->{error}=undef; $self->{errorString}="";
Returns the error string if there is one. If there is not, it will return ''.
if($self->error){ warn('error: '.$self->error.":".$self->errorString); }
Throws a warn like error message based
$self->warn;
Throws a warn like error in the same for mate as warn, but with a freeform message.
$self->warnString('some error');
Zane C. Bowers-Hadley, <vvelox at vvelox.net>
<vvelox at vvelox.net>
Please report any bugs or feature requests to bug-error-helper at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Error-Helper. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-error-helper at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Error::Helper
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Error-Helper
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Error-Helper
CPAN Ratings
http://cpanratings.perl.org/d/Error-Helper
Search CPAN
http://search.cpan.org/dist/Error-Helper/
Copyright 2011 Zane C. Bowers-Hadley.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Error::Helper, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Error::Helper
CPAN shell
perl -MCPAN -e shell install Error::Helper
For more information on module installation, please visit the detailed CPAN module installation guide.