Unexpected/TraitFor/TracingStacks.pm

filter: Statementstmt 100% 57 / 57 Branchbran 81.8% 18 / 22 (4 uncoverable) Conditioncond 83.3% 9 / 12 (3 uncoverable) MC/DCmcdc 87.5% 4 / 8 (3 uncoverable) Subroutinesub 100% 13 / 13 Podpod 100% 3 / 3 totaltotal 93.9% 104 / 115 (10 uncoverable) CC 17 SCAR 18.1
CC
17
Cov
93%
stacktrace
10.2
__ANON__
8.0
trace_frame_filter
1.0
CRAP 6.1
« Unexpected/TraitFor/ExceptionClasses.pm ↑ Summary Unexpected/Functions.pm »
1 package Unexpected::TraitFor::TracingStacks;
2  
3 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use Scalar::Util qw( weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Unexpected::Types qw( HashRef LoadableClass Tracer );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 requires qw( BUILD );
10  
11 # Object attributes (public)
12 25 ▶has 'trace' => is => 'lazy', isa => Tracer, builder => sub {
Subroutine _build_trace: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
13 25 $_[ 0 ]->trace_class->new( %{ $_[ 0 ]->trace_args } ) },
14 4 handles => [ qw( frames ) ], init_arg => undef;
15  
16 26 ▶has 'trace_args' => is => 'lazy', isa => HashRef, builder => sub { {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine _build_trace_args: called CC=1 SCAR=0.0
17 26 filter_frames_early => 1,
18 no_refs => 1,
19 respect_overload => 0,
20 max_arg_length => 0,
21 4 frame_filter => $_[ 0 ]->trace_frame_filter, } };
22  
23 4 has 'trace_class' => is => 'ro', isa => LoadableClass,
24 default => 'Devel::StackTrace';
25  
26 # Construction
27 31 ▶before 'BUILD' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
28 31 my $self = shift; $self->trace; return;
29 4 };
30  
31 # Public methods
32 1 ▶sub message { # Stringify self and a full stack trace
Subroutine message: called CC=1 SCAR=0.0
Pod documented
33 1 my $self = shift; return "${self}\n".$self->trace->as_string."\n";
34 }
35  
36 3 ▶sub stacktrace {
Subroutine stacktrace: called CC=10 SCAR=23.2
Pod documented
37 3 my ($self, $skip) = @_; my (@lines, %seen, $subr);
38  
39 3 for my $frame (reverse $self->frames) {
40 12 my $package = $frame->package; my $l_no;
41  
42 12 ▶ unless ($l_no = $seen{ $package } and $l_no == $frame->line) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($l_no = $seen{$package} and $l_no == $frame->line) 9 3 12
Condition100%3/3
$l_no = $seen{$package} and $l_no == $frame->line
!ll&&!rl&&r
363
MC/DC100%2/2
$l_no = $seen{$package} and $l_no == $frame->line
$l_no = $seen{$package} $l_no == $frame->line
Truth table100%3/3
A and B
A= $l_no = $seen{$package}B= $l_no == $frame->line
ABresult
0X0
100
111
43 9 ▶ my $lead = $subr || $package; # uncoverable condition false
Condition100%2/3
$subr || $package
l!l&&r!l&&!r
630
MC/DC100%0/2
$subr || $package
$subr $package
Truth table100%2/3
A || B
A= $subrB= $package
ABresult
1X1
011
000
44  
45 # uncoverable branch false
46 9 ▶ $lead !~ m{ (?: \A \(eval\) ) | (?: ::try) | (?: :: __ANON__ \z) }mx
Branch: 1 branch
BranchTrueFalseTotal
$lead =~ / (?: \A \(eval\) ) | (?: ::try) | (?: :: __ANON__ \z) /mx or push @lines, join(" ", $lead, "line", $frame->line) 0 9 9
47 and push @lines, join q( ), $lead, 'line', $frame->line;
48 9 $seen{ $package } = $frame->line;
49 }
50  
51 12 ▶ $frame->subroutine !~ m{ :: __ANON__ \z }mx # uncoverable branch false
Branch: 1 branch
BranchTrueFalseTotal
$frame->subroutine =~ / :: __ANON__ \z /mx or $subr = $frame->subroutine 0 12 12
52 and $subr = $frame->subroutine;
53 }
54  
55 3 ▶ defined $skip or $skip = 0; pop @lines while ($skip--);
Branch: 2 branches
BranchTrueFalseTotal
defined $skip or $skip = 0 1 2 3
$skip-- and do { pop @lines } 1 3 4
56  
57 3 ▶ return wantarray ? reverse @lines : (join "\n", reverse @lines)."\n";
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 1 3
58 }
59  
60 30 ▶sub trace_frame_filter { # Lifted from StackTrace::Auto
Subroutine trace_frame_filter: called CC=1 SCAR=0.0
Pod documented
61 30 my $self = shift; my $found_mark = 0; weaken( $self );
62  
63 268 ▶ return sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
64 268 my ($raw) = @_;
65 268 my $subr = $raw->{caller}->[ 3 ];
66 268 (my $package = $subr) =~ s{ :: \w+ \z }{}mx;
67  
68 # uncoverable branch true
69 # uncoverable condition right
70 268 ▶ $ENV{UNEXPECTED_SHOW_RAW_TRACE} and warn "${subr}\n";
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"UNEXPECTED_SHOW_RAW_TRACE"} and warn "$subr\n" 0 268 268
71  
72 268 ▶ if ($found_mark == 2) { return 1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($found_mark == 2) { } 59 209 268
elsif ($found_mark == 1) { } 29 180 209
73 elsif ($found_mark == 1) {
74 # uncoverable branch true
75 # uncoverable condition right
76 29 ▶ $subr =~ m{ :: new \z }mx and $self->isa( $package ) and return 0;
Branch: 1 branch
BranchTrueFalseTotal
$subr =~ / :: new \z /mx and $self->isa($package) and return 0 0 29 29
Condition66%1/3
$subr =~ / :: new \z /mx and $self->isa($package)
!ll&&!rl&&r
2900
MC/DC50%0/2
$subr =~ / :: new \z /mx and $self->isa($package)
$subr =~ / :: new \z /mx $self->isa($package)
Truth table66%1/3
A and B
A= $subr =~ / :: new \z /mxB= $self->isa($package)
ABresult
0X0
100
111
77 29 $found_mark++; return 1;
78 }
79  
80 # uncoverable condition right
81 180 ▶ $subr =~ m{ :: new \z }mx and $self->isa( $package ) and $found_mark++;
Branch: 1 branch
BranchTrueFalseTotal
$subr =~ / :: new \z /mx and $self->isa($package) and ++$found_mark 30 150 180
Condition66%3/3
$subr =~ / :: new \z /mx and $self->isa($package)
!ll&&!rl&&r
1203030
MC/DC100%2/2
$subr =~ / :: new \z /mx and $self->isa($package)
$subr =~ / :: new \z /mx $self->isa($package)
Truth table66%3/3
A and B
A= $subr =~ / :: new \z /mxB= $self->isa($package)
ABresult
0X0
100
111
82 180 return 0;
83 }
84 30 }
85  
86 4 1;
87  
88 __END__
« Unexpected/TraitFor/ExceptionClasses.pm ↑ Summary Unexpected/Functions.pm »