lib/PersonName/Format/Generic.pm

filter: Statementstmt 83.5% 112 / 134 Branchbran 67.5% 54 / 80 Conditioncond 50.7% 36 / 71 MC/DCmcdc 24.3% 9 / 37 Subroutinesub 91.3% 21 / 23 Podpod 100% 6 / 6 totaltotal 67.8% 238 / 351 CC 67 SCAR 38.1
CC
67
Cov
71%
pass_error
100.0
__ANON__
20.0
error
10.2
CRAP 45.2
« lib/PersonName/Format/PP.pm ↑ Summary lib/PersonName/Format.pm »
1 ##----------------------------------------------------------------------------
2 ## Person Name Format - ~/lib/PersonName/Format/Generic.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::Generic;
14 BEGIN
15 25 ▶{
Subroutine BEGIN: called CC=3 SCAR=13.2
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 Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
55 25 ▶ use PersonName::Format::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
56 25 ▶ use PersonName::Format::NullObject ();
Subroutine BEGIN: called CC=1 SCAR=0.0
57 25 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 25 our( $VERSION ) = 'v0.1.0';
59 };
60  
61 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 25 my $CLASS_ERROR = {};
65  
66 sub new
67 163 ▶{
Subroutine new: called CC=4 SCAR=14.4
Pod documented
68 163 my $that = shift( @_ );
69 163 ▶ my $class = ( ref( $that ) || $that );
Condition33%1/3
ref $that || $that
l!l&&r!l&&!r
01630
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table33%1/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
70 163 my $self = bless( {}, $class );
71 163 $CLASS_ERROR->{ $class } = undef;
72 163 my $result = $self->init( @_ );
73 163 ▶ if( !defined( $result ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 18 145 163
74 {
75 18 ▶ if( Scalar::Util::blessed( $that ) )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($that)) { } 0 18 18
76 {
77 0 return( $that->pass_error( $self->error ) );
78 }
79 else
80 {
81 18 return( $self->pass_error );
82 }
83 }
84 # Should be the same as $self, but not necessarily
85 145 return( $result );
86 }
87  
88 sub init
89 159 ▶{
Subroutine init: called CC=3 SCAR=11.0
Pod documented
90 159 my $self = shift( @_ );
91 159 my $args = $self->_get_args_as_hash( @_ );
92 159 ▶ $self->{debug} = delete( $args->{debug} ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $args->{'debug'} ? : 1 158 159
93 159 ▶ $self->{fatal} = delete( $args->{fatal} ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $args->{'fatal'} ? : 2 157 159
94 159 return( $self );
95 }
96  
97 3 ▶sub debug { return( shift->_set_get_scalar( 'debug', @_ ) ); }
Subroutine debug: called CC=1 SCAR=0.0
Pod documented
98  
99 sub error
100 302 ▶{
Subroutine error: called CC=10 SCAR=23.2
Pod documented
101 302 my $self = shift( @_ );
102 302 ▶ my $class = ref( $self ) || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
285170
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
103  
104 302 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 31 271 302
105 {
106 31 ▶ my $message = join( '', map( ref( $_ ) eq 'CODE' ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 37 37
107 31 my $exception = PersonName::Format::Exception->new({
108 skip_frames => 1,
109 message => $message,
110 });
111 31 $CLASS_ERROR->{ $class } = $exception;
112 31 ▶ $self->{error} = $exception if( ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 31 0 31
113  
114 31 ▶ if( ref( $self ) && $self->fatal )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self and $self->fatal) { } 1 30 31
Condition66%2/3
ref $self and $self->fatal
!ll&&!rl&&r
0301
MC/DC50%1/2
ref $self and $self->fatal
ref $self $self->fatal
Truth table66%2/3
A and B
A= ref $selfB= $self->fatal
ABresult
0X0
100
111
115 {
116 1 die( $exception );
117 }
118 else
119 {
120 30 ▶ if( warnings::enabled( 'PersonName::Format' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (warnings::enabled("PersonName::Format")) 20 10 30
121 {
122 20 warn( $message );
123 }
124 30 ▶ rreturn( PersonName::Format::NullObject->new ) if( want( 'OBJECT' ) );
Branch: 1 branch
BranchTrueFalseTotal
if want("OBJECT") 1 29 30
125 29 return;
126 }
127 }
128  
129 271 ▶ return( ref( $self ) ? $self->{error} : $CLASS_ERROR->{ $class } );
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 254 17 271
130 }
131  
132 34 ▶sub fatal { return( shift->_set_get_scalar( 'fatal', @_ ) ); }
Subroutine fatal: called CC=1 SCAR=0.0
Pod documented
133  
134 sub pass_error
135 46 ▶{
Subroutine pass_error: called CC=37 SCAR=46.1
Pod documented
136 46 my $self = shift( @_ );
137 46 ▶ my $class = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
4600
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
138 46 my $opts = {};
139 46 my( $error, $exception_class, $code );
140  
141 46 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 43 46
142 {
143 # Either an hash defining a new error and this will be passed along to error(); or
144 # an hash with a single property: { class => 'Some::ExceptionClass' }
145 3 ▶ if( scalar( @_ ) == 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and ref $_[0] eq 'HASH') { } 1 2 3
Condition100%3/3
scalar @_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
111
MC/DC100%2/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1 ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
146 ref( $_[0] ) eq 'HASH' )
147 {
148 1 $opts = shift( @_ );
149 }
150 else
151 {
152 2 ▶ if( scalar( @_ ) > 1 && ref( $_[-1] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1 and ref $_[-1] eq "HASH") 1 1 2
Condition66%2/3
scalar @_ > 1 and ref $_[-1] eq "HASH"
!ll&&!rl&&r
101
MC/DC50%1/2
scalar @_ > 1 and ref $_[-1] eq "HASH"
scalar @_ > 1 ref $_[-1] eq "HASH"
Truth table66%2/3
A and B
A= scalar @_ > 1B= ref $_[-1] eq "HASH"
ABresult
0X0
100
111
153 {
154 1 $opts = pop( @_ );
155 }
156 2 $error = $_[0];
157 }
158 }
159  
160 46 ▶ if( !defined( $error ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $error and exists $opts->{"error"} and defined $opts->{"error"} and length qq[$opts->{"error"}]) 0 46 46
Condition44%4/9
not defined $error and exists $opts->{"error"} and defined $opts->{"error"} and length qq[$opts->{"error"}]
!ll&&!rl&&r
4600
not defined $error and exists $opts->{"error"} and defined $opts->{"error"}
!ll&&!rl&&r
4600
not defined $error and exists $opts->{"error"}
!ll&&!rl&&r
2440
MC/DC0%0/4
not defined $error and exists $opts->{"error"} and defined $opts->{"error"} and length qq[$opts->{"error"}]
not defined $error exists $opts->{"error"} defined $opts->{"error"} length qq[$opts->{"error"}]
Truth table40%2/5
not(A) and B and C and D
A= not defined $errorB= exists $opts->{"error"}C= defined $opts->{"error"}D= length qq[$opts->{"error"}]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
161 exists( $opts->{error} ) &&
162 defined( $opts->{error} ) &&
163 length( "$opts->{error}" ) )
164 {
165 0 $error = $opts->{error};
166 }
167 46 ▶ if( exists( $opts->{class} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}) 0 46 46
Condition33%2/6
exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}
!ll&&!rl&&r
4600
exists $opts->{"class"} and defined $opts->{"class"}
!ll&&!rl&&r
4600
MC/DC0%0/3
exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}
exists $opts->{"class"} defined $opts->{"class"} length $opts->{"class"}
Truth table25%1/4
A and B and C
A= exists $opts->{"class"}B= defined $opts->{"class"}C= length $opts->{"class"}
ABCresult
0XX0
10X0
1100
1111
168 defined( $opts->{class} ) &&
169 length( $opts->{class} ) )
170 {
171 0 $exception_class = $opts->{class};
172 }
173 46 ▶ if( exists( $opts->{code} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"code"} and defined $opts->{"code"} and length qq[$opts->{"code"}]) 2 44 46
Condition66%4/6
exists $opts->{"code"} and defined $opts->{"code"} and length qq[$opts->{"code"}]
!ll&&!rl&&r
4402
exists $opts->{"code"} and defined $opts->{"code"}
!ll&&!rl&&r
4402
MC/DC33%1/3
exists $opts->{"code"} and defined $opts->{"code"} and length qq[$opts->{"code"}]
exists $opts->{"code"} defined $opts->{"code"} length qq[$opts->{"code"}]
Truth table50%2/4
A and B and C
A= exists $opts->{"code"}B= defined $opts->{"code"}C= length qq[$opts->{"code"}]
ABCresult
0XX0
10X0
1100
1111
174 defined( $opts->{code} ) &&
175 length( "$opts->{code}" ) )
176 {
177 2 $code = $opts->{code};
178 }
179  
180 # called with no argument, most likely from the same class to pass on an error
181 # set up earlier by another method; or
182 # with an hash containing just one argument class => 'Some::ExceptionClass'
183 46 ▶ if( !defined( $error ) && ( !scalar( @_ ) || defined( $exception_class ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $error and !scalar(@_) || defined $exception_class) { } 44 2 46
elsif (defined $error and builtin::blessed($error) and scalar @_ == 1 || scalar @_ == 2 && defined $exception_class) { } 2 0 2
Condition50%3/6
not defined $error and !scalar(@_) || defined $exception_class
!ll&&!rl&&r
2044
not scalar @_ or defined $exception_class
l!l&&r!l&&!r
4400
MC/DC33%1/3
not defined $error and !scalar(@_) || defined $exception_class
not defined $error not scalar @_ defined $exception_class
Truth table50%2/4
not(A) and not(B) or C
A= not defined $errorB= not scalar @_C= defined $exception_class
ABCresult
0XX0
1000
11X1
1011
184 {
185 44 ▶ $error = ref( $self ) ? $self->{error} : $CLASS_ERROR->{ $class };
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 44 0 44
186 44 ▶ if( !defined( $error ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $error) { } 0 44 44
187 {
188 0 ▶ warn( "No error object provided and no previous error set either! It seems the previous method call returned a simple undef" ) if( warnings::enabled( 'PersonName::Format' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("PersonName::Format") 0 0 0
189 }
190 else
191 {
192 44 ▶ $error = ( defined( $exception_class ) ? bless( $error => $exception_class ) : $error );
Branch: 1 branch
BranchTrueFalseTotal
defined $exception_class ? : 0 44 44
193 44 ▶ $error->code( $code ) if( defined( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code 1 43 44
194 }
195 }
196 ▶ elsif( defined( $error ) &&
Condition25%3/12
defined $error and builtin::blessed($error) and scalar @_ == 1 || scalar @_ == 2 && defined $exception_class
!ll&&!rl&&r
002
defined $error and builtin::blessed($error)
!ll&&!rl&&r
002
scalar @_ == 1 or scalar @_ == 2 and defined $exception_class
l!l&&r!l&&!r
200
scalar @_ == 2 and defined $exception_class
!ll&&!rl&&r
000
MC/DC0%0/5
defined $error and builtin::blessed($error) and scalar @_ == 1 || scalar @_ == 2 && defined $exception_class
defined $error builtin::blessed($error) scalar @_ == 1 scalar @_ == 2 defined $exception_class
Truth table16%1/6
A and B and C or D and E
A= defined $errorB= builtin::blessed($error)C= scalar @_ == 1D= scalar @_ == 2E= defined $exception_class
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
197 Scalar::Util::blessed( $error ) &&
198 ( scalar( @_ ) == 1 ||
199 ( scalar( @_ ) == 2 && defined( $exception_class ) )
200 ) )
201 {
202 2 ▶ my $err = defined( $exception_class ) ? bless( $error => $exception_class ) : $error;
Branch: 1 branch
BranchTrueFalseTotal
defined $exception_class ? : 0 2 2
203 2 ▶ $err->code( $code ) if( defined( $code ) && $err->can( 'code' ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code and $err->can("code") 1 1 2
Condition66%2/3
defined $code and $err->can("code")
!ll&&!rl&&r
101
MC/DC50%1/2
defined $code and $err->can("code")
defined $code $err->can("code")
Truth table66%2/3
A and B
A= defined $codeB= $err->can("code")
ABresult
0X0
100
111
204 2 $CLASS_ERROR->{ $class } = $err;
205 2 ▶ $self->{error} = $err if( ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 2 0 2
206 2 ▶ die( $err ) if( ref( $self ) && $self->fatal );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self and $self->fatal 1 1 2
Condition66%2/3
ref $self and $self->fatal
!ll&&!rl&&r
011
MC/DC50%1/2
ref $self and $self->fatal
ref $self $self->fatal
Truth table66%2/3
A and B
A= ref $selfB= $self->fatal
ABresult
0X0
100
111
207 }
208 # If the error provided is not an object, we call error to create one
209 else
210 {
211 0 return( $self->error( @_ ) );
212 }
213  
214 45 ▶ rreturn( PersonName::Format::NullObject->new ) if( want( 'OBJECT' ) );
Branch: 1 branch
BranchTrueFalseTotal
if want("OBJECT") 0 45 45
215 45 return;
216 }
217  
218 sub _can
219 154 ▶{
Subroutine _can: called CC=5 SCAR=16.2
220 154 my $self = shift( @_ );
221 154 my $object = shift( @_ );
222 154 my $methods = shift( @_ );
223 154 ▶ return(0) if( !Scalar::Util::blessed( $object ) );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($object) 0 154 154
224 154 ▶ $methods = [$methods] if( ref( $methods ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $methods ne "ARRAY" 0 154 154
225 154 foreach my $method ( @$methods )
226 {
227 435 ▶ return(0) if( !$object->can( $method ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $object->can($method) 3 432 435
228 }
229 151 return(1);
230 }
231  
232 sub _get_args_as_hash
233 490 ▶{
Subroutine _get_args_as_hash: called CC=7 SCAR=21.8
234 490 my $self = shift( @_ );
235 490 my $ref = {};
236 490 ▶ if( scalar( @_ ) == 1 &&
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1 and defined $_[0] and (ref $_[0] || '') eq 'HASH') { } 19 471 490
elsif (not scalar(@_) % 2) { } 471 0 471
Condition62%5/8
scalar @_ == 1 and defined $_[0] and (ref $_[0] || "") eq "HASH"
!ll&&!rl&&r
471019
scalar @_ == 1 and defined $_[0]
!ll&&!rl&&r
471019
ref $_[0] || ''
l!l
190
MC/DC33%1/3
scalar @_ == 1 and defined $_[0] and (ref $_[0] || "") eq "HASH"
scalar @_ == 1 defined $_[0] ref $_[0]
Truth table50%2/4
A and B and C
A= scalar @_ == 1B= defined $_[0]C= ref $_[0]
ABCresult
0XX0
10X0
1100
1111
237 defined( $_[0] ) &&
238 ( ref( $_[0] ) || '' ) eq 'HASH' )
239 {
240 19 $ref = shift( @_ );
241 }
242 elsif( !( scalar( @_ ) % 2 ) )
243 {
244 471 $ref = { @_ };
245 }
246 else
247 {
248 0 ▶ warn( "Uneven number of parameters provided." ) if( warnings::enabled( 'PersonName::Format' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("PersonName::Format") 0 0 0
249 }
250 490 return( $ref );
251 }
252  
253 sub _set_get_scalar
254 46 ▶{
Subroutine _set_get_scalar: called CC=2 SCAR=6.9
255 46 my $self = shift( @_ );
256 46 my $name = shift( @_ );
257 46 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 45 46
258 {
259 1 $self->{ $name } = shift( @_ );
260 }
261 46 return( $self->{ $name } );
262 }
263  
264 25 1;
265 # NOTE: POD
266 __END__
« lib/PersonName/Format/PP.pm ↑ Summary lib/PersonName/Format.pm »