The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Errors::Simple - Simple and but capable error management

VERSION

Version 0.1

DESCRIPTION

This is a simple error management and reporting module with more capabilities than other "simple" modules I found, but remains lightweight. For more robust error management, see Errors::Errors(3). Errors::Simple has been very handy for me when dealing with methods that can go wrong in multiple ways, particularly with methods that validate multiple pieces of form data.

SYNOPSIS

Your module:

        package Foo;
        use Errors::Simple;
        use base qw(Errors::Simple);
        
        sub new {
                return bless {}, shift
        }

        sub something   {
                my $self = shift;

                if($something_works)    {
                        return 1
                }
                elsif(!$something_else_works)   {
                        $self->e_report("Could not do something else
                                because of descriptive reason");
                        return undef;
                }
                else    {
                        $self->e_report("Could not do something because of
                                descriptive reason");
                        return undef;
                }
        }

Your calling file:

        $foo = Foo->new();
        if(!$foo->something() && $foo->e_check())       {
                print $foo->e_text();
        }

METHODS

e_new()

Create a new Errors::Simple object, in case you want one. No arguments required

e_init()

This is a private method that is called behind the scenes, you probably won't need it. It creates the needed data structure required for storing errors. This is called in most functions so that no initialization code is required in your subclass.

e_report($message)

This adds $message to the error list

e_check()

Checks to see if any errors have been reported (see e_report()). If errors are found, the number of errors reported is returned, 0 otherwise

e_get()

This returns a copy of the error list (array).

e_text()

Returns a string representing all the errors that have been reported. If no errors were found, returns an empty string. Also see e_html()

e_html()

Similar to e_text() except it is HTML-friendly. Returns HTML representation of errors reported. Empty string if none found

e_flush()

Removes all reported errors

AUTHOR

sili@cpan.org -- Feel free to email me with questions, suggestions, etc

SEE ALSO

perl(1), Errors::Errors(3), Error(3)

LICENSE

Same as perl itself