GX/Exception/StackTrace.pm

filter: Statementstmt 91.1% 41 / 45 Branchbran 62.5% 5 / 8 Conditioncond 44.4% 4 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 78.5% 11 / 14 Podpod 100% 5 / 5 totaltotal 76.7% 66 / 86 CC 9 SCAR 10.5
CC
9
Cov
81%
frames
6.0
as_string
5.2
build
3.0
CRAP 2.9
« GX/HTTP/Response.pm ↑ Summary GX/HTTP/Request.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/Exception/StackTrace.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::Exception::StackTrace;
7  
8 305 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 305 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 305 ▶use GX::Exception::StackTrace::Frame;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 305 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 # ----------------------------------------------------------------------------------------------------------------------
17 # Overloading
18 # ----------------------------------------------------------------------------------------------------------------------
19  
20 use overload
21 15 ▶ 'bool' => sub { 1 },
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: called CC=1 SCAR=0.0
22 0 ▶ '0+' => sub { $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 0 ▶ '""' => sub { $_[0]->as_string },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 377 ▶ '@{}' => sub { $_[0]->{'frames'} },
Subroutine __ANON__: called CC=1 SCAR=0.0
25 305 'fallback' => 1;
26  
27  
28 # ----------------------------------------------------------------------------------------------------------------------
29 # Constructor
30 # ----------------------------------------------------------------------------------------------------------------------
31  
32 775 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
33  
34 775 my $class = shift;
35  
36 775 my $self = bless {
37 'frames' => []
38 }, $class;
39  
40 775 return $self;
41  
42 }
43  
44  
45 # ----------------------------------------------------------------------------------------------------------------------
46 # Public methods
47 # ----------------------------------------------------------------------------------------------------------------------
48  
49 4463 ▶sub add {
Subroutine add: called CC=2 SCAR=7.2
Pod documented
50  
51 4463 my $self = shift;
52  
53 4463 ▶ push @{$self->{'frames'}}, grep { blessed $_ && $_->isa( 'GX::Exception::StackTrace::Frame' ) } @_;
Condition33%1/3
builtin::blessed($_) && $_->isa('GX::Exception::StackTrace::Frame')
!ll&&!rl&&r
004463
MC/DC0%0/2
builtin::blessed($_) && $_->isa('GX::Exception::StackTrace::Frame')
builtin::blessed($_) $_->isa('GX::Exception::StackTrace::Frame')
Truth table33%1/3
A && B
A= builtin::blessed($_)B= $_->isa('GX::Exception::StackTrace::Frame')
ABresult
0X0
100
111
54  
55 4463 return;
56  
57 }
58  
59 2 ▶sub as_string {
Subroutine as_string: called CC=5 SCAR=16.4
Pod documented
60  
61 2 my $self = shift;
62 2 my $offset = shift;
63  
64 2 ▶ $offset //= 0;
Condition50%1/2
$offset //= 0
l!l
20
MC/DC0%0/1
$offset //= 0
$offset
Truth table50%1/2
A
A= $offset
Aresult
11
00
65  
66 2 my $frames = $self->{'frames'};
67 2 my @lines;
68  
69 2 ▶ for ( my $i = $offset || 0; $i < @$frames; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$frames) 8 2 10
Condition50%1/2
$offset || 0
l!l
20
MC/DC0%0/1
$offset || 0
$offset
Truth table50%1/2
A
A= $offset
Aresult
11
00
70 8 push @lines, $frames->[$i]->as_string;
71 }
72  
73 2 ▶ return wantarray ? @lines : join( "\n", @lines ) . "\n";
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
74  
75 }
76  
77 775 ▶sub build {
Subroutine build: called CC=3 SCAR=11.0
Pod documented
78  
79 775 my $self = shift;
80 775 my $offset = shift;
81  
82 775 ▶ $offset //= 1;
Condition50%1/2
$offset //= 1
l!l
7750
MC/DC0%0/1
$offset //= 1
$offset
Truth table50%1/2
A
A= $offset
Aresult
11
00
83  
84 775 my $level = 0;
85  
86 775 ▶ while ( my @info = caller( $offset++ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@info) = caller $offset++) 4463 775 5238
87 4463 $self->add( GX::Exception::StackTrace::Frame->new( $level++, @info ) );
88 }
89  
90 775 return;
91  
92 }
93  
94 0 ▶sub frames {
Subroutine frames: not called CC=2 SCAR=17.9
Pod documented
95  
96 0 ▶ return wantarray ? @{$_[0]->{'frames'}} : $_[0]->{'frames'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
97  
98 }
99  
100  
101 305 1;
102  
103 __END__
« GX/HTTP/Response.pm ↑ Summary GX/HTTP/Request.pm »