lib/Module/Generic/Dynamic.pm

filter: Statementstmt 84.9% 270 / 318 Branchbran 56.5% 112 / 198 Conditioncond 52.4% 87 / 166 MC/DCmcdc 26.6% 24 / 90 Subroutinesub 96.2% 51 / 53 Podpod 48.0% 12 / 25 totaltotal 65.4% 556 / 850 CC 160 SCAR 50.9
CC
160
Cov
69%
AUTOLOAD
332.2
new
272.4
THAW
15.8
CRAP 162.8
« lib/Module/Generic/File/Cache.pm ↑ Summary lib/Module/Generic/Number/Format.pm »
1 ##----------------------------------------------------------------------------
2 ## Module Generic - ~/lib/Module/Generic/Dynamic.pm
3 ## Version v1.3.2
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/03/20
7 ## Modified 2026/06/04
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::Dynamic;
14 BEGIN
15 5 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 warnings::register_categories( 'Module::Generic' );
19 5 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶ use vars qw( $AUTOLOAD $VERSION $DEBUG );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶ use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶ use Module::Generic::Global ':const';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 our $DEBUG = 0;
25 5 our $VERSION = 'v1.3.2';
26 };
27  
28 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 5 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 sub new
32 24 ▶{
Subroutine new: called CC=89 SCAR=56.1
Pod documented
33 24 my $this = shift( @_ );
34 24 ▶ my $class = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0240
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
35 24 my $self = bless( {} => $class );
36 24 my $data = $self->{_data} = {};
37 # A Module::Generic object standard parameter
38 24 $self->{_data_repo} = '_data';
39 24 my $hash = {};
40 24 ▶ @_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and not defined $_[0] 0 24 24
Condition66%2/3
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
1230
MC/DC0%0/2
scalar @_ == 1 and not defined $_[0]
scalar @_ == 1 not defined $_[0]
Truth table66%2/3
A and not(B)
A= scalar @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
41 24 ▶ if( scalar( @_ ) == 1 && ( Scalar::Util::reftype( $_[0] ) // '' ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1 and (builtin::reftype($_[0]) // '') eq 'HASH') { } 22 2 24
elsif (@_) { } 1 1 2
Condition100%5/5
scalar @_ == 1 and (builtin::reftype($_[0]) // "") eq "HASH"
!ll&&!rl&&r
1122
builtin::reftype($_[0]) // ""
l!l
221
MC/DC100%2/2
scalar @_ == 1 and (builtin::reftype($_[0]) // "") eq "HASH"
scalar @_ == 1 builtin::reftype($_[0])
Truth table100%3/3
A and B
A= scalar @_ == 1B= builtin::reftype($_[0])
ABresult
0X0
100
111
42 {
43 22 $hash = shift( @_ );
44 22 ▶ $self->{debug} = $DEBUG if( $DEBUG && !CORE::exists( $hash->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $Module::Generic::Dynamic::DEBUG and not exists $hash->{"debug"} 0 22 22
Condition33%1/3
$Module::Generic::Dynamic::DEBUG and not exists $hash->{"debug"}
!ll&&!rl&&r
2200
MC/DC0%0/2
$Module::Generic::Dynamic::DEBUG and not exists $hash->{"debug"}
$Module::Generic::Dynamic::DEBUG not exists $hash->{"debug"}
Truth table33%1/3
A and not(B)
A= $Module::Generic::Dynamic::DEBUGB= not exists $hash->{"debug"}
ABresult
0X0
100
111
45 }
46 elsif( @_ )
47 {
48 1 ▶ CORE::warn( "Parameter provided is not an hash reference: '", join( "', '", @_ ), "'\n" ) if( $this->_warnings_is_enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $this->_warnings_is_enabled("Module::Generic") 1 0 1
49 }
50  
51 24 ▶ if( HAS_THREADS )
Branch: 1 branch
BranchTrueFalseTotal
if (&HAS_THREADS()) 0 24 24
52 {
53 0 ▶ if( threads->tid != 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ("threads"->tid != 0) 0 0 0
54 {
55 0 ▶ warn( "Module::Generic::Dynamic is not thread-safe and should not be called from a thread." ) if( $this->_warnings_is_enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $this->_warnings_is_enabled("Module::Generic") 0 0 0
56 }
57 }
58  
59 my $make_clean_field = sub
60 48 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
61 48 my $k = shift( @_ );
62 48 my $clean_field = $k;
63 48 $clean_field =~ tr/-/_/;
64 48 $clean_field =~ s/\_{2,}/_/g;
65 48 $clean_field =~ s/[^a-zA-Z0-9\_]+//g;
66 48 $clean_field =~ s/^\d+//g;
67 48 return( $clean_field );
68 24 };
69  
70 my $make_class = sub
71 8 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
72 8 my $k = shift( @_ );
73 8 my $new_class = $k;
74 8 $new_class =~ tr/-/_/;
75 8 $new_class =~ s/\_{2,}/_/g;
76 8 $new_class = join( '', map( ucfirst( lc( $_ ) ), split( /\_/, $new_class ) ) );
77 8 $new_class = "${class}\::${new_class}";
78 # Sanitise the key which will serve as a method name
79 8 my $clean_field = $make_clean_field->( $k );
80 8 my $perl = <<EOT;
81 package $new_class;
82 BEGIN
83 {
84 use strict;
85 use Module::Generic;
86 use parent -norequire, qw( Module::Generic::Dynamic );
87 };
88  
89 1;
90  
91 EOT
92 8 local $@;
93 8 ▶ my $rc = eval( $perl );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
94 8 ▶ die( "Unable to dynamically create module $new_class: $@" ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 8 8
95 8 return( $new_class, $clean_field );
96 24 };
97  
98  
99 24 local $@;
100 24 foreach my $k ( sort( keys( %$hash ) ) )
101 {
102 48 ▶ if( defined( $hash->{ $k } ) && ref( $hash->{ $k } ) eq 'HASH' )
Branch: 6 branches
BranchTrueFalseTotal
if (defined $hash->{$k} and ref $hash->{$k} eq 'HASH') { } 5 43 48
elsif (defined $hash->{$k} and $self->_is_array($hash->{$k})) { } 3 40 43
elsif (defined $hash->{$k} and ref $hash->{$k} eq 'CODE') { } 1 39 40
elsif (defined $hash->{$k} and $self->_is_object($hash->{$k})) { } 4 35 39
elsif (defined $hash->{$k} and $self->_is_glob($hash->{$k})) { } 0 35 35
elsif (not ref($hash->{$k} // '')) { } 35 0 35
Condition100%3/3
defined $hash->{$k} and ref $hash->{$k} eq "HASH"
!ll&&!rl&&r
1425
MC/DC100%2/2
defined $hash->{$k} and ref $hash->{$k} eq "HASH"
defined $hash->{$k} ref $hash->{$k} eq "HASH"
Truth table100%3/3
A and B
A= defined $hash->{$k}B= ref $hash->{$k} eq "HASH"
ABresult
0X0
100
111
103 {
104 5 my( $new_class, $clean_field ) = $make_class->( $k );
105 5 ▶ next unless( length( $clean_field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $clean_field 0 5 5
106 5 eval( "sub ${new_class}::${clean_field} { return( shift->_set_get_object( '$clean_field', '$new_class', \@_ ) ); }" );
107 5 ▶ die( $@ ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 5 5
108 5 my $rv = $self->$clean_field( $hash->{ $k } );
109 5 ▶ return( $self->pass_error ) if( !defined( $rv ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $rv and $self->error 0 5 5
Condition33%1/3
not defined $rv and $self->error
!ll&&!rl&&r
500
MC/DC0%0/2
not defined $rv and $self->error
not defined $rv $self->error
Truth table33%1/3
not(A) and B
A= not defined $rvB= $self->error
ABresult
0X0
100
111
110 }
111 # elsif( ref( $hash->{ $k } ) eq 'ARRAY' )
112 ▶ elsif( defined( $hash->{ $k } ) && $self->_is_array( $hash->{ $k } ) )
Condition100%3/3
defined $hash->{$k} and $self->_is_array($hash->{$k})
!ll&&!rl&&r
1393
MC/DC100%2/2
defined $hash->{$k} and $self->_is_array($hash->{$k})
defined $hash->{$k} $self->_is_array($hash->{$k})
Truth table100%3/3
A and B
A= defined $hash->{$k}B= $self->_is_array($hash->{$k})
ABresult
0X0
100
111
113 {
114 3 my( $new_class, $clean_field ) = $make_class->( $k );
115 # We take a peek at what we have to determine how we will handle the data
116 3 ▶ my $mode = lc( scalar( @{$hash->{ $k }} ) ? ref( $hash->{ $k }->[0] ) : '' );
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$hash->{$k};} ? : 3 0 3
117 3 ▶ if( $mode eq 'hash' )
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'hash') { } 0 3 3
118 {
119 0 my $all = [];
120 0 foreach my $this ( @{$hash->{ $k }} )
121 {
122 0 ▶ my $o = $this->{_looping} ? $this->{_looping} : $new_class->new( $this );
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_looping'} ? : 0 0 0
123 0 $this->{_looping} = $o;
124 0 CORE::push( @$all, $o );
125 }
126 0 eval( "sub ${new_class}::${clean_field} { return( shift->_set_get_object_array_object( '$clean_field', '$new_class', \@_ ) ); }" );
127 }
128 else
129 {
130 3 eval( "sub ${new_class}::${clean_field} { return( shift->_set_get_array_as_object( '$clean_field', \@_ ) ); }" );
131 }
132 3 ▶ die( $@ ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
133 3 my $rv = $self->$clean_field( $hash->{ $k } );
134 3 ▶ return( $self->pass_error ) if( !defined( $rv ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $rv and $self->error 0 3 3
Condition33%1/3
not defined $rv and $self->error
!ll&&!rl&&r
300
MC/DC0%0/2
not defined $rv and $self->error
not defined $rv $self->error
Truth table33%1/3
not(A) and B
A= not defined $rvB= $self->error
ABresult
0X0
100
111
135 }
136 # New/Improved: Handle other ref types with guesses
137 ▶ elsif( defined( $hash->{ $k } ) && ref( $hash->{ $k } ) eq 'CODE' )
Condition100%3/3
defined $hash->{$k} and ref $hash->{$k} eq "CODE"
!ll&&!rl&&r
1381
MC/DC100%2/2
defined $hash->{$k} and ref $hash->{$k} eq "CODE"
defined $hash->{$k} ref $hash->{$k} eq "CODE"
Truth table100%3/3
A and B
A= defined $hash->{$k}B= ref $hash->{$k} eq "CODE"
ABresult
0X0
100
111
138 {
139 1 my $clean_field = $make_clean_field->( $k );
140 1 ▶ next unless( length( $clean_field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $clean_field 0 1 1
141 1 my $func_name = '_set_get_code';
142 1 my $pl = "sub ${class}::${clean_field} { return( shift->${func_name}( '$clean_field', \@_ ) ); }";
143 1 ▶ eval( $pl );
Pod undocumented
144 1 ▶ die( $@ ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
145 1 my $rv = $self->$clean_field( $hash->{ $k } );
146 1 ▶ return( $self->pass_error ) if( !defined( $rv ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $rv and $self->error 0 1 1
Condition33%1/3
not defined $rv and $self->error
!ll&&!rl&&r
100
MC/DC0%0/2
not defined $rv and $self->error
not defined $rv $self->error
Truth table33%1/3
not(A) and B
A= not defined $rvB= $self->error
ABresult
0X0
100
111
147 }
148 ▶ elsif( defined( $hash->{ $k } ) && $self->_is_object( $hash->{ $k } ) )
Condition100%3/3
defined $hash->{$k} and $self->_is_object($hash->{$k})
!ll&&!rl&&r
1344
MC/DC100%2/2
defined $hash->{$k} and $self->_is_object($hash->{$k})
defined $hash->{$k} $self->_is_object($hash->{$k})
Truth table100%3/3
A and B
A= defined $hash->{$k}B= $self->_is_object($hash->{$k})
ABresult
0X0
100
111
149 {
150 4 my $clean_field = $make_clean_field->( $k );
151 4 ▶ next unless( length( $clean_field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $clean_field 0 4 4
152 4 my( $func_name, $pl );
153  
154 4 ▶ if( $hash->{ $k }->isa('JSON::PP::Boolean') ||
Branch: 4 branches
BranchTrueFalseTotal
if ($hash->{$k}->isa('JSON::PP::Boolean') or $hash->{$k}->isa('Module::Generic::Boolean')) { } 1 3 4
elsif ($hash->{$k}->isa('Module::Generic::File')) { } 1 2 3
elsif ($hash->{$k}->isa('Module::Generic::Array')) { } 0 2 2
elsif ($hash->{$k}->isa('Module::Generic::Number')) { } 1 1 2
Condition66%2/3
$hash->{$k}->isa("JSON::PP::Boolean") or $hash->{$k}->isa("Module::Generic::Boolean")
l!l&&r!l&&!r
103
MC/DC50%1/2
$hash->{$k}->isa("JSON::PP::Boolean") or $hash->{$k}->isa("Module::Generic::Boolean")
$hash->{$k}->isa("JSON::PP::Boolean") $hash->{$k}->isa("Module::Generic::Boolean")
Truth table66%2/3
A or B
A= $hash->{$k}->isa("JSON::PP::Boolean")B= $hash->{$k}->isa("Module::Generic::Boolean")
ABresult
1X1
011
000
155 $hash->{ $k }->isa('Module::Generic::Boolean') )
156 {
157 1 $func_name = '_set_get_boolean';
158 1 $pl = "sub ${class}::${clean_field} { return( shift->${func_name}( '$clean_field', \@_ ) ); }";
159 }
160 elsif( $hash->{ $k }->isa('Module::Generic::File') )
161 {
162 1 $func_name = '_set_get_file';
163 1 $pl = "sub ${class}::${clean_field} { return( shift->${func_name}( '$clean_field', \@_ ) ); }";
164 }
165 elsif( $hash->{ $k }->isa('Module::Generic::Array') )
166 {
167 0 $func_name = '_set_get_array_as_object';
168 0 $pl = "sub ${class}::${clean_field} { return( shift->${func_name}( '$clean_field', \@_ ) ); }";
169 }
170 elsif( $hash->{ $k }->isa('Module::Generic::Number') )
171 {
172 1 $func_name = '_set_get_number';
173 1 $pl = "sub ${class}::${clean_field} { return( shift->${func_name}( '$clean_field', \@_ ) ); }";
174 }
175 else
176 {
177 1 my $obj_class = ref( $hash->{ $k } );
178 1 $func_name = '_set_get_object';
179 1 $pl = "sub ${class}::${clean_field} { return( shift->${func_name}( '$clean_field', '$obj_class', \@_ ) ); }";
180 }
181 4 ▶ eval( $pl );
Pod documented
Pod documented
Pod undocumented
Pod documented
182 4 ▶ die( $@ ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 4 4
183 4 my $rv = $self->$clean_field( $hash->{ $k } );
184 4 ▶ return( $self->pass_error ) if( !defined( $rv ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $rv and $self->error 0 4 4
Condition33%1/3
not defined $rv and $self->error
!ll&&!rl&&r
400
MC/DC0%0/2
not defined $rv and $self->error
not defined $rv $self->error
Truth table33%1/3
not(A) and B
A= not defined $rvB= $self->error
ABresult
0X0
100
111
185 }
186 ▶ elsif( defined( $hash->{ $k } ) && $self->_is_glob( $hash->{ $k } ) )
Condition66%2/3
defined $hash->{$k} and $self->_is_glob($hash->{$k})
!ll&&!rl&&r
1340
MC/DC0%0/2
defined $hash->{$k} and $self->_is_glob($hash->{$k})
defined $hash->{$k} $self->_is_glob($hash->{$k})
Truth table66%2/3
A and B
A= defined $hash->{$k}B= $self->_is_glob($hash->{$k})
ABresult
0X0
100
111
187 {
188 0 my $clean_field = $make_clean_field->( $k );
189 0 ▶ next unless( length( $clean_field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $clean_field 0 0 0
190 0 my $func_name = '_set_get_glob';
191 0 my $pl = "sub ${class}::${clean_field} { return( shift->${func_name}( '$clean_field', \@_ ) ); }";
192 0 eval( $pl );
193 0 ▶ die( $@ ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
194 0 my $rv = $self->$clean_field( $hash->{ $k } );
195 0 ▶ return( $self->pass_error ) if( !defined( $rv ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $rv and $self->error 0 0 0
Condition0%0/3
not defined $rv and $self->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $rv and $self->error
not defined $rv $self->error
Truth table0%0/3
not(A) and B
A= not defined $rvB= $self->error
ABresult
0X0
100
111
196 }
197 ▶ elsif( !ref( $hash->{ $k } // '' ) )
Condition100%2/2
$hash->{$k} // ""
l!l
341
MC/DC100%1/1
$hash->{$k} // ""
$hash->{$k}
Truth table100%2/2
A
A= $hash->{$k}
Aresult
11
00
198 {
199 35 my $clean_field = $make_clean_field->( $k );
200 # Possibly there is no acceptable characters to make a field out of it
201 35 ▶ next unless( length( $clean_field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $clean_field 0 35 35
202 35 my $func_name = '_set_get_scalar_as_object';
203  
204 35 ▶ if( $clean_field =~ /(^|\b)date|datetime|created|modified($|\b)/ )
Branch: 9 branches
BranchTrueFalseTotal
if ($clean_field =~ /(^|\b)date|datetime|created|modified($|\b)/) { } 2 33 35
elsif ($clean_field =~ /(^|\b)(uri|url)($|\b)/ or defined $hash->{$k} and $hash->{$k} =~ m[^https?\:/{2}]) { } 2 31 33
elsif ($clean_field =~ /(^id$|id$|_id$)/ and (defined $hash->{$k} and $self->_is_uuid($hash->{$k}))) { } 0 31 31
elsif ($clean_field =~ /ip(_addr(ess)?)?$/i and (defined $hash->{$k} and $self->_is_ip($hash->{$k}))) { } 2 29 31
elsif ($clean_field =~ /version$/i and (defined $hash->{$k} and $self->_is_version($hash->{$k}))) { } 2 27 29
elsif ($clean_field =~ /^(is|has|enable|active|valid|disabled|inactive)/i and defined $hash->{$k} && $hash->{$k} =~ /^(?:0|1)$/i || !defined($hash->{$k}) || !length($hash->{$k} // '')) { } 2 25 27
elsif ($clean_field =~ /(file|path)$/i and defined $hash->{$k} and $self->_looks_like_path($hash->{$k})) { } 2 23 25
elsif ($clean_field =~ /(count|size|quantity)$/i and defined $hash->{$k} and $self->_is_integer($hash->{$k})) { } 1 22 23
elsif ($self->_is_number($hash->{$k})) { } 1 21 22
205 {
206 2 $func_name = '_set_get_datetime';
207 }
208 ▶ elsif( $clean_field =~ /(^|\b)(uri|url)($|\b)/ ||
Condition66%4/6
$clean_field =~ /(^|\b)(uri|url)($|\b)/ or defined $hash->{$k} and $hash->{$k} =~ m[^https?\:/{2}]
l!l&&r!l&&!r
2031
defined $hash->{$k} and $hash->{$k} =~ m[^https?\:/{2}]
!ll&&!rl&&r
1300
MC/DC33%1/3
$clean_field =~ /(^|\b)(uri|url)($|\b)/ or defined $hash->{$k} and $hash->{$k} =~ m[^https?\:/{2}]
$clean_field =~ /(^|\b)(uri|url)($|\b)/ defined $hash->{$k} $hash->{$k} =~ m[^https?\:/{2}]
Truth table75%3/4
A or B and C
A= $clean_field =~ /(^|\b)(uri|url)($|\b)/B= defined $hash->{$k}C= $hash->{$k} =~ m[^https?\:/{2}]
ABCresult
1XX1
0111
00X0
0100
209 ( defined( $hash->{ $k } ) && $hash->{ $k } =~ /^https?\:\/{2}/ ) )
210 {
211 2 $func_name = '_set_get_uri';
212 }
213 # New: UUID (field suggests ID + value matches standard UUID format)
214 ▶ elsif( $clean_field =~ /(^id$|id$|_id$)/ &&
Condition50%3/6
$clean_field =~ /(^id$|id$|_id$)/ and (defined $hash->{$k} and $self->_is_uuid($hash->{$k}))
!ll&&!rl&&r
3010
defined $hash->{$k} and $self->_is_uuid($hash->{$k})
!ll&&!rl&&r
010
MC/DC0%0/3
$clean_field =~ /(^id$|id$|_id$)/ and (defined $hash->{$k} and $self->_is_uuid($hash->{$k}))
$clean_field =~ /(^id$|id$|_id$)/ defined $hash->{$k} $self->_is_uuid($hash->{$k})
Truth table50%2/4
A and B and C
A= $clean_field =~ /(^id$|id$|_id$)/B= defined $hash->{$k}C= $self->_is_uuid($hash->{$k})
ABCresult
0XX0
10X0
1100
1111
215 ( defined( $hash->{ $k } ) && $self->_is_uuid( $hash->{ $k } ) ) )
216 {
217 0 $func_name = '_set_get_uuid';
218 }
219 # New: IP (field suggests IP + value matches simple IPv4; extend for IPv6 if needed)
220 ▶ elsif( $clean_field =~ /ip(_addr(ess)?)?$/i &&
Condition83%5/6
$clean_field =~ /ip(_addr(ess)?)?$/i and (defined $hash->{$k} and $self->_is_ip($hash->{$k}))
!ll&&!rl&&r
2812
defined $hash->{$k} and $self->_is_ip($hash->{$k})
!ll&&!rl&&r
012
MC/DC66%2/3
$clean_field =~ /ip(_addr(ess)?)?$/i and (defined $hash->{$k} and $self->_is_ip($hash->{$k}))
$clean_field =~ /ip(_addr(ess)?)?$/i defined $hash->{$k} $self->_is_ip($hash->{$k})
Truth table75%3/4
A and B and C
A= $clean_field =~ /ip(_addr(ess)?)?$/iB= defined $hash->{$k}C= $self->_is_ip($hash->{$k})
ABCresult
0XX0
10X0
1100
1111
221 ( defined( $hash->{ $k } ) && $self->_is_ip( $hash->{ $k } ) ) )
222 {
223 2 $func_name = '_set_get_ip';
224 }
225 # New: Version (field suggests version + value matches semver-like pattern)
226 ▶ elsif( $clean_field =~ /version$/i &&
Condition50%3/6
$clean_field =~ /version$/i and (defined $hash->{$k} and $self->_is_version($hash->{$k}))
!ll&&!rl&&r
2702
defined $hash->{$k} and $self->_is_version($hash->{$k})
!ll&&!rl&&r
002
MC/DC33%1/3
$clean_field =~ /version$/i and (defined $hash->{$k} and $self->_is_version($hash->{$k}))
$clean_field =~ /version$/i defined $hash->{$k} $self->_is_version($hash->{$k})
Truth table50%2/4
A and B and C
A= $clean_field =~ /version$/iB= defined $hash->{$k}C= $self->_is_version($hash->{$k})
ABCresult
0XX0
10X0
1100
1111
227 ( defined( $hash->{ $k } ) && $self->_is_version( $hash->{ $k } ) ) )
228 {
229 2 $func_name = '_set_get_version';
230 }
231 # New: Boolean (field suggests flag + value is boolean-ish)
232 # We have to be careful for pseudo boolean value like 'yes', 'no', 'true', 'false', because using _set_get_boolean will replace those by a Module::Generic::Boolean value that stringifies to '0' or '1', and nothing else...
233 ▶ elsif( $clean_field =~ /^(is|has|enable|active|valid|disabled|inactive)/i &&
Condition35%5/14
$clean_field =~ /^(is|has|enable|active|valid|disabled|inactive)/i and defined $hash->{$k} && $hash->{$k} =~ /^(?:0|1)$/i || !defined($hash->{$k}) || !length($hash->{$k} // "")
!ll&&!rl&&r
2502
defined $hash->{$k} and $hash->{$k} =~ /^(?:0|1)$/i or not defined $hash->{$k} or not length($hash->{$k} // "")
l!l&&r!l&&!r
200
defined $hash->{$k} and $hash->{$k} =~ /^(?:0|1)$/i or not defined $hash->{$k}
l!l&&r!l&&!r
200
defined $hash->{$k} and $hash->{$k} =~ /^(?:0|1)$/i
!ll&&!rl&&r
002
$hash->{$k} // ""
l!l
00
MC/DC20%1/5
$clean_field =~ /^(is|has|enable|active|valid|disabled|inactive)/i and defined $hash->{$k} && $hash->{$k} =~ /^(?:0|1)$/i || !defined($hash->{$k}) || !length($hash->{$k} // "")
$clean_field =~ /^(is|has|enable|active|valid|disabled|inactive)/i defined $hash->{$k} $hash->{$k} =~ /^(?:0|1)$/i not defined $hash->{$k} $hash->{$k}
Truth table25%2/8
A and B and C or not(D) or not(E)
A= $clean_field =~ /^(is|has|enable|active|valid|disabled|inactive)/iB= defined $hash->{$k}C= $hash->{$k} =~ /^(?:0|1)$/iD= not defined $hash->{$k}E= $hash->{$k}
ABCDEresult
0XXXX0
10X010
110010
111XX1
10X1X1
1101X1
10X001
110001
234 ( ( defined( $hash->{ $k } ) && $hash->{ $k } =~ /^(?:0|1)$/i ) || !defined( $hash->{ $k } ) || !length( $hash->{ $k } // '' ) ) )
235 {
236 2 $func_name = '_set_get_boolean';
237 }
238 # New: File/path (field suggests file/path + value looks like a path)
239 # This needs improvement, or it might catch false positive...
240 ▶ elsif( $clean_field =~ /(file|path)$/i &&
Condition83%5/6
$clean_field =~ /(file|path)$/i and defined $hash->{$k} and $self->_looks_like_path($hash->{$k})
!ll&&!rl&&r
2212
$clean_field =~ /(file|path)$/i and defined $hash->{$k}
!ll&&!rl&&r
2203
MC/DC66%2/3
$clean_field =~ /(file|path)$/i and defined $hash->{$k} and $self->_looks_like_path($hash->{$k})
$clean_field =~ /(file|path)$/i defined $hash->{$k} $self->_looks_like_path($hash->{$k})
Truth table75%3/4
A and B and C
A= $clean_field =~ /(file|path)$/iB= defined $hash->{$k}C= $self->_looks_like_path($hash->{$k})
ABCresult
0XX0
10X0
1100
1111
241 defined( $hash->{ $k } ) &&
242 $self->_looks_like_path( $hash->{ $k } ) )
243 {
244 2 $func_name = '_set_get_file';
245 }
246 ▶ elsif( $clean_field =~ /(count|size|quantity)$/i &&
Condition66%4/6
$clean_field =~ /(count|size|quantity)$/i and defined $hash->{$k} and $self->_is_integer($hash->{$k})
!ll&&!rl&&r
2201
$clean_field =~ /(count|size|quantity)$/i and defined $hash->{$k}
!ll&&!rl&&r
2201
MC/DC33%1/3
$clean_field =~ /(count|size|quantity)$/i and defined $hash->{$k} and $self->_is_integer($hash->{$k})
$clean_field =~ /(count|size|quantity)$/i defined $hash->{$k} $self->_is_integer($hash->{$k})
Truth table50%2/4
A and B and C
A= $clean_field =~ /(count|size|quantity)$/iB= defined $hash->{$k}C= $self->_is_integer($hash->{$k})
ABCresult
0XX0
10X0
1100
1111
247 defined( $hash->{ $k } ) && $self->_is_integer( $hash->{ $k } ) )
248 {
249 1 $func_name = '_set_get_number';
250 }
251 # New: Number (after other checks; use looks_like_number for certainty)
252 elsif( $self->_is_number( $hash->{ $k } ) )
253 {
254 1 $func_name = '_set_get_number';
255 }
256 35 my $pl = "sub ${class}::${clean_field} { return( shift->${func_name}( '$clean_field', \@_ ) ); }";
257 # my $pl = q[sub ${class}::${clean_field} { print( STDERR "Got here\n" ); }];
258 35 ▶ eval( $pl );
Subroutine method: called CC=1 SCAR=0.0
Subroutine method: called CC=1 SCAR=0.0
Subroutine proto: called CC=1 SCAR=0.0
Subroutine proto: called CC=1 SCAR=0.0
Subroutine uri: called CC=1 SCAR=0.0
Subroutine uri: called CC=1 SCAR=0.0
Subroutine fname: called CC=1 SCAR=0.0
Subroutine lname: called CC=1 SCAR=0.0
Subroutine location: called CC=1 SCAR=0.0
Pod documented
Pod undocumented
Pod undocumented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Pod documented
Pod documented
Pod documented
Pod documented
Pod undocumented
Pod documented
Pod documented
259 35 ▶ die( $@ ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 35 35
260 35 my $rv = $self->$clean_field( $hash->{ $k } );
261 35 ▶ return( $self->pass_error ) if( !defined( $rv ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $rv and $self->error 0 35 35
Condition66%2/3
not defined $rv and $self->error
!ll&&!rl&&r
3410
MC/DC0%0/2
not defined $rv and $self->error
not defined $rv $self->error
Truth table66%2/3
not(A) and B
A= not defined $rvB= $self->error
ABresult
0X0
100
111
262 }
263 else
264 {
265 # Fallback for unknown refs: use generic _set_get to store safely
266 0 my $clean_field = $make_clean_field->( $k );
267 0 ▶ next unless( length( $clean_field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $clean_field 0 0 0
268 0 my $func_name = '_set_get';
269 0 my $pl = "sub ${class}::${clean_field} { return( shift->${func_name}( '$clean_field', \@_ ) ); }";
270 0 eval( $pl );
271 0 ▶ die( "Error with code:\n$pl\n$@" ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
272 0 my $rv = $self->$clean_field( $hash->{ $k } );
273 0 ▶ return( $self->pass_error ) if( !defined( $rv ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $rv and $self->error 0 0 0
Condition0%0/3
not defined $rv and $self->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $rv and $self->error
not defined $rv $self->error
Truth table0%0/3
not(A) and B
A= not defined $rvB= $self->error
ABresult
0X0
100
111
274 }
275 }
276 24 return( $self );
277 }
278  
279 sub FREEZE
280 6 ▶{
Subroutine FREEZE: called CC=4 SCAR=13.9
Pod undocumented
281 6 my $self = CORE::shift( @_ );
282 6 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition50%1/2
shift @_ // ""
l!l
40
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
283 6 my $class = CORE::ref( $self );
284 6 my %hash = %$self;
285 # Return an array reference rather than a list so this works with Sereal and CBOR
286 # On or before Sereal version 4.023, Sereal did not support multiple values returned
287 6 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 1 3 4
288 {
289 3 require Sereal::Encoder;
290 4 require version;
291
292 4 ▶ 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
293 {
294 3 CORE::return( [$class, \%hash] );
295 }
296 }
297 # But CBOR and Storable want a list with the first element being the serialised element
298 7 CORE::return( $class, \%hash );
299 }
300  
301 6 ▶sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
Pod undocumented
302  
303 6 ▶sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: called CC=1 SCAR=0.0
Pod undocumented
304  
305 # 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.
306 # NOTE: Storable calls it with a blessed object it created followed with $cloning and any other arguments initially provided by STORABLE_freeze
307 sub THAW
308 6 ▶{
Subroutine THAW: called CC=10 SCAR=27.6
Pod undocumented
309 7 my( $self, undef, @args ) = @_;
310 7 ▶ 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 4 4
Condition33%1/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
400
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
311 7 ▶ 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 ? : 4 0 4
Condition22%2/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
004
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
004
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
312 7 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 4 0 4
313 7 my $new;
314 # Storable pattern requires to modify the object it created rather than returning a new one
315 7 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 3 1 4
316 {
317 6 foreach( CORE::keys( %$hash ) )
318 {
319 11 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
320 }
321 6 $new = $self;
322 }
323 else
324 {
325 4 $new = CORE::bless( $hash => $class );
326 }
327 7 CORE::return( $new );
328 }
329  
330 sub TO_JSON
331 2 ▶{
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod undocumented
332 3 my $self = CORE::shift( @_ );
333 3 my $ref = { %$self };
334 2 CORE::delete( $ref->{_data} );
335 2 CORE::delete( $ref->{_data_repo} );
336 2 CORE::return( $ref );
337 }
338  
339 sub AUTOLOAD
340 13 ▶{
Subroutine AUTOLOAD: called CC=57 SCAR=58.1
341 12 my( $method ) = our $AUTOLOAD =~ /([^:]+)$/;
342 5 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
343 13 my $self = shift( @_ );
344 13 ▶ my $class = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
1100
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
345 14 my $args = \@_;
346  
347 14 ▶ if( HAS_THREADS )
Branch: 1 branch
BranchTrueFalseTotal
if (&HAS_THREADS()) 0 11 11
348 {
349 3 ▶ if( threads->tid != 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ("threads"->tid != 0) 0 0 0
350 {
351 0 ▶ CORE::warn( "Module::Generic::Dynamic::AUTOLOAD is not thread-safe and should not be called from a thread." ) if( warnings::enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("Module::Generic") 0 0 0
352 # return( $self->error( "Module::Generic::Dynamic::AUTOLOAD is not thread-safe and should not be called from a thread." ) );
353 }
354 }
355  
356 # Check if method already exists
357 11 ▶ if( my $code = $self->can( $method ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $self->can($method)) 0 11 11
358 {
359 0 return( $code->( @_ ) );
360 }
361  
362 # Default handler
363 # my $handler = '_set_get_scalar_as_object';
364 11 my( $handler, $pl, $ref );
365 11 my $has_args = scalar( @_ );
366 11 my $first_arg = \'';
367 11 ▶ if( $has_args )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_args) 11 0 11
368 {
369 11 ▶ $ref = lc( ref( $_[0] // '' ) );
Condition50%1/2
$_[0] // ""
l!l
110
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
370 11 ▶ $first_arg = \$_[0] if( defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 11 0 11
371 }
372  
373 # We try to find the right handler based on the method name
374 # Those checks should be very conservative. If nothing is found, and we received data, we will check the data type to find the proper handler.
375 11 ▶ if( $method =~ /(^|\b)date|datetime|created|modified($|\b)/ )
Branch: 8 branches
BranchTrueFalseTotal
if ($method =~ /(^|\b)date|datetime|created|modified($|\b)/) { } 0 11 11
elsif ($method =~ /(^|\b)(uri|url)($|\b)/) { } 1 10 11
elsif ($method =~ /(^id$|id$|_id$)/) { } 1 9 10
elsif ($method =~ /ip(_addr(ess)?)?$/i) { } 0 9 9
elsif ($method =~ /version$/i) { } 0 9 9
elsif ($method =~ /^(is|has|enable|active|valid|disabled|inactive)/i) { } 1 8 9
elsif ($method =~ /(file|path)$/i) { } 1 7 8
elsif ($method =~ /(count|size|quantity)$/i) { } 1 6 7
376 {
377 0 $handler = '_set_get_datetime';
378 }
379 elsif( $method =~ /(^|\b)(uri|url)($|\b)/ )
380 {
381 1 $handler = '_set_get_uri';
382 }
383 elsif( $method =~ /(^id$|id$|_id$)/ )
384 {
385 1 $handler = '_set_get_uuid';
386 }
387 elsif( $method =~ /ip(_addr(ess)?)?$/i )
388 {
389 0 $handler = '_set_get_ip';
390 }
391 elsif( $method =~ /version$/i )
392 {
393 0 $handler = '_set_get_version';
394 }
395 elsif( $method =~ /^(is|has|enable|active|valid|disabled|inactive)/i )
396 {
397 1 $handler = '_set_get_boolean';
398 }
399 elsif( $method =~ /(file|path)$/i )
400 {
401 1 $handler = '_set_get_file';
402 }
403 elsif( $method =~ /(count|size|quantity)$/i )
404 {
405 1 $handler = '_set_get_number';
406 }
407  
408 # Some data types take precedence and some don't, so we keep checking
409 HANDLERS:
410 {
411 11 ▶ last HANDLERS unless( $has_args );
Branch: 1 branch
BranchTrueFalseTotal
unless $has_args 0 11 11
412 # We make that determination here, because we do not want that check to conflict with regular SCALAR that comes below
413 11 ▶ if( defined( $ref ) &&
Branch: 6 branches
BranchTrueFalseTotal
if (defined $ref and $ref eq 'scalar' and $$ref == 1 || $$ref == 0) { } 0 11 11
elsif (defined $ref and $ref eq 'hash' || $ref eq 'array' || $ref eq 'scalar') { } 5 6 11
elsif ($ref eq 'CODE') { } 0 6 6
elsif ($self->_is_object($$first_arg)) { } 1 5 6
elsif ($self->_is_glob($$first_arg)) { } 0 5 5
elsif ($has_args and not $ref) { } 5 0 5
Condition22%2/9
defined $ref and $ref eq "scalar" and $$ref == 1 || $$ref == 0
!ll&&!rl&&r
1100
defined $ref and $ref eq "scalar"
!ll&&!rl&&r
0110
$$ref == 1 or $$ref == 0
l!l&&r!l&&!r
000
MC/DC0%0/4
defined $ref and $ref eq "scalar" and $$ref == 1 || $$ref == 0
defined $ref $ref eq "scalar" $$ref == 1 $$ref == 0
Truth table20%1/5
A and B and C or D
A= defined $refB= $ref eq "scalar"C= $$ref == 1D= $$ref == 0
ABCDresult
0XXX0
10XX0
11000
111X1
11011
414 $ref eq 'scalar' &&
415 ( $$ref == 1 || $$ref == 0 ) )
416 {
417 0 $handler = '_set_get_boolean';
418 }
419 # Using hash is very broad, so if we already have a handler
420 ▶ elsif( defined( $ref ) && ( $ref eq 'hash' || $ref eq 'array' || $ref eq 'scalar' ) )
Condition77%7/9
defined $ref and $ref eq "hash" || $ref eq "array" || $ref eq "scalar"
!ll&&!rl&&r
065
$ref eq "hash" or $ref eq "array" or $ref eq "scalar"
l!l&&r!l&&!r
506
$ref eq "hash" or $ref eq "array"
l!l&&r!l&&!r
416
MC/DC50%2/4
defined $ref and $ref eq "hash" || $ref eq "array" || $ref eq "scalar"
defined $ref $ref eq "hash" $ref eq "array" $ref eq "scalar"
Truth table60%3/5
A and B or C or D
A= defined $refB= $ref eq "hash"C= $ref eq "array"D= $ref eq "scalar"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
421 {
422 5 ▶ last HANDLERS if( defined( $handler ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $handler 0 5 5
423 5 $handler = "_set_get_${ref}_as_object";
424 }
425 elsif( $ref eq 'CODE' )
426 {
427 0 $handler = '_set_get_code';
428 }
429 elsif( $self->_is_object( $$first_arg ) )
430 {
431 1 ▶ if( $self->_is_a( $$first_arg => [qw( JSON::PP::Boolean Module::Generic::Boolean )] ) )
Branch: 5 branches
BranchTrueFalseTotal
if ($self->_is_a($$first_arg, ['JSON::PP::Boolean', 'Module::Generic::Boolean'])) { } 0 1 1
elsif ($self->_is_a($$first_arg, 'Module::Generic::File')) { } 0 1 1
elsif ($self->_is_a($$first_arg, 'Module::Generic::Array')) { } 1 0 1
elsif ($self->_is_a($$first_arg, 'Module::Generic::Number')) { } 0 0 0
elsif ($self->_is_a($$first_arg, ['DateTime::Lite', 'DateTime', 'Module::Generic::DateTime'])) { } 0 0 0
432 {
433 0 $handler = '_set_get_boolean';
434 }
435 elsif( $self->_is_a( $$first_arg => 'Module::Generic::File' ) )
436 {
437 0 $handler = '_set_get_file';
438 }
439 elsif( $self->_is_a( $$first_arg => 'Module::Generic::Array' ) )
440 {
441 1 $handler = '_set_get_array_as_object';
442 }
443 elsif( $self->_is_a( $$first_arg => 'Module::Generic::Number' ) )
444 {
445 0 $handler = '_set_get_number';
446 }
447 elsif( $self->_is_a( $$first_arg => [qw( DateTime::Lite DateTime Module::Generic::DateTime )] ) )
448 {
449 0 $handler = '_set_get_datetime';
450 }
451 else
452 {
453 0 my $obj_class = ref( $$first_arg );
454 0 $handler = '_set_get_object';
455 0 $pl = "sub ${class}::${method} { return( shift->$handler( '$method', '$obj_class', \@_ ) ); }";
456 }
457 }
458 elsif( $self->_is_glob( $$first_arg ) )
459 {
460 0 $handler = '_set_get_glob';
461 }
462 # We have arguments, but they are just not reference
463 ▶ elsif( $has_args && !$ref )
Condition33%1/3
$has_args and not $ref
!ll&&!rl&&r
005
MC/DC0%0/2
$has_args and not $ref
$has_args not $ref
Truth table33%1/3
A and not(B)
A= $has_argsB= not $ref
ABresult
0X0
100
111
464 {
465 5 ▶ if( (
Branch: 8 branches
BranchTrueFalseTotal
if ($self->_load_class('Regexp::Common', 'URI') and $$first_arg =~ /^(?:$Regexp::Common::URI::RE{'URI'}{'HTTP'}|$Regexp::Common::URI::RE{'URI'}{'HTTP'}{join $;, '-scheme', 'https'})$/ or $$first_arg =~ m[^https?\:/{2}[^\s\0-\x1F\x7F]+$] and not $$first_arg =~ /[<>\"|?*]/) { } 1 4 5
elsif ($self->_is_uuid($$first_arg)) { } 1 3 4
elsif ($self->_is_ip($$first_arg)) { } 0 3 3
elsif ($handler eq '_set_get_boolean' and $$first_arg == 1 || $$first_arg == 0) { } 1 2 3
elsif ($self->_looks_like_path($$first_arg)) { } 1 1 2
elsif ($self->_is_integer($$first_arg)) { } 1 0 1
elsif ($self->_is_number($$first_arg)) { } 0 0 0
elsif ($self->_is_version($$first_arg)) { } 0 0 0
Condition55%5/9
$self->_load_class("Regexp::Common", "URI") and $$first_arg =~ /^(?:$Regexp::Common::URI::RE{"URI"}{"HTTP"}|$Regexp::Common::URI::RE{"URI"}{"HTTP"}{join $;, "-scheme", "https"})$/ or $$first_arg =~ m[^https?\:/{2}[^\s\0-\x1F\x7F]+$] and not $$first_arg =~ /[<>\"|?*]/
l!l&&r!l&&!r
014
$self->_load_class("Regexp::Common", "URI") and $$first_arg =~ /^(?:$Regexp::Common::URI::RE{"URI"}{"HTTP"}|$Regexp::Common::URI::RE{"URI"}{"HTTP"}{join $;, "-scheme", "https"})$/
!ll&&!rl&&r
500
$$first_arg =~ m[^https?\:/{2}[^\s\0-\x1F\x7F]+$] and not $$first_arg =~ /[<>\"|?*]/
!ll&&!rl&&r
401
MC/DC25%1/4
$self->_load_class("Regexp::Common", "URI") and $$first_arg =~ /^(?:$Regexp::Common::URI::RE{"URI"}{"HTTP"}|$Regexp::Common::URI::RE{"URI"}{"HTTP"}{join $;, "-scheme", "https"})$/ or $$first_arg =~ m[^https?\:/{2}[^\s\0-\x1F\x7F]+$] and not $$first_arg =~ /[<>\"|?*]/
$self->_load_class("Regexp::Common", "URI") $$first_arg =~ /^(?:$Regexp::Common::URI::RE{"URI"}{"HTTP"}|$Regexp::Common::URI::RE{"URI"}{"HTTP"}{join $;, "-scheme", "https"})$/ $$first_arg =~ m[^https?\:/{2}[^\s\0-\x1F\x7F]+$] not $$first_arg =~ /[<>\"|?*]/
Truth table28%2/7
A and B or C and not(D)
A= $self->_load_class("Regexp::Common", "URI")B= $$first_arg =~ /^(?:$Regexp::Common::URI::RE{"URI"}{"HTTP"}|$Regexp::Common::URI::RE{"URI"}{"HTTP"}{join $;, "-scheme", "https"})$/C= $$first_arg =~ m[^https?\:/{2}[^\s\0-\x1F\x7F]+$]D= not $$first_arg =~ /[<>\"|?*]/
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
466 $self->_load_class( 'Regexp::Common', 'URI' ) &&
467 $$first_arg =~ /^(?:$Regexp::Common::URI::RE{URI}{HTTP}|$Regexp::Common::URI::RE{URI}{HTTP}{-scheme => 'https'})$/
468 ) ||
469 (
470 $$first_arg =~ /^https?\:\/{2}[^\s\0-\x1F\x7F]+$/ &&
471 $$first_arg !~ /[<>\"|?*]/
472 ) )
473 {
474 1 $handler = '_set_get_uri';
475 }
476 elsif( $self->_is_uuid( $$first_arg ) )
477 {
478 1 $handler = '_set_get_uuid';
479 }
480 elsif( $self->_is_ip( $$first_arg ) )
481 {
482 0 $handler = '_set_get_ip';
483 }
484 # We just do this here, so it does not get misconstrued for a version or an integer
485 ▶ elsif( $handler eq '_set_get_boolean' &&
Condition50%3/6
$handler eq "_set_get_boolean" and $$first_arg == 1 || $$first_arg == 0
!ll&&!rl&&r
201
$$first_arg == 1 or $$first_arg == 0
l!l&&r!l&&!r
010
MC/DC33%1/3
$handler eq "_set_get_boolean" and $$first_arg == 1 || $$first_arg == 0
$handler eq "_set_get_boolean" $$first_arg == 1 $$first_arg == 0
Truth table50%2/4
A and B or C
A= $handler eq "_set_get_boolean"B= $$first_arg == 1C= $$first_arg == 0
ABCresult
0XX0
1000
11X1
1011
486 ( $$first_arg == 1 || $$first_arg == 0 ) )
487 {
488 # ok, we're good
489 }
490 elsif( $self->_looks_like_path( $$first_arg ) )
491 {
492 1 $handler = '_set_get_file';
493 }
494 elsif( $self->_is_integer( $$first_arg ) )
495 {
496 1 $handler = '_set_get_number';
497 }
498 elsif( $self->_is_number( $$first_arg ) )
499 {
500 0 $handler = '_set_get_number';
501 }
502 # We do version at the end, because '0' is a proper version, and it would conflict with integer and number checks.
503 elsif( $self->_is_version( $$first_arg ) )
504 {
505 0 $handler = '_set_get_version';
506 }
507 }
508  
509 # Fallback also applies for the special object class Regexp
510 11 ▶ unless( defined( $handler ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $handler) 0 11 11
511 {
512 0 ▶ $handler = ( $ref eq 'scalar' || !$ref ) ? '_set_get_scalar_as_object' : '_set_get_scalar';
Branch: 1 branch
BranchTrueFalseTotal
$ref eq 'scalar' || !$ref ? : 0 0 0
Condition0%0/3
$ref eq "scalar" or not $ref
l!l&&r!l&&!r
000
MC/DC0%0/2
$ref eq "scalar" or not $ref
$ref eq "scalar" not $ref
Truth table0%0/3
A or not(B)
A= $ref eq "scalar"B= not $ref
ABresult
1X1
011
000
513 }
514 };
515  
516 # Common code here for simple handlers
517 11 ▶ if( defined( $handler ) && !defined( $pl ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $handler and not defined $pl) { } 11 0 11
elsif (not defined $handler) { } 0 0 0
Condition33%1/3
defined $handler and not defined $pl
!ll&&!rl&&r
0011
MC/DC0%0/2
defined $handler and not defined $pl
defined $handler not defined $pl
Truth table33%1/3
A and not(B)
A= defined $handlerB= not defined $pl
ABresult
0X0
100
111
518 {
519 11 $pl = "sub ${class}::${method} { return( shift->$handler( '$method', \@_ ) ); }";
520 }
521 elsif( !defined( $handler ) )
522 {
523 0 $handler = '_set_get_scalar';
524 }
525 11 local $@;
526 11 $pl = "sub ${class}::${method} { return( shift->$handler( '$method', \@_ ) ); }";
527 11 eval( $pl );
528 11 ▶ return( $self->error( "Failed to create method $method in $class: $@" ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 11 11
529 # die( $@ ) if( $@ );
530 11 return( $self->$method( @_ ) );
531 };
532  
533 # Avoid being called by AUTOLOAD
534 sub DESTROY
535 34 ▶{
Subroutine DESTROY: called CC=3 SCAR=11.4
536 # <https://perldoc.perl.org/perlobj#Destructors>
537 31 CORE::local( $., $@, $!, $^E, $? );
538 31 ▶ CORE::return if( Module::Generic::_in_global_destruction() );
Branch: 1 branch
BranchTrueFalseTotal
if Module::Generic::_in_global_destruction() 0 28 28
539 31 my $self = CORE::shift( @_ );
540 31 ▶ CORE::return if( !CORE::defined( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $self 0 28 28
541 };
542  
543 7 1;
544  
545 __END__
« lib/Module/Generic/File/Cache.pm ↑ Summary lib/Module/Generic/Number/Format.pm »