| 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')
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')
| |||||||||||||||||||||
| 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
MC/DC0%0/1
$offset //= 0
$offset
Truth table50%1/2
A
A= $offset
| |||||||||||||||||||||
| 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
Condition50%1/2
$offset || 0
MC/DC0%0/1
$offset || 0
$offset
Truth table50%1/2
A
A= $offset
| |||||||||||||||||||||
| 70 | 8 | push @lines, $frames->[$i]->as_string; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 2 | ▶ | return wantarray ? @lines : join( "\n", @lines ) . "\n"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
MC/DC0%0/1
$offset //= 1
$offset
Truth table50%1/2
A
A= $offset
| |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 775 | my $level = 0; | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 775 | ▶ | while ( my @info = caller( $offset++ ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 305 | 1; | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||