blib/lib/Devel/Confess.pm

filter: Statementstmt 78.5% 220 / 280 Branchbran 67.5% 108 / 160 Conditioncond 52.1% 48 / 92 MC/DCmcdc 22.6% 12 / 53 Subroutinesub 84.2% 32 / 38 Podpod n/a totaltotal 67.4% 420 / 623 SCAR 60.8
CC
113
Cov
71%
_convert
57.3
import
31.8
_colorize
20.0
CRAP 435.0
↑ Summary blib/lib/Devel/Confess/Builtin.pm »
1 package Devel::Confess;
2 BEGIN {
3 26 ▶ my $can_use_informative_names = "$]" >= 5.008;
Subroutine BEGIN: called CC=4 SCAR=15.2
4 # detect -d:Confess. disable debugger features for now. we'll
5 # enable them when we need them.
6 26 ▶ if (!defined &DB::DB && $^P & 0x02) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined &DB::DB and $^P & 2) 0 26 26
Condition33%1/3
not defined &DB::DB and $^P & 2
!ll&&!rl&&r
0130
MC/DC0%0/2
not defined &DB::DB and $^P & 2
not defined &DB::DB $^P & 2
Truth table33%1/3
not(A) and B
A= not defined &DB::DBB= $^P & 2
ABresult
0X0
100
111
7 13 $can_use_informative_names = 1;
8 13 $^P = 0;
9 }
10 *_CAN_USE_INFORMATIVE_NAMES
11 26 ▶ = $can_use_informative_names ? sub () { 1 } : sub () { 0 };
Branch: 1 branch
BranchTrueFalseTotal
$can_use_informative_names ? : 13 0 13
12 }
13  
14 26 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 26 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 130 ▶no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 our $VERSION = '0.009003';
20 $VERSION = eval $VERSION;
21  
22 13 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 13 ▶use Symbol ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 26 use Devel::Confess::_Util qw(
25 blessed
26 refaddr
27 weaken
28 longmess
29 _str_val
30 _in_END
31 _can_stringify
32 _can
33 _isa
34 26 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
35 26 ▶use Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36 BEGIN {
37 *_BROKEN_CLONED_DESTROY_REBLESS
38 13 ▶ = ("$]" >= 5.008009 && "$]" < 5.010000) ? sub () { 1 } : sub () { 0 };
Subroutine BEGIN: called CC=8 SCAR=25.8
Branch: 1 branch
BranchTrueFalseTotal
"$]" >= 5.008009 && "$]" < 5.01 ? : 0 13 13
Condition33%1/3
"$]" >= "5.008009" and "$]" < "5.01"
!ll&&!rl&&r
0130
MC/DC0%0/2
"$]" >= "5.008009" and "$]" < "5.01"
"$]" >= "5.008009" "$]" < "5.01"
Truth table33%1/3
A and B
A= "$]" >= "5.008009"B= "$]" < "5.01"
ABresult
0X0
100
111
39 *_BROKEN_CLONED_GLOB_UNDEF
40 13 ▶ = ("$]" > 5.008009 && "$]" <= 5.010000) ? sub () { 1 } : sub () { 0 };
Branch: 1 branch
BranchTrueFalseTotal
"$]" > 5.008009 && "$]" <= 5.01 ? : 0 13 13
Condition33%1/3
"$]" > "5.008009" and "$]" <= "5.01"
!ll&&!rl&&r
0130
MC/DC0%0/2
"$]" > "5.008009" and "$]" <= "5.01"
"$]" > "5.008009" "$]" <= "5.01"
Truth table33%1/3
A and B
A= "$]" > "5.008009"B= "$]" <= "5.01"
ABresult
0X0
100
111
41 *_BROKEN_SIG_DELETE
42 13 ▶ = ("$]" < 5.008008) ? sub () { 1 } : sub () { 0 };
Branch: 1 branch
BranchTrueFalseTotal
"$]" < 5.008008 ? : 0 13 13
43 *_DEBUGGING
44 = (
45 defined &Config::non_bincompat_options
46 ? (grep $_ eq 'DEBUGGING', Config::non_bincompat_options())
47 : ($Config::Config{ccflags} =~ /-DDEBUGGING\b/)
48 13 ▶ ) ? sub () { 1 } : sub () { 0 };
Branch: 2 branches
BranchTrueFalseTotal
(defined &Config::non_bincompat_options ? grep(($_ eq 'DEBUGGING'), Config::non_bincompat_options()) : $Config::Config{'ccflags'} =~ /-DDEBUGGING\b/) ? : 0 13 13
defined &Config::non_bincompat_options ? : 13 0 13
49 13 my $inf = 9**9**9;
50 0 ▶ *_INF = sub () { $inf }
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 13 }
52  
53 $Carp::Internal{+__PACKAGE__}++;
54  
55 our %NoTrace;
56 $NoTrace{'Throwable::Error'}++;
57 $NoTrace{'Moose::Error::Default'}++;
58  
59 our %OPTIONS = (
60 objects => !!1,
61 builtin => undef,
62 dump => !!0,
63 color => !!0,
64 source => 0,
65 evalsource => 0,
66 errors => !!1,
67 warnings => !!1,
68 better_names => !!1,
69 );
70 our %ENABLEOPTS = (
71 dump => 3,
72 source => 3,
73 evalsource => 3,
74 );
75 our %NUMOPTS = (
76 dump => 1,
77 source => 1,
78 evalsource => 1,
79 );
80  
81 our @options = sort keys %OPTIONS;
82 our ($opt_match) =
83 map qr/^-?(?:(no[_-]?)(?:$_)|(?:$_)(?:(\d+)|=(.*)|))$/,
84 join '|',
85 map {
86 my $o = $_;
87 $o =~ s/_/[-_]?/g;
88 '('.$o.')';
89 }
90 @options;
91  
92 sub _parse_options {
93 56 ▶ my %opts;
Subroutine _parse_options: called CC=16 SCAR=27.7
94 my @bad;
95 56 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 53 56 109
96 53 my $arg = shift;
97 53 ▶ my @match = defined $arg ? $arg =~ $opt_match : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $arg ? : 52 1 53
98 53 ▶ if (@match) {
Branch: 1 branch
BranchTrueFalseTotal
if (@match) { } 47 6 53
99 47 my $no = shift @match;
100 47 my $equal = pop @match;
101 47 my $num = pop @match;
102 47 my ($opt) =
103 map $options[$_ % @options],
104 grep defined $match[$_],
105 0 .. $#match;
106 my $value
107 = defined $no ? !!0
108 : defined $equal ? $equal
109 : defined $num ? $num
110 : @_ && (!defined $_[0] || $_[0] =~ /^\d+$/) ? shift
111 47 ▶ : defined $ENABLEOPTS{$opt} ? $ENABLEOPTS{$opt}
Branch: 5 branches
BranchTrueFalseTotal
defined $no ? : 21 26 47
defined $equal ? : 2 24 26
defined $num ? : 4 20 24
@_ && (!defined($_[0]) || $_[0] =~ /^\d+$/) ? : 2 18 20
defined $Devel::Confess::ENABLEOPTS{$opt} ? : 13 5 18
Condition100%6/6
@_ and !defined($_[0]) || $_[0] =~ /^\d+$/
!ll&&!rl&&r
1712
not defined $_[0] or $_[0] =~ /^\d+$/
l!l&&r!l&&!r
111
MC/DC100%3/3
@_ and !defined($_[0]) || $_[0] =~ /^\d+$/
@_ not defined $_[0] $_[0] =~ /^\d+$/
Truth table100%4/4
A and not(B) or C
A= @_B= not defined $_[0]C= $_[0] =~ /^\d+$/
ABCresult
0XX0
1000
11X1
1011
112 : !!1;
113  
114 47 ▶ if ($NUMOPTS{$opt}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Devel::Confess::NUMOPTS{$opt}) 16 31 47
115 16 ▶ $value
Branch: 2 branches
BranchTrueFalseTotal
!defined($value) ? : 0 16 16
!$value ? : 2 14 16
116 = !defined $value ? 0
117 : !$value ? _INF
118 : 0+$value;
119 }
120 47 $opts{$opt} = $value;
121 }
122 else {
123 6 push @bad, $arg;
124 }
125 }
126 56 ▶ if (@bad) {
Branch: 1 branch
BranchTrueFalseTotal
if (@bad) 5 51 56
127 5 local $SIG{__DIE__};
128 5 ▶ Carp::croak("invalid options: " . join(', ', map { defined $_ ? $_ : '[undef]' } @bad));
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 5 1 6
129 }
130 51 \%opts;
131 }
132  
133 if (my $env = $ENV{DEVEL_CONFESS_OPTIONS}) {
134 local $@;
135 eval {
136 my $options = _parse_options(grep length, split /[\s,]+/, $env);
137 @OPTIONS{keys %$options} = values %$options;
138 1;
139 } or warn "DEVEL_CONFESS_OPTIONS: $@";
140 }
141  
142 our %OLD_SIG;
143  
144 sub import {
145 37 ▶ my $class = shift;
Subroutine import: called CC=17 SCAR=34.6
146  
147 37 my $options = _parse_options(@_);
148 37 @OPTIONS{keys %$options} = values %$options;
149  
150 37 ▶ if (defined $OPTIONS{builtin}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Devel::Confess::OPTIONS{"builtin"}) 0 37 37
151 0 require Devel::Confess::Builtin;
152 0 ▶ my $do = $OPTIONS{builtin} ? 'import' : 'unimport';
Branch: 1 branch
BranchTrueFalseTotal
$Devel::Confess::OPTIONS{'builtin'} ? : 0 0 0
153 0 Devel::Confess::Builtin->$do;
154 }
155 37 ▶ if ($OPTIONS{source} || $OPTIONS{evalsource}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Devel::Confess::OPTIONS{"source"} or $Devel::Confess::OPTIONS{"evalsource"}) 10 27 37
Condition66%2/3
$Devel::Confess::OPTIONS{"source"} or $Devel::Confess::OPTIONS{"evalsource"}
l!l&&r!l&&!r
10027
MC/DC50%1/2
$Devel::Confess::OPTIONS{"source"} or $Devel::Confess::OPTIONS{"evalsource"}
$Devel::Confess::OPTIONS{"source"} $Devel::Confess::OPTIONS{"evalsource"}
Truth table66%2/3
A or B
A= $Devel::Confess::OPTIONS{"source"}B= $Devel::Confess::OPTIONS{"evalsource"}
ABresult
1X1
011
000
156 10 require Devel::Confess::Source;
157 10 Devel::Confess::Source->import;
158 }
159 37 ▶ if ($OPTIONS{color} && $^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Devel::Confess::OPTIONS{"color"} and $^O eq "MSWin32") 0 37 37
Condition33%1/3
$Devel::Confess::OPTIONS{"color"} and $^O eq "MSWin32"
!ll&&!rl&&r
3700
MC/DC0%0/2
$Devel::Confess::OPTIONS{"color"} and $^O eq "MSWin32"
$Devel::Confess::OPTIONS{"color"} $^O eq "MSWin32"
Truth table33%1/3
A and B
A= $Devel::Confess::OPTIONS{"color"}B= $^O eq "MSWin32"
ABresult
0X0
100
111
160 0 ▶ if (eval { require Win32::Console::ANSI }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Win32::Console::ANSI } }) { } 0 0 0
161 0 Win32::Console::ANSI->import;
162 }
163 else {
164 0 local $SIG{__WARN__};
165 0 Carp::carp
166 "Devel::Confess color option requires Win32::Console::ANSI on Windows";
167 0 $OPTIONS{color} = 0;
168 }
169 }
170  
171 37 ▶ if ($OPTIONS{errors} && !$OLD_SIG{__DIE__}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Devel::Confess::OPTIONS{"errors"} and not $Devel::Confess::OLD_SIG{"__DIE__"}) 37 0 37
Condition33%1/3
$Devel::Confess::OPTIONS{"errors"} and not $Devel::Confess::OLD_SIG{"__DIE__"}
!ll&&!rl&&r
0037
MC/DC0%0/2
$Devel::Confess::OPTIONS{"errors"} and not $Devel::Confess::OLD_SIG{"__DIE__"}
$Devel::Confess::OPTIONS{"errors"} not $Devel::Confess::OLD_SIG{"__DIE__"}
Truth table33%1/3
A and not(B)
A= $Devel::Confess::OPTIONS{"errors"}B= not $Devel::Confess::OLD_SIG{"__DIE__"}
ABresult
0X0
100
111
172 $OLD_SIG{__DIE__} = $SIG{__DIE__}
173 37 ▶ if $SIG{__DIE__} && $SIG{__DIE__} ne \&_die;
Branch: 1 branch
BranchTrueFalseTotal
if $SIG{"__DIE__"} and $SIG{"__DIE__"} ne \&Devel::Confess::_die 6 31 37
Condition100%3/3
$SIG{"__DIE__"} and $SIG{"__DIE__"} ne \&Devel::Confess::_die
!ll&&!rl&&r
2836
MC/DC100%2/2
$SIG{"__DIE__"} and $SIG{"__DIE__"} ne \&Devel::Confess::_die
$SIG{"__DIE__"} $SIG{"__DIE__"} ne \&Devel::Confess::_die
Truth table100%3/3
A and B
A= $SIG{"__DIE__"}B= $SIG{"__DIE__"} ne \&Devel::Confess::_die
ABresult
0X0
100
111
174 37 $SIG{__DIE__} = \&_die;
175 }
176 37 ▶ if ($OPTIONS{warnings} && !$OLD_SIG{__WARN__}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Devel::Confess::OPTIONS{"warnings"} and not $Devel::Confess::OLD_SIG{"__WARN__"}) 19 18 37
Condition66%2/3
$Devel::Confess::OPTIONS{"warnings"} and not $Devel::Confess::OLD_SIG{"__WARN__"}
!ll&&!rl&&r
18019
MC/DC50%1/2
$Devel::Confess::OPTIONS{"warnings"} and not $Devel::Confess::OLD_SIG{"__WARN__"}
$Devel::Confess::OPTIONS{"warnings"} not $Devel::Confess::OLD_SIG{"__WARN__"}
Truth table66%2/3
A and not(B)
A= $Devel::Confess::OPTIONS{"warnings"}B= not $Devel::Confess::OLD_SIG{"__WARN__"}
ABresult
0X0
100
111
177 $OLD_SIG{__WARN__} = $SIG{__WARN__}
178 19 ▶ if $SIG{__WARN__} && $SIG{__WARN__} ne \&_warn;
Branch: 1 branch
BranchTrueFalseTotal
if $SIG{"__WARN__"} and $SIG{"__WARN__"} ne \&Devel::Confess::_warn 2 17 19
Condition100%3/3
$SIG{"__WARN__"} and $SIG{"__WARN__"} ne \&Devel::Confess::_warn
!ll&&!rl&&r
1432
MC/DC100%2/2
$SIG{"__WARN__"} and $SIG{"__WARN__"} ne \&Devel::Confess::_warn
$SIG{"__WARN__"} $SIG{"__WARN__"} ne \&Devel::Confess::_warn
Truth table100%3/3
A and B
A= $SIG{"__WARN__"}B= $SIG{"__WARN__"} ne \&Devel::Confess::_warn
ABresult
0X0
100
111
179 19 $SIG{__WARN__} = \&_warn;
180 }
181  
182 # enable better names for evals and anon subs
183 $^P |= 0x100 | 0x200
184 37 ▶ if _CAN_USE_INFORMATIVE_NAMES && $OPTIONS{better_names};
Branch: 1 branch
BranchTrueFalseTotal
if $Devel::Confess::OPTIONS{"better_names"} 37 0 37
185 }
186  
187 sub unimport {
188 27 ▶ for my $sig (
Subroutine unimport: called CC=6 SCAR=18.8
189 [ __DIE__ => \&_die ],
190 [ __WARN__ => \&_warn ],
191 ) {
192 54 my ($name, $sub) = @$sig;
193 54 ▶ my $now = $SIG{$name} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $now = $SIG{$name} or next 18 36 54
194 36 my $old = $OLD_SIG{$name};
195 36 ▶ if ($now ne $sub && $old) {
Branch: 2 branches
BranchTrueFalseTotal
if ($now ne $sub and $old) { } 0 36 36
elsif ($old) { } 5 31 36
Condition33%1/3
$now ne $sub and $old
!ll&&!rl&&r
3600
MC/DC0%0/2
$now ne $sub and $old
$now ne $sub $old
Truth table33%1/3
A and B
A= $now ne $subB= $old
ABresult
0X0
100
111
196 0 local $SIG{__WARN__};
197 0 warn "Can't restore $name handler!\n";
198 0 delete $SIG{$sig};
199 }
200 elsif ($old) {
201 5 $SIG{$name} = $old;
202 5 delete $OLD_SIG{$name};
203 }
204 else {
205 13 ▶ no warnings 'uninitialized'; # bogus warnings on perl < 5.8.8
Subroutine BEGIN: called CC=1 SCAR=0.0
206 31 undef $SIG{$name}
207 if _BROKEN_SIG_DELETE;
208 31 delete $SIG{$name};
209 }
210 }
211 }
212  
213 sub _find_sig {
214 70 ▶ my $sig = $_[0];
Subroutine _find_sig: called CC=6 SCAR=17.9
215 return undef
216 70 ▶ if !defined $sig;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sig 49 21 70
217 21 ▶ return $sig
Branch: 1 branch
BranchTrueFalseTotal
if ref $sig 9 12 21
218 if ref $sig;
219 return undef
220 12 ▶ if $sig eq 'DEFAULT' || $sig eq 'IGNORE';
Branch: 1 branch
BranchTrueFalseTotal
if $sig eq "DEFAULT" or $sig eq "IGNORE" 4 8 12
Condition100%3/3
$sig eq "DEFAULT" or $sig eq "IGNORE"
l!l&&r!l&&!r
228
MC/DC100%2/2
$sig eq "DEFAULT" or $sig eq "IGNORE"
$sig eq "DEFAULT" $sig eq "IGNORE"
Truth table100%3/3
A or B
A= $sig eq "DEFAULT"B= $sig eq "IGNORE"
ABresult
1X1
011
000
221 # this isn't really needed because %SIG entries are always fully qualified
222 package #hide
223 main;
224 13 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
225 8 ▶ defined &{$sig} ? \&{$sig} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined &{$sig;} ? : 5 3 8
226 }
227  
228 sub _warn {
229 2 ▶ local $SIG{__WARN__};
Subroutine _warn: called CC=4 SCAR=18.7
230 2 my @convert = _convert(@_);
231 2 ▶ if (my $sig = _find_sig($OLD_SIG{__WARN__})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sig = _find_sig($Devel::Confess::OLD_SIG{'__WARN__'})) { } 2 0 2
232 2 ▶ (\&$sig)->(ref $convert[0] ? $convert[0] : join('', @convert));
Branch: 1 branch
BranchTrueFalseTotal
ref $convert[0] ? : 0 2 2
233 }
234 else {
235 0 @convert = _ex_as_strings(@convert);
236 0 ▶ @convert = _colorize(33, @convert) if $OPTIONS{color};
Branch: 1 branch
BranchTrueFalseTotal
if $Devel::Confess::OPTIONS{"color"} 0 0 0
237 0 warn @convert;
238 }
239 }
240 sub _die {
241 54 ▶ local $SIG{__DIE__};
Subroutine _die: called CC=7 SCAR=19.9
242 54 my @convert = _convert(@_);
243 54 ▶ if (my $sig = _find_sig($OLD_SIG{__DIE__})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sig = _find_sig($Devel::Confess::OLD_SIG{"__DIE__"})) 4 50 54
244 4 ▶ (\&$sig)->(ref $convert[0] ? $convert[0] : join('', @convert));
Branch: 1 branch
BranchTrueFalseTotal
ref $convert[0] ? : 0 4 4
245 }
246 54 ▶ @convert = _ex_as_strings(@convert) if _can_stringify;
Branch: 1 branch
BranchTrueFalseTotal
if &_can_stringify() 1 53 54
247 54 ▶ @convert = _colorize(31, @convert) if $OPTIONS{color} && _can_stringify;
Branch: 1 branch
BranchTrueFalseTotal
if $Devel::Confess::OPTIONS{"color"} and &_can_stringify() 0 54 54
Condition33%1/3
$Devel::Confess::OPTIONS{"color"} and &_can_stringify()
!ll&&!rl&&r
5400
MC/DC0%0/2
$Devel::Confess::OPTIONS{"color"} and &_can_stringify()
$Devel::Confess::OPTIONS{"color"} &_can_stringify()
Truth table33%1/3
A and B
A= $Devel::Confess::OPTIONS{"color"}B= &_can_stringify()
ABresult
0X0
100
111
248 54 if (_DEBUGGING && _in_END) {
249 local $SIG{__WARN__};
250 warn @convert;
251 $! ||= 1;
252 return;
253 }
254 54 ▶ die @convert unless ref $convert[0];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $convert[0] 50 4 54
255 }
256  
257 sub _colorize {
258 0 ▶ my ($color, @convert) = @_;
Subroutine _colorize: not called CC=4 SCAR=30.0
259 0 ▶ if ($OPTIONS{color} eq 'force' || -t *STDERR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Devel::Confess::OPTIONS{"color"} eq "force" or -t *STDERR) 0 0 0
Condition0%0/3
$Devel::Confess::OPTIONS{"color"} eq "force" or -t *STDERR
l!l&&r!l&&!r
000
MC/DC0%0/2
$Devel::Confess::OPTIONS{"color"} eq "force" or -t *STDERR
$Devel::Confess::OPTIONS{"color"} eq "force" -t *STDERR
Truth table0%0/3
A or B
A= $Devel::Confess::OPTIONS{"color"} eq "force"B= -t *STDERR
ABresult
1X1
011
000
260 0 ▶ if (@convert == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@convert == 1) 0 0 0
261 0 $convert[0] = s/(.*)//;
262 0 unshift @convert, $1;
263 }
264 0 $convert[0] = "\e[${color}m$convert[0]\e[m";
265 }
266 0 return @convert;
267 }
268  
269 sub _ref_formatter {
270 15 ▶ require Data::Dumper;
Subroutine _ref_formatter: called CC=2 SCAR=6.9
271 15 ▶ local $SIG{__WARN__} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
272 15 ▶ local $SIG{__DIE__} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
273 13 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
274 15 local $Data::Dumper::Indent = 0;
275 15 local $Data::Dumper::Purity = 0;
276 15 local $Data::Dumper::Terse = 1;
277 15 local $Data::Dumper::Useqq = 1;
278 15 ▶ local $Data::Dumper::Maxdepth = $OPTIONS{dump} == _INF ? 0 : $OPTIONS{dump};
Branch: 1 branch
BranchTrueFalseTotal
$Devel::Confess::OPTIONS{'dump'} == 9**9**9 ? : 3 12 15
279 15 Data::Dumper::Dumper($_[0]);
280 }
281  
282 sub _stack_trace {
283 13 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
284 local $Carp::RefArgFormatter
285 55 ▶ = $OPTIONS{dump} ? \&_ref_formatter : \&_str_val;
Subroutine _stack_trace: called CC=5 SCAR=16.2
Branch: 1 branch
BranchTrueFalseTotal
$Devel::Confess::OPTIONS{'dump'} ? : 5 50 55
286 55 my $message = &longmess;
287 55 $message =~ s/\.?$/./m;
288 55 ▶ if ($OPTIONS{source} || $OPTIONS{evalsource}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Devel::Confess::OPTIONS{"source"} or $Devel::Confess::OPTIONS{"evalsource"}) 19 36 55
Condition66%2/3
$Devel::Confess::OPTIONS{"source"} or $Devel::Confess::OPTIONS{"evalsource"}
l!l&&r!l&&!r
19036
MC/DC50%1/2
$Devel::Confess::OPTIONS{"source"} or $Devel::Confess::OPTIONS{"evalsource"}
$Devel::Confess::OPTIONS{"source"} $Devel::Confess::OPTIONS{"evalsource"}
Truth table66%2/3
A or B
A= $Devel::Confess::OPTIONS{"source"}B= $Devel::Confess::OPTIONS{"evalsource"}
ABresult
1X1
011
000
289 $message .= Devel::Confess::Source::source_trace(1,
290 19 ▶ $OPTIONS{evalsource} ? ($OPTIONS{evalsource}, 1) : $OPTIONS{source});
Branch: 1 branch
BranchTrueFalseTotal
$Devel::Confess::OPTIONS{'evalsource'} ? : 0 19 19
291 }
292 55 $message;
293 }
294  
295 # these are package varibles to control their lifetime. they should not be
296 # used externally.
297 our $PACK_SUFFIX = 'A000';
298  
299 our %EXCEPTIONS;
300 our %PACKAGES;
301 our %MESSAGES;
302 our %CLONED;
303  
304 sub CLONE {
305 my %id_map = map {
306 1 ▶ my $ex = $EXCEPTIONS{$_};
Subroutine CLONE: called CC=3 SCAR=11.0
307 1 ▶ defined $ex ? ($_ => refaddr($ex)) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $ex ? : 1 0 1
308 } keys %EXCEPTIONS;
309  
310 1 %EXCEPTIONS = map {; $id_map{$_} => $EXCEPTIONS{$_}} keys %id_map;
311 1 %PACKAGES = map {; $id_map{$_} => $PACKAGES{$_}} keys %id_map;
312 1 %MESSAGES = map {; $id_map{$_} => $MESSAGES{$_}} keys %id_map;
313 1 %CLONED = map {; $_ => 1 } values %id_map
314 if _BROKEN_CLONED_DESTROY_REBLESS || _BROKEN_CLONED_GLOB_UNDEF;
315 weaken($_)
316 1 for values %EXCEPTIONS;
317 }
318  
319 sub _update_ex_refs {
320 56 ▶ for my $id ( keys %EXCEPTIONS ) {
Subroutine _update_ex_refs: called CC=3 SCAR=22.0
321 next
322 0 ▶ if defined $EXCEPTIONS{$id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Devel::Confess::EXCEPTIONS{$id} 0 0 0
323 0 delete $EXCEPTIONS{$id};
324 0 delete $PACKAGES{$id};
325 0 delete $MESSAGES{$id};
326 0 delete $CLONED{$id}
327 if _BROKEN_CLONED_DESTROY_REBLESS || _BROKEN_CLONED_GLOB_UNDEF;
328 }
329 }
330  
331 sub _convert {
332 56 ▶ _update_ex_refs;
Subroutine _convert: called CC=30 SCAR=40.5
333 56 ▶ if (my $class = blessed(my $ex = $_[0])) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $class = builtin::blessed(my $ex = $_[0])) { } 4 52 56
elsif (ref($ex = $_[0])) { } 0 52 52
334 return @_
335 4 ▶ unless $OPTIONS{objects};
Branch: 1 branch
BranchTrueFalseTotal
unless $Devel::Confess::OPTIONS{"objects"} 0 4 4
336 return @_
337 4 ▶ if ! do {no strict 'refs'; defined &{"Devel::Confess::_Attached::DESTROY"} };
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless do { no strict 'refs'; defined &{"Devel::Confess::_Attached::DESTROY";} } 1 3 4
338 3 my $message;
339 3 my $id = refaddr($ex);
340 3 ▶ if (defined $EXCEPTIONS{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Devel::Confess::EXCEPTIONS{$id}) 0 3 3
341 return @_
342 0 ▶ if _isa($ex, "Devel::Confess::_Attached");
Branch: 1 branch
BranchTrueFalseTotal
if _isa($ex, "Devel::Confess::_Attached") 0 0 0
343  
344 # something is going very wrong. possibly from a Safe compartment.
345 # we probably broke something, but do the best we can.
346 0 ▶ if ((ref $ex) =~ /^Devel::Confess::__ANON_/) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($ex) =~ /^Devel::Confess::__ANON_/) { } 0 0 0
347 0 my $oldclass = $PACKAGES{$id};
348 0 $message = $MESSAGES{$id};
349 0 bless $ex, $oldclass;
350 }
351 else {
352 # give up
353 0 return @_;
354 }
355 }
356  
357 3 ▶ my $does = _can($ex, 'can') && ($ex->can('does') || $ex->can('DOES')) || sub () { 0 };
Condition33%3/9
_can($ex, 'can') && ($ex->can('does') || $ex->can('DOES')) || sub () { 0 }
l!l&&r!l&&!r
300
_can($ex, "can") and $ex->can("does") || $ex->can("DOES")
!ll&&!rl&&r
003
$ex->can("does") or $ex->can("DOES")
l!l&&r!l&&!r
030
MC/DC0%0/4
_can($ex, 'can') && ($ex->can('does') || $ex->can('DOES')) || sub () { 0 }
_can($ex, "can") $ex->can("does") $ex->can("DOES") sub () { 0 }
Truth table16%1/6
A and B or C || D
A= _can($ex, "can")B= $ex->can("does")C= $ex->can("DOES")D= sub () { 0 }
ABCDresult
11XX1
101X1
0XX11
10011
0XX00
10000
358 3 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$Devel::Confess::NoTrace{$_} and _can($ex, "isa") and $ex->isa($_) or $ex->$does($_);} keys %Devel::Confess::NoTrace) 0 3 3
359 grep {
360 6 ▶ $NoTrace{$_}
Branch: 1 branch
BranchTrueFalseTotal
$Devel::Confess::NoTrace{$_} and _can($ex, "isa") and $ex->isa($_) or $ex->$does($_) 6 0 6
Condition33%2/6
$Devel::Confess::NoTrace{$_} and _can($ex, "isa") and $ex->isa($_)
!ll&&!rl&&r
060
$Devel::Confess::NoTrace{$_} and _can($ex, "isa")
!ll&&!rl&&r
006
MC/DC0%0/3
$Devel::Confess::NoTrace{$_} and _can($ex, "isa") and $ex->isa($_)
$Devel::Confess::NoTrace{$_} _can($ex, "isa") $ex->isa($_)
Truth table0%0/4
A and B and C
A= $Devel::Confess::NoTrace{$_}B= _can($ex, "isa")C= $ex->isa($_)
ABCresult
0XX0
10X0
1100
1111
361 && _can($ex, 'isa')
362 && $ex->isa($_)
363 || $ex->$does($_)
364 } keys %NoTrace
365 ) {
366 0 return @_;
367 }
368  
369 3 ▶ $message ||= _stack_trace();
Condition33%1/3
$message ||= _stack_trace()
l!l&&r!l&&!r
030
MC/DC0%0/2
$message ||= _stack_trace()
$message _stack_trace()
Truth table33%1/3
A ||= B
A= $messageB= _stack_trace()
ABresult
1X1
011
000
370  
371 3 weaken($EXCEPTIONS{$id} = $ex);
372 3 $PACKAGES{$id} = $class;
373 3 $MESSAGES{$id} = $message;
374  
375 3 my $newclass = __PACKAGE__ . '::__ANON_' . $PACK_SUFFIX++ . '__';
376  
377 {
378 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
379 3 @{$newclass . '::ISA'} = ('Devel::Confess::_Attached', $class);
380 }
381  
382 3 bless $ex, $newclass;
383 3 return $ex;
384 }
385 elsif (ref($ex = $_[0])) {
386 0 my $id = refaddr($ex);
387  
388 0 my $message = _stack_trace;
389  
390 0 weaken($EXCEPTIONS{$id} = $ex);
391 0 $PACKAGES{$id} = undef;
392 0 ▶ $MESSAGES{$id} ||= $message;
Condition0%0/3
$Devel::Confess::MESSAGES{$id} ||= $message
l!l&&r!l&&!r
000
MC/DC0%0/2
$Devel::Confess::MESSAGES{$id} ||= $message
$Devel::Confess::MESSAGES{$id} $message
Truth table0%0/3
A ||= B
A= $Devel::Confess::MESSAGES{$id}B= $message
ABresult
1X1
011
000
393  
394 0 return $ex;
395 }
396  
397 52 my $out = join('', @_);
398  
399 52 ▶ if (caller(1) eq 'Carp') {
Branch: 1 branch
BranchTrueFalseTotal
if (caller 1 eq "Carp") 24 28 52
400 24 my $long = longmess();
401 24 my $long_trail = $long;
402 24 $long_trail =~ s/.*?\n//;
403 24 ▶ $out =~ s/\Q$long\E\z|\Q$long_trail\E\z//
Branch: 1 branch
BranchTrueFalseTotal
$out =~ s/\Q$long\E\z|\Q$long_trail\E\z// or $out =~ s/(.*) at .*? line .*?\n\z/$1/ 12 12 24
404 or $out =~ s/(.*) at .*? line .*?\n\z/$1/;
405 }
406  
407 52 my $source_trace;
408 $out =~ s/^(={75}\ncontext for .*^={75}\n\z)//ms
409 and $source_trace = $1
410 52 ▶ if $OPTIONS{source} || $OPTIONS{evalsource};
Branch: 1 branch
BranchTrueFalseTotal
if $Devel::Confess::OPTIONS{"source"} or $Devel::Confess::OPTIONS{"evalsource"} 19 33 52
Condition77%7/9
($Devel::Confess::OPTIONS{'source'} || $Devel::Confess::OPTIONS{'evalsource'}) && ($out =~ s/^(={75}\ncontext for .*^={75}\n\z)//ms && ($source_trace = $1))
!ll&&!rl&&r
33181
$Devel::Confess::OPTIONS{"source"} or $Devel::Confess::OPTIONS{"evalsource"}
l!l&&r!l&&!r
19033
$out =~ s/^(={75}\ncontext for .*^={75}\n\z)//ms and $source_trace = $1
!ll&&!rl&&r
1090
MC/DC0%0/4
($Devel::Confess::OPTIONS{'source'} || $Devel::Confess::OPTIONS{'evalsource'}) && ($out =~ s/^(={75}\ncontext for .*^={75}\n\z)//ms && ($source_trace = $1))
$Devel::Confess::OPTIONS{"source"} $Devel::Confess::OPTIONS{"evalsource"} $out =~ s/^(={75}\ncontext for .*^={75}\n\z)//ms $source_trace = $1
Truth table14%1/7
A or B && C and D
A= $Devel::Confess::OPTIONS{"source"}B= $Devel::Confess::OPTIONS{"evalsource"}C= $out =~ s/^(={75}\ncontext for .*^={75}\n\z)//msD= $source_trace = $1
ABCDresult
00XX0
1X0X0
1X100
010X0
01100
1X111
01111
411 52 my $trace = _stack_trace();
412 52 $trace =~ s/^(.*\n?)//;
413 52 my $where = $1;
414 52 my $new_source_trace;
415 $trace =~ s/^(={75}\ncontext for .*^={75}\n\z)//ms
416 and $new_source_trace = $1
417 52 ▶ if $OPTIONS{source} || $OPTIONS{evalsource};
Branch: 1 branch
BranchTrueFalseTotal
if $Devel::Confess::OPTIONS{"source"} or $Devel::Confess::OPTIONS{"evalsource"} 19 33 52
Condition66%6/9
($Devel::Confess::OPTIONS{'source'} || $Devel::Confess::OPTIONS{'evalsource'}) && ($trace =~ s/^(={75}\ncontext for .*^={75}\n\z)//ms && ($new_source_trace = $1))
!ll&&!rl&&r
33181
$Devel::Confess::OPTIONS{"source"} or $Devel::Confess::OPTIONS{"evalsource"}
l!l&&r!l&&!r
19033
$trace =~ s/^(={75}\ncontext for .*^={75}\n\z)//ms and $new_source_trace = $1
!ll&&!rl&&r
0190
MC/DC0%0/4
($Devel::Confess::OPTIONS{'source'} || $Devel::Confess::OPTIONS{'evalsource'}) && ($trace =~ s/^(={75}\ncontext for .*^={75}\n\z)//ms && ($new_source_trace = $1))
$Devel::Confess::OPTIONS{"source"} $Devel::Confess::OPTIONS{"evalsource"} $trace =~ s/^(={75}\ncontext for .*^={75}\n\z)//ms $new_source_trace = $1
Truth table14%1/7
A or B && C and D
A= $Devel::Confess::OPTIONS{"source"}B= $Devel::Confess::OPTIONS{"evalsource"}C= $trace =~ s/^(={75}\ncontext for .*^={75}\n\z)//msD= $new_source_trace = $1
ABCDresult
00XX0
1X0X0
1X100
010X0
01100
1X111
01111
418 52 my $find = $where;
419 52 $find =~ s/(\.?\n?)\z//;
420 52 ▶ my $trace_re = length $trace ? "(?:\Q$trace\E)?" : '';
Branch: 1 branch
BranchTrueFalseTotal
length $trace ? : 52 0 52
421 52 ▶ $out =~ s/(\Q$find\E(?: during global destruction)?(\.?\n?))$trace_re\z//
Branch: 1 branch
BranchTrueFalseTotal
$out =~ s/(\Q$find\E(?: during global destruction)?(\.?\n?))$trace_re\z// and $where = $1 40 12 52
422 and $where = $1;
423 52 ▶ if (defined $source_trace) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $source_trace) 9 43 52
424 9 ▶ if (defined $new_source_trace) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new_source_trace) 9 0 9
425 9 $new_source_trace =~ s/^={75}\n//;
426 9 $source_trace =~ s/^(([-=])\2{74}\n)(?:\Q$new_source_trace\E)?\z/$1/ms;
427 }
428 9 $trace .= $source_trace;
429 }
430 52 ▶ if (defined $new_source_trace) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new_source_trace) 19 33 52
431 19 $trace .= $new_source_trace;
432 }
433 52 return ($out, $where . $trace);
434 }
435  
436 sub _ex_as_strings {
437 2 ▶ my $ex = $_[0];
Subroutine _ex_as_strings: called CC=8 SCAR=23.9
438 return @_
439 2 ▶ unless ref $ex;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ex 1 1 2
440 1 my $id = refaddr($ex);
441 1 my $class = $PACKAGES{$id};
442 1 my $message = $MESSAGES{$id};
443 1 my $out;
444 1 ▶ if (blessed $ex) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($ex)) { } 1 0 1
elsif ($Devel::Confess::OPTIONS{'dump'}) { } 0 0 0
445 1 my $newclass = ref $ex;
446 1 ▶ bless $ex, $class if $class;
Branch: 1 branch
BranchTrueFalseTotal
if $class 1 0 1
447 1 ▶ if ($OPTIONS{dump} && !overload::OverloadedStringify($ex)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Devel::Confess::OPTIONS{'dump'} and not overload::OverloadedStringify($ex)) { } 0 1 1
Condition33%1/3
$Devel::Confess::OPTIONS{"dump"} and not overload::OverloadedStringify($ex)
!ll&&!rl&&r
100
MC/DC0%0/2
$Devel::Confess::OPTIONS{"dump"} and not overload::OverloadedStringify($ex)
$Devel::Confess::OPTIONS{"dump"} not overload::OverloadedStringify($ex)
Truth table33%1/3
A and not(B)
A= $Devel::Confess::OPTIONS{"dump"}B= not overload::OverloadedStringify($ex)
ABresult
0X0
100
111
448 0 $out = _ref_formatter($ex);
449 }
450 else {
451 1 $out = "$ex";
452 }
453 1 ▶ bless $ex, $newclass if $class;
Branch: 1 branch
BranchTrueFalseTotal
if $class 1 0 1
454 }
455 elsif ($OPTIONS{dump}) {
456 0 $out = _ref_formatter($ex);
457 }
458 else {
459 0 $out = "$ex";
460 }
461 1 return ($out, $message);
462 }
463  
464 {
465 package #hide
466 Devel::Confess::_Attached;
467 use overload
468 fallback => 1,
469 'bool' => sub {
470 package
471 Devel::Confess;
472 0 ▶ my $ex = $_[0];
Subroutine __ANON__: not called CC=2 SCAR=17.9
473 0 my $class = $PACKAGES{refaddr($ex)};
474 0 my $newclass = ref $ex;
475 0 bless $ex, $class;
476 0 ▶ my $out = $ex ? !!1 : !!0;
Branch: 1 branch
BranchTrueFalseTotal
$ex ? : 0 0 0
477 0 bless $ex, $newclass;
478 0 return $out;
479 },
480 '0+' => sub {
481 package
482 Devel::Confess;
483 0 ▶ my $ex = $_[0];
Subroutine __ANON__: not called CC=1 SCAR=6.9
484 0 my $class = $PACKAGES{refaddr($ex)};
485 0 my $newclass = ref $ex;
486 0 bless $ex, $class;
487 0 my $out = 0+sprintf '%.20g', $ex;
488 0 bless $ex, $newclass;
489 0 return $out;
490 },
491 '""' => sub {
492 package
493 Devel::Confess;
494 1 ▶ join('', _ex_as_strings(@_));
Subroutine __ANON__: called CC=1 SCAR=0.0
495 },
496 13 ▶ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
497  
498 sub DESTROY {
499 package
500 Devel::Confess;
501 2 ▶ my $ex = $_[0];
Subroutine DESTROY: called CC=4 SCAR=14.5
502 2 my $id = refaddr($ex);
503 2 ▶ my $class = delete $PACKAGES{$id} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $class = delete $Devel::Confess::PACKAGES{$id} or return 0 2 2
504 2 delete $MESSAGES{$id};
505 2 delete $EXCEPTIONS{$id};
506  
507 2 my $newclass = ref $ex;
508  
509 2 my $cloned;
510 # delete_package is more complete, but can explode on some perls
511 2 if (_BROKEN_CLONED_GLOB_UNDEF && delete $CLONED{$id}) {
512 $cloned = 1;
513 13 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
514 @{"${newclass}::ISA"} = ();
515 my $stash = \%{"${newclass}::"};
516 delete @{$stash}{keys %$stash};
517 }
518 else {
519 2 Symbol::delete_package($newclass);
520 }
521  
522 2 ▶ if (_BROKEN_CLONED_DESTROY_REBLESS && $cloned || delete $CLONED{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $Devel::Confess::CLONED{$id}) 0 2 2
523 0 ▶ my $destroy = _can($class, 'DESTROY') || return;
Condition0%0/2
_can($class, 'DESTROY') || (return)
l!l
00
MC/DC0%0/1
_can($class, 'DESTROY') || (return)
_can($class, 'DESTROY')
Truth table0%0/2
A
A= _can($class, 'DESTROY')
Aresult
11
00
524 0 goto $destroy;
525 }
526  
527 2 bless $ex, $class;
528  
529 # after reblessing, perl will re-dispatch to the class's own DESTROY.
530 2 ();
531 }
532 }
533  
534 1;
535 __END__
↑ Summary blib/lib/Devel/Confess/Builtin.pm »