blib/lib/Devel/Confess/Source.pm

filter: Statementstmt 93.7% 45 / 48 Branchbran 76.9% 20 / 26 Conditioncond 66.6% 12 / 18 MC/DCmcdc 45.4% 5 / 11 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 80.1% 89 / 111 SCAR 31.8
CC
22
Cov
84%
source_trace
16.7
import
6.3
_get_content
5.0
CRAP 24.1
« blib/lib/Devel/Confess/Builtin.pm ↑ Summary blib/lib/Devel/Confess/_Util.pm »
1 package Devel::Confess::Source;
2 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 sub import {
7 10 ▶ $^P |= "$]" >= 5.010 ? 0x400 : do {
Subroutine import: called CC=3 SCAR=18.4
Branch: 1 branch
BranchTrueFalseTotal
"$]" >= 5.01 ? : 10 0 10
8 *DB::DB = sub {}
9 0 ▶ unless defined &DB::DB;
Branch: 1 branch
BranchTrueFalseTotal
unless defined &DB::DB 0 0 0
10 0 0x02;
11 };
12 }
13  
14 my $want_color = $^O ne 'MSWin32' ? 1 : eval {
15 require Win32::Console::ANSI;
16 Win32::Console::ANSI->import;
17 1;
18 };
19  
20 sub source_trace {
21 19 ▶ my ($skip, $context, $evalonly) = @_;
Subroutine source_trace: called CC=16 SCAR=28.2
Pod undocumented
22 19 ▶ $skip ||= 1;
Condition50%1/2
$skip ||= 1
l!l
190
MC/DC0%0/1
$skip ||= 1
$skip
Truth table50%1/2
A
A= $skip
Aresult
11
00
23 19 $skip += $Carp::CarpLevel;
24 19 ▶ $context ||= 3;
Condition50%1/2
$context ||= 3
l!l
190
MC/DC0%0/1
$context ||= 3
$context
Truth table50%1/2
A
A= $context
Aresult
11
00
25 19 my $i = $skip;
26 19 my @out;
27 19 ▶ while (my ($pack, $file, $line) = (caller($i++))[0..2]) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = (caller $i++)[0..2]) 154 19 173
28 next
29 154 ▶ if $Carp::Internal{$pack} || $Carp::CarpInternal{$pack};
Branch: 1 branch
BranchTrueFalseTotal
if $Carp::Internal{$pack} or $Carp::CarpInternal{$pack} 50 104 154
Condition100%3/3
$Carp::Internal{$pack} or $Carp::CarpInternal{$pack}
l!l&&r!l&&!r
3812104
MC/DC100%2/2
$Carp::Internal{$pack} or $Carp::CarpInternal{$pack}
$Carp::Internal{$pack} $Carp::CarpInternal{$pack}
Truth table100%3/3
A or B
A= $Carp::Internal{$pack}B= $Carp::CarpInternal{$pack}
ABresult
1X1
011
000
30 next
31 104 ▶ if $evalonly && $file !~ /^\(eval \d+\)(?:\[|$)/;
Branch: 1 branch
BranchTrueFalseTotal
if $evalonly and not $file =~ /^\(eval \d+\)(?:\[|$)/ 0 104 104
Condition33%1/3
$evalonly and not $file =~ /^\(eval \d+\)(?:\[|$)/
!ll&&!rl&&r
10400
MC/DC0%0/2
$evalonly and not $file =~ /^\(eval \d+\)(?:\[|$)/
$evalonly not $file =~ /^\(eval \d+\)(?:\[|$)/
Truth table33%1/3
A and not(B)
A= $evalonlyB= not $file =~ /^\(eval \d+\)(?:\[|$)/
ABresult
0X0
100
111
32 104 ▶ my $lines = _get_content($file) || next;
Condition50%1/2
_get_content($file) || (next)
l!l
1040
MC/DC0%0/1
_get_content($file) || (next)
_get_content($file)
Truth table50%1/2
A
A= _get_content($file)
Aresult
11
00
33  
34 104 my $start = $line - $context;
35 104 ▶ $start = 1 if $start < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $start < 1 18 86 104
36 104 ▶ $start = $#$lines if $start > $#$lines;
Branch: 1 branch
BranchTrueFalseTotal
if $start > $lines->$#* 7 97 104
37 104 my $end = $line + $context;
38 104 ▶ $end = $#$lines if $end > $#$lines;
Branch: 1 branch
BranchTrueFalseTotal
if $end > $lines->$#* 23 81 104
39  
40 104 my $context = "context for $file line $line:\n";
41 104 for my $read_line ($start..$end) {
42 646 my $code = $lines->[$read_line];
43 646 $code =~ s/\n\z//;
44 646 ▶ if ($want_color && $read_line == $line) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_color and $read_line == $line) 97 549 646
Condition66%2/3
$want_color and $read_line == $line
!ll&&!rl&&r
054997
MC/DC50%1/2
$want_color and $read_line == $line
$want_color $read_line == $line
Truth table66%2/3
A and B
A= $want_colorB= $read_line == $line
ABresult
0X0
100
111
45 97 $code = "\e[30;43m$code\e[m";
46 }
47 646 $context .= sprintf "%5s : %s\n", $read_line, $code;
48 }
49 104 push @out, $context;
50 }
51 19 ▶ return ''
Branch: 1 branch
BranchTrueFalseTotal
unless @out 0 19 19
52 if !@out;
53 19 return join(('=' x 75) . "\n",
54 '',
55 join(('-' x 75) . "\n", @out),
56 '',
57 );
58 }
59  
60 sub _get_content {
61 104 ▶ my $file = shift;
Subroutine _get_content: called CC=5 SCAR=16.1
62 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
63 104 ▶ if (exists $::{'_<'.$file} && @{ '::_<'.$file }) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $main::main::{'_<' . $file} and @{'::_<' . $file;}) { } 56 48 104
elsif ($file =~ /^\(eval \d+\)(?:\[.*\])?$/) { } 7 41 48
elsif (open my $fh, '<', $file) { } 41 0 41
Condition100%3/3
exists $main::main::{'_<' . $file} and @{'::_<' . $file;}
!ll&&!rl&&r
74156
MC/DC100%2/2
exists $main::main::{'_<' . $file} and @{'::_<' . $file;}
exists $main::main::{'_<' . $file} @{'::_<' . $file;}
Truth table100%3/3
A and B
A= exists $main::main::{'_<' . $file}B= @{'::_<' . $file;}
ABresult
0X0
100
111
64 56 return \@{ '::_<'.$file };
65 }
66 elsif ($file =~ /^\(eval \d+\)(?:\[.*\])?$/) {
67 7 return ["Can't get source of evals unless debugger available!"];
68 }
69 elsif (open my $fh, '<', $file) {
70 41 my @lines = ('', <$fh>);
71 41 return \@lines;
72 }
73 else {
74 0 return ["Source file not available!"];
75 }
76 }
77  
78 1;
« blib/lib/Devel/Confess/Builtin.pm ↑ Summary blib/lib/Devel/Confess/_Util.pm »