| 1 | |||||||||||||||||||||||||||||||||||||||||||||||
| 2 | package Zoidberg::Utils::Error; | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 69 | our $VERSION = '0.981'; | |||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 69 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 69 | ▶ | use Exporter::Tidy default => [qw/error bug todo/]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | use overload | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 69 | ▶ | '""' => \&stringify, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | 'eq' => sub { $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 69 | fallback => 'TRUE'; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 69 | ▶ | use Scalar::Util qw/reftype/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 69 | our $Scope = $0; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 69 | $Scope =~ s#.*/##; | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # ################ # | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # Exported methods # | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # ################ # | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1363 | ▶ | sub error { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=20 SCAR=40.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1363 | my @caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1363 | ▶ | if ($@ && !@_) { # make it work more like die | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ and not @_
MC/DC0%0/2
$@ and not @_
$@
not @_
Truth table33%1/3
A and not(B)
A= $@B= not @_
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my $can_propagate = do { | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | eval{ $error->can( 'PROPAGATE') }; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | die $@->PROPAGATE(@caller[1,2]) if $can_propagate; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | unshift @_, PROPAGATE({}, @caller[1,2]), $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1363 | my $error = bless {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1363 | for (@_) { # compiling the error here | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1375 | ▶ | if ( (reftype $_ || '') eq 'HASH') { %$error = (%$error, %$_) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
builtin::reftype($_) || ''
MC/DC100%1/1
builtin::reftype($_) || ''
builtin::reftype($_)
Truth table100%2/2
A
A= builtin::reftype($_)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1361 | else { $$error{string} .= $_ } | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1363 | ▶ | unless ($$error{string}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | $$error{string} = | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | $$error{is_bug} ? 'This is a bug' | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | : $$error{is_todo} ? 'Something TODO here' : 'Error' ; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | elsif ($$error{string} =~ s/\(\@INC contains\: (.*?)\)\s*//g) { # make it less verbose | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $$error{INC} = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # trace stack | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1363 | ▶ | $$error{stack} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$error->{"stack"} ||= []
MC/DC100%1/1
$error->{"stack"} ||= []
$error->{"stack"}
Truth table100%2/2
A
A= $error->{"stack"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 69 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | @caller = caller(${$caller[0].'::ERROR_CALLER'}) | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1363 | ▶ | if ${$caller[0].'::ERROR_CALLER'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1363 | push @{$$error{stack}}, \@caller; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1363 | ▶ | if ( # debug code | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
${$caller[0] . '::DEBUG';} || $Zoidberg::CURRENT->{'settings'}{'debug'}
MC/DC0%0/2
${$caller[0] . '::DEBUG';} || $Zoidberg::CURRENT->{'settings'}{'debug'}
${$caller[0] . '::DEBUG';}
$Zoidberg::CURRENT->{'settings'}{'debug'}
Truth table33%1/3
A || B
A= ${$caller[0] . '::DEBUG';}B= $Zoidberg::CURRENT->{'settings'}{'debug'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1363 | $$error{debug} = ${$caller[0].'::DEBUG'} | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | || $Zoidberg::CURRENT->{settings}{debug} | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | push @{$$error{stack}}, [ (caller $_)[0..2] ] | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | for (1..$$error{debug}); | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1363 | ▶ | if (defined $Scope) { # set fake caller | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1363 | ▶ | $$error{scope} ||= ref($Scope) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$error->{"scope"} ||= ref $Zoidberg::Utils::Error::Scope ? [$Zoidberg::Utils::Error::Scope->[0], $Zoidberg::Utils::Error::Scope->[1] || $caller[2]] : [$Zoidberg::Utils::Error::Scope]
$Zoidberg::Utils::Error::Scope->[1] || $caller[2]
MC/DC0%0/2
$error->{"scope"} ||= ref $Zoidberg::Utils::Error::Scope ? [$Zoidberg::Utils::Error::Scope->[0], $Zoidberg::Utils::Error::Scope->[1] || $caller[2]] : [$Zoidberg::Utils::Error::Scope]
$error->{"scope"}
ref $Zoidberg::Utils::Error::Scope ? [$Zoidberg::Utils::Error::Scope->[0], $Zoidberg::Utils::Error::Scope->[1] || $caller[2]] : [$Zoidberg::Utils::Error::Scope]
MC/DC0%0/2
$Zoidberg::Utils::Error::Scope->[1] || $caller[2]
$Zoidberg::Utils::Error::Scope->[1]
$caller[2]
Truth table33%1/3
A ||= B
A= $error->{"scope"}B= ref $Zoidberg::Utils::Error::Scope ? [$Zoidberg::Utils::Error::Scope->[0], $Zoidberg::Utils::Error::Scope->[1] || $caller[2]] : [$Zoidberg::Utils::Error::Scope]
Truth table0%0/3
A || B
A= $Zoidberg::Utils::Error::Scope->[1]B= $caller[2]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ? [ $$Scope[0], $$Scope[1] || $caller[2] ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | : [ $Scope ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1363 | die $error; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | ▶ | sub bug { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bug: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | unshift @_, { is_bug => 1 }; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | goto \&error; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub todo { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
todo: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | unshift @_, { is_todo => 1 }; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | goto \&error; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # ############## # | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Object methods # | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # ############## # | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 585 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=11 SCAR=29.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # TODO verbosity optie | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 69 | ▶ | no warnings; # lots of stupid warnings here (due to 'overload' ?) | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 585 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 585 | my %opt = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 585 | my $string; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 585 | ▶ | if ($opt{format} eq 'gnu') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $string = join( ': ', grep {defined $_} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | ( $$self{scope} ? (@{$$self{scope}}) : (@{$$self{stack}[0]}) ), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ( $$self{is_bug} ? 'BUG' : $$self{is_todo} ? 'TODO' : undef ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $$self{string} ) . "\n" ; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | $string = ($$self{is_bug} ? 'BUG: ' : $$self{is_todo} ? 'TODO: ' : '') | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 585 | ▶ | . $self->{string}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 585 | ▶ | $string .= qq# at $$self{stack}[0][1] line $$self{stack}[0][2]\n# | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | unless $string =~ /\n$/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 585 | ▶ | if (exists $$self{propagated} and ref $$self{propagated}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $self->{"propagated"} and ref $self->{"propagated"}
MC/DC50%1/2
exists $self->{"propagated"} and ref $self->{"propagated"}
exists $self->{"propagated"}
ref $self->{"propagated"}
Truth table66%2/3
A and B
A= exists $self->{"propagated"}B= ref $self->{"propagated"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 62 | $string = PROPAGATE($string, @$_) for @{$self->{propagated}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 585 | return $string; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 114 | ▶ | sub PROPAGATE { # see perldoc -f die | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PROPAGATE: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 114 | my ($self, $file, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 114 | ▶ | ($file, $line) = ( caller() )[1,2] unless $file or $line; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$file or $line
MC/DC50%1/2
$file or $line
$file
$line
Truth table66%2/3
A or B
A= $fileB= $line
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 114 | ▶ | if (ref $self) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 20 | ▶ | $self->{propagated} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"propagated"} ||= []
MC/DC100%1/1
$self->{"propagated"} ||= []
$self->{"propagated"}
Truth table100%2/2
A
A= $self->{"propagated"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 20 | push @{$self->{propagated}}, [$file, $line]; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 94 | else { $self .= "\t...propagated at $file line $line\n" } | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 114 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 69 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||