Show.pm

filter: Statementstmt 69.5% 185 / 266 Branchbran 54.5% 60 / 110 Conditioncond 42.0% 29 / 69 MC/DCmcdc 10.0% 4 / 40 Subroutinesub 92.3% 12 / 13 Podpod 50.0% 2 / 4 totaltotal 58.1% 292 / 502 SCAR 63.1
CC
90
Cov
62%
import
175.4
context
58.6
splain
30.0
CRAP 549.6
↑ Summary Show/Internal.pm »
1 package Error::Show;
2  
3 4 ▶use 5.024000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use feature "say";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9  
10 4 our $VERSION = 'v0.3.0';
11  
12 4 ▶use constant DEBUG=>undef;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 use enum ("PACKAGE=0",qw<FILENAME LINE SUBROUTINE
14 HASARGS WANTARRAY EVALTEXT IS_REQUIRE HINTS BITMASK
15 4 ▶ HINT_HASH MESSAGE SEQUENCE CODE_LINES>);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18  
19 #
20 # A list of top level file paths or scalar refs to check for syntax errors
21 #
22 4 my @IINC;
23 sub context;
24  
25
26 sub import {
27 4 ▶ my $package=shift;
Subroutine import: called CC=16 SCAR=51.7
28 4 my @caller=caller;
29 4 my @options=@_;
30  
31  
32 # Only have one sub to export and we only export it if the caller has a line
33 # number. Otherise we are being invoked from the CLI
34 #
35 4 ▶ if($caller[LINE]){
Branch: 1 branch
BranchTrueFalseTotal
if ($caller[2]) 4 0 4
36 4 ▶ no strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
37 4 my $name=$caller[0]."::context";
38 4 *{$name}=\&{"context"};
39 4 return;
40 }
41  
42 #
43 # CLI Options include
44 #
45  
46 0 require POSIX; #For _exit;
47 0 require IPC::Open3;
48 0 require Symbol;
49 0 my %options;
50  
51 0 my $clean=grep /clean/i, @options;
52 0 my $splain=grep /splain/i, @options;
53 0 my $do_warn=grep /warn/i, @options;
54  
55 0 ▶ my @warn=$do_warn?():"-MError::Show::Internal";
Branch: 1 branch
BranchTrueFalseTotal
$do_warn ? : 0 0 0
56  
57  
58 #
59 # 1. Command line argument activation ie -MError::Show
60 #
61 # Find out any extra lib paths used. To do this we:
62 #
63 # a. fork/exec a new perl process using the value of $^X.
64 # b. The new process dumps the @INC array to STDOUT
65 # c. This process reads the output and stores in @IINC
66 #
67 # Only run it the first time its used
68 # Is this the best way? Not sure. At least this way there is no argument
69 # processing, perl process does it for us.
70 #
71
72 0 ▶ @IINC=map {chomp; $_} do {
Branch: 1 branch
BranchTrueFalseTotal
unless @IINC 0 0 0
73 0 ▶ open my $fh, "-|", $^X . q| -E 'map print("$_\n"), @INC'| or die "$!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "-|", $^X . q[ -E 'map print("$_\\n"), @INC'] or die "$!" 0 0 0
74 0 <$fh>;
75 } unless @IINC;
76  
77 #
78 # 2. Extract the extra include paths
79 #
80 # Built up the 'extra' array of any include paths not already listed
81 # from the STDOUT dumping above
82 #
83 0 my @extra=map {("-I", $_)} grep {my $i=$_; !grep { $i eq $_} @IINC} @INC;
84  
85  
86  
87 #
88 # 3. Syntax checking the program
89 #
90 # Now we have the include paths sorted,
91 # a. fork/exec again, this time with the -c switch for perl to check syntax
92 # b. slurp STDERR from child process
93 # c. execute the context routine to parse and show more source code context
94 # d. print!
95 # The proc
96  
97 0 local $/=undef;
98 0 my $file=$0;
99  
100 #push @file, @ARGV;
101  
102 #my $runnable=not $^C;#$options{check};
103 #for my $file(@file){
104 0 ▶ die "Error::Show cannot process STDIN, -e and -E programs" if $file eq "-e" or $file eq "-E" or $file eq "-";
Branch: 1 branch
BranchTrueFalseTotal
if $file eq "-e" or $file eq "-E" or $file eq "-" 0 0 0
Condition0%0/6
$file eq "-e" or $file eq "-E" or $file eq "-"
l!l&&r!l&&!r
000
$file eq "-e" or $file eq "-E"
l!l&&r!l&&!r
000
MC/DC0%0/3
$file eq "-e" or $file eq "-E" or $file eq "-"
$file eq "-e" $file eq "-E" $file eq "-"
Truth table0%0/4
A or B or C
A= $file eq "-e"B= $file eq "-E"C= $file eq "-"
ABCresult
1XX1
01X1
0011
0000
105 0 ▶ die "Error::Show cannot access \"$file\"" unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
106 0 my @cmd= ($^X ,@warn, @extra, "-c", $file);
107  
108 0 my $pid;
109 my $result;
110 0 eval {
111 0 $pid=IPC::Open3::open3(my $chld_in, my $chld_out, my $chld_err = Symbol::gensym(), @cmd);
112 0 $result=<$chld_err>;
113 0 close $chld_in;
114 0 close $chld_out;
115 0 close $chld_err;
116 0 wait;
117 };
118 0 ▶ if(!$pid and $@){
Branch: 1 branch
BranchTrueFalseTotal
if (not $pid and $@) 0 0 0
Condition0%0/3
not $pid and $@
!ll&&!rl&&r
000
MC/DC0%0/2
not $pid and $@
not $pid $@
Truth table0%0/3
not(A) and B
A= not $pidB= $@
ABresult
0X0
100
111
119 0 die "Error::Show failed to syntax check";
120 }
121  
122  
123 #
124 # 4. Status code from child indicates success
125 # When 0 this means syntax was ok. Otherwise error
126 # Attempt to propogate code to exit status
127 #
128 0 ▶ my $code=$?>255? (0xFF & ~$?): $?;
Branch: 1 branch
BranchTrueFalseTotal
$? > 255 ? : 0 0 0
129  
130 0 my $runnable=$?==0;
131  
132 0 my $status=context(splain=>$splain, clean=>$clean, error=>$result )."\n";
133  
134 0 ▶ if($^C){
Branch: 1 branch
BranchTrueFalseTotal
if ($^C) { } 0 0 0
135 0 ▶ if($runnable){
Branch: 1 branch
BranchTrueFalseTotal
if ($runnable) { } 0 0 0
136 #only print status if we want warnings
137 0 ▶ print STDERR $do_warn?$status: "$file syntax OK\n";
Branch: 1 branch
BranchTrueFalseTotal
$do_warn ? : 0 0 0
138  
139 }
140 else{
141 #Not runnable, thus syntax error. Always print
142 0 print STDERR $status;
143  
144 }
145 0 POSIX::_exit $code;
146  
147 }
148 else{
149 #not checking, we want to run
150 0 ▶ if($runnable){
Branch: 1 branch
BranchTrueFalseTotal
if ($runnable) { } 0 0 0
151 # don't bother with warnings
152  
153 }
154 else{
155 #Not runnable, thus syntax error. Always print
156 0 print STDERR $status;
157 0 POSIX::_exit $code;
158 }
159 }
160 }
161  
162  
163 sub process_string_error{
164 13 ▶ my $error=pop;
Subroutine process_string_error: called CC=8 SCAR=21.2
Pod undocumented
165 13 my %opts=@_;
166  
167 13 my @error_lines;
168 my @errors;
169 #my @entry;
170 13 my %entry;
171 13 ▶ if(defined $error){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) { } 13 0 13
172 #local $_=$error;
173 #Substitue with a line number relative to the start marker
174 #Reported line numbers are 1 based, stored lines are 0 based
175 #my $translation=$opts{translation};
176 #my $start=$opts{start};
177
178 13 my $i=0;
179 13 for(split "\n", $error){
180 10 DEBUG and say STDERR "ERROR LINE: ".$_;
181 10 ▶ if(/at (.*?) line (\d+)/
Branch: 1 branch
BranchTrueFalseTotal
if (/at (.*?) line (\d+)/u or /Missing right curly or square bracket at (.*?) (\d+) at end of line/u) 10 0 10
Condition33%1/3
/at (.*?) line (\d+)/u or /Missing right curly or square bracket at (.*?) (\d+) at end of line/u
l!l&&r!l&&!r
1000
MC/DC0%0/2
/at (.*?) line (\d+)/u or /Missing right curly or square bracket at (.*?) (\d+) at end of line/u
/at (.*?) line (\d+)/u /Missing right curly or square bracket at (.*?) (\d+) at end of line/u
Truth table33%1/3
A or B
A= /at (.*?) line (\d+)/uB= /Missing right curly or square bracket at (.*?) (\d+) at end of line/u
ABresult
1X1
011
000
182 or /Missing right curly or square bracket at (.*?) (\d+) at end of line/){
183 #
184 # Group by file names
185 #
186 10 DEBUG and say STDERR "PROCESSING: ".$_;
187 10 DEBUG and say STDERR "file: $1 and line $2";
188 10 ▶ my $entry=$entry{$1}//=[];
Condition50%1/2
$entry{$1} //= []
l!l
010
MC/DC0%0/1
$entry{$1} //= []
$entry{$1}
Truth table50%1/2
A
A= $entry{$1}
Aresult
11
00
189 #push @$entry, {file=>$1, line=>$2,message=>$_, sequence=>$i++};
190 10 my $a=[];
191 10 $a->[FILENAME]=$1;
192 10 $a->[LINE]=$2-1;
193 10 $a->[MESSAGE]=$_;
194 10 ▶ $a->[MESSAGE]=$opts{message} if $opts{message};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"message"} 0 10 10
195 10 $a->[SEQUENCE]=$i++;
196 10 ▶ $a->[EVALTEXT]=$opts{program} if $opts{program};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"program"} 4 6 10
197 10 push @$entry, $a;
198 }
199 }
200  
201
202 }
203 else {
204 #Assume a target line
205 #push @error_lines, $opts{line}-1;
206 }
207  
208 #Key is file name
209 # value is a hash of filename,line number, perl error string and the sequence number
210  
211 13 \%entry;
212  
213 }
214  
215 # Takes a hash ref error sources
216  
217 sub text_output {
218 24 ▶ my $info_ref=pop;
Subroutine text_output: called CC=26 SCAR=33.1
Pod undocumented
219 24 my %opts=@_;
220 24 my $total="";
221  
222 24 DEBUG and say STDERR "Reverse flag in text output set to: $opts{reverse}";
223  
224 # Sort by sequence number
225 # Errors are stored by filename internally. Sort by sequence number.
226 #
227  
228 my @sorted_info=
229 3 sort {$a->[SEQUENCE] <=> $b->[SEQUENCE] }
230 24 map { $_->@* } values %$info_ref;
231  
232 # Reverse the order if we want the first error listed last
233 #
234 24 ▶ @sorted_info=reverse (@sorted_info) if $opts{reverse};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"reverse"} 3 21 24
235  
236 # Process each of the errors in sequence
237 24 my $counter=0;
238 24 ▶ my $limit=$opts{limit}//100;
Condition50%1/2
$opts{"limit"} // 100
l!l
024
MC/DC0%0/1
$opts{"limit"} // 100
$opts{"limit"}
Truth table50%1/2
A
A= $opts{"limit"}
Aresult
11
00
239 24 for my $info (@sorted_info){
240 21 ▶ last if $counter>=$limit and $limit >0;
Branch: 1 branch
BranchTrueFalseTotal
if $counter >= $limit and $limit > 0 0 21 21
Condition33%1/3
$counter >= $limit and $limit > 0
!ll&&!rl&&r
2100
MC/DC0%0/2
$counter >= $limit and $limit > 0
$counter >= $limit $limit > 0
Truth table33%1/3
A and B
A= $counter >= $limitB= $limit > 0
ABresult
0X0
100
111
241 21 $counter++;
242 21 ▶ unless(exists $info->[CODE_LINES]){
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $info->[13]) 21 0 21
243 21 my @code;
244
245 21 ▶ if($info->[EVALTEXT]){
Branch: 1 branch
BranchTrueFalseTotal
if ($info->[6]) { } 4 17 21
246 4 @code=split "\n", $info->[EVALTEXT];
247 }
248 else {
249 17 @code=split "\n", do {
250 17 ▶ open my $fh, "<", $info->[FILENAME] or warn "Could not open file for reading: $info->[FILENAME]";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $info->[1] or warn "Could not open file for reading: $info->[1]" 0 17 17
251 17 local $/=undef;
252 17 <$fh>;
253 };
254 }
255 21 $info->[CODE_LINES]=\@code;
256 }
257  
258 # At this point we have lines of code in an array
259 #
260
261 #Find start mark and end mark
262 #
263 21 my $start_line=0;
264 21 ▶ if($opts{start_mark}){
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"start_mark"}) 2 19 21
265 2 my $counter=0;
266 2 my $start_mark=$opts{start_mark};
267 2 for($info->[CODE_LINES]->@*){
268 8 ▶ if(/$start_mark/){
Branch: 1 branch
BranchTrueFalseTotal
if (/$start_mark/u) 2 6 8
269 2 $start_line+=$counter+1;
270 2 last;
271 }
272 6 $counter++;
273 }
274 # Don't include the start marker in the results
275 }
276  
277 21 my $end_line=$info->[CODE_LINES]->@*-1;
278  
279 21 ▶ if($opts{end_mark}){
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"end_mark"}) 2 19 21
280 2 my $counter=0;
281 2 my $end_mark=$opts{end_mark};
282 2 for (reverse($info->[CODE_LINES]->@*)){
283 8 ▶ if(/$end_mark/){
Branch: 1 branch
BranchTrueFalseTotal
if (/$end_mark/u) 2 6 8
284 2 $end_line-=$counter;
285 2 last;
286 }
287 6 $counter++;
288 }
289 }
290  
291 21 ▶ $start_line+=$opts{start_offset} if $opts{start_offset};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"start_offset"} 0 21 21
292 21 ▶ $end_line-=$opts{end_offset } if $opts{end_offset};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"end_offset"} 0 21 21
293  
294 # preclamp the error line to within this range so that 'Unmatched ' errors
295 # at least show ssomething.
296 #
297 21 ▶ $info->[LINE]=$end_line if $info->[LINE]>$end_line;
Branch: 1 branch
BranchTrueFalseTotal
if $info->[2] > $end_line 0 21 21
298  
299 21 DEBUG and say "START LINE after offset: $start_line";
300 21 DEBUG and say "END LINE after offset: $end_line";
301 # At this point the file min and max lines we should consider are
302 # start_line and end line inclusive. The $start_line is also used as an
303 # offset to shift error sources
304 #
305  
306 21 my $min=$info->[LINE]-$opts{pre_lines};
307 21 my $max=$info->[LINE]+$opts{post_lines};
308  
309 21 my $target= $info->[LINE];#-$start_line;
310 21 DEBUG and say "TARGET: $target";
311  
312 21 ▶ $min=$min<$start_line ? $start_line: $min;
Branch: 1 branch
BranchTrueFalseTotal
$min < $start_line ? : 5 16 21
313  
314 21 ▶ $max=$max>$end_line?$end_line:$max;
Branch: 1 branch
BranchTrueFalseTotal
$max > $end_line ? : 6 15 21
315  
316 #
317 # format counter on the largest number to be expected
318 #
319 21 my $f_len=length("$max");
320  
321 21 my $out="$opts{indent}$info->[FILENAME]\n";
322
323 21 ▶ my $indent=$opts{indent}//"";
Condition50%1/2
$opts{"indent"} // ""
l!l
210
MC/DC0%0/1
$opts{"indent"} // ""
$opts{"indent"}
Truth table50%1/2
A
A= $opts{"indent"}
Aresult
11
00
324 21 my $format="$indent%${f_len}d% 2s %s\n";
325 21 my $mark="";
326  
327 #Change min and max to one based index
328 #$min++;
329 #$max--;
330 21 DEBUG and say STDERR "min before print $min";
331 21 DEBUG and say STDERR "max before print $max";
332 21 for my $l($min..$max){
333 201 $mark="";
334  
335 201 my $a=$l-$start_line+1;
336  
337 #Perl line number is 1 based
338 201 ▶ $mark="=>" if $l==$target;
Branch: 1 branch
BranchTrueFalseTotal
if $l == $target 21 180 201
339  
340  
341 # Print lines as per the index in file array
342 201 $out.=sprintf $format, $a, $mark, $info->[CODE_LINES][$l];
343 }
344  
345 21 $total.=$out;
346
347 # Modifiy the message now with updated line numbers
348 # TODO: Tidy this up
349 21 ▶ $info->[MESSAGE]=~s/line (\d+)(?:\.|,)/(($1-1)>$max?$max:$1-1)-$start_line+1/e;
Branch: 1 branch
BranchTrueFalseTotal
$1 - 1 > $max ? : 0 10 10
350  
351 21 ▶ $total.=$info->[MESSAGE]."\n" unless $opts{clean};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"clean"} 21 0 21
352  
353 }
354 24 ▶ if($opts{splain}){
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"splain"}) 0 24 24
355 0 $total=splain($total);
356 }
357 24 $total;
358 }
359  
360  
361 #Take an error string and attempt to contextualize it
362 # context options_pairs, error string
363 sub _context{
364 #use feature ":all";
365 24 ▶ DEBUG and say STDERR "IN context call";
Subroutine _context: called CC=12 SCAR=25.6
366 #my ($package, $file, $caller_line)=caller;
367 #
368 # Error is set by single argument, key/value pair, or if no
369 # argument $@ is used
370 #
371 24 my %opts=@_;
372  
373 24 my $error= $opts{error};
374  
375  
376  
377 #$opts{start_mark};#//=qr|.*|; #regex which matches the start of the code
378 24 ▶ $opts{pre_lines}//=5; #Number of lines to show before target line
Condition50%1/2
$opts{"pre_lines"} //= 5
l!l
024
MC/DC0%0/1
$opts{"pre_lines"} //= 5
$opts{"pre_lines"}
Truth table50%1/2
A
A= $opts{"pre_lines"}
Aresult
11
00
379 24 ▶ $opts{post_lines}//=5; #Number of lines to show after target line
Condition50%1/2
$opts{"post_lines"} //= 5
l!l
024
MC/DC0%0/1
$opts{"post_lines"} //= 5
$opts{"post_lines"}
Truth table50%1/2
A
A= $opts{"post_lines"}
Aresult
11
00
380 24 ▶ $opts{start_offset}//=0; #Offset past start mark to consider as min line
Condition50%1/2
$opts{"start_offset"} //= 0
l!l
024
MC/DC0%0/1
$opts{"start_offset"} //= 0
$opts{"start_offset"}
Truth table50%1/2
A
A= $opts{"start_offset"}
Aresult
11
00
381 24 ▶ $opts{end_offset}//=0; #Offset before end to consider as max line
Condition50%1/2
$opts{"end_offset"} //= 0
l!l
024
MC/DC0%0/1
$opts{"end_offset"} //= 0
$opts{"end_offset"}
Truth table50%1/2
A
A= $opts{"end_offset"}
Aresult
11
00
382 24 ▶ $opts{translation}//=0; #A static value added to the line numbering
Condition50%1/2
$opts{"translation"} //= 0
l!l
024
MC/DC0%0/1
$opts{"translation"} //= 0
$opts{"translation"}
Truth table50%1/2
A
A= $opts{"translation"}
Aresult
11
00
383 24 ▶ $opts{indent}//="";
Condition100%2/2
$opts{"indent"} //= ""
l!l
1113
MC/DC100%1/1
$opts{"indent"} //= ""
$opts{"indent"}
Truth table100%2/2
A
A= $opts{"indent"}
Aresult
11
00
384 24 ▶ $opts{file}//="";
Condition50%1/2
$opts{"file"} //= ""
l!l
024
MC/DC0%0/1
$opts{"file"} //= ""
$opts{"file"}
Truth table50%1/2
A
A= $opts{"file"}
Aresult
11
00
385  
386 # Get the all the info we need to process
387 24 my $info_ref;
388 24 ▶ if(defined($error) and ref($error) eq ""){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error and ref $error eq '') { } 13 11 24
Condition66%2/3
defined $error and ref $error eq ""
!ll&&!rl&&r
01113
MC/DC50%1/2
defined $error and ref $error eq ""
defined $error ref $error eq ""
Truth table66%2/3
A and B
A= defined $errorB= ref $error eq ""
ABresult
0X0
100
111
389 #A string error. A normal string die/warn or compile time errors/warnings
390 13 $info_ref=process_string_error %opts, $error;
391 }
392 else{
393 #Some kind of object, converted into line and file hash
394 11 $info_ref= {$error->[FILENAME]=>[$error]};# {$error->{file}=>[$error]};
395 11 ▶ $error->[MESSAGE]=$opts{message}//""; #Store the message
Condition100%2/2
$opts{"message"} // ""
l!l
47
MC/DC100%1/1
$opts{"message"} // ""
$opts{"message"}
Truth table100%2/2
A
A= $opts{"message"}
Aresult
11
00
396 11 ▶ $error->[EVALTEXT]=$opts{program} if $opts{program};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"program"} 0 11 11
397 }
398
399 # Override text/file to search
400 24 my $output;
401 24 $output=text_output %opts, $info_ref;
402
403 #TODO:
404 #
405 24 $output;
406
407 }
408  
409  
410 #
411 # Front end to the main processing sub. Configures and checks the inputs
412 #
413 4 my $msg= "Trace must be a ref to array of {file=>.., line=>..} pairs";
414 sub context{
415 17 ▶ shift if(defined $_[0] and $_[0] eq __PACKAGE__);
Subroutine context: called CC=28 SCAR=40.7
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq __PACKAGE__ 0 17 17
Condition66%2/3
defined $_[0] and $_[0] eq __PACKAGE__
!ll&&!rl&&r
4130
MC/DC0%0/2
defined $_[0] and $_[0] eq __PACKAGE__
defined $_[0] $_[0] eq __PACKAGE__
Truth table66%2/3
A and B
A= defined $_[0]B= $_[0] eq __PACKAGE__
ABresult
0X0
100
111
416 17 my %opts;
417 my $out;
418 17 ▶ if(@_==0){
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 0) { } 3 14 17
elsif (@_ == 1) { } 4 10 14
419 3 $opts{error}=$@;
420 }
421 elsif(@_==1){
422 4 $opts{error}=shift;
423 }
424 else {
425 10 %opts=@_;
426 }
427 17 ▶ if($opts{frames}){
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"frames"}) 3 14 17
428 3 $opts{error}=delete $opts{frames};
429 }
430  
431 # For the special case of error undefined, we assume we want to dump the current location/context
432 #
433 17 ▶ unless(defined $opts{error}){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"error"}) 1 16 17
434 1 my $i=0;
435  
436 #build call frames
437 1 my @frame;
438 my @stack;
439  
440 1 ▶ while(@frame=caller($i++)){
Branch: 1 branch
BranchTrueFalseTotal
if (@frame = caller $i++) 1 1 2
441 1 push @stack, [@frame];
442 }
443 1 $opts{error}=\@stack;
444 }
445
446 # Convert from supported exceptions classes to internal format
447  
448 17 my $ref=ref $opts{error};
449 17 my $dstf="Devel::StackTrace::Frame";
450  
451 17 require Scalar::Util;
452 17 ▶ if((Scalar::Util::blessed($opts{error})//"") eq $dstf){
Branch: 5 branches
BranchTrueFalseTotal
if ((builtin::blessed($opts{'error'}) // '') eq $dstf) { } 0 17 17
elsif ($ref eq 'ARRAY' and ref $opts{'error'}[0] eq '') { } 0 17 17
elsif ($ref eq '') { } 13 4 17
elsif ($ref eq 'ARRAY' and ref $opts{'error'}[0] eq 'ARRAY') { } 4 0 4
elsif ($ref eq 'ARRAY' and builtin::blessed($opts{'error'}[0]) eq $dstf) { } 0 0 0
Condition50%1/2
builtin::blessed($opts{"error"}) // ""
l!l
017
MC/DC0%0/1
builtin::blessed($opts{"error"}) // ""
builtin::blessed($opts{"error"})
Truth table50%1/2
A
A= builtin::blessed($opts{"error"})
Aresult
11
00
453 # Single DSTF stack frame. Convert to an array
454 0 $opts{error}=[$opts{error}];
455 }
456 ▶ elsif($ref eq "ARRAY" and ref($opts{error}[0]) eq ""){
Condition66%2/3
$ref eq "ARRAY" and ref $opts{"error"}[0] eq ""
!ll&&!rl&&r
1340
MC/DC0%0/2
$ref eq "ARRAY" and ref $opts{"error"}[0] eq ""
$ref eq "ARRAY" ref $opts{"error"}[0] eq ""
Truth table66%2/3
A and B
A= $ref eq "ARRAY"B= ref $opts{"error"}[0] eq ""
ABresult
0X0
100
111
457 # Array of scalars - a normal stack frame - wrap it
458 0 $opts{error}=[[$opts{error}->@*]];
459 }
460 elsif($ref eq ""){
461 # Not a reference - A string error
462 }
463 ▶ elsif($ref eq "ARRAY" and ref($opts{error}[0]) eq "ARRAY"){
Condition33%1/3
$ref eq "ARRAY" and ref $opts{"error"}[0] eq "ARRAY"
!ll&&!rl&&r
004
MC/DC0%0/2
$ref eq "ARRAY" and ref $opts{"error"}[0] eq "ARRAY"
$ref eq "ARRAY" ref $opts{"error"}[0] eq "ARRAY"
Truth table33%1/3
A and B
A= $ref eq "ARRAY"B= ref $opts{"error"}[0] eq "ARRAY"
ABresult
0X0
100
111
464 # Array of arrays of scalars
465 4 $opts{error}=[map { [$_->@*] } $opts{error}->@* ];
466
467 }
468 ▶ elsif($ref eq "ARRAY" and Scalar::Util::blessed($opts{error}[0]) eq $dstf){
Condition0%0/3
$ref eq "ARRAY" and builtin::blessed($opts{"error"}[0]) eq $dstf
!ll&&!rl&&r
000
MC/DC0%0/2
$ref eq "ARRAY" and builtin::blessed($opts{"error"}[0]) eq $dstf
$ref eq "ARRAY" builtin::blessed($opts{"error"}[0]) eq $dstf
Truth table0%0/3
A and B
A= $ref eq "ARRAY"B= builtin::blessed($opts{"error"}[0]) eq $dstf
ABresult
0X0
100
111
469 #Array of DSTF object
470 }
471 else {
472 # Force stringification of error as a last ditch attempt
473 0 $opts{error}="$opts{error}";
474 }
475
476 17 DEBUG and say STDERR "Reverse flag set to: $opts{reverse}";
477  
478 # Reverse the ordering of errors here if requested
479 #
480 17 ▶ $opts{error}->@*=reverse $opts{error}->@* if $opts{reverse};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"reverse"} 1 16 17
481 # Check for trace kv pair. If this is present. We ignore the error
482 #
483 17 ▶ if(ref($opts{error}) eq "ARRAY" and ref $opts{error}[0]){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts{'error'} eq 'ARRAY' and ref $opts{'error'}[0]) { } 4 13 17
Condition66%2/3
ref $opts{"error"} eq "ARRAY" and ref $opts{"error"}[0]
!ll&&!rl&&r
1304
MC/DC50%1/2
ref $opts{"error"} eq "ARRAY" and ref $opts{"error"}[0]
ref $opts{"error"} eq "ARRAY" ref $opts{"error"}[0]
Truth table66%2/3
A and B
A= ref $opts{"error"} eq "ARRAY"B= ref $opts{"error"}[0]
ABresult
0X0
100
111
484 # Iterate through the list
485 4 ▶ my $_indent=$opts{indent}//=" ";
Condition50%1/2
$opts{"indent"} //= " "
l!l
04
MC/DC0%0/1
$opts{"indent"} //= " "
$opts{"indent"}
Truth table50%1/2
A
A= $opts{"indent"}
Aresult
11
00
486 4 my $current_indent="";
487  
488 4 my %_opts=%opts;
489 4 my $i=0; #Sequence number
490 4 for my $e ($opts{error}->@*) {
491  
492 11 ▶ if((Scalar::Util::blessed($e)//"") eq "Devel::StackTrace::Frame"){
Branch: 1 branch
BranchTrueFalseTotal
if ((builtin::blessed($e) // "") eq "Devel::StackTrace::Frame") 0 11 11
Condition50%1/2
builtin::blessed($e) // ""
l!l
011
MC/DC0%0/1
builtin::blessed($e) // ""
builtin::blessed($e)
Truth table50%1/2
A
A= builtin::blessed($e)
Aresult
11
00
493 #Convert to an array
494 0 my @a;
495 0 $a[PACKAGE]=$e->package;
496 0 $a[FILENAME]=$e->filename;
497 0 $a[LINE]=$e->line;
498 0 $a[SUBROUTINE]=$e->subroutine;
499 0 $a[HASARGS]=$e->hasargs;
500 0 $a[WANTARRAY]=$e->wantarray;
501 0 $a[EVALTEXT]=$e->evaltext;
502 0 $a[IS_REQUIRE]=$e->is_require;
503 0 $a[HINTS]=$e->hints;
504 0 $a[BITMASK]=$e->bitmask;
505 0 $a[HINT_HASH]=$e->hints;
506 0 $e=\@a;
507 }
508  
509  
510 11 ▶ if($e->[FILENAME] and $e->[LINE]){
Branch: 1 branch
BranchTrueFalseTotal
if ($e->[1] and $e->[2]) { } 11 0 11
Condition33%1/3
$e->[1] and $e->[2]
!ll&&!rl&&r
0011
MC/DC0%0/2
$e->[1] and $e->[2]
$e->[1] $e->[2]
Truth table33%1/3
A and B
A= $e->[1]B= $e->[2]
ABresult
0X0
100
111
511 11 ▶ $e->[MESSAGE]//="";
Condition50%1/2
$e->[11] //= ""
l!l
011
MC/DC0%0/1
$e->[11] //= ""
$e->[11]
Truth table50%1/2
A
A= $e->[11]
Aresult
11
00
512  
513 #Force a message if one is provided
514 11 $e->[LINE]--; #Make the error 0 based
515 11 ▶ $e->[MESSAGE]=$opts{message} if $opts{message};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"message"} 4 7 11
516 11 $e->[SEQUENCE]=$i++;
517
518 # Generate the context here
519 #
520 11 $_opts{indent}=$current_indent;
521 11 $_opts{error}=$e;
522 11 $out.=_context %_opts;
523 11 $current_indent.=$_indent;
524 }
525 else{
526 0 die $msg;
527 }
528 }
529  
530 }
531 else {
532 13 $out=_context %opts;
533 }
534 17 $out;
535 }
536  
537  
538  
539 4 my ($chld_in, $chld_out, $chld_err);
540 4 my @cmd="splain";
541 4 my $pid;
542  
543 sub splain {
544 0 ▶ my $out;
Subroutine splain: not called CC=5 SCAR=34.0
Pod documented
545 #Attempt to open splain process if it isn't already
546 0 ▶ unless($pid){
Branch: 1 branch
BranchTrueFalseTotal
unless ($pid) 0 0 0
547 0 eval{
548 0 $pid= IPC::Open3::open3($chld_in, $chld_out, $chld_err = Symbol::gensym(), @cmd);
549 #$chld_in->autoflush(1);
550  
551 };
552 0 ▶ if(!$pid and $@){
Branch: 1 branch
BranchTrueFalseTotal
if (not $pid and $@) 0 0 0
Condition0%0/3
not $pid and $@
!ll&&!rl&&r
000
MC/DC0%0/2
not $pid and $@
not $pid $@
Truth table0%0/3
not(A) and B
A= not $pidB= $@
ABresult
0X0
100
111
553 0 warn "Error::Show Could not splain the results";
554 }
555 };
556  
557 #Attempt to write to the process and read from it
558 0 eval {
559 0 print $chld_in $_[0], "\n";;
560 0 close $chld_in;
561 0 $out=<$chld_out>;
562 0 close $chld_out;
563 0 close $chld_err;
564 };
565  
566 0 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
567 0 $pid=undef;
568 0 close $chld_in;
569 0 close $chld_out;
570 0 close $chld_err;
571 0 warn "Error::Show Could not splain the results";
572 }
573 0 $out;
574 }
575  
576 #sub wrap_eval{
577 # my $program=shift;
578 # "sub { $program }";
579 #}
580  
581 4 1;
582 __END__
↑ Summary Show/Internal.pm »