| 1 | package Devel::DollarAt; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use base qw(Class::Accessor::Fast); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Devel::Backtrace; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | __PACKAGE__->mk_accessors( | |||||||||||||||||||||||||||||||||||||||||
| 10 | qw(backtrace err propagated inputline inputhandle filename line) | ||||||||||||||||||||||||||||||||||||||||||
| 11 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | # Note that to_string also internally called if an exception isn't catched by | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # any eval and the error must be printed to STDERR. | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use overload '""' => \&to_string; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | $SIG{__DIE__} = \&_diehandler; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | our $FRAME; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | # This will be called every time the code says "die". However it won't be | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # called for other errors, such as division by zero. So we still have to use | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # $SIG{__DIE__}. | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | *CORE::GLOBAL::die = sub (@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $text = ''; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | defined and $text .= $_ for @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if (defined($err) && length($err) && !length $text) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $err and length $err and not length $text
defined $err and length $err
MC/DC0%0/3
defined $err and length $err and not length $text
defined $err
length $err
not length $text
Truth table0%0/4
A and B and not(C)
A= defined $errB= length $errC= not length $text
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | # In this case, perl would pass "$@\t...propagated at foo line bar.\n" | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # to the __DIE__ handler. Because we don't want to parse that, we make | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # perl think $text is not empty. | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # We have to store $err in our NullMessage because perl will cleanse $@ | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # before calling the __DIE__ handler. This is very strange, because it | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # won't get cleansed if we don't override *CORE::GLOBAL::die. | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $text = Devel::DollarAt::NullMessage->_new(propagated=>$err); | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | CORE::die($text); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | sub _diehandler { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_diehandler: called CC=8 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | my ($err) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | my $propagated = $@; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | if (ref($err) && $err->isa('Devel::DollarAt::NullMessage')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $err and $err->isa("Devel::DollarAt::NullMessage")
MC/DC0%0/2
ref $err and $err->isa("Devel::DollarAt::NullMessage")
ref $err
$err->isa("Devel::DollarAt::NullMessage")
Truth table33%1/3
A and B
A= ref $errB= $err->isa("Devel::DollarAt::NullMessage")
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $propagated = $err->{propagated}; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $err = ''; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | my $backtrace = Devel::Backtrace->new(1); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | my $skip = $backtrace->skipmysubs(); # skips this handler plus our overridden | |||||||||||||||||||||||||||||||||||||||||
| 56 | # CORE::GLOBAL::die if possible | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | CORE::die "Strange:\n$backtrace" unless $skip; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | my ($inputhandle, $inputline); | |||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | if ($err =~ s/^(.*) at .*?(?:<(.*)> line (\d+)|)\.\n\z/$1/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | ($inputhandle, $inputline) = ($2, $3); | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | my $dollarat = __PACKAGE__->_new({ | |||||||||||||||||||||||||||||||||||||||||
| 65 | backtrace => $backtrace, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | err => $err, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | filename => $skip->filename, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | line => $skip->line, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | if (defined $inputline) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $dollarat->inputline($inputline); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $dollarat->inputhandle($inputhandle); | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | ▶ | if (defined $propagated and length $propagated) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $propagated and length $propagated
MC/DC0%0/2
defined $propagated and length $propagated
defined $propagated
length $propagated
Truth table33%1/3
A and B
A= defined $propagatedB= length $propagated
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $dollarat->propagated($propagated); | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | CORE::die($dollarat); | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | # Try to appear exactly like the normal $@ | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | sub to_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=6 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | my $text = $this->err; | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | if (defined ($this->propagated)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if (!length($text)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $text = $this->propagated . "\t...propagated"; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | ▶ | unless ($text =~ /\n\z/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | $text .= ' at ' . $this->filename . ' line ' . $this->line; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | if (defined $this->inputline) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $text .= ', <'.$this->inputhandle . '> line ' . $this->inputline; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | $text .= '.'; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | $text = "[[$text]]" if $FRAME; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | $text .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | ▶ | sub _new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | my $this = $class->SUPER::new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | return $this; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=18.4
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | for (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ('frame' eq $_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $FRAME = 1; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | die 'Unknown parameter for '.__PACKAGE__.": $_"; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub redie { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
redie: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my ($package, $filename, $line) = caller; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | push @{$this->{redispatch_points}}, Devel::DollarAt::RedispatchPoint->new({ | |||||||||||||||||||||||||||||||||||||||||
| 132 | package => $package, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | filename => $filename, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | line => $line, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | CORE::die($this); | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub redispatch_points { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
redispatch_points: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | return @{$this->{redispatch_points} || []}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$this->{'redispatch_points'} || []
MC/DC0%0/1
$this->{'redispatch_points'} || []
$this->{'redispatch_points'}
Truth table0%0/2
A
A= $this->{'redispatch_points'}
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | package # hide from pause | ||||||||||||||||||||||||||||||||||||||||||
| 147 | Devel::DollarAt::NullMessage; | ||||||||||||||||||||||||||||||||||||||||||
| 148 | #use overload '""' => sub {''}; | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub _new { shift; bless {@_}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | package # hide from pause | ||||||||||||||||||||||||||||||||||||||||||
| 152 | Devel::DollarAt::RedispatchPoint; | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | ▶ | use base qw(Class::Accessor::Fast); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | __PACKAGE__->mk_ro_accessors(qw(package filename line)); | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | ▶ | use overload '""' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | return 'redispatched from '.$this->package.' at ' | |||||||||||||||||||||||||||||||||||||||||
| 160 | .$this->filename.':'.$this->line."\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | 1 | |||||||||||||||||||||||||||||||||||||||||
| 164 | __END__ | ||||||||||||||||||||||||||||||||||||||||||