| 1 | package Error::Show; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.024000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use feature "say"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use POSIX; #For _exit; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use IPC::Open3; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Symbol 'gensym'; # vivify a separate handle for STDERR | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Scalar::Util qw<blessed>; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | #use Exporter qw<import>; | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use base "Exporter"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | our %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | ) ] ); | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} }); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | our @EXPORT = qw(); | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | our $VERSION = 'v0.1.0'; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use constant DEBUG=>0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | use enum ("PACKAGE=0",qw<FILENAME LINE SUBROUTINE | |||||||||||||||||||||||||||||||||||||||||
| 29 | HASARGS WANTARRAY EVALTEXT IS_REQUIRE HINTS BITMASK | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | HINT_HASH MESSAGE SEQUENCE CODE_LINES>); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | ################################ | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # my $buffer=""; # | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # open THITHER ,">",\$buffer; # | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ################################ | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | # | ||||||||||||||||||||||||||||||||||||||||||
| 39 | # A list of top level file paths or scalar refs to check for syntax errors | ||||||||||||||||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | my @IINC; | |||||||||||||||||||||||||||||||||||||||||
| 42 | sub context; | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | sub import { | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | ▶ | my $package=shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=16 SCAR=54.2
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | my @caller=caller; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | my @options=@_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # We don't export anything. Return when we are used withing code | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # Continue if caller has no line number, meaning from the CLI | ||||||||||||||||||||||||||||||||||||||||||
| 53 | # | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | return if($caller[LINE]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # CLI Options include | ||||||||||||||||||||||||||||||||||||||||||
| 58 | # | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my %options; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $clean=grep /clean/i, @options; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $splain=grep /splain/i, @options; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $do_warn=grep /warn/i, @options; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my @warn=$do_warn?():"-MError::Show::Internal"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # 1. Command line argument activation ie -MError::Show | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # Find out any extra lib paths used. To do this we: | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # a. fork/exec a new perl process using the value of $^X. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # b. The new process dumps the @INC array to STDOUT | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # c. This process reads the output and stores in @IINC | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # Only run it the first time its used | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # Is this the best way? Not sure. At least this way there is no argument | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # processing, perl process does it for us. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | @IINC=map {chomp; $_} do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | open my $fh, "-|", $^X . q| -E 'map print("$_\n"), @INC'| or die "$!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } unless @IINC; | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | # | ||||||||||||||||||||||||||||||||||||||||||
| 88 | # 2. Extract the extra include paths | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # Built up the 'extra' array of any include paths not already listed | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # from the STDOUT dumping above | ||||||||||||||||||||||||||||||||||||||||||
| 92 | # | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my @extra=map {("-I", $_)} grep {my $i=$_; !grep { $i eq $_} @IINC} @INC; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | # | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # 3. Syntax checking the program | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # Now we have the include paths sorted, | ||||||||||||||||||||||||||||||||||||||||||
| 101 | # a. fork/exec again, this time with the -c switch for perl to check syntax | ||||||||||||||||||||||||||||||||||||||||||
| 102 | # b. slurp STDERR from child process | ||||||||||||||||||||||||||||||||||||||||||
| 103 | # c. execute the context routine to parse and show more source code context | ||||||||||||||||||||||||||||||||||||||||||
| 104 | # d. print! | ||||||||||||||||||||||||||||||||||||||||||
| 105 | # The proc | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | local $/=undef; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $file=$0; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | #push @file, @ARGV; | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | #my $runnable=not $^C;#$options{check}; | ||||||||||||||||||||||||||||||||||||||||||
| 113 | #for my $file(@file){ | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 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
Condition0%0/6
$file eq "-e" or $file eq "-E" or $file eq "-"
$file eq "-e" or $file eq "-E"
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 "-"
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | die "Error::Show cannot access \"$file\"" unless -f $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my @cmd= ($^X ,@warn, @extra, "-c", $file); | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $pid; | |||||||||||||||||||||||||||||||||||||||||
| 119 | my $result; | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $pid=open3(my $chld_in, my $chld_out, my $chld_err = gensym, @cmd); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $result=<$chld_err>; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | close $chld_in; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | close $chld_out; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | close $chld_err; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | wait; | |||||||||||||||||||||||||||||||||||||||||
| 127 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if(!$pid and $@){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $pid and $@
MC/DC0%0/2
not $pid and $@
not $pid
$@
Truth table0%0/3
not(A) and B
A= not $pidB= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | die "Error::Show failed to syntax check"; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | # | ||||||||||||||||||||||||||||||||||||||||||
| 134 | # 4. Status code from child indicates success | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # When 0 this means syntax was ok. Otherwise error | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # Attempt to propogate code to exit status | ||||||||||||||||||||||||||||||||||||||||||
| 137 | # | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | my $code=$?>255? (0xFF & ~$?): $?; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $runnable=$?==0; | |||||||||||||||||||||||||||||||||||||||||
| 141 | #say "SYNTAX RUNNABLE: $runnable"; | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $status=context(splain=>$splain, clean=>$clean, error=>$result )."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if($^C){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if($runnable){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | #only print status if we want warnings | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | print STDERR $do_warn?$status: "$file syntax OK\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | else{ | ||||||||||||||||||||||||||||||||||||||||||
| 152 | #Not runnable, thus syntax error. Always print | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | print STDERR $status; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | POSIX::_exit $code; | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | else{ | ||||||||||||||||||||||||||||||||||||||||||
| 160 | #not checking, we want to run | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if($runnable){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | # don't bother with warnings | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | else{ | ||||||||||||||||||||||||||||||||||||||||||
| 166 | #Not runnable, thus syntax error. Always print | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | print STDERR $status; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | POSIX::_exit $code; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | our %exception_adaptors; | |||||||||||||||||||||||||||||||||||||||||
| 175 | ▶ | $exception_adaptors{"Exception::Base"}=sub { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | $exception_adaptors{"Exception::Class::Base"}=sub { | ||||||||||||||||||||||||||||||||||||||||||
| 180 | #take an error | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | my $e=shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | sub process_ref_errror{ | ||||||||||||||||||||||||||||||||||||||||||
| 186 | # | ||||||||||||||||||||||||||||||||||||||||||
| 187 | # This can only be a (single) runtime error | ||||||||||||||||||||||||||||||||||||||||||
| 188 | # | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | my $error=pop; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_ref_errror: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my %opts=@_; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my $ref=ref $error; | |||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my %entry; | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | # | ||||||||||||||||||||||||||||||||||||||||||
| 197 | # TODO: | ||||||||||||||||||||||||||||||||||||||||||
| 198 | # Lookup handler code to process this type of error | ||||||||||||||||||||||||||||||||||||||||||
| 199 | # | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | \%entry; | |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | sub process_string_error{ | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 9 | ▶ | my $error=pop; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_string_error: called CC=7 SCAR=19.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 9 | my %opts=@_; | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 9 | my @error_lines; | |||||||||||||||||||||||||||||||||||||||||
| 210 | my @errors; | ||||||||||||||||||||||||||||||||||||||||||
| 211 | #my @entry; | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 9 | my %entry; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 9 | ▶ | if(defined $error){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | #local $_=$error; | ||||||||||||||||||||||||||||||||||||||||||
| 215 | #Substitue with a line number relative to the start marker | ||||||||||||||||||||||||||||||||||||||||||
| 216 | #Reported line numbers are 1 based, stored lines are 0 based | ||||||||||||||||||||||||||||||||||||||||||
| 217 | #my $translation=$opts{translation}; | ||||||||||||||||||||||||||||||||||||||||||
| 218 | #my $start=$opts{start}; | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 9 | my $i=0; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 9 | for(split "\n", $error){ | |||||||||||||||||||||||||||||||||||||||||
| 222 | 6 | ▶ | if(/at (.*?) line (\d+)/){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | # | ||||||||||||||||||||||||||||||||||||||||||
| 224 | # Group by file names | ||||||||||||||||||||||||||||||||||||||||||
| 225 | # | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 6 | ▶ | my $entry=$entry{$1}//=[]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$entry{$1} //= []
MC/DC0%0/1
$entry{$1} //= []
$entry{$1}
Truth table50%1/2
A
A= $entry{$1}
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | #push @$entry, {file=>$1, line=>$2,message=>$_, sequence=>$i++}; | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 6 | my $a=[]; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 6 | $a->[FILENAME]=$1; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 6 | $a->[LINE]=$2; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 6 | $a->[MESSAGE]=$_; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 6 | ▶ | $a->[MESSAGE]=$opts{message} if $opts{message}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 6 | $a->[SEQUENCE]=$i++; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 6 | ▶ | $a->[EVALTEXT]=$opts{program} if $opts{program}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 6 | push @$entry, $a; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 242 | #Assume a target line | ||||||||||||||||||||||||||||||||||||||||||
| 243 | #push @error_lines, $opts{line}-1; | ||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | #Key is file name | ||||||||||||||||||||||||||||||||||||||||||
| 247 | # value is a hash of filename,line number, perl error string and the sequence number | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 9 | \%entry; | |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | sub text_output { | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 13 | ▶ | my $info_ref=pop; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text_output: called CC=12 SCAR=25.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 13 | my %opts=@_; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 13 | my $total=""; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | # Sort by sequence number | ||||||||||||||||||||||||||||||||||||||||||
| 259 | # Errors are stored by filename internally. Sort by sequence number. | ||||||||||||||||||||||||||||||||||||||||||
| 260 | # | ||||||||||||||||||||||||||||||||||||||||||
| 261 | my @sorted_info= | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 3 | sort { $a->[SEQUENCE] <=> $b->[SEQUENCE] } | |||||||||||||||||||||||||||||||||||||||||
| 263 | 13 | map { $_->@* } values %$info_ref; | |||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | # Process each of the errors in sequence | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 13 | for my $info (@sorted_info){ | |||||||||||||||||||||||||||||||||||||||||
| 267 | 10 | ▶ | unless(exists $info->[CODE_LINES]){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 10 | my @code; | |||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 10 | ▶ | if($info->[EVALTEXT]){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | @code=split "\n", $info->[EVALTEXT]; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 10 | @code=split "\n", do { | |||||||||||||||||||||||||||||||||||||||||
| 275 | 10 | ▶ | open my $fh, "<", $info->[FILENAME] or warn "Could not open file for reading: $info->[FILENAME]"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 10 | local $/=undef; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 10 | <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 278 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 10 | $info->[CODE_LINES]=\@code; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 10 | my $min=$info->[LINE]-$opts{pre_lines}; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 10 | my $max=$info->[LINE]+$opts{post_lines}; | |||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 10 | my $target= $info->[LINE]; | |||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 10 | ▶ | $min=$min<0 ? 0: $min; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 10 | my $count=$info->[CODE_LINES]->@*; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 10 | ▶ | $max=$max>=$count?$count:$max; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | # | ||||||||||||||||||||||||||||||||||||||||||
| 293 | # format counter on the largest number to be expected | ||||||||||||||||||||||||||||||||||||||||||
| 294 | # | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 10 | my $f_len=length("$max"); | |||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 10 | my $out="$opts{indent}$info->[FILENAME]\n"; | |||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 10 | ▶ | my $indent=$opts{indent}//""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"indent"} // ""
MC/DC0%0/1
$opts{"indent"} // ""
$opts{"indent"}
Truth table50%1/2
A
A= $opts{"indent"}
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 10 | my $format="$indent%${f_len}d% 2s %s\n"; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 10 | my $mark=""; | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | #Change min and max to one based index | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 10 | $min++; | |||||||||||||||||||||||||||||||||||||||||
| 305 | #$max--; | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 10 | for my $l($min..$max){ | |||||||||||||||||||||||||||||||||||||||||
| 308 | 82 | $mark=""; | |||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | #Perl line number is 1 based | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 82 | ▶ | $mark="=>" if $l==$info->[LINE]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | #However our code lines are stored in a 0 based array | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 82 | $out.=sprintf $format, $l, $mark, $info->[CODE_LINES][$l-1]; | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 10 | $total.=$out; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 10 | ▶ | $total.=$info->[MESSAGE]."\n" unless $opts{clean}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 13 | ▶ | if($opts{splain}){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $total=splain($total); | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 13 | $total; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | #Take an error string and attempt to contextualize it | ||||||||||||||||||||||||||||||||||||||||||
| 328 | # context options_pairs, error string | ||||||||||||||||||||||||||||||||||||||||||
| 329 | sub _context{ | ||||||||||||||||||||||||||||||||||||||||||
| 330 | #use feature ":all"; | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 13 | ▶ | DEBUG and say STDERR "IN context call"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_context: called CC=13 SCAR=27.3
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | #my ($package, $file, $caller_line)=caller; | ||||||||||||||||||||||||||||||||||||||||||
| 333 | # | ||||||||||||||||||||||||||||||||||||||||||
| 334 | # Error is set by single argument, key/value pair, or if no | ||||||||||||||||||||||||||||||||||||||||||
| 335 | # argument $@ is used | ||||||||||||||||||||||||||||||||||||||||||
| 336 | # | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 13 | my %opts=@_; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 13 | my $error= $opts{error}; | |||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 13 | ▶ | $opts{start_mark}//=qr|.*|; #regex which matches the start of the code | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{"start_mark"} //= qr/.*/u
MC/DC0%0/2
$opts{"start_mark"} //= qr/.*/u
$opts{"start_mark"}
qr/.*/u
Truth table33%1/3
A //= B
A= $opts{"start_mark"}B= qr/.*/u
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 13 | ▶ | $opts{pre_lines}//=5; #Number of lines to show before target line | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"pre_lines"} //= 5
MC/DC0%0/1
$opts{"pre_lines"} //= 5
$opts{"pre_lines"}
Truth table50%1/2
A
A= $opts{"pre_lines"}
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 13 | ▶ | $opts{post_lines}//=5; #Number of lines to show after target line | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"post_lines"} //= 5
MC/DC0%0/1
$opts{"post_lines"} //= 5
$opts{"post_lines"}
Truth table50%1/2
A
A= $opts{"post_lines"}
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 13 | ▶ | $opts{offset_start}//=0; #Offset past start to consider as min line | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"offset_start"} //= 0
MC/DC0%0/1
$opts{"offset_start"} //= 0
$opts{"offset_start"}
Truth table50%1/2
A
A= $opts{"offset_start"}
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 13 | ▶ | $opts{offset_end}//=0; #Offset before end to consider as max line | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"offset_end"} //= 0
MC/DC0%0/1
$opts{"offset_end"} //= 0
$opts{"offset_end"}
Truth table50%1/2
A
A= $opts{"offset_end"}
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 13 | ▶ | $opts{translation}//=0; #A static value added to the line numbering | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"translation"} //= 0
MC/DC0%0/1
$opts{"translation"} //= 0
$opts{"translation"}
Truth table50%1/2
A
A= $opts{"translation"}
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 13 | ▶ | $opts{indent}//=""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{"indent"} //= ""
MC/DC100%1/1
$opts{"indent"} //= ""
$opts{"indent"}
Truth table100%2/2
A
A= $opts{"indent"}
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 13 | ▶ | $opts{file}//=""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"file"} //= ""
MC/DC0%0/1
$opts{"file"} //= ""
$opts{"file"}
Truth table50%1/2
A
A= $opts{"file"}
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | # Get the all the info we need to process | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 13 | my $info_ref; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 13 | ▶ | if(defined($error) and ref($error) eq ""){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $error and ref $error eq ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | #A string error. A normal string die/warn or compile time errors/warnings | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 9 | $info_ref=process_string_error %opts, $error; | |||||||||||||||||||||||||||||||||||||||||
| 357 | #say "infor ref ".join ", ", $info_ref; | ||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | else{ | ||||||||||||||||||||||||||||||||||||||||||
| 360 | #Some kind of object, converted into line and file hash | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 4 | $info_ref= {$error->[FILENAME]=>[$error]};# {$error->{file}=>[$error]}; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 4 | ▶ | $error->[MESSAGE]=$opts{message}//""; #Store the message | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"message"} // ""
MC/DC0%0/1
$opts{"message"} // ""
$opts{"message"}
Truth table50%1/2
A
A= $opts{"message"}
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 4 | ▶ | $error->[EVALTEXT]=$opts{program} if $opts{program}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | # Override text/file to search | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 13 | my $output; | |||||||||||||||||||||||||||||||||||||||||
| 368 | 13 | $output=text_output %opts, $info_ref; | |||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | #TODO: | ||||||||||||||||||||||||||||||||||||||||||
| 371 | # | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 13 | $output; | |||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | # | ||||||||||||||||||||||||||||||||||||||||||
| 378 | # This only works with errors objects which captured a trace as a Devel::StackTrace object | ||||||||||||||||||||||||||||||||||||||||||
| 379 | # | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 2 | my $msg= "Trace must be a ref to array of {file=>.., line=>..} pairs"; | |||||||||||||||||||||||||||||||||||||||||
| 381 | sub context{ | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 10 | ▶ | my %opts; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
context: called CC=23 SCAR=41.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | my $out; | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 10 | ▶ | if(@_==0){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 3 | $opts{error}=$@; | |||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 387 | elsif(@_==1){ | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 3 | $opts{error}=shift; | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 4 | %opts=@_; | |||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 10 | ▶ | if($opts{frames}){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 1 | $opts{error}=delete $opts{frames}; | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | # Convert from supported exceptions classes to internal format | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 10 | my $ref=ref $opts{error}; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 10 | my $dstf="Devel::StackTrace::Frame"; | |||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 10 | ▶ | if((blessed($opts{error})//"") eq $dstf){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition50%1/2
builtin::blessed($opts{"error"}) // ""
MC/DC0%0/1
builtin::blessed($opts{"error"}) // ""
builtin::blessed($opts{"error"})
Truth table50%1/2
A
A= builtin::blessed($opts{"error"})
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | # Single DSTF stack frame. Convert to an array | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $opts{error}=[$opts{error}]; | |||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | ▶ | elsif($ref eq "ARRAY" and ref($opts{error}[0]) eq ""){ | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$ref eq "ARRAY" and ref $opts{"error"}[0] eq ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | # Array of scalars - a normal stack frame - wrap it | ||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | $opts{error}=[$opts{error}]; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | elsif($ref eq ""){ | ||||||||||||||||||||||||||||||||||||||||||
| 413 | # Not a reference - A string error | ||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | ▶ | elsif($ref eq "ARRAY" and ref($opts{error}[0]) eq "ARRAY"){ | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$ref eq "ARRAY" and ref $opts{"error"}[0] eq "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | # Array of arrays of scalars | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | ▶ | elsif($ref eq "ARRAY" and blessed($opts{error}[0]) eq $dstf){ | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ref eq "ARRAY" and builtin::blessed($opts{"error"}[0]) eq $dstf
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
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | #Array of DSTF object | ||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 423 | #warn "Expecting a string, caller() type array or a $dstf object, or arrays of these"; | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $opts{error}="$opts{error}"; | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | #Check for trace kv pair. If this is present. We ignore the error | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 10 | ▶ | if(ref($opts{error}) eq "ARRAY" and ref $opts{error}[0]){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $opts{"error"} eq "ARRAY" and ref $opts{"error"}[0]
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]
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | # Iterate through the list | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | ▶ | my $_indent=$opts{indent}//=" "; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"indent"} //= " "
MC/DC0%0/1
$opts{"indent"} //= " "
$opts{"indent"}
Truth table50%1/2
A
A= $opts{"indent"}
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 1 | my $current_indent=""; | |||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | 1 | my %_opts=%opts; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 1 | for my $e ($opts{error}->@*) { | |||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 4 | ▶ | if((blessed($e)//"") eq "Devel::StackTrace::Frame"){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
builtin::blessed($e) // ""
MC/DC0%0/1
builtin::blessed($e) // ""
builtin::blessed($e)
Truth table50%1/2
A
A= builtin::blessed($e)
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | #Convert to an array | ||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | my @a; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | $a[PACKAGE]=$e->package; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | $a[FILENAME]=$e->filename; | |||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | $a[LINE]=$e->line; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | $a[SUBROUTINE]=$e->subroutine; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | $a[HASARGS]=$e->hasargs; | |||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | $a[WANTARRAY]=$e->wantarray; | |||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $a[EVALTEXT]=$e->evaltext; | |||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | $a[IS_REQUIRE]=$e->is_require; | |||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | $a[HINTS]=$e->hints; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | $a[BITMASK]=$e->bitmask; | |||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | $a[HINT_HASH]=$e->hints; | |||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | $e=\@a; | |||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | 4 | ▶ | if($e->[FILENAME] and $e->[LINE]){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$e->[1] and $e->[2]
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]
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 4 | ▶ | $e->[MESSAGE]//=""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$e->[11] //= ""
MC/DC0%0/1
$e->[11] //= ""
$e->[11]
Truth table50%1/2
A
A= $e->[11]
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | #Force a message if one is provided | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 4 | ▶ | $e->[MESSAGE]=$opts{message} if $opts{message}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 4 | $_opts{indent}=$current_indent; | |||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 4 | $_opts{error}=$e; | |||||||||||||||||||||||||||||||||||||||||
| 462 | 4 | $out.=_context %_opts; | |||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 4 | $current_indent.=$_indent; | |||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | else{ | ||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | die $msg; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 473 | #say "NOT AN ARRAY: ". join ", ", %opts; | ||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 9 | $out=_context %opts; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | 10 | $out; | |||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 2 | my ($chld_in, $chld_out, $chld_err); | |||||||||||||||||||||||||||||||||||||||||
| 481 | 2 | my @cmd="splain"; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 2 | my $pid; | |||||||||||||||||||||||||||||||||||||||||
| 483 | sub splain { | ||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | my $out; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
splain: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | #Attempt to open splain process if it isn't already | ||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | unless($pid){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | eval{ | |||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | $pid= open3($chld_in, $chld_out, $chld_err = gensym, @cmd); | |||||||||||||||||||||||||||||||||||||||||
| 489 | #$chld_in->autoflush(1); | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | if(!$pid and $@){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $pid and $@
MC/DC0%0/2
not $pid and $@
not $pid
$@
Truth table0%0/3
not(A) and B
A= not $pidB= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | warn "Error::Show Could not splain the results"; | |||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | #Attempt to write to the process and read from it | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | print $chld_in $_[0], "\n";; | |||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | close $chld_in; | |||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | $out=<$chld_out>; | |||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | close $chld_out; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | close $chld_err; | |||||||||||||||||||||||||||||||||||||||||
| 504 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | ▶ | if($@){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | $pid=undef; | |||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | close $chld_in; | |||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | close $chld_out; | |||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | close $chld_err; | |||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | warn "Error::Show Could not splain the results"; | |||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | $out; | |||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | sub wrap_eval{ | ||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | my $program=shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wrap_eval: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | "sub { $program }"; | |||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 521 | __END__ | ||||||||||||||||||||||||||||||||||||||||||