| 1 | package Exception::Chain; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use 5.008005; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | use overload | ||||||||||||||||||||||||||||
| 6 | 3 | ▶ | '""' => sub { $_[0]->to_string || $_[0] }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Class::Accessor::Lite ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ro => [qw/ delivery /], | |||||||||||||||||||||||||||
| 10 | 3 | ); | |||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Data::Util qw(is_instance); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | our $VERSION = "0.11"; | |||||||||||||||||||||||||||
| 15 | 3 | our $SkipDepth = 0; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 2 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | my $self = bless { | |||||||||||||||||||||||||||
| 21 | tags => {}, | ||||||||||||||||||||||||||||
| 22 | stack => [], | ||||||||||||||||||||||||||||
| 23 | message => undef, | ||||||||||||||||||||||||||||
| 24 | delivery => undef, | ||||||||||||||||||||||||||||
| 25 | }, $class; | ||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 3 | ▶ | sub _target_caller { | ||||||||||||||||||||||||||
|
Subroutine
_target_caller: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 29 | 3 | my $class = shift; | |||||||||||||||||||||||||||
| 30 | 3 | my $i = 0; | |||||||||||||||||||||||||||
| 31 | 3 | ▶ | while (my @caller = caller(++$i)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 6 | ▶ | unless ($caller[0] =~ /^Exception::Chain/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 3 | my $level = $i + $SkipDepth; | |||||||||||||||||||||||||||
| 34 | 3 | @caller = caller($level); | |||||||||||||||||||||||||||
| 35 | 3 | return @caller; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 3 | ▶ | sub _build_arg { | ||||||||||||||||||||||||||
|
Subroutine
_build_arg: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||
| 41 | 3 | my ($class, @info) = @_; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 3 | ▶ | if (scalar @info == 0) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 44 | 0 | return { }; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | elsif (scalar @info == 1) { | ||||||||||||||||||||||||||||
| 47 | 1 | ▶ | if ($class->_is_my_instance($info[0])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 1 | return { error => $info[0] }; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||
| 51 | 0 | return { message => $class->dumper($info[0]) }; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | else { | ||||||||||||||||||||||||||||
| 55 | 2 | my %data = @info; | |||||||||||||||||||||||||||
| 56 | 2 | my $ret = {}; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 2 | $ret->{message} = $class->dumper($data{message}); | |||||||||||||||||||||||||||
| 59 | 2 | for my $name (qw/tag error delivery/) { | |||||||||||||||||||||||||||
| 60 | 6 | $ret->{$name} = $data{$name}; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | return $ret; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 2 | ▶ | sub _is_my_instance { | ||||||||||||||||||||||||||
|
Subroutine
_is_my_instance: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | 2 | my ($class, $instance) = @_; | |||||||||||||||||||||||||||
| 69 | 2 | is_instance($instance, 'Exception::Chain'); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 2 | ▶ | sub dumper { | ||||||||||||||||||||||||||
|
Subroutine
dumper: called CC=3 SCAR=15.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 73 | 2 | my ($self, $value) = @_; | |||||||||||||||||||||||||||
| 74 | 2 | ▶ | if ( defined $value && ref($value) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $value and ref $value
MC/DC0%0/2
defined $value and ref $value
defined $value
ref $value
Truth table33%1/3
A and B
A= defined $valueB= ref $value
| |||||||||||||||||||||||||||||
| 75 | 0 | local $Data::Dumper::Terse = 1; | |||||||||||||||||||||||||||
| 76 | 0 | local $Data::Dumper::Indent = 0; | |||||||||||||||||||||||||||
| 77 | 0 | local $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||
| 78 | 0 | return Data::Dumper::Dumper($value); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 2 | return $value; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 3 | ▶ | sub throw { | ||||||||||||||||||||||||||
|
Subroutine
throw: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 3 | my ($class, @args) = @_; | |||||||||||||||||||||||||||
| 85 | 3 | my $builded_args = $class->_build_arg(@args); | |||||||||||||||||||||||||||
| 86 | 3 | my $self; | |||||||||||||||||||||||||||
| 87 | 3 | ▶ | if (not defined $builded_args->{error}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 88 | 2 | $self = $class->new; | |||||||||||||||||||||||||||
| 89 | 2 | $self->{message} = $builded_args->{message}; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | elsif ($class->_is_my_instance($builded_args->{error})) { | ||||||||||||||||||||||||||||
| 92 | 1 | $self = delete $builded_args->{error}; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | else { | ||||||||||||||||||||||||||||
| 95 | 0 | $self = $class->new; | |||||||||||||||||||||||||||
| 96 | 0 | push @{$self->{stack}}, $builded_args->{error}; | |||||||||||||||||||||||||||
| 97 | 0 | $self->rethrow(%{$builded_args}); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 3 | $self->logging($builded_args); | |||||||||||||||||||||||||||
| 100 | 3 | die $self; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub rethrow { | ||||||||||||||||||||||||||
|
Subroutine
rethrow: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 105 | 0 | $self->logging($self->_build_arg(@args)); | |||||||||||||||||||||||||||
| 106 | 0 | die $self; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 6 | ▶ | sub to_string { | ||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 110 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 111 | 6 | my $string = join( ' ', @{$self->{stack}} ); | |||||||||||||||||||||||||||
| 112 | 6 | $string =~ s/\n//g; | |||||||||||||||||||||||||||
| 113 | 6 | return $string; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub match { | ||||||||||||||||||||||||||
|
Subroutine
match: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 0 | my ($self, @tags) = @_; | |||||||||||||||||||||||||||
| 118 | 0 | return scalar grep { defined $self->{tags}{$_} } @tags; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1 | ▶ | sub first_message { | ||||||||||||||||||||||||||
|
Subroutine
first_message: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 123 | 1 | return $self->{message}; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub add_message { | ||||||||||||||||||||||||||
|
Subroutine
add_message: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 127 | 0 | my ($self, $message) = @_; | |||||||||||||||||||||||||||
| 128 | 0 | $self->logging($self->_build_arg($message)); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 3 | ▶ | sub logging { | ||||||||||||||||||||||||||
|
Subroutine
logging: called CC=7 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 132 | 3 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 3 | my ($pkg, $file, $line) = $self->_target_caller; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 3 | ▶ | if (%{$args}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 2 | ▶ | if (my $tags = $args->{tag}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | $tags = [$tags] unless ref $tags; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 0 | for my $tag (@$tags) { | |||||||||||||||||||||||||||
| 140 | 0 | $self->{tags}{$tag} = 1; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 2 | ▶ | if (my $message = $args->{message}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 2 | push @{$self->{stack}}, "$message at $file line $line."; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 2 | ▶ | if (my $delivery = $args->{delivery}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 0 | $self->{delivery} = $delivery; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | else { | ||||||||||||||||||||||||||||
| 151 | 1 | push @{$self->{stack}}, "at $file line $line."; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 3 | 1; | |||||||||||||||||||||||||||
| 156 | __END__ | ||||||||||||||||||||||||||||