lib/PersonName/Format/Exception.pm

filter: Statementstmt 73.0% 76 / 104 Branchbran 52.5% 21 / 40 Conditioncond 57.1% 12 / 21 MC/DCmcdc 38.4% 5 / 13 Subroutinesub 74.0% 20 / 27 Podpod 92.3% 12 / 13 totaltotal 66.9% 146 / 218 CC 31 SCAR 20.3
CC
31
Cov
66%
__ANON__
20.0
new
14.4
PROPAGATE
12.0
CRAP 7.6
« lib/PersonName/Format/Pattern.pm ↑ Summary lib/PersonName/Format/Compiled.pm »
1 ##----------------------------------------------------------------------------
2 ## Person Name Format - ~/lib/PersonName/Format/Exception.pm
3 ## Version v0.1.0
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2026/07/17
7 ## Modified 2026/07/17
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 PersonName::Format::Exception;
14 BEGIN
15 25 ▶{
Subroutine BEGIN: called CC=3 SCAR=13.8
16 25 ▶ use v5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 25 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 25 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 25 ▶ if( $] < 5.013 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.013") 0 25 25
20 {
21 25 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 0 ▶ unless( defined( &warnings::register_categories ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &warnings::register_categories) 0 0 0
23 {
24 *warnings::_mkMask = sub
25 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 0 my $bit = shift( @_ );
27 0 my $mask = "";
28 0 vec( $mask, $bit, 1 ) = 1;
29 0 return( $mask );
30 0 };
31  
32 *warnings::register_categories = sub
33 0 ▶ {
Subroutine __ANON__: not called CC=4 SCAR=30.0
34 0 my @names = @_;
35 0 foreach my $name ( @names )
36 {
37 0 ▶ if( !defined( $warnings::Bits{ $name } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $warnings::Bits{$name}) 0 0 0
38 {
39 0 $warnings::Offsets{ $name } = $warnings::LAST_BIT;
40 0 $warnings::Bits{ $name } = warnings::_mkMask( $warnings::LAST_BIT++ );
41 0 $warnings::DeadBits{ $name } = warnings::_mkMask( $warnings::LAST_BIT++ );
42 0 ▶ if( length( $warnings::Bits{ $name } ) > length( $warnings::Bits{all} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $warnings::Bits{$name} > length $warnings::Bits{"all"}) 0 0 0
43 {
44 0 $warnings::Bits{all} .= "\x55";
45 0 $warnings::DeadBits{all} .= "\xaa";
46 }
47 }
48 }
49 0 };
50 }
51 }
52 25 warnings::register_categories( 'PersonName::Format' );
53 25 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
54 25 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
55 '""' => \&as_string,
56 2 ▶ bool => sub{1},
Subroutine __ANON__: called CC=1 SCAR=0.0
57 25 fallback => 1,
58 25 );
59 25 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
60 25 our( $VERSION ) = 'v0.1.0';
61 };
62  
63 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
65  
66 sub new
67 34 ▶{
Subroutine new: called CC=14 SCAR=26.7
Pod documented
68 34 my $this = shift( @_ );
69 34 ▶ my $class = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0340
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
70 34 my $self = bless( {}, $class );
71 34 my @info = caller;
72 34 @$self{ qw( package file line ) } = @info[0..2];
73  
74 34 ▶ if( @_ == 1 && ref( $_[0] ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 31 3 34
elsif (@_ == 1 and builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)) { } 1 2 3
Condition100%3/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
1231
MC/DC100%2/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
75 {
76 31 my $args = shift( @_ );
77 31 ▶ if( $args->{skip_frames} )
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"skip_frames"}) 31 0 31
78 {
79 31 @info = caller( int( $args->{skip_frames} ) );
80 31 @$self{ qw( package file line ) } = @info[0..2];
81 }
82 31 foreach my $key ( qw( package file line message code type retry_after ) )
83 {
84 217 ▶ if( exists( $args->{ $key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{$key}) 31 186 217
85 {
86 31 $self->{ $key } = $args->{ $key };
87 }
88 }
89 31 ▶ $self->{message} = '' if( !defined( $self->{message} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"message"} 0 31 31
90 }
91 ▶ elsif( @_ == 1 &&
Condition83%5/6
@_ == 1 and builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
!ll&&!rl&&r
201
@_ == 1 and builtin::blessed($_[0])
!ll&&!rl&&r
111
MC/DC66%2/3
@_ == 1 and builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
@_ == 1 builtin::blessed($_[0]) $_[0]->isa(__PACKAGE__)
Truth table75%3/4
A and B and C
A= @_ == 1B= builtin::blessed($_[0])C= $_[0]->isa(__PACKAGE__)
ABCresult
0XX0
10X0
1100
1111
92 Scalar::Util::blessed( $_[0] ) &&
93 $_[0]->isa( __PACKAGE__ ) )
94 {
95 1 my $exception = shift( @_ );
96 1 foreach my $key ( qw( package file line message code type retry_after ) )
97 {
98 7 ▶ if( exists( $exception->{ $key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $exception->{$key}) 7 0 7
99 {
100 7 $self->{ $key } = $exception->{ $key };
101 }
102 }
103 }
104 else
105 {
106 2 ▶ $self->{message} = join( '', map( ref( $_ ) eq 'CODE' ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 1 2 3
107 }
108  
109 34 return( $self );
110 }
111  
112 sub as_string
113 25 ▶{
Subroutine as_string: called CC=7 SCAR=20.2
Pod documented
114 25 my $self = shift( @_ );
115 25 ▶ if( defined( $self->{_cache_value} ) && !$self->{_reset} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_cache_value"} and not $self->{"_reset"}) 1 24 25
Condition66%2/3
defined $self->{"_cache_value"} and not $self->{"_reset"}
!ll&&!rl&&r
2401
MC/DC50%1/2
defined $self->{"_cache_value"} and not $self->{"_reset"}
defined $self->{"_cache_value"} not $self->{"_reset"}
Truth table66%2/3
A and not(B)
A= defined $self->{"_cache_value"}B= not $self->{"_reset"}
ABresult
0X0
100
111
116 {
117 1 return( $self->{_cache_value} );
118 }
119  
120 24 ▶ my $message = defined( $self->{message} ) ? $self->{message} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'message'} ? : 24 0 24
121 24 $message = "$message";
122 24 $message =~ s/\r?\n$//g;
123 $message .= sprintf(
124 " within package %s at line %s in file %s\n",
125 defined( $self->{package} ) ? $self->{package} : 'undef',
126 defined( $self->{line} ) ? $self->{line} : 'undef',
127 24 ▶ defined( $self->{file} ) ? $self->{file} : 'undef',
Branch: 3 branches
BranchTrueFalseTotal
defined $self->{'package'} ? : 24 0 24
defined $self->{'line'} ? : 24 0 24
defined $self->{'file'} ? : 24 0 24
128 );
129 24 $self->{_cache_value} = $message;
130 24 delete( $self->{_reset} );
131 24 return( $message );
132 }
133  
134 sub clone
135 1 ▶{
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
136 1 my $self = shift( @_ );
137 1 return( ref( $self )->new( $self ) );
138 }
139  
140 6 ▶sub code { return( shift->_set_get_property( 'code', @_ ) ); }
Subroutine code: called CC=1 SCAR=0.0
Pod documented
141 0 ▶sub file { return( shift->_set_get_property( 'file', @_ ) ); }
Subroutine file: not called CC=1 SCAR=6.9
Pod documented
142 0 ▶sub line { return( shift->_set_get_property( 'line', @_ ) ); }
Subroutine line: not called CC=1 SCAR=6.9
Pod documented
143 9 ▶sub message { return( shift->_set_get_property( 'message', @_ ) ); }
Subroutine message: called CC=1 SCAR=0.0
Pod documented
144 0 ▶sub package { return( shift->_set_get_property( 'package', @_ ) ); }
Subroutine package: not called CC=1 SCAR=6.9
Pod documented
145 2 ▶sub retry_after { return( shift->_set_get_property( 'retry_after', @_ ) ); }
Subroutine retry_after: called CC=1 SCAR=0.0
Pod documented
146 2 ▶sub type { return( shift->_set_get_property( 'type', @_ ) ); }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
147  
148 sub PROPAGATE
149 0 ▶{
Subroutine PROPAGATE: not called CC=3 SCAR=24.8
Pod undocumented
150 0 my( $self, $file, $line ) = @_;
151 0 ▶ return( $self ) if( !defined( $file ) || !defined( $line ) );
Branch: 1 branch
BranchTrueFalseTotal
unless 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
152 0 my $clone = $self->clone;
153 0 $clone->file( $file );
154 0 $clone->line( $line );
155 0 return( $clone );
156 }
157  
158 sub rethrow
159 1 ▶{
Subroutine rethrow: called CC=1 SCAR=0.0
Pod documented
160 1 my $self = shift( @_ );
161 1 die( $self );
162 }
163  
164 sub throw
165 0 ▶{
Subroutine throw: not called CC=2 SCAR=17.9
Pod documented
166 0 my $self = shift( @_ );
167 0 ▶ my $exception = @_ ? ref( $self )->new({
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
168 skip_frames => 1,
169 message => join( '', @_ ),
170 }) : $self;
171 0 die( $exception );
172 }
173  
174 sub _set_get_property
175 19 ▶{
Subroutine _set_get_property: called CC=4 SCAR=14.2
176 19 my $self = shift( @_ );
177 19 my $property = shift( @_ );
178 19 ▶ die( "No exception property was provided." )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $property and length $property 0 19 19
Condition33%1/3
defined $property and length $property
!ll&&!rl&&r
0019
MC/DC0%0/2
defined $property and length $property
defined $property length $property
Truth table33%1/3
A and B
A= defined $propertyB= length $property
ABresult
0X0
100
111
179 if( !defined( $property ) || !length( $property ) );
180 19 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 5 14 19
181 {
182 5 $self->{ $property } = shift( @_ );
183 5 $self->{_reset} = 1;
184 }
185 19 return( $self->{ $property } );
186 }
187  
188 25 1;
189 # NOTE: POD
190 __END__
« lib/PersonName/Format/Pattern.pm ↑ Summary lib/PersonName/Format/Compiled.pm »