| 1 | package Error::Pure; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 5 | ▶ | use base qw(Exporter); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 5 | ▶ | use English qw(-no_match_vars); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 5 | ▶ | use Error::Pure::Utils qw(); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 5 | ▶ | use Readonly; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | # Constants. | ||||||||||||||
| 12 | 5 | Readonly::Array our @EXPORT_OK => qw(err); | |||||||||||||
| 13 | 5 | Readonly::Scalar my $TYPE_DEFAULT => 'Die'; | |||||||||||||
| 14 | 5 | Readonly::Scalar my $LEVEL_DEFAULT => 4; | |||||||||||||
| 15 | |||||||||||||||
| 16 | 5 | our $VERSION = 0.31; | |||||||||||||
| 17 | |||||||||||||||
| 18 | # Type of error. | ||||||||||||||
| 19 | 5 | our $TYPE; | |||||||||||||
| 20 | |||||||||||||||
| 21 | # Level for this class. | ||||||||||||||
| 22 | 5 | our $LEVEL = $LEVEL_DEFAULT; | |||||||||||||
| 23 | |||||||||||||||
| 24 | # Process error. | ||||||||||||||
| 25 | sub err { | ||||||||||||||
| 26 | 9 | ▶ | my @msg = @_; | ||||||||||||
|
Subroutine
err: called CC=6 SCAR=19.1
Pod
documented
| |||||||||||||||
| 27 | 9 | $Error::Pure::Utils::LEVEL = $LEVEL; | |||||||||||||
| 28 | 9 | my $class; | |||||||||||||
| 29 | 9 | ▶ | if (defined $TYPE) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 30 | 5 | $class = 'Error::Pure::'.$TYPE; | |||||||||||||
| 31 | } elsif ($ENV{'ERROR_PURE_TYPE'}) { | ||||||||||||||
| 32 | $class = 'Error::Pure::'. | ||||||||||||||
| 33 | 0 | $ENV{'ERROR_PURE_TYPE'}; | |||||||||||||
| 34 | } else { | ||||||||||||||
| 35 | 4 | $class = 'Error::Pure::'.$TYPE_DEFAULT; | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | 9 | eval "require $class"; | |||||||||||||
| 38 | 9 | ▶ | if ($EVAL_ERROR) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 39 | |||||||||||||||
| 40 | # Switch to default, module doesn't exist. | ||||||||||||||
| 41 | 1 | $class = 'Error::Pure::'.$TYPE_DEFAULT; | |||||||||||||
| 42 | 1 | eval "require $class"; | |||||||||||||
| 43 | 1 | ▶ | if ($EVAL_ERROR) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | 0 | my $err = $EVAL_ERROR; | |||||||||||||
| 45 | 0 | $err =~ s/\ at.*$//ms; | |||||||||||||
| 46 | 0 | die $err; | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | } | ||||||||||||||
| 49 | 9 | eval $class.'::err @msg'; | |||||||||||||
| 50 | 9 | ▶ | if ($EVAL_ERROR) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 51 | 9 | die $EVAL_ERROR; | |||||||||||||
| 52 | } | ||||||||||||||
| 53 | 0 | return; | |||||||||||||
| 54 | } | ||||||||||||||
| 55 | |||||||||||||||
| 56 | 5 | 1; | |||||||||||||
| 57 | |||||||||||||||
| 58 | __END__ | ||||||||||||||