Log/Report/Dispatcher.pm

filter: Statementstmt 86.9% 160 / 184 Branchbran 62.2% 51 / 82 Conditioncond 50.6% 38 / 75 MC/DCmcdc 17.0% 7 / 41 Subroutinesub 78.5% 33 / 42 Podpod 77.7% 14 / 18 totaltotal 68.5% 303 / 442 CC 70 SCAR 33.5
CC
70
Cov
73%
translate
91.4
stackTraceLine
13.1
init
11.8
CRAP 28.5
« Log/Report/Domain.pm ↑ Summary Log/Report/Dispatcher/File.pm »
1 # This code is part of Perl distribution Log-Report version 1.46.
2 # The POD got stripped from this file by OODoc version 3.06.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2007-2026 by Mark Overmeer.
6  
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10  
11  
12 package Log::Report::Dispatcher;{
13 17 our $VERSION = '1.46';
14 }
15  
16  
17 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 17 ▶use Log::Report 'log-report', import => [ qw/__x N__ __ alert error info panic textdomain trace/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
21 17 ▶use Log::Report::Util qw/parse_locale expand_reasons %reason_code escape_chars use_errno/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 17 ▶use POSIX qw/strerror/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 17 ▶use List::Util qw/sum first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 17 ▶use Encode qw/find_encoding FB_DEFAULT/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 17 ▶use Devel::GlobalDestruction qw/in_global_destruction/;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 17 eval { POSIX->import('locale_h') };
29 17 ▶if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 17 17
30 17 ▶{ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 0 ▶ *setlocale = sub { $_[1] }; *LC_ALL = sub { undef };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 }
33  
34 17 my %modes = (NORMAL => 0, VERBOSE => 1, ASSERT => 2, DEBUG => 3, 0 => 0, 1 => 1, 2 => 2, 3 => 3);
35 17 my @default_accept = ('NOTICE-', 'INFO-', 'ASSERT-', 'ALL');
36 17 my %always_loc = map +($_ => 1), qw/ASSERT ALERT FAILURE PANIC/;
37  
38 17 my %predef_dispatchers = map +(uc($_) => __PACKAGE__.'::'.$_),
39 qw/File Perl Syslog Try Callback Log4perl/;
40  
41 42 ▶my @skip_stack = sub { $_[0][0] =~ m/^Log\:\:Report(?:\:\:|$)/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
42  
43 #--------------------
44  
45 sub new(@)
46 43 ▶{ my ($class, $type, $name, %args) = @_;
Subroutine new: called CC=4 SCAR=15.6
Pod documented
47  
48 # $type is a class name or predefined name.
49 my $backend
50 43 ▶ = $predef_dispatchers{$type} ? $predef_dispatchers{$type}
Branch: 2 branches
BranchTrueFalseTotal
$predef_dispatchers{$type} ? : 43 0 43
$type->isa('Log::Dispatch::Output') ? : 0 0 0
51 : $type->isa('Log::Dispatch::Output') ? __PACKAGE__.'::LogDispatch'
52 : $type;
53  
54 43 eval "require $backend";
55 43 ▶ $@ and alert "cannot use class $backend:\n$@";
Branch: 1 branch
BranchTrueFalseTotal
$@ and &alert("cannot use class ${backend}:\n$@") 0 43 43
56  
57 43 (bless {name => $name, type => $type, filters => []}, $backend)->init(\%args);
58 }
59  
60 my %format_reason = (
61 6 ▶ LOWERCASE => sub { lc $_[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
62 3 ▶ UPPERCASE => sub { uc $_[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
63 0 ▶ UCFIRST => sub { ucfirst lc $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 1 ▶ IGNORE => sub { '' },
Subroutine __ANON__: called CC=1 SCAR=0.0
65 17 );
66  
67 17 my $default_mode = 'NORMAL';
68  
69 sub init($)
70 43 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=9 SCAR=24.6
Pod undocumented
71  
72 43 ▶ my $mode = $self->_set_mode(delete $args->{mode} || $default_mode);
Condition66%2/3
delete $args->{'mode'} || $default_mode
l!l&&r!l&&!r
2410
MC/DC0%0/2
delete $args->{'mode'} || $default_mode
delete $args->{'mode'} $default_mode
Truth table66%2/3
A || B
A= delete $args->{'mode'}B= $default_mode
ABresult
1X1
011
000
73 43 $self->{locale} = delete $args->{locale};
74  
75 43 ▶ my $accept = delete $args->{accept} || $default_accept[$mode];
Condition66%2/3
delete $args->{'accept'} || $default_accept[$mode]
l!l&&r!l&&!r
20230
MC/DC0%0/2
delete $args->{'accept'} || $default_accept[$mode]
delete $args->{'accept'} $default_accept[$mode]
Truth table66%2/3
A || B
A= delete $args->{'accept'}B= $default_accept[$mode]
ABresult
1X1
011
000
76 43 $self->{needs} = [ expand_reasons $accept ];
77  
78 43 ▶ my $f = delete $args->{format_reason} || 'LOWERCASE';
Condition100%2/2
delete $args->{'format_reason'} || 'LOWERCASE'
l!l
241
MC/DC100%1/1
delete $args->{'format_reason'} || 'LOWERCASE'
delete $args->{'format_reason'}
Truth table100%2/2
A
A= delete $args->{'format_reason'}
Aresult
11
00
79 43 ▶ $self->{format_reason} = ref $f eq 'CODE' ? $f : $format_reason{$f}
Branch: 2 branches
BranchTrueFalseTotal
$self->{"format_reason"} = ref $f eq "CODE" ? $f : $format_reason{$f} or &error(&__x("illegal format_reason '{format}' for dispatcher", "format", $f)) 43 0 43
ref $f eq 'CODE' ? : 0 43 43
80 or error __x"illegal format_reason '{format}' for dispatcher", format => $f;
81  
82 43 my $csenc;
83 43 ▶ if(my $cs = delete $args->{charset})
Branch: 1 branch
BranchTrueFalseTotal
if (my $cs = delete $args->{"charset"}) 0 43 43
84 0 ▶ { my $enc = find_encoding $cs
Branch: 1 branch
BranchTrueFalseTotal
my $enc = &find_encoding($cs) or &error(&__x("Perl does not support charset {cs}", "cs", $cs)) 0 0 0
85 or error __x"Perl does not support charset {cs}", cs => $cs;
86 0 ▶ $csenc = sub { no warnings 'utf8'; $enc->encode($_[0]) };
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine __ANON__: not called CC=1 SCAR=0.6
87 }
88  
89 43 ▶ $self->{charset_enc} = $csenc || sub { $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$csenc || sub { $_[0]; }
l!l&&r!l&&!r
0430
MC/DC0%0/2
$csenc || sub { $_[0]; }
$csenc sub { $_[0]; }
Truth table33%1/3
A || B
A= $csencB= sub { $_[0]; }
ABresult
1X1
011
000
90 43 $self;
91 }
92  
93 21 ▶sub DESTROY { in_global_destruction or shift->close }
Subroutine DESTROY: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
&in_global_destruction() or (shift())->close 0 21 21
94  
95 #--------------------
96  
97 43 ▶sub name { $_[0]->{name} }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
98  
99  
100 0 ▶sub type() { $_[0]->{type} }
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
101  
102  
103 10 ▶sub mode() { $_[0]->{mode} }
Subroutine mode: called CC=1 SCAR=0.0
Pod documented
104  
105 #Please use C<dispatcher mode => $MODE;>
106 0 ▶sub defaultMode($) { $default_mode = $_[1] }
Subroutine defaultMode: not called CC=1 SCAR=6.9
Pod undocumented
107  
108 # only to be used via Log::Report::dispatcher(mode => ...)
109 # because requires re-investigating collective dispatcher needs
110 sub _set_mode($)
111 43 ▶{ my $self = shift;
Subroutine _set_mode: called CC=3 SCAR=11.0
112 43 my $mode = $self->{mode} = $modes{$_[0]};
113 43 ▶ defined $mode or panic "unknown run mode $_[0]";
Branch: 1 branch
BranchTrueFalseTotal
defined $mode or &panic("unknown run mode $_[0]") 43 0 43
114  
115 43 $self->{needs} = [ expand_reasons $default_accept[$mode] ];
116  
117 43 ▶ $self->isa('Log::Report::Dispatcher::Try')
Branch: 1 branch
BranchTrueFalseTotal
$self->isa("Log::Report::Dispatcher::Try") or &trace(&__x("switching to run mode {mode} for {pkg}, accept {accept}", "mode", $mode, "pkg", ref $self, "accept", $default_accept[$mode])) 21 22 43
118 or trace __x"switching to run mode {mode} for {pkg}, accept {accept}",
119 mode => $mode, pkg => ref $self, accept => $default_accept[$mode];
120  
121 43 $mode;
122 }
123  
124 # only to be called from Log::Report::dispatcher()!!
125 # because requires re-investigating needs
126 sub _disabled($)
127 0 ▶{ my $self = shift;
Subroutine _disabled: not called CC=2 SCAR=17.9
128 0 ▶ @_ ? ($self->{disabled} = shift) : $self->{disabled};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
129 }
130  
131  
132 1 ▶sub isDisabled() { $_[0]->{disabled} }
Subroutine isDisabled: called CC=1 SCAR=0.0
Pod documented
133  
134  
135 sub needs(;$)
136 44 ▶{ my $self = shift;
Subroutine needs: called CC=3 SCAR=11.0
Pod documented
137 44 ▶ return () if $self->{disabled};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"disabled"} 0 44 44
138  
139 44 my $needs = $self->{needs};
140 44 ▶ @_ or return @$needs;
Branch: 1 branch
BranchTrueFalseTotal
@_ or return @$needs 11 33 44
141  
142 11 my $need = shift;
143 11 ▶ first {$need eq $_} @$needs;
Subroutine __ANON__: called CC=1 SCAR=0.0
144 }
145  
146 #--------------------
147  
148 sub close()
149 43 ▶{ my $self = shift;
Subroutine close: called CC=2 SCAR=7.0
Pod documented
150 43 ▶ $self->{closed}++ and return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"closed"}++ and return undef 0 43 43
151 43 $self->{disabled}++;
152 43 $self;
153 }
154  
155  
156 sub log($$$$)
157 0 ▶{ panic "method log() must be extended per back-end";
Subroutine log: not called CC=1 SCAR=6.9
Pod documented
158 }
159  
160  
161 sub translate($$$)
162 10 ▶{ my ($self, $opts, $reason, $msg) = @_;
Subroutine translate: called CC=30 SCAR=45.2
Pod documented
163  
164 10 my $mode = $self->{mode};
165 10 ▶ my $code = $reason_code{$reason}
Branch: 1 branch
BranchTrueFalseTotal
my $code = $Log::Report::Dispatcher::reason_code{$reason} or &panic("unknown reason '${reason}'") 10 0 10
166 or panic "unknown reason '$reason'";
167  
168 my $show_loc
169 = $always_loc{$reason}
170 || ($mode==2 && $code >= $reason_code{WARNING})
171 10 ▶ || ($mode==3 && $code >= $reason_code{MISTAKE});
Condition50%6/12
$always_loc{$reason} || $mode == 2 && $code >= $Log::Report::Dispatcher::reason_code{'WARNING'} || $mode == 3 && $code >= $Log::Report::Dispatcher::reason_code{'MISTAKE'}
l!l&&r!l&&!r
307
$always_loc{$reason} or $mode == 2 and $code >= $Log::Report::Dispatcher::reason_code{"WARNING"}
l!l&&r!l&&!r
307
$mode == 2 and $code >= $Log::Report::Dispatcher::reason_code{"WARNING"}
!ll&&!rl&&r
700
$mode == 3 and $code >= $Log::Report::Dispatcher::reason_code{"MISTAKE"}
!ll&&!rl&&r
700
MC/DC20%1/5
$always_loc{$reason} || $mode == 2 && $code >= $Log::Report::Dispatcher::reason_code{'WARNING'} || $mode == 3 && $code >= $Log::Report::Dispatcher::reason_code{'MISTAKE'}
$always_loc{$reason} $mode == 2 $code >= $Log::Report::Dispatcher::reason_code{"WARNING"} $mode == 3 $code >= $Log::Report::Dispatcher::reason_code{"MISTAKE"}
Truth table25%2/8
A or B and C || D and E
A= $always_loc{$reason}B= $mode == 2C= $code >= $Log::Report::Dispatcher::reason_code{"WARNING"}D= $mode == 3E= $code >= $Log::Report::Dispatcher::reason_code{"MISTAKE"}
ABCDEresult
1XXXX1
011XX1
00X111
010111
00X0X0
00X100
0100X0
010100
172  
173 my $show_stack
174 = $reason eq 'PANIC'
175 || ($mode==2 && $code >= $reason_code{ALERT})
176 10 ▶ || ($mode==3 && $code >= $reason_code{ERROR});
Condition33%4/12
$reason eq 'PANIC' || $mode == 2 && $code >= $Log::Report::Dispatcher::reason_code{'ALERT'} || $mode == 3 && $code >= $Log::Report::Dispatcher::reason_code{'ERROR'}
l!l&&r!l&&!r
0010
$reason eq "PANIC" or $mode == 2 and $code >= $Log::Report::Dispatcher::reason_code{"ALERT"}
l!l&&r!l&&!r
0010
$mode == 2 and $code >= $Log::Report::Dispatcher::reason_code{"ALERT"}
!ll&&!rl&&r
1000
$mode == 3 and $code >= $Log::Report::Dispatcher::reason_code{"ERROR"}
!ll&&!rl&&r
1000
MC/DC0%0/5
$reason eq 'PANIC' || $mode == 2 && $code >= $Log::Report::Dispatcher::reason_code{'ALERT'} || $mode == 3 && $code >= $Log::Report::Dispatcher::reason_code{'ERROR'}
$reason eq "PANIC" $mode == 2 $code >= $Log::Report::Dispatcher::reason_code{"ALERT"} $mode == 3 $code >= $Log::Report::Dispatcher::reason_code{"ERROR"}
Truth table12%1/8
A or B and C || D and E
A= $reason eq "PANIC"B= $mode == 2C= $code >= $Log::Report::Dispatcher::reason_code{"ALERT"}D= $mode == 3E= $code >= $Log::Report::Dispatcher::reason_code{"ERROR"}
ABCDEresult
1XXXX1
011XX1
00X111
010111
00X0X0
00X100
0100X0
010100
177  
178 my $locale
179 = defined $msg->msgid
180 ? ($opts->{locale} || $self->{locale}) # translate whole
181 10 ▶ : (textdomain $msg->domain)->nativeLanguage;
Branch: 1 branch
BranchTrueFalseTotal
defined $msg->msgid ? : 0 10 10
Condition0%0/3
$opts->{"locale"} or $self->{"locale"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"locale"} or $self->{"locale"}
$opts->{"locale"} $self->{"locale"}
Truth table0%0/3
A or B
A= $opts->{"locale"}B= $self->{"locale"}
ABresult
1X1
011
000
182  
183 10 ▶ my $oldloc = setlocale(&LC_ALL) // "";
Condition50%1/2
setlocale(&LC_ALL) // ""
l!l
100
MC/DC0%0/1
setlocale(&LC_ALL) // ""
setlocale(&LC_ALL)
Truth table50%1/2
A
A= setlocale(&LC_ALL)
Aresult
11
00
184 10 ▶ setlocale(&LC_ALL, $locale)
Branch: 1 branch
BranchTrueFalseTotal
if $locale and $locale ne $oldloc 0 10 10
Condition33%1/3
$locale and $locale ne $oldloc
!ll&&!rl&&r
1000
MC/DC0%0/2
$locale and $locale ne $oldloc
$locale $locale ne $oldloc
Truth table33%1/3
A and B
A= $localeB= $locale ne $oldloc
ABresult
0X0
100
111
185 if $locale && $locale ne $oldloc;
186  
187 10 my $r = $self->{format_reason}->((__$reason)->toString);
188 10 ▶ my $e = use_errno($reason) ? strerror($opts->{errno} || 1) : undef;
Branch: 1 branch
BranchTrueFalseTotal
&use_errno($reason) ? : 2 8 10
Condition50%1/2
$opts->{'errno'} || 1
l!l
20
MC/DC0%0/1
$opts->{'errno'} || 1
$opts->{'errno'}
Truth table50%1/2
A
A= $opts->{'errno'}
Aresult
11
00
189  
190 10 ▶ my $format
Branch: 3 branches
BranchTrueFalseTotal
$r && $e ? : 2 8 10
$r ? : 7 1 8
$e ? : 0 1 1
Condition100%3/3
$r and $e
!ll&&!rl&&r
172
MC/DC100%2/2
$r and $e
$r $e
Truth table100%3/3
A and B
A= $rB= $e
ABresult
0X0
100
111
191 = $r && $e ? N__"{reason}: {message}; {error}"
192 : $r ? N__"{reason}: {message}"
193 : $e ? N__"{message}; {error}"
194 : undef;
195  
196 10 ▶ my $text
Branch: 1 branch
BranchTrueFalseTotal
defined $format ? : 9 1 10
197 = ( defined $format
198 ? __x($format, message => $msg->toString , reason => $r, error => $e)
199 : $msg
200 )->toString;
201 10 $text =~ s/\n*\z/\n/;
202  
203 10 ▶ if($show_loc)
Branch: 1 branch
BranchTrueFalseTotal
if ($show_loc) 3 7 10
204 3 ▶ { if(my $loc = $opts->{location} || $self->collectLocation)
Branch: 1 branch
BranchTrueFalseTotal
if (my $loc = $opts->{"location"} || $self->collectLocation) 3 0 3
Condition33%1/3
$opts->{'location'} || $self->collectLocation
l!l&&r!l&&!r
300
MC/DC0%0/2
$opts->{'location'} || $self->collectLocation
$opts->{'location'} $self->collectLocation
Truth table33%1/3
A || B
A= $opts->{'location'}B= $self->collectLocation
ABresult
1X1
011
000
205 3 { my ($pkg, $fn, $line, $sub) = @$loc;
206 # pkg and sub are missing when decoded by ::Die
207 3 $text .= " "
208 . __x('at {filename} line {line}', filename => $fn, line => $line)->toString
209 . "\n";
210 }
211 }
212  
213 10 ▶ if($show_stack)
Branch: 1 branch
BranchTrueFalseTotal
if ($show_stack) 0 10 10
214 0 ▶ { my $stack = $opts->{stack} ||= $self->collectStack;
Condition0%0/3
$opts->{"stack"} ||= $self->collectStack
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"stack"} ||= $self->collectStack
$opts->{"stack"} $self->collectStack
Truth table0%0/3
A ||= B
A= $opts->{"stack"}B= $self->collectStack
ABresult
1X1
011
000
215 0 foreach (@$stack)
216 0 { $text .= $_->[0] . " "
217 . __x('at {filename} line {line}', filename => $_->[1], line => $_->[2])->toString
218 . "\n";
219 }
220 }
221  
222 10 ▶ setlocale(&LC_ALL, $oldloc)
Branch: 1 branch
BranchTrueFalseTotal
if $locale and $locale ne $oldloc 0 10 10
Condition33%1/3
$locale and $locale ne $oldloc
!ll&&!rl&&r
1000
MC/DC0%0/2
$locale and $locale ne $oldloc
$locale $locale ne $oldloc
Truth table33%1/3
A and B
A= $localeB= $locale ne $oldloc
ABresult
0X0
100
111
223 if $locale && $locale ne $oldloc;
224  
225 10 $self->{charset_enc}->($text);
226 }
227  
228  
229 sub collectStack($)
230 3 ▶{ my ($thing, $max) = @_;
Subroutine collectStack: called CC=4 SCAR=13.9
Pod documented
231 3 my $nest = $thing->skipStack;
232  
233 # special trick by Perl for Carp::Heavy: adds @DB::args
234 3 { package DB; # non-blank before package to avoid problem with OODoc
235  
236 3 my @stack;
237 3 ▶ while(!defined $max || $max--)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $max or $max--) 14 1 15
Condition100%3/3
not defined $max or $max--
l!l&&r!l&&!r
1131
MC/DC100%2/2
not defined $max or $max--
not defined $max $max--
Truth table100%3/3
not(A) or B
A= not defined $maxB= $max--
ABresult
1X1
011
000
238 14 { my ($pkg, $fn, $linenr, $sub) = caller $nest++;
239 14 ▶ defined $pkg or last;
Branch: 1 branch
BranchTrueFalseTotal
defined $pkg or last 12 2 14
240  
241 12 my $line = $thing->stackTraceLine(call => $sub, params => \@DB::args);
242 12 push @stack, [$line, $fn, $linenr];
243 }
244  
245 3 \@stack;
246 }
247 }
248  
249  
250 sub addSkipStack(@)
251 0 ▶{ my $thing = shift;
Subroutine addSkipStack: not called CC=1 SCAR=6.9
Pod documented
252 0 push @skip_stack, @_;
253 0 $thing;
254 }
255  
256  
257 sub skipStack()
258 20 ▶{ my $thing = shift;
Subroutine skipStack: called CC=4 SCAR=14.0
Pod documented
259 20 my $nest = 1;
260 20 my $args;
261  
262 42 do { $args = [caller ++$nest] }
263 20 ▶ while @$args && first {$_->($args)} @skip_stack;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
@$args and &first(sub { &$_($args); } , @skip_stack) and do { do { $args = [caller ++$nest] } } 22 20 42
Condition66%2/3
@$args and &first(sub { &$_($args); } , @skip_stack)
!ll&&!rl&&r
02022
MC/DC50%1/2
@$args and &first(sub { &$_($args); } , @skip_stack)
@$args &first(sub { &$_($args); } , @skip_stack)
Truth table66%2/3
A and B
A= @$argsB= &first(sub { &$_($args); } , @skip_stack)
ABresult
0X0
100
111
264  
265 # do not count my own stack level in!
266 20 ▶ @$args ? $nest-1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
@$args ? : 20 0 20
267 }
268  
269  
270 17 ▶sub collectLocation() { [caller shift->skipStack] }
Subroutine collectLocation: called CC=1 SCAR=0.0
Pod documented
271  
272  
273 sub stackTraceLine(@)
274 12 ▶{ my ($thing, %args) = @_;
Subroutine stackTraceLine: called CC=12 SCAR=25.7
Pod documented
275  
276 12 ▶ my $max = $args{max_line} ||= 500;
Condition50%1/2
$args{"max_line"} ||= 500
l!l
012
MC/DC0%0/1
$args{"max_line"} ||= 500
$args{"max_line"}
Truth table50%1/2
A
A= $args{"max_line"}
Aresult
11
00
277 12 ▶ my $abstract = $args{abstract} || 1;
Condition50%1/2
$args{'abstract'} || 1
l!l
012
MC/DC0%0/1
$args{'abstract'} || 1
$args{'abstract'}
Truth table50%1/2
A
A= $args{'abstract'}
Aresult
11
00
278 12 ▶ my $maxparams = $args{max_params} || 8;
Condition50%1/2
$args{'max_params'} || 8
l!l
012
MC/DC0%0/1
$args{'max_params'} || 8
$args{'max_params'}
Truth table50%1/2
A
A= $args{'max_params'}
Aresult
11
00
279 12 my @params = @{$args{params}};
280 12 my $call = $args{call};
281  
282 12 ▶ my $obj = ref $params[0] && $call =~ m/^(.*\:\:)/ && UNIVERSAL::isa($params[0], $1)
Branch: 1 branch
BranchTrueFalseTotal
ref $params[0] && $call =~ /^(.*\:\:)/ && UNIVERSAL::isa($params[0], $1) ? : 0 12 12
Condition83%5/6
ref $params[0] and $call =~ /^(.*\:\:)/ and UNIVERSAL::isa($params[0], $1)
!ll&&!rl&&r
1020
ref $params[0] and $call =~ /^(.*\:\:)/
!ll&&!rl&&r
912
MC/DC0%0/3
ref $params[0] and $call =~ /^(.*\:\:)/ and UNIVERSAL::isa($params[0], $1)
ref $params[0] $call =~ /^(.*\:\:)/ UNIVERSAL::isa($params[0], $1)
Truth table75%3/4
A and B and C
A= ref $params[0]B= $call =~ /^(.*\:\:)/C= UNIVERSAL::isa($params[0], $1)
ABCresult
0XX0
10X0
1100
1111
283 ? shift @params : undef;
284  
285 12 my $listtail = '';
286 12 ▶ if(@params > $maxparams)
Branch: 1 branch
BranchTrueFalseTotal
if (@params > $maxparams) 0 12 12
287 0 { $listtail = ', [' . (@params-$maxparams) . ' more]';
288 0 $#params = $maxparams -1;
289 }
290  
291 12 $max -= @params * 2 - length($listtail); # \( ( \,[ ] ){n-1} \)
292  
293 12 my $calling = $thing->stackTraceCall(\%args, $abstract, $call, $obj);
294 12 my @out = map $thing->stackTraceParam(\%args, $abstract, $_), @params;
295 12 my $total = sum map {length $_} $calling, @out;
296  
297 ATTEMPT:
298 12 ▶ while($total <= $max)
Branch: 1 branch
BranchTrueFalseTotal
if ($total <= $max) 16 0 16
299 16 { $abstract++;
300 16 ▶ last if $abstract > 2; # later more levels
Branch: 1 branch
BranchTrueFalseTotal
if $abstract > 2 4 12 16
301  
302 12 foreach my $p (reverse 0..$#out)
303 8 { my $old = $out[$p];
304 8 $out[$p] = $thing->stackTraceParam(\%args, $abstract, $params[$p]);
305 8 $total -= length($old) - length($out[$p]);
306 8 ▶ last ATTEMPT if $total <= $max;
Branch: 1 branch
BranchTrueFalseTotal
if $total <= $max 8 0 8
307 }
308  
309 4 my $old = $calling;
310 4 $calling = $thing->stackTraceCall(\%args, $abstract, $call, $obj);
311 4 $total -= length($old) - length($calling);
312 }
313  
314 12 $calling .'(' . join(', ',@out) . $listtail . ')';
315 }
316  
317 # 1: My::Object(0x123141, "my string")
318 # 2: My::Object=HASH(0x1231451)
319 # 3: My::Object("my string")
320 # 4: My::Object()
321  
322 sub stackTraceCall($$$;$)
323 16 ▶{ my ($thing, $args, $abstract, $call, $obj) = @_;
Subroutine stackTraceCall: called CC=2 SCAR=8.4
Pod undocumented
324  
325 16 ▶ if(defined $obj) # object oriented
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj) { } 0 16 16
326 0 { my ($pkg, $method) = $call =~ m/^(.*\:\:)(.*)/;
327 0 return overload::StrVal($obj) . '->' . $call;
328 }
329 else # imperative
330 16 { return $call;
331 }
332 }
333  
334 sub stackTraceParam($$$)
335 22 ▶{ my ($thing, $args, $abstract, $param) = @_;
Subroutine stackTraceParam: called CC=5 SCAR=16.4
Pod undocumented
336 22 ▶ defined $param
Branch: 1 branch
BranchTrueFalseTotal
defined $param or return "undef" 22 0 22
337 or return 'undef';
338  
339 22 ▶ $param = overload::StrVal($param)
Branch: 1 branch
BranchTrueFalseTotal
if ref $param 6 16 22
340 if ref $param;
341  
342 22 ▶ return $param # int or float
Branch: 1 branch
BranchTrueFalseTotal
if $param =~ /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/ 8 14 22
343 if $param =~ /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/;
344  
345 14 my $escaped = escape_chars $param;
346 14 ▶ if(length $escaped > 80)
Branch: 1 branch
BranchTrueFalseTotal
if (length $escaped > 80) 0 14 14
347 0 { $escaped = substr($escaped, 0, 30)
348 . '...['. (length($escaped) -80) .' chars more]...'
349 . substr($escaped, -30);
350 }
351  
352 14 qq{"$escaped"};
353 }
354  
355 #--------------------
356  
357 17 1;
« Log/Report/Domain.pm ↑ Summary Log/Report/Dispatcher/File.pm »