NAME

Error::Pure::Utils - Utilities for structured errors.

SYNOPSIS

use Error::Pure::Utils qw(clean err_get err_helper err_msg err_msg_hr);
clean();
my @errors = err_get($clean);
my @err_msg = err_msg();
my $err_msg_hr = err_msg_hr();
my @errors = err_helper('This is a fatal error', 'name', 'value');

SUBROUTINES

clean()
Resets internal variables with errors.
It is exportable.
Returns undef.
err_get([$clean])
Get and clean processed errors.
err_get() returns error structure.
err_get(1) returns error structure and delete it internally.
It is exportable.
Returns array of errors.
err_msg()
Get first error messages array.
Is is usable in situation >>err 'Error', 'item1', 'item2', 'item3', 'item4'<<.
Then returns ('Error', 'item1', 'item2', 'item3', 'item4') array.
See EXAMPLE2.
It is exportable.
Returns array of error messages.
err_msg_hr()
Get first error message key, value pairs as hash reference.
Is is usable in situation >>err 'Error', 'key1', 'val1', 'key2', 'val2'<<.
Then returns {'key1' => 'val1', 'key2' => 'val2'} structure.
See EXAMPLE3.
It is exportable.
Returns reference to hash with error messages.
err_helper(@msg)
Subroutine for additional module above Error::Pure.
@msg is array of messages.
It is exportable.
Returns array of errors.

VARIABLES

$LEVEL

Default value is 2.

$MAX_LEVELS

Default value is 50.

$MAX_EVAL

Default value is 100.

$MAX_ARGS

Default value is 10.

$MAX_ARG_LEN

Default value is 50.

$PROGRAM
Program name in stack information.
Default value is ''.

EXAMPLE1

# Pragmas.
use strict;
use warnings;

# Modules.
use Dumpvalue;
use Error::Pure::Die qw(err);
use Error::Pure::Utils qw(err_get);

# Error in eval.
eval { err '1', '2', '3'; };

# Error structure.
my @err = err_get();

# Dump.
my $dump = Dumpvalue->new;
$dump->dumpValues(\@err);

# In \@err:
# [
#         {
#                 'msg' => [
#                         '1',
#                         '2',
#                         '3',
#                 ],
#                 'stack' => [
#                         {
#                                 'args' => '(1)',
#                                 'class' => 'main',
#                                 'line' => '9',
#                                 'prog' => 'script.pl',
#                                 'sub' => 'err',
#                         },
#                         {
#                                 'args' => '',
#                                 'class' => 'main',
#                                 'line' => '9',
#                                 'prog' => 'script.pl',
#                                 'sub' => 'eval {...}',
#                         },
#                 ],
#         },
# ],

EXAMPLE2

# Pragmas.
use strict;
use warnings;

# Modules.
use English qw(-no_match_vars);
use Error::Pure qw(err);
use Error::Pure::Utils qw(err_msg);

# Error in eval.
eval {
        err 'Error', 'item1', 'item2', 'item3', 'item4';
};
if ($EVAL_ERROR) {
        my @err_msg = err_msg();
        foreach my $item (@err_msg) {
                print "$item\n";
        }
}

# Output:
# Error
# item1
# item2
# item3
# item4

EXAMPLE3

# Pragmas.
use strict;
use warnings;

# Modules.
use English qw(-no_match_vars);
use Error::Pure qw(err);
use Error::Pure::Utils qw(err_msg_hr);

# Error in eval.
eval {
        err 'Error',
                'key1', 'val1',
                'key2', 'val2';
};
if ($EVAL_ERROR) {
        print $EVAL_ERROR;
        my $err_msg_hr = err_msg_hr();
        foreach my $key (sort keys %{$err_msg_hr}) {
                print "$key: $err_msg_hr->{$key}\n";
        }
}

# Output:
# Error
# key1: val1
# key2: val2

DEPENDENCIES

Cwd, Exporter, Readonly.

SEE ALSO

Error::Pure, Error::Pure::AllError, Error::Pure::Error, Error::Pure::ErrorList, Error::Pure::HTTP::AllError, Error::Pure::HTTP::Error, Error::Pure::HTTP::ErrorList, Error::Pure::HTTP::Print, Error::Pure::Output::Text, Error::Pure::Print.

REPOSITORY

https://github.com/tupinek/Error-Pure

AUTHOR

Michal Špaček mailto:skim@cpan.org

http://skim.cz

LICENSE AND COPYRIGHT

BSD license.

VERSION

0.14