| 1 | package Language::FormulaEngine::Error; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | my @subclasses; | |||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | @subclasses= qw( ErrInval ErrNA ErrREF ErrNUM ErrNAME ); | |||||||||||||||||||||||||||||||||||||||||
| 6 | # For each subclass name, export a function which can be used as the package | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # name or as the package constructor. | ||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | for (@subclasses) { | |||||||||||||||||||||||||||||||||||||||||
| 9 | 40 | my $pkg= __PACKAGE__.'::'.$_; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 14 | ▶ | *$_= sub { @_? $pkg->new(@_) : $pkg } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 40 | } | |||||||||||||||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | our @EXPORT_OK= ( @subclasses, qw( auto_wrap_error ) ); | |||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | our %EXPORT_TAGS= ( all => \@EXPORT_OK ); | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | # ABSTRACT: Exception objects for formula functions | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 8 | our $VERSION = '0.08'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 8 | has message => ( is => 'rw', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub mine { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mine: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | return Language::FormulaEngine::ErrorMine->new($_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 12 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 12 | my $pkg= shift; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 12 | ▶ | return $_[0] if @_ == 1 && ref $_[0] eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC100%2/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | # If odd number of arguments, and first is a scalar, then treat it as the message | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 11 | ▶ | unshift @_, 'message' if @_ & 1 and !ref $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ & 1 and not ref $_[0]
MC/DC50%1/2
@_ & 1 and not ref $_[0]
@_ & 1
not ref $_[0]
Truth table66%2/3
A and not(B)
A= @_ & 1B= not ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 11 | return { @_ }; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 8 | our %err_patterns= ( | |||||||||||||||||||||||||||||||||||||||||
| 37 | ErrNA => qr/uninitialized|undefined/, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | ErrNUM => qr/numeric/, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | sub auto_wrap_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auto_wrap_error: called CC=10 SCAR=31.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | # allow to be called as package method, or not | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | shift if @_ && !ref $_[0] && $_[0]->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@_ and not ref $_[0] and $_[0]->isa(__PACKAGE__)
@_ and not ref $_[0]
MC/DC0%0/3
@_ and not ref $_[0] and $_[0]->isa(__PACKAGE__)
@_
not ref $_[0]
$_[0]->isa(__PACKAGE__)
Truth table25%1/4
A and not(B) and C
A= @_B= not ref $_[0]C= $_[0]->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my $msg= shift; | |||||||||||||||||||||||||||||||||||||||||
| 44 | # return things which are already Error objects (or mines) | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | if (ref $msg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | return $msg->disarm if ref($msg)->can('disarm'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | return $msg if ref($msg)->can('message'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | # Match message against patterns that Perl might have generated | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | if (defined $msg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | $msg =~ s/ at \(eval.*//; # isn't useful | |||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | for (keys %err_patterns) { | |||||||||||||||||||||||||||||||||||||||||
| 53 | return (__PACKAGE__.'::'.$_)->new(message => $msg) | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | if $msg =~ $err_patterns{$_}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $msg= '<undef>'; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return __PACKAGE__->new(message => $msg); | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 48 | ▶ | sub _fake_inc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fake_inc: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 48 | (my $pkg= caller) =~ s,::,/,g; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 48 | $INC{$pkg.'.pm'}= $INC{'Language/FormulaEngine/Error.pm'}; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub _stringify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stringify: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $cls= ref $self; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $cls =~ s/^Language::FormulaEngine::Error:://; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $cls . ': ' . $self->message; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 8 | ▶ | use overload '""' => \&_stringify; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | package Language::FormulaEngine::ErrorMine; | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 8 | Language::FormulaEngine::Error::_fake_inc(); | |||||||||||||||||||||||||||||||||||||||||
| 78 | use overload # SOMEONE SET US UP THE BOMB! | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | '0+' => sub { die ${$_[0]} }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | '""' => sub { die ${$_[0]} }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | bool => sub { die ${$_[0]} }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.6
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub new { bless $_[0], shift } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub disarm { ${$_[0]} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disarm: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | package Language::FormulaEngine::Error::ErrInval; | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 8 | Language::FormulaEngine::Error::_fake_inc(); | |||||||||||||||||||||||||||||||||||||||||
| 88 | 8 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 8 | extends 'Language::FormulaEngine::Error'; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | package Language::FormulaEngine::Error::ErrNA; | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 8 | Language::FormulaEngine::Error::_fake_inc(); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 8 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 8 | extends 'Language::FormulaEngine::Error'; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | package Language::FormulaEngine::Error::ErrREF; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 8 | Language::FormulaEngine::Error::_fake_inc(); | |||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 8 | extends 'Language::FormulaEngine::Error'; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | package Language::FormulaEngine::Error::ErrNUM; | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 8 | Language::FormulaEngine::Error::_fake_inc(); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 8 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 8 | extends 'Language::FormulaEngine::Error::ErrInval'; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | package Language::FormulaEngine::Error::ErrNAME; | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 8 | Language::FormulaEngine::Error::_fake_inc(); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 8 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 8 | extends 'Language::FormulaEngine::Error'; | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||||||||||||||||||||||||