lib/Module/Generic/Exception.pm

filter: Statementstmt 77.6% 170 / 219 Branchbran 54.8% 57 / 104 Conditioncond 33.8% 21 / 62 MC/DCmcdc 8.3% 3 / 36 Subroutinesub 80.4% 37 / 46 Podpod 80.0% 20 / 25 totaltotal 62.6% 308 / 492 CC 79 SCAR 31.0
CC
79
Cov
64%
init
58.4
_obj_eq
41.9
caught
20.0
CRAP 22.1
« lib/Module/Generic/Tie.pm ↑ Summary lib/Module/Generic/JSON.pm »
1 ##----------------------------------------------------------------------------
2 ## Module Generic - ~/lib/Module/Generic/Exception.pm
3 ## Version v1.4.1
4 ## Copyright(c) 2025 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/03/20
7 ## Modified 2026/01/22
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package Module::Generic::Exception;
14 BEGIN
15 19 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
16 19 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 19 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 19 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 19 ▶ use vars qw( $VERSION $CALLER_LEVEL $CALLER_INTERNAL );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 19 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 19 ▶ use Devel::StackTrace;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 19 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.4
23 '""' => 'as_string',
24 0 ▶ '==' => sub{ _obj_eq(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 0 ▶ '!=' => sub{ !_obj_eq(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 66 ▶ bool => sub{1},
Subroutine __ANON__: called CC=1 SCAR=0.0
27 19 fallback => 1,
28 19 );
29 19 $CALLER_LEVEL = 0;
30 19 $CALLER_INTERNAL->{'Module::Generic'}++;
31 19 $CALLER_INTERNAL->{'Module::Generic::Exception'}++;
32 19 our $VERSION = 'v1.4.1';
33 };
34  
35 BEGIN
36 19 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
37 19 Module::Generic->_implement_freeze_thaw( qw( Devel::StackTrace Devel::StackTrace::Frame ) );
38 };
39  
40 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 19 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 sub init
44 96 ▶{
Subroutine init: called CC=33 SCAR=40.7
Pod documented
45 96 my $self = shift( @_ );
46 96 ▶ $self->{cause} = undef unless( length( $self->{cause} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"cause"} 96 0 96
47 96 ▶ $self->{code} = '' unless( length( $self->{code} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"code"} 96 0 96
48 96 ▶ $self->{file} = '' unless( length( $self->{file} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"file"} 96 0 96
49 96 ▶ $self->{lang} = '' unless( length( $self->{lang} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"lang"} 96 0 96
50 96 ▶ $self->{line} = '' unless( length( $self->{line} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"line"} 96 0 96
51 96 ▶ $self->{message} = '' unless( length( $self->{message} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"message"} 96 0 96
52 96 ▶ $self->{package} = '' unless( length( $self->{package} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"package"} 96 0 96
53 96 ▶ $self->{retry_after} = '' unless( length( $self->{retry_after} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"retry_after"} 96 0 96
54 96 ▶ $self->{subroutine} = '' unless( length( $self->{subroutine} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"subroutine"} 96 0 96
55 96 ▶ $self->{type} = '' unless( length( $self->{type} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"type"} 96 0 96
56 96 my $args = {};
57 96 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 93 3 96
58 {
59 93 ▶ if( Scalar::Util::blessed( $_[0] ) && $_[0]->isa( 'Module::Generic::Exception' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($_[0]) and $_[0]->isa('Module::Generic::Exception')) { } 0 93 93
elsif (ref $_[0] eq 'HASH') { } 85 8 93
Condition33%1/3
builtin::blessed($_[0]) and $_[0]->isa("Module::Generic::Exception")
!ll&&!rl&&r
9300
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa("Module::Generic::Exception")
builtin::blessed($_[0]) $_[0]->isa("Module::Generic::Exception")
Truth table33%1/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("Module::Generic::Exception")
ABresult
0X0
100
111
60 {
61 0 $args->{object} = shift( @_ );
62 }
63 elsif( ref( $_[0] ) eq 'HASH' )
64 {
65 85 $args = shift( @_ );
66 }
67 else
68 {
69 8 ▶ $args->{message} = join( '', map( ref( $_ ) eq 'CODE' ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 14 14
70 }
71 }
72 # $self->SUPER::init( @_ );
73 96 ▶ $self->debug( $args->{debug} ) if( exists( $args->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"debug"} 85 11 96
74  
75 96 ▶ unless( length( $args->{skip_frames} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length $args->{"skip_frames"}) 94 2 96
76 {
77 # NOTE: Taken from Carp to find the right point in the stack to start from
78 19 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
79 94 my $caller_func;
80 0 ▶ $caller_func = \&{"CORE::GLOBAL::caller"} if( defined( &{"CORE::GLOBAL::caller"} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"CORE::GLOBAL::caller";} 0 94 94
81 94 ▶ my $call_pack = $caller_func ? $caller_func->() : caller();
Branch: 1 branch
BranchTrueFalseTotal
$caller_func ? : 0 94 94
82 ## Check if this is an internal package or a package inheriting from us
83 94 ▶ local $CALLER_LEVEL = ( $CALLER_INTERNAL->{ $call_pack } || bless( {} => $call_pack )->isa( 'Module::Generic::Exception' ) )
Branch: 1 branch
BranchTrueFalseTotal
$Module::Generic::Exception::CALLER_INTERNAL->{$call_pack} || bless({}, $call_pack)->isa('Module::Generic::Exception') ? : 94 0 94
Condition33%1/3
$Module::Generic::Exception::CALLER_INTERNAL->{$call_pack} or bless({}, $call_pack)->isa("Module::Generic::Exception")
l!l&&r!l&&!r
9400
MC/DC0%0/2
$Module::Generic::Exception::CALLER_INTERNAL->{$call_pack} or bless({}, $call_pack)->isa("Module::Generic::Exception")
$Module::Generic::Exception::CALLER_INTERNAL->{$call_pack} bless({}, $call_pack)->isa("Module::Generic::Exception")
Truth table33%1/3
A or B
A= $Module::Generic::Exception::CALLER_INTERNAL->{$call_pack}B= bless({}, $call_pack)->isa("Module::Generic::Exception")
ABresult
1X1
011
000
84 ? $CALLER_LEVEL
85 : $CALLER_LEVEL + 1;
86 my $error_start_frame = sub
87 94 ▶ {
Subroutine __ANON__: called CC=7 SCAR=23.7
88 94 my $i;
89 94 my $lvl = $CALLER_LEVEL;
90 {
91 94 ++$i;
92 295 ▶ my @caller = $caller_func ? $caller_func->( $i ) : caller( $i );
Branch: 1 branch
BranchTrueFalseTotal
$caller_func ? : 0 295 295
93 295 my $pkg = $caller[0];
94 295 ▶ unless( defined( $pkg ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pkg) 0 295 295
95 {
96 0 ▶ if( defined( $caller[2] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $caller[2]) { } 0 0 0
97 {
98 # this can happen when the stash has been deleted
99 # in that case, just assume that it's a reasonable place to
100 # stop (the file and line data will still be intact in any
101 # case) - the only issue is that we can't detect if the
102 # deleted package was internal (so don't do that then)
103 # -doy
104 0 ▶ redo unless( 0 > --$lvl );
Branch: 1 branch
BranchTrueFalseTotal
unless 0 > --$lvl 0 0 0
105 0 last;
106 }
107 else
108 {
109 0 return(2);
110 }
111 }
112 295 ▶ redo if( $CALLER_INTERNAL->{ $pkg } );
Branch: 1 branch
BranchTrueFalseTotal
if $Module::Generic::Exception::CALLER_INTERNAL->{$pkg} 201 94 295
113 94 ▶ redo unless( 0 > --$lvl );
Branch: 1 branch
BranchTrueFalseTotal
unless 0 > --$lvl 0 94 94
114 }
115 94 return( $i - 1 );
116 94 };
117  
118 94 $args->{skip_frames} = $error_start_frame->();
119 }
120  
121 96 ▶ my $skip_frame = $args->{skip_frames} || 0;
Condition50%1/2
$args->{'skip_frames'} || 0
l!l
960
MC/DC0%0/1
$args->{'skip_frames'} || 0
$args->{'skip_frames'}
Truth table50%1/2
A
A= $args->{'skip_frames'}
Aresult
11
00
122 # Skip one frame to exclude us
123 96 $skip_frame++;
124  
125 96 my $trace = Devel::StackTrace->new( skip_frames => $skip_frame, indent => 1 );
126 96 my $frame = $trace->next_frame;
127 96 my $frame2 = $trace->next_frame;
128 96 $trace->reset_pointer;
129 96 ▶ if( ref( $args->{object} ) && Scalar::Util::blessed( $args->{object} ) && $args->{object}->isa( 'Module::Generic::Exception' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args->{'object'} and builtin::blessed($args->{'object'}) and $args->{'object'}->isa('Module::Generic::Exception')) { } 0 96 96
Condition33%2/6
ref $args->{"object"} and builtin::blessed($args->{"object"}) and $args->{"object"}->isa("Module::Generic::Exception")
!ll&&!rl&&r
9600
ref $args->{"object"} and builtin::blessed($args->{"object"})
!ll&&!rl&&r
9600
MC/DC0%0/3
ref $args->{"object"} and builtin::blessed($args->{"object"}) and $args->{"object"}->isa("Module::Generic::Exception")
ref $args->{"object"} builtin::blessed($args->{"object"}) $args->{"object"}->isa("Module::Generic::Exception")
Truth table25%1/4
A and B and C
A= ref $args->{"object"}B= builtin::blessed($args->{"object"})C= $args->{"object"}->isa("Module::Generic::Exception")
ABCresult
0XX0
10X0
1100
1111
130 {
131 0 my $o = $args->{object};
132 0 $self->message( $o->message );
133 0 $self->code( $o->code );
134 0 $self->type( $o->type );
135 0 $self->retry_after( $o->retry_after );
136 }
137 else
138 {
139 # print( STDERR __PACKAGE__, "::init() Got here with args: ", Module::Generic->dump( $args ), "\n" );
140 96 ▶ $self->message( $args->{message} || '' );
Condition100%2/2
$args->{'message'} || ''
l!l
933
MC/DC100%1/1
$args->{'message'} || ''
$args->{'message'}
Truth table100%2/2
A
A= $args->{'message'}
Aresult
11
00
141 96 ▶ $self->code( $args->{code} ) if( exists( $args->{code} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"code"} 3 93 96
142 96 ▶ $self->type( $args->{type} ) if( exists( $args->{type} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"type"} 1 95 96
143 96 ▶ $self->retry_after( $args->{retry_after} ) if( exists( $args->{retry_after} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"retry_after"} 0 96 96
144 # I do not want to alter the original hash reference, which may adversely affect the calling code if they depend on its content for further execution for example.
145 96 my $copy = {};
146 96 %$copy = %$args;
147 96 CORE::delete( @$copy{ qw( message code type retry_after skip_frames file line subroutine ) } );
148 # print( STDERR __PACKAGE__, "::init() Following non-standard keys to set up: '", join( "', '", sort( keys( %$copy ) ) ), "'\n" );
149 # Do we have some non-standard parameters?
150 96 foreach my $p ( keys( %$copy ) )
151 {
152 170 my $p2 = $p;
153 170 $p2 =~ tr/-/_/;
154 170 $p2 =~ s/[^a-zA-Z0-9\_]+//g;
155 170 $p2 =~ s/^\d+//g;
156 # We do not want to trigger an error by calling non-existing subroutines
157 170 ▶ if( my $subref = $self->can( $p2 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $subref = $self->can($p2)) 86 84 170
158 {
159 86 $subref->( $self => $copy->{ $p } );
160 }
161 }
162 }
163 96 $self->file( $frame->filename );
164 96 $self->line( $frame->line );
165 ## The caller sub routine ( caller( n ) )[3] returns the sub called by our caller instead of the sub that called our caller, so we go one frame back to get it
166 96 ▶ $self->subroutine( $frame2->subroutine ) if( $frame2 );
Branch: 1 branch
BranchTrueFalseTotal
if $frame2 89 7 96
167 96 $self->package( $frame->package );
168 96 $self->trace( $trace );
169 96 return( $self );
170 }
171  
172 # This is important as stringification is called by die, so as per the manual page, we need to end with new line
173 # And will add the stack trace
174 sub as_string
175 138 ▶{
Subroutine as_string: called CC=4 SCAR=14.0
Pod documented
176 19 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
177 138 my $self = shift( @_ );
178 138 ▶ return( $self->{_cache} ) if( $self->{_cache} && !CORE::length( $self->{_reset} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_cache"} and not length $self->{"_reset"} 13 125 138
Condition66%2/3
$self->{"_cache"} and not length $self->{"_reset"}
!ll&&!rl&&r
125013
MC/DC50%1/2
$self->{"_cache"} and not length $self->{"_reset"}
$self->{"_cache"} not length $self->{"_reset"}
Truth table66%2/3
A and not(B)
A= $self->{"_cache"}B= not length $self->{"_reset"}
ABresult
0X0
100
111
179 125 my $str = $self->message;
180 125 ▶ if( $self->_can_overload( $str => '""' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_can_overload($str, "\"\"")) 0 125 125
181 {
182 19 ▶ use overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
183 0 $str = "$str";
184 }
185 125 $str =~ s/\r?\n$//g;
186 125 $str .= sprintf( " within package %s at line %d in file %s\n%s", $self->package, $self->line, $self->file, $self->trace->as_string );
187 125 $self->{_cache} = $str;
188 125 CORE::delete( $self->{_reset} );
189 125 return( $str );
190 }
191  
192 sub caught
193 0 ▶{
Subroutine caught: not called CC=4 SCAR=30.0
Pod documented
194 0 my( $class, $e ) = @_;
195 0 ▶ return if( ref( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
196 0 ▶ return unless( Scalar::Util::blessed( $e ) && $e->isa( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($e) and $e->isa($class) 0 0 0
Condition0%0/3
builtin::blessed($e) and $e->isa($class)
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($e) and $e->isa($class)
builtin::blessed($e) $e->isa($class)
Truth table0%0/3
A and B
A= builtin::blessed($e)B= $e->isa($class)
ABresult
0X0
100
111
197 0 return( $e );
198 }
199  
200 2 ▶sub cause { return( shift->reset(@_)->_set_get_hash_as_mix_object( 'cause', @_ ) ); }
Subroutine cause: called CC=1 SCAR=0.0
Pod documented
201  
202 8 ▶sub code { return( shift->reset(@_)->_set_get_scalar( 'code', @_ ) ); }
Subroutine code: called CC=1 SCAR=0.0
Pod documented
203  
204 221 ▶sub file { return( shift->reset(@_)->_set_get_scalar( 'file', @_ ) ); }
Subroutine file: called CC=1 SCAR=0.0
Pod documented
205  
206 98 ▶sub lang { return( shift->reset(@_)->_set_get_scalar( 'lang', @_ ) ); }
Subroutine lang: called CC=1 SCAR=0.0
Pod documented
207  
208 221 ▶sub line { return( shift->reset(@_)->_set_get_scalar( 'line', @_ ) ); }
Subroutine line: called CC=1 SCAR=0.0
Pod documented
209  
210 1 ▶sub locale { return( shift->reset(@_)->_set_get_scalar( 'lang', @_ ) ); }
Subroutine locale: called CC=1 SCAR=0.0
Pod documented
211  
212 273 ▶sub message { return( shift->reset(@_)->_set_get_scalar( {
Subroutine message: called CC=1 SCAR=0.4
Pod documented
213 field => 'message',
214 callbacks =>
215 {
216 set => sub
217 96 ▶ {
Subroutine __ANON__: called CC=7 SCAR=22.1
218 96 my( $self, $val ) = @_;
219 96 ▶ $self->__message( 12, "Value being set is '", ( $val // 'undef' ), "' (", overload::StrVal( $val // '' ), ")" );
Condition50%2/4
$val // "undef"
l!l
960
$val // ""
l!l
960
MC/DC0%0/1
$val // "undef"
$val
MC/DC0%0/1
$val // ""
$val
Truth table50%1/2
A
A= $val
Aresult
11
00
Truth table50%1/2
A
A= $val
Aresult
11
00
220 96 ▶ if( defined( $val ) && !$self->lang )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and not $self->lang) 96 0 96
Condition33%1/3
defined $val and not $self->lang
!ll&&!rl&&r
0096
MC/DC0%0/2
defined $val and not $self->lang
defined $val not $self->lang
Truth table33%1/3
A and not(B)
A= defined $valB= not $self->lang
ABresult
0X0
100
111
221 {
222 96 ▶ if( $self->_can( $val => 'locale' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_can($val, 'locale')) { } 1 95 96
elsif ($self->_can($val, 'lang')) { } 0 95 95
223 {
224 1 $self->lang( $val->locale );
225 }
226 elsif( $self->_can( $val => 'lang' ) )
227 {
228 0 $self->lang( $val->lang );
229 }
230 }
231 96 return( $val );
232 },
233 },
234 273 }, @_ ) ); }
235  
236 221 ▶sub package { return( shift->reset(@_)->_set_get_scalar( 'package', @_ ) ); }
Subroutine package: called CC=1 SCAR=0.0
Pod documented
237  
238 # From perlfunc docmentation on "die":
239 # "If LIST was empty or made an empty string, and $@ contains an
240 # object reference that has a "PROPAGATE" method, that method will
241 # be called with additional file and line number parameters. The
242 # return value replaces the value in $@; i.e., as if "$@ = eval {
243 # $@->PROPAGATE(__FILE__, __LINE__) };" were called."
244 sub PROPAGATE
245 0 ▶{
Subroutine PROPAGATE: not called CC=3 SCAR=24.8
Pod documented
246 0 my( $self, $file, $line ) = @_;
247 0 ▶ if( defined( $file ) && defined( $line ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file and defined $line) 0 0 0
Condition0%0/3
defined $file and defined $line
!ll&&!rl&&r
000
MC/DC0%0/2
defined $file and defined $line
defined $file defined $line
Truth table0%0/3
A and B
A= defined $fileB= defined $line
ABresult
0X0
100
111
248 {
249 0 my $clone = $self->clone;
250 0 $clone->file( $file );
251 0 $clone->line( $line );
252 0 return( $clone );
253 }
254 0 return( $self );
255 }
256  
257 sub reset
258 1357 ▶{
Subroutine reset: called CC=3 SCAR=11.0
Pod documented
259 1357 my $self = shift( @_ );
260 1357 ▶ if( !CORE::length( $self->{_reset} ) && scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not length $self->{"_reset"} and scalar @_) 96 1261 1357
Condition100%2/2
not length $self->{"_reset"} and scalar @_
!ll
1030327
MC/DC100%1/1
not length $self->{"_reset"} and scalar @_
not length $self->{"_reset"}
Truth table100%2/2
not(A)
A= not length $self->{"_reset"}
Aresult
00
11
261 {
262 96 $self->{_reset} = scalar( @_ );
263 }
264 1357 return( $self );
265 }
266  
267 sub rethrow
268 0 ▶{
Subroutine rethrow: not called CC=2 SCAR=17.9
Pod documented
269 0 my $self = shift( @_ );
270 0 ▶ return if( !Scalar::Util::blessed( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self) 0 0 0
271 0 die( $self );
272 }
273  
274 0 ▶sub retry_after { return( shift->reset(@_)->_set_get_scalar( 'retry_after', @_ ) ); }
Subroutine retry_after: not called CC=1 SCAR=6.9
Pod documented
275  
276 89 ▶sub subroutine { return( shift->reset(@_)->_set_get_scalar( 'subroutine', @_ ) ); }
Subroutine subroutine: called CC=1 SCAR=0.0
Pod documented
277  
278 sub throw
279 0 ▶{
Subroutine throw: not called CC=2 SCAR=17.9
Pod documented
280 0 my $self = shift( @_ );
281 0 my $e;
282 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
283 {
284 0 my $msg = shift( @_ );
285 0 $e = $self->new({
286 skip_frames => 1,
287 message => $msg,
288 });
289 }
290 else
291 {
292 0 $e = $self;
293 }
294 0 die( $e );
295 }
296  
297 # Devel::StackTrace has a stringification overloaded so users can use the object to get more information or simply use it as a string to get the stack trace equivalent of doing $trace->as_string
298 221 ▶sub trace { return( shift->reset(@_)->_set_get_object( 'trace', 'Devel::StackTrace', @_ ) ); }
Subroutine trace: called CC=1 SCAR=0.0
Pod documented
299  
300 2 ▶sub type { return( shift->reset(@_)->_set_get_scalar( 'type', @_ ) ); }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
301  
302 sub _obj_eq
303 0 ▶{
Subroutine _obj_eq: not called CC=7 SCAR=37.3
304 ##return overload::StrVal( $_[0] ) eq overload::StrVal( $_[1] );
305 19 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
306 0 my $self = shift( @_ );
307 0 my $other = shift( @_ );
308 0 my $me;
309 0 ▶ if( Scalar::Util::blessed( $other ) && $other->isa( 'Module::Generic::Exception' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($other) and $other->isa('Module::Generic::Exception')) { } 0 0 0
elsif (not ref $other) { } 0 0 0
Condition0%0/3
builtin::blessed($other) and $other->isa("Module::Generic::Exception")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($other) and $other->isa("Module::Generic::Exception")
builtin::blessed($other) $other->isa("Module::Generic::Exception")
Truth table0%0/3
A and B
A= builtin::blessed($other)B= $other->isa("Module::Generic::Exception")
ABresult
0X0
100
111
310 {
311 0 ▶ if( $self->message eq $other->message &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->message eq $other->message and $self->file eq $other->file and $self->line == $other->line) { } 0 0 0
Condition0%0/6
$self->message eq $other->message and $self->file eq $other->file and $self->line == $other->line
!ll&&!rl&&r
000
$self->message eq $other->message and $self->file eq $other->file
!ll&&!rl&&r
000
MC/DC0%0/3
$self->message eq $other->message and $self->file eq $other->file and $self->line == $other->line
$self->message eq $other->message $self->file eq $other->file $self->line == $other->line
Truth table0%0/4
A and B and C
A= $self->message eq $other->messageB= $self->file eq $other->fileC= $self->line == $other->line
ABCresult
0XX0
10X0
1100
1111
312 $self->file eq $other->file &&
313 $self->line == $other->line )
314 {
315 0 return(1);
316 }
317 else
318 {
319 0 return(0);
320 }
321 }
322 # Compare error message
323 elsif( !ref( $other ) )
324 {
325 0 my $me = $self->message;
326 0 return( $me eq $other );
327 }
328 # Otherwise some reference data to which we cannot compare
329 0 return(0) ;
330 }
331  
332 sub FREEZE
333 88 ▶{
Subroutine FREEZE: called CC=6 SCAR=18.1
Pod undocumented
334 88 my $self = CORE::shift( @_ );
335 88 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition50%1/2
shift @_ // ""
l!l
880
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
336 88 my $class = CORE::ref( $self );
337 # We purposely exclude the trace object to save space.
338 88 my @props = qw( cause code debug file lang line message package retry_after skip_frames subroutine type );
339 88 my $hash = {};
340 88 foreach my $prop ( @props )
341 {
342 1056 ▶ if( exists( $self->{ $prop } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$prop}) 966 90 1056
343 {
344 966 $hash->{ $prop } = $self->{ $prop };
345 }
346 }
347 # Return an array reference rather than a list so this works with Sereal and CBOR
348 # On or before Sereal version 4.023, Sereal did not support multiple values returned
349 88 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 1 87 88
350 {
351 1 require Sereal::Encoder;
352 1 require version;
353
354 1 ▶ if( version->parse( Sereal::Encoder->VERSION ) <= version->parse( '4.023' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ("version"->parse("Sereal::Encoder"->VERSION) <= "version"->parse("4.023")) 0 1 1
355 {
356 0 CORE::return( [$class, $hash] );
357 }
358 }
359 # But Storable want a list with the first element being the serialised element
360 88 CORE::return( $class, $hash );
361 }
362  
363 87 ▶sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
Pod undocumented
364  
365 38 ▶sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: called CC=1 SCAR=0.0
Pod undocumented
366  
367 # NOTE: CBOR will call the THAW method with the stored classname as first argument, the constant string CBOR as second argument, and all values returned by FREEZE as remaining arguments.
368 # NOTE: Storable calls it with a blessed object it created followed with $cloning and any other arguments initially provided by STORABLE_freeze
369 sub THAW
370 39 ▶{
Subroutine THAW: called CC=10 SCAR=27.6
Pod undocumented
371 39 my( $self, undef, @args ) = @_;
372 39 ▶ my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
Branch: 1 branch
BranchTrueFalseTotal
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 0 39 39
Condition33%1/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
3900
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
Truth table33%1/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
373 39 ▶ my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && ref $ref eq 'ARRAY' && scalar @$ref > 1 ? : 39 0 39
Condition22%2/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
0039
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
0039
ref $self or $self
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref ref $ref eq "ARRAY" scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self $self
Truth table25%1/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
374 39 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 39 0 39
375 39 my $new;
376 # Storable pattern requires to modify the object it created rather than returning a new one
377 39 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 38 1 39
378 {
379 38 foreach( CORE::keys( %$hash ) )
380 {
381 417 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
382 }
383 38 $new = $self;
384 }
385 else
386 {
387 1 $new = CORE::bless( $hash => $class );
388 }
389 39 CORE::return( $new );
390 }
391  
392 0 ▶sub TO_JSON { return( shift->as_string ); }
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod documented
393  
394 sub UNIVERSAL::exception
395 2 ▶{
Subroutine exception: called CC=3 SCAR=11.2
Pod undocumented
396 2 my $class = shift( @_ );
397 2 my $me = __PACKAGE__;
398 2 my $opts = $me->_get_args_as_hash( @_ );
399 2 ▶ $opts->{extends} //= $me;
Condition66%2/3
$opts->{"extends"} //= $me
l!l&&r!l&&!r
110
MC/DC0%0/2
$opts->{"extends"} //= $me
$opts->{"extends"} $me
Truth table66%2/3
A //= B
A= $opts->{"extends"}B= $me
ABresult
1X1
011
000
400 2 ▶ my $rv = $class->create_class( %$opts ) || die( Module::Generic->error );
Condition50%1/2
$class->create_class(%$opts) || die('Module::Generic'->error)
l!l
20
MC/DC0%0/1
$class->create_class(%$opts) || die('Module::Generic'->error)
$class->create_class(%$opts)
Truth table50%1/2
A
A= $class->create_class(%$opts)
Aresult
11
00
401 2 return( $rv );
402 }
403  
404 19 1;
405 # NOTE: POD
406 __END__
« lib/Module/Generic/Tie.pm ↑ Summary lib/Module/Generic/JSON.pm »