| 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
Condition100%3/3
$l_no = $seen{$package} and $l_no == $frame->line
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
| |||||||||||||||||||||||||||||
| 43 | 9 | ▶ | my $lead = $subr || $package; # uncoverable condition false | ||||||||||||||||||||||||||
|
Condition100%2/3
$subr || $package
MC/DC100%0/2
$subr || $package
$subr
$package
Truth table100%2/3
A || B
A= $subrB= $package
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # uncoverable branch false | ||||||||||||||||||||||||||||
| 46 | 9 | ▶ | $lead !~ m{ (?: \A \(eval\) ) | (?: ::try) | (?: :: __ANON__ \z) }mx | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 52 | and $subr = $frame->subroutine; | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 3 | ▶ | defined $skip or $skip = 0; pop @lines while ($skip--); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 3 | ▶ | return wantarray ? reverse @lines : (join "\n", reverse @lines)."\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 268 | ▶ | if ($found_mark == 2) { return 1 } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
Condition66%1/3
$subr =~ / :: new \z /mx and $self->isa($package)
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)
| |||||||||||||||||||||||||||||
| 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
Condition66%3/3
$subr =~ / :: new \z /mx and $self->isa($package)
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)
| |||||||||||||||||||||||||||||
| 82 | 180 | return 0; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 30 | } | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 4 | 1; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||