lib/Module/Generic.pm

filter: Statementstmt 46.2% 2059 / 4457 Branchbran 32.5% 1083 / 3324 Conditioncond 25.8% 781 / 3023 MC/DCmcdc 5.1% 83 / 1612 Subroutinesub 72.0% 211 / 293 Podpod 92.5% 37 / 40 totaltotal 33.3% 4254 / 12749 CC 3062 SCAR 74.0
CC
3062
Cov
36%
serialise
15085.9
deserialise
8714.9
_set_get_object_without_init
5216.1
CRAP 1634.5
↑ Summary lib/Module/Generic/File.pm »
1 ## -*- perl -*-
2 ##----------------------------------------------------------------------------
3 ## Module Generic - ~/lib/Module/Generic.pm
4 ## Version v1.8.1
5 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
6 ## Author: Jacques Deguest <jack@deguest.jp>
7 ## Created 2019/08/24
8 ## Modified 2026/09/25
9 ## All rights reserved
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;
14 BEGIN
15 39 ▶{
Subroutine BEGIN: called CC=3 SCAR=11.0
16 109 ▶ use v5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 103 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 101 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 35 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 33 ▶ use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 $MOD_PERL $AUTOLOAD $ERROR $PARAM_CHECKER_LOAD_ERROR $VERBOSE $DEBUG
22 $SILENT_AUTOLOAD $PARAM_CHECKER_LOADED $CALLER_LEVEL $COLOUR_NAME_TO_RGB
23 $true $false $DEBUG_LOG_IO %RE $stderr $stderr_raw $SERIALISER
24 $NUMBER_REAL_RE $IPV4_RE $IPV6_RE
25 $AUTOLOAD_SUBS $SUB_ATTR_LIST $DATA_POS $HAS_LOCAL_TZ $VERSION_LAX_REGEX
26 $PARSE_DATE_FRACTIONAL1_RE $PARSE_DATE_WITH_MILI_SECONDS_RE $PARSE_DATE_HTTP_RE
27 $PARSE_DATE_NON_STDANDARD_RE $PARSE_DATE_ONLY_RE $PARSE_DATE_ONLY_US_SHORT_RE
28 $PARSE_DATE_ONLY_EU_SHORT_RE $PARSE_DATE_ONLY_US_LONG_RE $PARSE_DATE_ONLY_EU_LONG_RE
29 $PARSE_DATE_DOTTED_ONLY_EU_RE $PARSE_DATE_ROMAN_RE $PARSE_DATE_DIGITS_ONLY_RE
30 $PARSE_DATE_ONLY_JP_RE $PARSE_DATETIME_JP_RE $PARSE_DATE_TIMESTAMP_RE
31 $PARSE_DATETIME_RELATIVE_RE $PARSE_DATES_ALL_RE $PARSE_DATE_NON_STDANDARD2_RE
32 $XS_LOADED
33 33 );
34 98 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 37 ▶ use B ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36 35 ▶ use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 35 ▶ use Module::Generic::Global ':const';
Subroutine BEGIN: called CC=1 SCAR=0.0
38 35 ▶ use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 88 ▶ use Scalar::Util qw( openhandle );
Subroutine BEGIN: called CC=1 SCAR=0.0
40 # To get some context on what the caller expect. This is used in our error() method to allow chaining without breaking
41 116 ▶ use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 83 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 83 ▶ use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 61 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
45 55 our @ISA = qw( Exporter );
46 51 our @EXPORT = qw( );
47 51 our @EXPORT_OK = qw( subclasses );
48 55 our %EXPORT_TAGS = ();
49 # local $^W;
50 # mod_perl/2.0.10
51 55 ▶ if( exists( $ENV{MOD_PERL} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"MOD_PERL"} and ($Module::Generic::MOD_PERL) = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]u) 64 40 104
Condition66%2/3
exists $ENV{"MOD_PERL"} and ($Module::Generic::MOD_PERL) = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]u
!ll&&!rl&&r
92011
MC/DC50%1/2
exists $ENV{"MOD_PERL"} and ($Module::Generic::MOD_PERL) = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]u
exists $ENV{"MOD_PERL"} ($Module::Generic::MOD_PERL) = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]u
Truth table66%2/3
A and B
A= exists $ENV{"MOD_PERL"}B= ($Module::Generic::MOD_PERL) = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]u
ABresult
0X0
100
111
52 &&
53 ( ( $MOD_PERL ) = $ENV{MOD_PERL} =~ /^mod_perl\/(\d+\.[\d\.]+)/ ) )
54 {
55 18 select( ( select( STDOUT ), $| = 1 )[0] );
56 3 require Apache2::Log;
57 # For _is_class_loaded method
58 3 require Apache2::Module;
59 3 require Apache2::ServerUtil;
60 68 require Apache2::RequestUtil;
61 64 require Apache2::ServerRec;
62 64 require ModPerl::Util;
63 64 require Apache2::Const;
64 64 Apache2::Const->import( compile => qw( :log OK ) );
65 }
66 91 $VERBOSE = 0;
67 37 $DEBUG = 0;
68 37 $SILENT_AUTOLOAD = 1;
69 43 $PARAM_CHECKER_LOADED = 0;
70 53 $CALLER_LEVEL = 0;
71 57 $COLOUR_NAME_TO_RGB = {};
72 42 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
73 # Can use Sereal also
74 49 $SERIALISER = 'Storable::Improved';
75  
76 191 $SUB_ATTR_LIST = qr{
77 [[:blank:]\h]* : [[:blank:]\h]*
78 (?:
79 # one attribute
80 (?> # no backtrack
81 (?! \d) \w+
82 (?<nested> \( (?: [^()]++ | (?&nested)++ )*+ \) ) ?
83 )
84 (?: [[:blank:]\h]* : [[:blank:]\h]* | [[:blank:]\h]ss+ (?! :) )
85 )*
86 }x;
87 # From version::regex
88 # We use /x rather than (?^x: because the (?^alupimnsx) embedded pattern-match modifiers were not fully implemented until perl v5.12 or v5.14.
89 188 $VERSION_LAX_REGEX = qr/(?: (?:
90 (?<has_v>v) (?<ver>(?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )?)
91 |
92 (?<ver>(?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)?)
93 ) | (?: (?<ver>(?:[0-9]+) (?: (?:\.[0-9]+) | \. )? (?:_[0-9]+)?)
94 |
95 (?<ver>(?:\.[0-9]+) (?:_[0-9]+)?)
96 )
97 )/x;
98 # Unfortunately, Regexp::Common does not install under perl v5.10.1 because of a bug in its test t/test_comments.t, so we copy here those regular expression constants
99 188 $NUMBER_REAL_RE = qr/(?:(?i)(?:[-+]?)(?:(?=[.]?[0123456789])(?:[0123456789]*)(?:(?:[.])(?:[0123456789]{0,}))?)(?:(?:[E])(?:(?:[-+]?)(?:[0123456789]+))|))/;
100 191 $IPV4_RE = qr/(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2}))/;
101 187 $IPV6_RE = qr/(?:(?|(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4})|(?::(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?::(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?::(?:)(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?::(?:)(?:)(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?::(?:)(?:)(?:)(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?::(?:)(?:)(?:)(?:)(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}))|(?::(?:)(?:)(?:)(?:)(?:)(?:)(?:)(?:):)|(?:(?:[0-9a-fA-F]{1,4}):(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:)(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:)(?:)(?:)(?:)(?:):)|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:)(?:)(?:)(?:):)|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:)(?:)(?:):)|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:)(?:):)|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:):(?:[0-9a-fA-F]{1,4}))|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:)(?:):)|(?:(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:[0-9a-fA-F]{1,4}):(?:)(?:):)))/;
102 187 our $XS_LOADED = 0;
103 # Used by all modules, and possibly from other classes too.
104 # Module::Generic requires perl v5.16.0, where ${^GLOBAL_PHASE} is always
105 # defined, so the historical fallback through B::main_cv() is dead code
106 # and has been removed.
107 190 ▶ *_in_global_destruction = sub{ ${^GLOBAL_PHASE} eq 'DESTRUCT' };
Subroutine __ANON__: called CC=1 SCAR=0.0
108 # NOTE: _in_end_phase
109 # Returns true while perl is running END blocks. This is distinct from
110 # _in_global_destruction, which only becomes true during DESTRUCT (the phase
111 # that follows END). We need to detect END separately because some
112 # operations on threads::shared structures, such as marking a fresh variable
113 # as :shared, are unsafe at that point on older threads::shared releases
114 # (notably the 1.4 bundled with perl 5.16) and abort the interpreter with
115 # an S_get_userlock assertion. Combining !_in_end_phase() and
116 # !_in_global_destruction() gives a complete guard against creating new
117 # shared state on the way out.
118 189 ▶ *_in_end_phase = sub{ ${^GLOBAL_PHASE} eq 'END' };
Subroutine __ANON__: called CC=1 SCAR=0.0
119  
120 186 our $VERSION = 'v1.8.1';
121 };
122  
123 # Load the XS shared library (Generic.so) which provides faster implementations of
124 # some methods like _is_object, _is_array, _is_hash, _obj2h and _refaddr.
125 # The same .so is also loaded by Module::Generic::File::Magic when needed.
126 #
127 # $XS_LOADED is set to 1 on success so that Module::Generic::File::Magic,
128 # which shares the same .so, can skip its own XSLoader::load call and avoid
129 # the "subroutine redefined" warnings that a double bootstrap causes.
130 #
131 # NOTE: If the .so fails to load, the pure-Perl implementations defined later
132 # in this file serve as fallback, so pure-Perl installs remain fully functional, and
133 # $XS_LOADED remains 0.
134 {
135 37 local $@;
136 eval
137 37 {
138 37 XSLoader::load( 'Module::Generic', $Module::Generic::VERSION );
139 37 $XS_LOADED = 1;
140 };
141 }
142  
143 189 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
144 # use strict;
145  
146 # We put it here to avoid 'redefine' error
147 33 require Module::Generic::Boolean;
148  
149 33 require IO::File;
150 33 our $stderr = IO::File->new;
151 33 $stderr->fdopen( fileno( STDERR ), 'w' );
152 41 $stderr->binmode( ':utf8' );
153 33 $stderr->autoflush( 1 );
154 33 our $stderr_raw = IO::File->new;
155 33 $stderr_raw->fdopen( fileno( STDERR ), 'w' );
156 33 $stderr_raw->binmode( ':raw' );
157 33 $stderr_raw->autoflush( 1 );
158 # $stderr = stderr( binmode => 'utf-8', autoflush => 1 );
159 # $stderr_raw = stderr( binmode => 'raw', autoflush => 1 );
160  
161 {
162 179 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
163 33 $true = $Module::Generic::Boolean::true;
164 33 $false = $Module::Generic::Boolean::false;
165 }
166  
167 # NOTE: Predeclaration of available methods for autoload
168 # for sub in `perl -ln -E 'say "$1" if( /^sub (\w+)[[:blank:]\v]*(?:\{|\Z|[[:blank:]\v]*:[[:blank:]\v]*lvalue)/ && $1 ne "STORABLE_freeze" && $1 ne "STORABLE_thaw" && $1 ne "STORABLE_thaw_post_processing" )' ./lib/Module/Generic.pm | LC_COLLATE=C sort -uV`; do echo "sub $sub;"; done
169 sub AUTOLOAD;
170 sub DEBUG;
171 sub DESTROY;
172 sub FREEZE;
173 sub THAW;
174 sub TO_JSON;
175 sub VERBOSE;
176 sub as_hash;
177 sub clear;
178 sub clear_error;
179 sub clone;
180 sub coloured;
181 sub colour_close;
182 sub colour_closest;
183 sub colour_format;
184 sub colour_max_depth;
185 sub colour_open;
186 sub colour_parse;
187 sub colour_to_rgb;
188 sub debug;
189 sub deserialise;
190 sub deserialize;
191 sub dump;
192 sub dumper;
193 sub dumpto_dumper;
194 sub dumpto_printer;
195 sub dump_hex;
196 sub dump_print;
197 sub errno;
198 sub error;
199 sub error_handler;
200 sub false;
201 sub fatal;
202 sub force_tty;
203 sub get;
204 sub import;
205 sub init;
206 sub log_handler;
207 sub messagef_colour;
208 sub message_colour;
209 sub new;
210 sub new_array;
211 sub new_datetime;
212 sub new_file;
213 sub new_glob;
214 sub new_hash;
215 sub new_json;
216 sub new_json_safe;
217 sub new_null;
218 sub new_number;
219 sub new_scalar;
220 sub new_tempdir;
221 sub new_tempfile;
222 sub new_version;
223 sub noexec;
224 sub pass_error;
225 sub printer;
226 sub quiet;
227 sub save;
228 sub serialise;
229 sub serialize;
230 sub set;
231 sub subclasses;
232 sub true;
233 sub verbose;
234 sub will;
235 sub _autoload_subs;
236 sub _can;
237 sub _can_overload;
238 sub _dump_options;
239 sub _error_callbacks;
240 sub _get_args_as_array;
241 sub _get_args_as_hash;
242 sub _get_datetime_regexp;
243 sub _get_stack_trace;
244 sub _get_symbol;
245 sub _has_base64;
246 sub _has_symbol;
247 sub _implement_freeze_thaw;
248 sub _instantiate_object;
249 sub _is_a;
250 sub _is_array;
251 sub _is_class_loadable;
252 sub _is_class_loaded;
253 sub _is_code;
254 sub _is_empty;
255 sub _is_glob;
256 sub _is_hash;
257 sub _is_integer;
258 sub _is_ip;
259 sub _is_number;
260 sub _is_object;
261 sub _is_overloaded;
262 sub _is_scalar;
263 sub _is_tty;
264 sub _is_uuid;
265 sub _is_version;
266 sub _is_warnings_enabled;
267 sub _list_symbols;
268 sub _load_class;
269 sub _load_classes;
270 sub _looks_like_path;
271 sub _look_like_number;
272 sub _lvalue;
273 sub _message_check;
274 sub _message_frame;
275 sub _message_log;
276 sub _message_log_io;
277 sub _obj2h;
278 sub _on_error;
279 sub _parse_timestamp;
280 sub _refaddr;
281 sub _register_error_callback;
282 sub _remove_error_callback;
283 sub _set_get;
284 sub _set_get_array;
285 sub _set_get_array_as_object;
286 sub _set_get_boolean;
287 sub _set_get_callback;
288 sub _set_get_class;
289 sub _set_get_class_array;
290 sub _set_get_class_array_object;
291 sub _set_get_code;
292 sub _set_get_datetime;
293 sub _set_get_enum;
294 sub _set_get_file;
295 sub _set_get_glob;
296 sub _set_get_hash;
297 sub _set_get_hash_as_mix_object;
298 sub _set_get_hash_as_object;
299 sub _set_get_ip;
300 sub _set_get_lvalue;
301 sub _set_get_number;
302 sub _set_get_number_as_object;
303 sub _set_get_number_as_scalar;
304 sub _set_get_number_or_object;
305 sub _set_get_object;
306 sub _set_get_object_array;
307 sub _set_get_object_array2;
308 sub _set_get_object_array_object;
309 sub _set_get_object_lvalue;
310 sub _set_get_object_variant;
311 sub _set_get_object_without_init;
312 sub _set_get_scalar;
313 sub _set_get_scalar_as_object;
314 sub _set_get_scalar_or_object;
315 sub _set_get_uri;
316 sub _set_get_uuid;
317 sub _set_get_version;
318 sub _set_symbol;
319 sub _str_val;
320 sub _subinfo;
321 sub _subname;
322 sub _to_array_object;
323 sub _warnings_is_enabled;
324 sub _warnings_is_registered;
325 sub __colour_data;
326 sub __create_class;
327 sub __dbh;
328 sub __instantiate_object;
329 sub __message;
330 sub __messagef;
331  
332 # no warnings 'redefine';
333 sub import
334 139 ▶{
Subroutine import: called CC=5 SCAR=16.1
335 155 my $self = shift( @_ );
336 139 my( $pkg, $file, $line ) = caller();
337 139 local $Exporter::ExportLevel = 1;
338 139 Exporter::import( $self, @_ );
339 139 our $SILENT_AUTOLOAD;
340  
341 139 ( my $dir = $pkg ) =~ s/::/\//g;
342 139 my $path = $INC{ $dir . '.pm' };
343 139 ▶ if( defined( $path ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $path) 49 97 146
344 {
345 # Try absolute path name
346 52 $path =~ s/^(.*)$dir\.pm$/${1}auto\/$dir\/autosplit.ix/;
347 52 local $@;
348 eval
349 52 {
350 115 ▶ local $SIG{ '__DIE__' } = sub{ };
Subroutine __ANON__: called CC=1 SCAR=0.0
351 135 ▶ local $SIG{ '__WARN__' } = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=0.0
352 115 require $path;
353 };
354 115 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 54 59 113
355 {
356 115 $path = "auto/$dir/autosplit.ix";
357 115 local $@;
358 eval
359 115 {
360 115 ▶ local $SIG{ '__DIE__' } = sub{ };
Subroutine __ANON__: called CC=1 SCAR=0.0
361 115 ▶ local $SIG{ '__WARN__' } = sub{ };
Subroutine __ANON__: not called CC=1 SCAR=0.0
362 115 require $path;
363 };
364 }
365 115 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 51 3 54
366 {
367 49 ▶ CORE::warn( $@ ) unless( $SILENT_AUTOLOAD );
Branch: 1 branch
BranchTrueFalseTotal
unless $SILENT_AUTOLOAD 2 49 51
368 }
369 }
370 }
371  
372 sub new
373 1376 ▶{
Subroutine new: called CC=9 SCAR=22.0
Pod documented
374 1442 my $that = shift( @_ );
375 1442 ▶ my $class = ref( $that ) || $that;
Condition100%3/3
ref $that || $that
l!l&&r!l&&!r
20712345
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table66%2/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
376 1442 my $self = {};
377 111 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
378 1442 ▶ if( defined( ${ "${class}\::OBJECT_PERMS" } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined ${"${class}::OBJECT_PERMS";}) 0 1376 1376
379 {
380 66 ▶ $that->_load_class( 'Module::Generic::Tie' ) || return( $that->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$that->_load_class("Module::Generic::Tie") or return $that->pass_error 0 0 0
381 66 my %hash = ();
382 my $obj = tie(
383 %hash,
384 'Module::Generic::Tie',
385 'pkg' => [ __PACKAGE__, $class ],
386 66 'perms' => ${ "${class}::OBJECT_PERMS" },
387 );
388 66 $self = \%hash;
389 }
390 1442 bless( $self, $class );
391 1442 ▶ if( defined( ${ "${class}\::LOG_DEBUG" } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined ${"${class}::LOG_DEBUG";}) 4 1437 1441
392 {
393 66 $self->{log_debug} = ${ "${class}::LOG_DEBUG" };
394 }
395  
396 1442 ▶ if( Wanted::want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (Wanted::want("OBJECT")) 26 1411 1437
397 {
398 90 return( $self->init( @_ ) );
399 }
400 1418 my $new = $self->init( @_ );
401 # Returned undef; there was an error potentially
402 1416 ▶ if( !defined( $new ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new) 57 1354 1411
403 {
404 # If we are called on an object, we hand it the error so the caller can check it using the object:
405 # my $new = $old->new || die( $old->error );
406 66 ▶ if( $self->_is_object( $that ) && $that->can( 'pass_error' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_object($that) and $that->can('pass_error')) { } 2 2 4
Condition66%2/3
$self->_is_object($that) and $that->can("pass_error")
!ll&&!rl&&r
6705
MC/DC0%0/2
$self->_is_object($that) and $that->can("pass_error")
$self->_is_object($that) $that->can("pass_error")
Truth table33%1/3
A and B
A= $self->_is_object($that)B= $that->can("pass_error")
ABresult
0X0
100
111
407 {
408 64 return( $that->pass_error( $self->error ) );
409 }
410 else
411 {
412 66 return( $self->pass_error );
413 }
414 };
415 1414 return( $new );
416 }
417  
418 sub new_glob
419 0 ▶{
Subroutine new_glob: not called CC=7 SCAR=21.1
Pod documented
420 64 my $that = shift( @_ );
421 64 ▶ my $class = ref( $that ) || $that;
Condition66%2/3
ref $that || $that
l!l&&r!l&&!r
203
MC/DC50%1/2
ref $that || $that
ref $that $that
Truth table66%2/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
422 105 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
423 1 my $self = bless( \do{ local *FH } => $class );
424 1 *$self = {};
425 35 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
426 0 ▶ if( defined( ${ "${class}\::LOG_DEBUG" } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined ${"${class}::LOG_DEBUG";}) 0 2 2
427 {
428 64 *$self->{log_debug} = ${ "${class}::LOG_DEBUG" };
429 }
430 60 ▶ if( Wanted::want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (Wanted::want("OBJECT")) 0 83 83
431 {
432 4 return( $self->init( @_ ) );
433 }
434 0 my $new = $self->init( @_ );
435 0 ▶ if( !defined( $new ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new) 50 28 78
436 {
437 # If we are called on an object, we hand it the error so the caller can check it using the object:
438 # my $new = $old->new || die( $old->error );
439 0 ▶ if( $self->_is_object( $that ) && $that->can( 'pass_error' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_object($that) and $that->can('pass_error')) { } 6 22 28
Condition66%2/3
$self->_is_object($that) and $that->can("pass_error")
!ll&&!rl&&r
0455
MC/DC50%1/2
$self->_is_object($that) and $that->can("pass_error")
$self->_is_object($that) $that->can("pass_error")
Truth table66%2/3
A and B
A= $self->_is_object($that)B= $that->can("pass_error")
ABresult
0X0
100
111
440 {
441 0 return( $that->pass_error( $self->error ) );
442 }
443 else
444 {
445 0 return( $self->pass_error );
446 }
447 };
448 0 return( $new );
449 }
450  
451 sub clear_error
452 5460 ▶{
Subroutine clear_error: called CC=5 SCAR=16.2
Pod documented
453 5460 my $self = shift( @_ );
454 5520 ▶ my $class = ref( $self ) || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
5465078
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
455 5463 my $this = $self->_obj2h;
456 64 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
457 5463 ▶ my $err_key = HAS_THREADS() ? join( ';', $class, $$, threads->tid ) : join( ';', $class, $$ );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 9 5478 5487
458  
459 5463 $this->{error} = '';
460 # $self->__message( 6, "Are we running under threads, switching to shared data ? ", ( $rv ? 'yes' : 'no' ) );
461 5463 ▶ $self->__message( 106, "Are we running under threads, switching to shared data ? ", ( HAS_THREADS ? 'yes' : 'no' ) );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 18 5465 5483
462 5463 ▶ my $repo = Module::Generic::Global->new( 'errors' => $class, key => $err_key ) ||
Condition33%1/3
'Module::Generic::Global'->new('errors', $class, 'key', $err_key) || die('Module::Generic::Global'->error)
l!l
553800
MC/DC0%0/1
'Module::Generic::Global'->new('errors', $class, 'key', $err_key) || die('Module::Generic::Global'->error)
'Module::Generic::Global'->new('errors', $class, 'key', $err_key)
Truth table50%1/2
A
A= 'Module::Generic::Global'->new('errors', $class, 'key', $err_key)
Aresult
11
00
463 die( Module::Generic::Global->error );
464 5463 $repo->remove;
465 # ${ $class . '::ERROR' } = '';
466 5463 return( $self );
467 }
468  
469 sub deserialise
470 1 ▶{
Subroutine deserialise: called CC=176 SCAR=90.7
Pod documented
471 4 my $self = shift( @_ );
472 4 my $data;
473 4 ▶ $data = shift( @_ ) if( scalar( @_ ) && ( @_ % 2 ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ and @_ % 2 7 17 24
Condition100%3/3
scalar @_ and @_ % 2
!ll&&!rl&&r
5315
MC/DC0%0/2
scalar @_ and @_ % 2
scalar @_ @_ % 2
Truth table33%1/3
A and B
A= scalar @_B= @_ % 2
ABresult
0X0
100
111
474 4 my $opts = $self->_get_args_as_hash( @_ );
475 4 ▶ $opts->{base64} //= '';
Condition100%3/3
$opts->{"base64"} //= ""
l!l
4214
MC/DC100%1/1
$opts->{"base64"} //= ""
$opts->{"base64"}
Truth table100%2/2
A
A= $opts->{"base64"}
Aresult
11
00
476 1 ▶ $opts->{data} = $data if( defined( $data ) && length( $data ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $data and length $data 65 9 74
Condition66%2/3
defined $data and length $data
!ll&&!rl&&r
8015
MC/DC0%0/2
defined $data and length $data
defined $data length $data
Truth table33%1/3
A and B
A= defined $dataB= length $data
ABresult
0X0
100
111
477 82 my $this = $self->_obj2h;
478 1 ▶ my $class = $opts->{serialiser} || $opts->{serializer} || $SERIALISER;
Condition66%4/6
$opts->{'serialiser'} || $opts->{'serializer'} || $SERIALISER
l!l&&r!l&&!r
400
$opts->{"serialiser"} or $opts->{"serializer"}
l!l&&r!l&&!r
1658
MC/DC0%0/3
$opts->{'serialiser'} || $opts->{'serializer'} || $SERIALISER
$opts->{"serialiser"} $opts->{"serializer"} $SERIALISER
Truth table25%1/4
A or B || C
A= $opts->{"serialiser"}B= $opts->{"serializer"}C= $SERIALISER
ABCresult
1XX1
01X1
0011
0000
479 1 ▶ return( $self->error( "No serialiser class was provided nor set in \$Module::Generic::SERIALISER" ) ) if( !defined( $class ) || !length( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $class and length $class 6 63 69
Condition100%3/3
defined $class and length $class
!ll&&!rl&&r
88701
MC/DC0%0/2
defined $class and length $class
defined $class length $class
Truth table33%1/3
A and B
A= defined $classB= length $class
ABresult
0X0
100
111
480  
481 # Well, nothing to do
482 1 ▶ if( ( !defined( $opts->{file} ) || !length( $opts->{file} ) ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $opts->{'file'} && length $opts->{'file'} || defined $opts->{'io'} && length $opts->{'io'} || defined $opts->{'data'} && length $opts->{'data'}) { } 8 157 165
elsif (exists $opts->{'data'} and defined $opts->{'data'} and $opts->{'data'} =~ /\x{00}$/) { } 84 77 161
Condition86%13/15
defined $opts->{'file'} && length $opts->{'file'} || defined $opts->{'io'} && length $opts->{'io'} || defined $opts->{'data'} && length $opts->{'data'}
l!l&&r!l&&!r
88704
defined $opts->{"file"} and length $opts->{"file"} or defined $opts->{"io"} and length $opts->{"io"}
l!l&&r!l&&!r
85668
defined $opts->{"file"} and length $opts->{"file"}
!ll&&!rl&&r
15703
defined $opts->{"io"} and length $opts->{"io"}
!ll&&!rl&&r
78671
defined $opts->{"data"} and length $opts->{"data"}
!ll&&!rl&&r
74078
MC/DC0%0/6
defined $opts->{'file'} && length $opts->{'file'} || defined $opts->{'io'} && length $opts->{'io'} || defined $opts->{'data'} && length $opts->{'data'}
defined $opts->{"file"} length $opts->{"file"} defined $opts->{"io"} length $opts->{"io"} defined $opts->{"data"} length $opts->{"data"}
Truth table6%1/15
A and B or C and D || E and F
A= defined $opts->{"file"}B= length $opts->{"file"}C= defined $opts->{"io"}D= length $opts->{"io"}E= defined $opts->{"data"}F= length $opts->{"data"}
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
483 ( !defined( $opts->{io} ) || !length( $opts->{io} ) ) &&
484 ( !defined( $opts->{data} ) || !length( $opts->{data} ) ) )
485 {
486 0 return( '' );
487 }
488 # The data provided may be composed only of null bytes, which is the case sometime
489 # when retrieved from memory, and in such case, there is no point passing it to
490 # deserialiser. Even worse, CBOR::XS does not deal with extra null padded data in the first
491 # place, and Sereal would not like a string made only of null bytes
492 ▶ elsif( CORE::exists( $opts->{data} ) &&
Condition66%4/6
exists $opts->{"data"} and defined $opts->{"data"} and $opts->{"data"} =~ /\x{00}$/
!ll&&!rl&&r
7110
exists $opts->{"data"} and defined $opts->{"data"}
!ll&&!rl&&r
7101
MC/DC0%0/3
exists $opts->{"data"} and defined $opts->{"data"} and $opts->{"data"} =~ /\x{00}$/
exists $opts->{"data"} defined $opts->{"data"} $opts->{"data"} =~ /\x{00}$/
Truth table25%1/4
A and B and C
A= exists $opts->{"data"}B= defined $opts->{"data"}C= $opts->{"data"} =~ /\x{00}$/
ABCresult
0XX0
10X0
1100
1111
493 CORE::defined( $opts->{data} ) &&
494 $opts->{data} =~ /\x{00}$/ )
495 {
496 0 ( my $temp = $opts->{data} ) =~ s/\x{00}+$//gs;
497 # There is nothing to do
498 0 ▶ return( '' ) if( !length( $temp ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $temp 90 70 160
499 }
500  
501 1 ▶ if( $class eq 'CBOR' || $class eq 'CBOR::XS' )
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq 'CBOR' or $class eq 'CBOR::XS') { } 64 93 157
Condition100%3/3
$class eq "CBOR" or $class eq "CBOR::XS"
l!l&&r!l&&!r
7131
MC/DC0%0/2
$class eq "CBOR" or $class eq "CBOR::XS"
$class eq "CBOR" $class eq "CBOR::XS"
Truth table33%1/3
A or B
A= $class eq "CBOR"B= $class eq "CBOR::XS"
ABresult
1X1
011
000
502 {
503 0 ▶ $self->_load_class( 'CBOR::XS' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("CBOR::XS") or return $self->pass_error 71 75 146
504 }
505 else
506 {
507 1 ▶ $self->_load_class( $class ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($class) or return $self->pass_error 73 5 78
508 1 ▶ if( $class eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "Sereal") 22 60 82
509 {
510 0 ▶ $self->_load_class( 'Sereal::Decoder' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Sereal::Decoder") or return $self->pass_error 1 55 56
511 }
512 }
513  
514 # This should be an array with two entries: encoder and decoder handler code reference
515 1 my $base64;
516 1 ▶ if( defined( $opts->{base64} ) && $opts->{base64} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"base64"} and $opts->{"base64"}) 31 24 55
Condition100%3/3
defined $opts->{"base64"} and $opts->{"base64"}
!ll&&!rl&&r
7113
MC/DC0%0/2
defined $opts->{"base64"} and $opts->{"base64"}
defined $opts->{"base64"} $opts->{"base64"}
Truth table33%1/3
A and B
A= defined $opts->{"base64"}B= $opts->{"base64"}
ABresult
0X0
100
111
517 {
518 0 $base64 = $self->_has_base64( $opts->{base64} );
519 0 ▶ return( $self->error( "base64 option '$opts->{base64}' has been provided for deserialising, but could not get handlers." ) ) if( !$base64 );
Branch: 1 branch
BranchTrueFalseTotal
unless $base64 31 23 54
520 0 ▶ if( ref( $base64 ) ne 'ARRAY' ||
Branch: 1 branch
BranchTrueFalseTotal
if (ref $base64 ne "ARRAY" or scalar @$base64 < 2 or not defined $base64->[0] or not defined $base64->[1] or ref $base64->[0] ne "CODE" or ref $base64->[1] ne "CODE") 0 31 31
Condition60%9/15
ref $base64 ne "ARRAY" or scalar @$base64 < 2 or not defined $base64->[0] or not defined $base64->[1] or ref $base64->[0] ne "CODE" or ref $base64->[1] ne "CODE"
l!l&&r!l&&!r
6632
ref $base64 ne "ARRAY" or scalar @$base64 < 2 or not defined $base64->[0] or not defined $base64->[1] or ref $base64->[0] ne "CODE"
l!l&&r!l&&!r
2200
ref $base64 ne "ARRAY" or scalar @$base64 < 2 or not defined $base64->[0] or not defined $base64->[1]
l!l&&r!l&&!r
5400
ref $base64 ne "ARRAY" or scalar @$base64 < 2 or not defined $base64->[0]
l!l&&r!l&&!r
14300
ref $base64 ne "ARRAY" or scalar @$base64 < 2
l!l&&r!l&&!r
13274
MC/DC0%0/6
ref $base64 ne "ARRAY" or scalar @$base64 < 2 or not defined $base64->[0] or not defined $base64->[1] or ref $base64->[0] ne "CODE" or ref $base64->[1] ne "CODE"
ref $base64 ne "ARRAY" scalar @$base64 < 2 not defined $base64->[0] not defined $base64->[1] ref $base64->[0] ne "CODE" ref $base64->[1] ne "CODE"
Truth table0%0/7
A or B or not(C) or not(D) or E or F
A= ref $base64 ne "ARRAY"B= scalar @$base64 < 2C= not defined $base64->[0]D= not defined $base64->[1]E= ref $base64->[0] ne "CODE"F= ref $base64->[1] ne "CODE"
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
521 scalar( @$base64 ) < 2 ||
522 !defined( $base64->[0] ) ||
523 !defined( $base64->[1] ) ||
524 ref( $base64->[0] ) ne 'CODE' ||
525 ref( $base64->[1] ) ne 'CODE' )
526 {
527 0 return( $self->error( "Value returned by _has_base64 is not an array reference containing two code references." ) );
528 }
529 }
530  
531 # NOTE: deserialise with CBOR or CBOR::XS
532 1 ▶ if( $class eq 'CBOR' || $class eq 'CBOR::XS' )
Branch: 5 branches
BranchTrueFalseTotal
if ($class eq 'CBOR' or $class eq 'CBOR::XS') { } 0 39 39
elsif ($class eq 'CBOR::Free') { } 2 6 8
elsif ($class eq 'JSON') { } 0 4 4
elsif ($class eq 'Sereal') { } 1 25 26
elsif ($class eq 'Storable::Improved' or $class eq 'Storable') { } 34 23 57
Condition100%3/3
$class eq "CBOR" or $class eq "CBOR::XS"
l!l&&r!l&&!r
59232
MC/DC0%0/2
$class eq "CBOR" or $class eq "CBOR::XS"
$class eq "CBOR" $class eq "CBOR::XS"
Truth table33%1/3
A or B
A= $class eq "CBOR"B= $class eq "CBOR::XS"
ABresult
1X1
011
000
533 {
534 0 my @options = qw( max_depth max_size allow_unknown allow_sharing allow_cycles forbid_objects pack_strings text_keys text_strings validate_utf8 filter );
535 0 my $cbor = CBOR::XS->new;
536 0 $cbor->allow_sharing(1);
537 0 for( @options )
538 {
539 0 ▶ next unless( CORE::exists( $opts->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{$_} 140 4 144
540 0 $cbor->$_( $opts->{ $_ } );
541 }
542  
543 0 ▶ if( exists( $opts->{file} ) && $opts->{file} )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opts->{'file'} and $opts->{'file'}) { } 80 1 81
elsif (exists $opts->{'data'}) { } 2 79 81
Condition66%2/3
exists $opts->{"file"} and $opts->{"file"}
!ll&&!rl&&r
56024
MC/DC50%1/2
exists $opts->{"file"} and $opts->{"file"}
exists $opts->{"file"} $opts->{"file"}
Truth table66%2/3
A and B
A= exists $opts->{"file"}B= $opts->{"file"}
ABresult
0X0
100
111
544 {
545 0 ▶ my $f = $self->new_file( $opts->{file} ) || return( $self->pass_error );
Condition66%2/3
$self->new_file($opts->{'file'}) || (return $self->pass_error)
l!l
56024
MC/DC0%0/1
$self->new_file($opts->{'file'}) || (return $self->pass_error)
$self->new_file($opts->{'file'})
Truth table50%1/2
A
A= $self->new_file($opts->{'file'})
Aresult
11
00
546 0 ▶ return( $self->error( "File provided \"$opts->{file}\" does not exist." ) ) if( !$f->exists );
Branch: 1 branch
BranchTrueFalseTotal
unless $f->exists 0 1 1
547 0 ▶ return( $self->error( "File provided \"$opts->{file}\" is actually a directory." ) ) if( $f->is_directory );
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_directory 1 0 1
548 0 ▶ return( $self->error( "File provided \"$opts->{file}\" to deserialise is empty." ) ) if( $f->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_empty 2 1 3
549 0 ▶ if( $opts->{lock} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"lock"}) 0 2 2
550 {
551 0 ▶ if( !$f->lock( shared => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($f->lock("shared", 1)) 1 0 1
552 {
553 0 ▶ warn( "Could not acquire shared lock on '$f': ", $f->error ) if( $self->_is_warnings_enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("Module::Generic") 79 4 83
554 }
555 }
556 0 my $data = $f->load( binmode => 'raw' );
557 0 ▶ $f->unlock if( $opts->{lock} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"lock"} 4 78 82
558 0 ▶ return( $self->pass_error( $f->error ) ) if( !defined( $data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 61 23 84
559 0 my $ref;
560 # try-catch
561 0 local $@;
562 eval
563 0 {
564 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) { } 28 118 146
565 {
566 0 my $decoded = $base64->[1]->( $data );
567 0 ( $ref, my $bytes ) = $cbor->decode_prefix( $decoded );
568 }
569 else
570 {
571 0 ( $ref, my $bytes ) = $cbor->decode_prefix( $data );
572 }
573 };
574 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 77 66 143
575 {
576 0 return( $self->error( "Error trying to deserialise data with $class: $@" ) );
577 }
578 0 return( $ref );
579 }
580 elsif( exists( $opts->{data} ) )
581 {
582 0 ▶ return( $self->error( "Data provided to deserialise with $class is empty." ) ) if( !defined( $opts->{data} ) || !length( $opts->{data} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"data"} and length $opts->{"data"} 3 0 3
Condition66%2/3
defined $opts->{"data"} and length $opts->{"data"}
!ll&&!rl&&r
56024
MC/DC50%1/2
defined $opts->{"data"} and length $opts->{"data"}
defined $opts->{"data"} length $opts->{"data"}
Truth table66%2/3
A and B
A= defined $opts->{"data"}B= length $opts->{"data"}
ABresult
0X0
100
111
583 0 my $ref;
584 # try-catch
585 0 local $@;
586 eval
587 0 {
588 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) { } 1 0 1
589 {
590 0 my $decoded = $base64->[1]->( $opts->{data} );
591 0 ( $ref, my $bytes ) = $cbor->decode_prefix( $decoded );
592 }
593 else
594 {
595 0 ( $ref, my $bytes ) = $cbor->decode_prefix( $opts->{data} );
596 }
597 };
598 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 13 83 96
599 {
600 0 return( $self->error( "Error trying to deserialise data with $class: $@" ) );
601 }
602 0 return( $ref );
603 }
604 else
605 {
606 0 return( $self->error( "No file and no data was provided to deserialise with $class." ) );
607 }
608 }
609 # NOTE: deserialise with CBOR::Free
610 elsif( $class eq 'CBOR::Free' )
611 {
612 0 ▶ if( exists( $opts->{file} ) && $opts->{file} )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opts->{'file'} and $opts->{'file'}) { } 4 3 7
elsif (exists $opts->{'data'}) { } 6 87 93
Condition33%1/3
exists $opts->{"file"} and $opts->{"file"}
!ll&&!rl&&r
100
MC/DC0%0/2
exists $opts->{"file"} and $opts->{"file"}
exists $opts->{"file"} $opts->{"file"}
Truth table0%0/3
A and B
A= exists $opts->{"file"}B= $opts->{"file"}
ABresult
0X0
100
111
613 {
614 0 ▶ my $f = $self->new_file( $opts->{file} ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($opts->{'file'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($opts->{'file'}) || (return $self->pass_error)
$self->new_file($opts->{'file'})
Truth table0%0/2
A
A= $self->new_file($opts->{'file'})
Aresult
11
00
615 0 ▶ return( $self->error( "File provided \"$opts->{file}\" does not exist." ) ) if( !$f->exists );
Branch: 1 branch
BranchTrueFalseTotal
unless $f->exists 5 84 89
616 0 ▶ return( $self->error( "File provided \"$opts->{file}\" is actually a directory." ) ) if( $f->is_directory );
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_directory 5 83 88
617 0 ▶ return( $self->error( "File provided \"$opts->{file}\" to deserialise is empty." ) ) if( $f->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_empty 4 0 4
618 0 ▶ if( $opts->{lock} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"lock"}) 4 83 87
619 {
620 0 ▶ if( !$f->lock( shared => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($f->lock("shared", 1)) 5 5 10
621 {
622 0 ▶ warn( "Could not acquire shared lock on '$f': ", $f->error ) if( $self->_is_warnings_enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("Module::Generic") 5 87 92
623 }
624 }
625 0 my $data = $f->load( binmode => 'raw' );
626 0 ▶ $f->unlock if( $opts->{lock} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"lock"} 8 83 91
627 0 ▶ return( $self->pass_error( $f->error ) ) if( !defined( $data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 5 83 88
628 # try-catch
629 0 local $@;
630 my $ref = eval
631 0 {
632 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) { } 5 83 88
633 {
634 0 my $decoded = $base64->[1]->( $data );
635 0 return( CBOR::Free::decode( $decoded ) );
636 }
637 else
638 {
639 0 return( CBOR::Free::decode( $data ) );
640 }
641 };
642 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 4 86 90
643 {
644 0 return( $self->error( "Error trying to deserialise data with $class: $@" ) );
645 }
646 0 return( $ref );
647 }
648 elsif( exists( $opts->{data} ) )
649 {
650 0 ▶ return( $self->error( "Data provided to deserialise with $class is empty." ) ) if( !defined( $opts->{data} ) || !length( $opts->{data} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"data"} and length $opts->{"data"} 4 86 90
Condition0%0/3
defined $opts->{"data"} and length $opts->{"data"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts->{"data"} and length $opts->{"data"}
defined $opts->{"data"} length $opts->{"data"}
Truth table0%0/3
A and B
A= defined $opts->{"data"}B= length $opts->{"data"}
ABresult
0X0
100
111
651 # try-catch
652 0 local $@;
653 my $ref = eval
654 0 {
655 69 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
656 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) { } 4 86 90
657 {
658 0 my $decoded = $base64->[1]->( $opts->{data} );
659 0 return( CBOR::Free::decode( $decoded ) );
660 }
661 else
662 {
663 0 return( CBOR::Free::decode( $opts->{data} ) );
664 }
665 };
666 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 7 83 90
667 {
668 0 return( $self->error( "Error trying to deserialise data with $class: $@" ) );
669 }
670 0 return( $ref );
671 }
672 else
673 {
674 0 return( $self->error( "No file and no data was provided to deserialise with $class." ) );
675 }
676 }
677 # NOTE: deserialise with JSON
678 elsif( $class eq 'JSON' )
679 {
680 0 my @options = qw(
681 allow_blessed allow_nonref allow_unknown allow_tags ascii boolean_values
682 canonical convert_blessed filter_json_object filter_json_single_key_object
683 indent latin1 max_depth max_size pretty relaxed space_after space_before utf8
684 );
685 0 my $json = JSON->new;
686 0 for( @options )
687 {
688 0 ▶ next unless( CORE::exists( $opts->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{$_} 7 83 90
689 0 ▶ if( my $code = $json->can( $_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $json->can($_)) 7 83 90
690 {
691 0 $code->( $json, $opts->{ $_ } );
692 }
693 }
694  
695 0 ▶ if( exists( $opts->{file} ) && $opts->{file} )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opts->{'file'} and $opts->{'file'}) { } 7 83 90
elsif (exists $opts->{'data'}) { } 7 83 90
Condition33%1/3
exists $opts->{"file"} and $opts->{"file"}
!ll&&!rl&&r
8000
MC/DC0%0/2
exists $opts->{"file"} and $opts->{"file"}
exists $opts->{"file"} $opts->{"file"}
Truth table0%0/3
A and B
A= exists $opts->{"file"}B= $opts->{"file"}
ABresult
0X0
100
111
696 {
697 0 ▶ my $f = $self->new_file( $opts->{file} ) || return( $self->pass_error );
Condition50%1/2
$self->new_file($opts->{'file'}) || (return $self->pass_error)
l!l
790
MC/DC0%0/1
$self->new_file($opts->{'file'}) || (return $self->pass_error)
$self->new_file($opts->{'file'})
Truth table50%1/2
A
A= $self->new_file($opts->{'file'})
Aresult
11
00
698 0 ▶ return( $self->error( "File provided \"$opts->{file}\" does not exist." ) ) if( !$f->exists );
Branch: 1 branch
BranchTrueFalseTotal
unless $f->exists 3 87 90
699 0 ▶ return( $self->error( "File provided \"$opts->{file}\" is actually a directory." ) ) if( $f->is_directory );
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_directory 3 2 5
700 0 ▶ return( $self->error( "File provided \"$opts->{file}\" to deserialise is empty." ) ) if( $f->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_empty 3 2 5
701 0 ▶ if( $opts->{lock} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"lock"}) 3 2 5
702 {
703 0 ▶ if( !$f->lock( shared => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($f->lock("shared", 1)) 0 5 5
704 {
705 0 ▶ warn( "Could not acquire shared lock on '$f': ", $f->error ) if( $self->_is_warnings_enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("Module::Generic") 1 1 2
706 }
707 }
708 0 my $data = $f->load( binmode => 'raw' );
709 0 ▶ $f->unlock if( $opts->{lock} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"lock"} 1 0 1
710 0 ▶ return( $self->pass_error( $f->error ) ) if( !defined( $data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 3 1 4
711 0 my $ref;
712 # try-catch
713 0 local $@;
714 eval
715 0 {
716 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) { } 66 0 66
717 {
718 0 my $decoded = $base64->[1]->( $data );
719 0 ( $ref, my $bytes ) = $json->decode_prefix( $decoded );
720 }
721 else
722 {
723 0 ( $ref, my $bytes ) = $json->decode_prefix( $data );
724 }
725 };
726 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 67 67
727 {
728 0 return( $self->error( "Error trying to serialise data with $class: $@" ) );
729 }
730 0 return( $ref );
731 }
732 elsif( exists( $opts->{data} ) )
733 {
734 0 ▶ return( $self->error( "Data provided to deserialise with $class is empty." ) ) if( !defined( $opts->{data} ) || !length( $opts->{data} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"data"} and length $opts->{"data"} 61 5 66
Condition33%1/3
defined $opts->{"data"} and length $opts->{"data"}
!ll&&!rl&&r
100
MC/DC0%0/2
defined $opts->{"data"} and length $opts->{"data"}
defined $opts->{"data"} length $opts->{"data"}
Truth table0%0/3
A and B
A= defined $opts->{"data"}B= length $opts->{"data"}
ABresult
0X0
100
111
735 0 my $ref;
736 # try-catch
737 0 local $@;
738 eval
739 0 {
740 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) { } 60 6 66
741 {
742 0 my $decoded = $base64->[1]->( $opts->{data} );
743 0 ( $ref, my $bytes ) = $json->decode_prefix( $decoded );
744 }
745 else
746 {
747 0 ( $ref, my $bytes ) = $json->decode_prefix( $opts->{data} );
748 }
749 };
750 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 64 0 64
751 {
752 0 return( $self->error( "Error trying to serialise data with $class: $@" ) );
753 }
754 0 return( $ref );
755 }
756 else
757 {
758 0 return( $self->error( "No file and no data was provided to deserialise with $class." ) );
759 }
760 }
761 # NOTE: deserialise with Sereal
762 elsif( $class eq 'Sereal' )
763 {
764 0 my @options = qw( refuse_snappy refuse_objects no_bless_objects validate_utf8 max_recursion_depth max_num_hash_entries max_num_array_entries max_string_length max_uncompressed_size incremental alias_smallint alias_varint_under use_undef set_readonly set_readonly_scalars );
765 0 my $ref = {};
766 0 for( @options )
767 {
768 0 ▶ $ref->{ $_ } = $opts->{ $_ } if( exists( $opts->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{$_} 0 0 0
769 }
770  
771 0 my $code;
772 0 my $dec = Sereal::Decoder->new( $ref );
773 0 ▶ if( exists( $opts->{file} ) && $opts->{file} )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opts->{'file'} and $opts->{'file'}) { } 0 0 0
elsif (exists $opts->{'data'}) { } 1 63 64
Condition33%1/3
exists $opts->{"file"} and $opts->{"file"}
!ll&&!rl&&r
7800
MC/DC0%0/2
exists $opts->{"file"} and $opts->{"file"}
exists $opts->{"file"} $opts->{"file"}
Truth table0%0/3
A and B
A= exists $opts->{"file"}B= $opts->{"file"}
ABresult
0X0
100
111
774 {
775 0 ▶ return( $self->error( "File provided \"$opts->{file}\" does not exist." ) ) if( !-e( "$opts->{file}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless -e qq[$opts->{"file"}] 0 1 1
776 0 ▶ return( $self->error( "File provided \"$opts->{file}\" is actually a directory." ) ) if( -d( "$opts->{file}" ) );
Branch: 1 branch
BranchTrueFalseTotal
if -d qq[$opts->{"file"}] 60 4 64
777 0 ▶ return( $self->error( "File provided \"$opts->{file}\" to deserialise is empty." ) ) if( -z( "$opts->{file}" ) );
Branch: 1 branch
BranchTrueFalseTotal
if -z qq[$opts->{"file"}] 3 0 3
778 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) { } 0 0 0
779 {
780 0 ▶ my $f = $self->new_file( $opts->{file} ) || return( $self->pass_error );
Condition50%1/2
$self->new_file($opts->{'file'}) || (return $self->pass_error)
l!l
780
MC/DC0%0/1
$self->new_file($opts->{'file'}) || (return $self->pass_error)
$self->new_file($opts->{'file'})
Truth table50%1/2
A
A= $self->new_file($opts->{'file'})
Aresult
11
00
781 0 ▶ return( $self->error( "File provided \"$opts->{file}\" does not exist." ) ) if( !$f->exists );
Branch: 1 branch
BranchTrueFalseTotal
unless $f->exists 0 0 0
782 0 ▶ return( $self->error( "File provided \"$opts->{file}\" is actually a directory." ) ) if( $f->is_directory );
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_directory 0 0 0
783 0 ▶ return( $self->error( "File provided \"$opts->{file}\" to deserialise is empty." ) ) if( $f->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_empty 0 0 0
784 0 ▶ if( $opts->{lock} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"lock"}) 0 0 0
785 {
786 0 ▶ if( !$f->lock( shared => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($f->lock("shared", 1)) 0 0 0
787 {
788 0 ▶ warn( "Could not acquire shared lock on '$f': ", $f->error ) if( $self->_is_warnings_enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("Module::Generic") 0 0 0
789 }
790 }
791 0 my $data = $f->load( binmode => 'raw' );
792 0 ▶ $f->unlock if( $opts->{lock} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"lock"} 0 0 0
793 0 ▶ return( $self->pass_error( $f->error ) ) if( !defined( $data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 0 0
794 0 my $decoded = $base64->[1]->( $data );
795 # try-catch
796 0 local $@;
797 my $result = eval
798 0 {
799 0 $dec->decode( $decoded );
800 };
801 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
802 {
803 0 return( $self->error( "Error trying to deserialise data with $class: $@" ) );
804 }
805 0 return( $result );
806 }
807 else
808 {
809 0 $self->__message( 5, "Deserialising file '$opts->{file}'" );
810 # try-catch
811 0 local $@;
812 my $result = eval
813 0 {
814 0 $dec->decode_from_file( "$opts->{file}" => $code );
815 };
816 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
817 {
818 0 return( $self->error( "Error trying to deserialise data with $class: $@" ) );
819 }
820 0 $self->__message( 5, "Ok, object is deserialised, returning it." );
821 0 return( $result );
822 }
823 }
824 elsif( exists( $opts->{data} ) )
825 {
826 0 ▶ return( $self->error( "Data provided to deserialise with $class is empty." ) ) if( !defined( $opts->{data} ) || !length( $opts->{data} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"data"} and length $opts->{"data"} 0 0 0
Condition33%1/3
defined $opts->{"data"} and length $opts->{"data"}
!ll&&!rl&&r
7800
MC/DC0%0/2
defined $opts->{"data"} and length $opts->{"data"}
defined $opts->{"data"} length $opts->{"data"}
Truth table0%0/3
A and B
A= defined $opts->{"data"}B= length $opts->{"data"}
ABresult
0X0
100
111
827 my $is_sereal = sub
828 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
829 0 my $type = Sereal::Decoder->looks_like_sereal( $_[0] );
830 # return( $self->error( "Data retrieved from share memory block does not look like sereal data." ) ) if( !$type );
831 0 };
832  
833 # try-catch
834 0 local $@;
835 eval
836 0 {
837 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) { } 0 0 0
838 {
839 0 my $decoded = $base64->[1]->( $opts->{data} );
840 0 ▶ $is_sereal->( $decoded ) if( $self->debug );
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
841 0 $dec->decode( $decoded => $code );
842 }
843 else
844 {
845 0 ▶ $is_sereal->( $opts->{data} ) if( $self->debug );
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
846 0 $dec->decode( $opts->{data} => $code );
847 }
848 };
849 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
850 {
851 0 ▶ return( $self->error( "Error trying to deserialise with $class ", CORE::length( $opts->{data} ), " bytes of data (", ( CORE::length( $opts->{data} ) > 128 ? ( substr( $opts->{data}, 0, 128 ) . '(trimmed)' ) : $opts->{data} ), ": $@" ) );
Branch: 1 branch
BranchTrueFalseTotal
length $opts->{'data'} > 128 ? : 0 0 0
852 }
853 }
854 else
855 {
856 0 return( $self->error( "No file and no data was provided to deserialise with $class." ) );
857 }
858 0 return( $code );
859 }
860 # NOTE: deserialise with Storable::Improved or Storable
861 ▶ elsif( $class eq 'Storable::Improved' || $class eq 'Storable' )
Condition33%1/3
$class eq "Storable::Improved" or $class eq "Storable"
l!l&&r!l&&!r
200
MC/DC0%0/2
$class eq "Storable::Improved" or $class eq "Storable"
$class eq "Storable::Improved" $class eq "Storable"
Truth table33%1/3
A or B
A= $class eq "Storable::Improved"B= $class eq "Storable"
ABresult
1X1
011
000
862 {
863 1 ▶ if( exists( $opts->{file} ) && $opts->{file} )
Branch: 3 branches
BranchTrueFalseTotal
if (exists $opts->{'file'} and $opts->{'file'}) { } 0 1 1
elsif (exists $opts->{'data'}) { } 1 0 1
elsif (exists $opts->{'io'}) { } 0 0 0
Condition33%1/3
exists $opts->{"file"} and $opts->{"file"}
!ll&&!rl&&r
14400
MC/DC0%0/2
exists $opts->{"file"} and $opts->{"file"}
exists $opts->{"file"} $opts->{"file"}
Truth table33%1/3
A and B
A= exists $opts->{"file"}B= $opts->{"file"}
ABresult
0X0
100
111
864 {
865 0 ▶ return( $self->error( "File provided \"$opts->{file}\" does not exist." ) ) if( !-e( "$opts->{file}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless -e qq[$opts->{"file"}] 0 0 0
866 0 ▶ return( $self->error( "File provided \"$opts->{file}\" is actually a directory." ) ) if( -d( "$opts->{file}" ) );
Branch: 1 branch
BranchTrueFalseTotal
if -d qq[$opts->{"file"}] 0 0 0
867 0 ▶ return( $self->error( "File provided \"$opts->{file}\" to deserialise is empty." ) ) if( -z( "$opts->{file}" ) );
Branch: 1 branch
BranchTrueFalseTotal
if -z qq[$opts->{"file"}] 0 0 0
868 # We need to check if the serialised data were created with Storable::store
869 # or by Storable::freeze then stored into a file separately with print or syswrite
870 # The latter would not have the necessary headers
871 # As per Storable documentation, if the following return an hash it is a
872 # valid file with header, otherwise it would return undef
873 0 my $info;
874 0 my $code = $class->can( 'file_magic' );
875 0 ▶ if( defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $code) { } 0 0 0
876 {
877 0 $info = $code->( "$opts->{file}" );
878 }
879 else
880 {
881 0 return( $self->error( "The class $class does not support the method 'file_magic'." ) );
882 }
883 0 ▶ if( ref( $info ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $info eq 'HASH') { } 0 0 0
884 {
885 # if( $this->{debug} || $opts->{debug} )
886 # {
887 # print( STDERR <<EOT );
888 # Byte order... : $info->{byteorder}
889 # File......... : $info->{file}
890 # Header size.. : $info->{hdrsize}
891 # Integer size. : $info->{intsize}
892 # Long size.... : $info->{longsize}
893 # Major version : $info->{major}
894 # Minor version : $info->{minor}
895 # Net order.... : $info->{netorder}
896 # NV size...... : $info->{nvsize}
897 # PTR size..... : $info->{ptrsize}
898 # Version...... : $info->{version}
899 # Version NV... : $info->{version_nv}
900 # EOT
901 # }
902  
903 0 ▶ if( defined( $base64 ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $base64) { } 0 0 0
elsif ($opts->{'lock'}) { } 0 0 0
904 {
905 0 ▶ my $f = $self->new_file( $opts->{file} ) || return( $self->pass_error );
Condition66%2/3
$self->new_file($opts->{'file'}) || (return $self->pass_error)
l!l
118025
MC/DC100%1/1
$self->new_file($opts->{'file'}) || (return $self->pass_error)
$self->new_file($opts->{'file'})
Truth table100%2/2
A
A= $self->new_file($opts->{'file'})
Aresult
11
00
906 0 ▶ return( $self->error( "File provided \"$opts->{file}\" does not exist." ) ) if( !$f->exists );
Branch: 1 branch
BranchTrueFalseTotal
unless $f->exists 0 0 0
907 0 ▶ return( $self->error( "File provided \"$opts->{file}\" is actually a directory." ) ) if( $f->is_directory );
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_directory 0 0 0
908 0 ▶ return( $self->error( "File provided \"$opts->{file}\" to deserialise is empty." ) ) if( $f->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_empty 0 0 0
909 0 ▶ if( $opts->{lock} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"lock"}) 0 0 0
910 {
911 0 ▶ if( !$f->lock( shared => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($f->lock("shared", 1)) 0 0 0
912 {
913 0 ▶ warn( "Could not acquire shared lock on '$f': ", $f->error ) if( $self->_is_warnings_enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("Module::Generic") 0 0 0
914 }
915 }
916 0 my $data = $f->load( binmode => 'raw' );
917 0 ▶ $f->unlock if( $opts->{lock} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"lock"} 0 0 0
918 0 ▶ return( $self->pass_error( $f->error ) ) if( !defined( $data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 0 0
919 0 my $decoded = $base64->[1]->( $data );
920 # try-catch
921 0 local $@;
922 my $result = eval
923 0 {
924 0 my $code = $class->can( 'thaw' );
925 0 ▶ if( !defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 0 0
926 {
927 0 die( "The class $class does not support the method 'thaw'." );
928 }
929 0 return( $code->( $decoded ) );
930 };
931 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
932 {
933 0 return( $self->error( "Error trying to deserialise data with $class: $@" ) );
934 }
935 0 return( $result );
936 }
937 elsif( $opts->{lock} )
938 {
939 # try-catch
940 0 local $@;
941 my $rv = eval
942 0 {
943 0 my $code = $class->can( 'lock_retrieve' );
944 0 ▶ if( !defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 0 0
945 {
946 0 die( "The class $class does not support the method 'lock_retrieve'." );
947 }
948 0 return( $code->( "$opts->{file}" ) );
949 };
950 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
951 {
952 0 return( $self->error( "Error trying to deserialise data with $class: $@" ) );
953 }
954 0 return( $rv );
955 }
956 else
957 {
958 # try-catch
959 0 local $@;
960 my $rv = eval
961 0 {
962 0 my $code = $class->can( 'retrieve' );
963 0 ▶ if( !defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 0 0
964 {
965 0 die( "The class $class does not support the method 'retrieve'." );
966 }
967 0 return( $code->( "$opts->{file}" ) );
968 };
969 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
970 {
971 0 return( $self->error( "Error trying to deserialise data with $class: $@" ) );
972 }
973 0 return( $rv );
974 }
975 }
976 else
977 {
978 0 ▶ my $f = $self->new_file( $opts->{file} ) || return( $self->pass_error );
Condition100%3/3
$self->new_file($opts->{'file'}) || (return $self->pass_error)
l!l
711125
MC/DC100%1/1
$self->new_file($opts->{'file'}) || (return $self->pass_error)
$self->new_file($opts->{'file'})
Truth table100%2/2
A
A= $self->new_file($opts->{'file'})
Aresult
11
00
979 0 ▶ if( $opts->{lock} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"lock"}) 0 0 0
980 {
981 0 ▶ if( !$f->lock( shared => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($f->lock("shared", 1)) 0 0 0
982 {
983 0 ▶ warn( "Could not acquire shared lock on '$f': ", $f->error ) if( $self->_is_warnings_enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("Module::Generic") 0 0 0
984 }
985 }
986 0 my $data = $f->load( binmode => 'raw' );
987 0 ▶ $f->unlock if( $opts->{lock} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"lock"} 0 0 0
988 0 ▶ return( $data ) if( !defined( $data ) || !length( $data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data and length $data 0 0 0
Condition66%2/3
defined $data and length $data
!ll&&!rl&&r
77066
MC/DC50%1/2
defined $data and length $data
defined $data length $data
Truth table66%2/3
A and B
A= defined $dataB= length $data
ABresult
0X0
100
111
989 # try-catch
990 0 local $@;
991 my $decoded = eval
992 0 {
993 0 my $code = $class->can( 'thaw' );
994 0 ▶ if( !defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 0 0
995 {
996 0 die( "The class $class does not support the method 'thaw'." );
997 }
998 0 return( $code->( $data ) );
999 };
1000 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1001 {
1002 0 return( $self->error( "Error trying to deserialise data with $class: $@" ) );
1003 }
1004 # return( &{"${class}\::thaw"}( $data ) );
1005 0 return( $decoded );
1006 }
1007 }
1008 elsif( exists( $opts->{data} ) )
1009 {
1010 1 ▶ return( $self->error( "Data provided to deserialise with $class is empty." ) ) if( !defined( $opts->{data} ) || !length( $opts->{data} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"data"} and length $opts->{"data"} 0 1 1
Condition66%2/3
defined $opts->{"data"} and length $opts->{"data"}
!ll&&!rl&&r
66078
MC/DC0%0/2
defined $opts->{"data"} and length $opts->{"data"}
defined $opts->{"data"} length $opts->{"data"}
Truth table33%1/3
A and B
A= defined $opts->{"data"}B= length $opts->{"data"}
ABresult
0X0
100
111
1011 # try-catch
1012 1 local $@;
1013 my $rv = eval
1014 1 {
1015 1 my $code = $class->can( 'thaw' );
1016 1 ▶ if( !defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 1 1
1017 {
1018 0 die( "The class $class does not support the method 'thaw'." );
1019 }
1020 1 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) { } 0 1 1
1021 {
1022 0 my $decoded = $base64->[1]->( $opts->{data} );
1023 0 return( $code->( $decoded ) );
1024 }
1025 else
1026 {
1027 1 return( $code->( "$opts->{data}" ) );
1028 }
1029 };
1030 1 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
1031 {
1032 0 return( $self->error( "Error trying to deserialise data with $class: $@" ) );
1033 }
1034 1 return( $rv );
1035 }
1036 elsif( exists( $opts->{io} ) )
1037 {
1038 0 ▶ return( $self->error( "File handle provided ($opts->{io}) is not an actual file handle to get data to deserialise." ) ) if( ( Scalar::Util::reftype( $opts->{io} ) // '' ) ne 'GLOB' );
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($opts->{"io"}) // "") ne "GLOB" 0 0 0
Condition33%1/3
builtin::reftype($opts->{"io"}) // ""
l!l
0660
MC/DC0%0/1
builtin::reftype($opts->{"io"}) // ""
builtin::reftype($opts->{"io"})
Truth table50%1/2
A
A= builtin::reftype($opts->{"io"})
Aresult
11
00
1039 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) { } 0 0 0
1040 {
1041 0 my $data = '';
1042 0 ▶ while( read( $opts->{io}, my $buff, 2048 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (read $opts->{"io"}, my $buff, 2048) 0 0 0
1043 {
1044 0 $data .= $buff;
1045 }
1046 0 my $decoded = $base64->[1]->( $data );
1047 # try-catch
1048 0 local $@;
1049 my $rv = eval
1050 0 {
1051 0 my $code = $class->can( 'thaw' );
1052 0 ▶ if( !defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 0 0
1053 {
1054 0 die( "The class $class does not support the method 'thaw'." );
1055 }
1056 0 return( $code->( $decoded ) );
1057 };
1058 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1059 {
1060 0 return( $self->error( "Error trying to deserialise data with $class: $@" ) );
1061 }
1062 0 return( $rv );
1063 }
1064 else
1065 {
1066 # try-catch
1067 0 local $@;
1068 my $rv = eval
1069 0 {
1070 0 my $code = $class->can( 'fd_retrieve' );
1071 0 ▶ if( !defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 0 0
1072 {
1073 0 die( "The class $class does not support the method 'fd_retrieve'." );
1074 }
1075 0 return( $code->( $opts->{io} ) );
1076 };
1077 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1078 {
1079 0 return( $self->error( "Error trying to deserialise data with $class: $@" ) );
1080 }
1081 0 return( $rv );
1082 }
1083 }
1084 else
1085 {
1086 0 return( $self->error( "No file and no data was provided to deserialise with $class." ) );
1087 }
1088 }
1089 else
1090 {
1091 0 return( $self->error( "Unsupporterd serialiser \"$class\"." ) );
1092 }
1093 }
1094  
1095 0 ▶sub deserialize { return( shift->deserialise( @_ ) ); }
Subroutine deserialize: not called CC=1 SCAR=6.9
Pod documented
1096  
1097 sub debug
1098 1233 ▶{
Subroutine debug: called CC=6 SCAR=17.9
Pod documented
1099 1233 my $self = shift( @_ );
1100 1233 ▶ my $class = ( ref( $self ) || $self );
Condition100%3/3
ref $self || $self
l!l&&r!l&&!r
1232166
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1101 1233 my $this = $self->_obj2h;
1102 33 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1103 67 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
1104 1233 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 662 571 1233
1105 {
1106 662 my $flag = shift( @_ );
1107 662 $this->{debug} = $flag;
1108 662 ▶ if( $this->{debug} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"debug"} and not $this->{"debug_level"}) 5 657 662
Condition100%3/3
$this->{"debug"} and not $this->{"debug_level"}
!ll&&!rl&&r
73315
MC/DC100%2/2
$this->{"debug"} and not $this->{"debug_level"}
$this->{"debug"} not $this->{"debug_level"}
Truth table100%3/3
A and not(B)
A= $this->{"debug"}B= not $this->{"debug_level"}
ABresult
0X0
100
111
1109 !$this->{debug_level} )
1110 {
1111 5 $this->{debug_level} = $this->{debug};
1112 }
1113 }
1114 1233 ▶ return( $this->{debug} || ${"$class\:\:DEBUG"} );
Condition100%3/3
$this->{'debug'} || ${"${class}::DEBUG";}
l!l&&r!l&&!r
151119926
MC/DC50%1/2
$this->{'debug'} || ${"${class}::DEBUG";}
$this->{'debug'} ${"${class}::DEBUG";}
Truth table66%2/3
A || B
A= $this->{'debug'}B= ${"${class}::DEBUG";}
ABresult
1X1
011
000
1115 }
1116  
1117 sub dump
1118 0 ▶{
Subroutine dump: not called CC=9 SCAR=39.4
Pod documented
1119 0 my $self = shift( @_ );
1120 0 my $opts = {};
1121 0 ▶ if( @_ > 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1 and ref $_[-1] eq 'HASH' and exists $_[-1]{'filter'} and ref $_[-1]{'filter'} eq 'CODE') { } 0 0 0
Condition66%6/9
@_ > 1 and ref $_[-1] eq "HASH" and exists $_[-1]{"filter"} and ref $_[-1]{"filter"} eq "CODE"
!ll&&!rl&&r
9102
@_ > 1 and ref $_[-1] eq "HASH" and exists $_[-1]{"filter"}
!ll&&!rl&&r
602
@_ > 1 and ref $_[-1] eq "HASH"
!ll&&!rl&&r
404
MC/DC25%1/4
@_ > 1 and ref $_[-1] eq "HASH" and exists $_[-1]{"filter"} and ref $_[-1]{"filter"} eq "CODE"
@_ > 1 ref $_[-1] eq "HASH" exists $_[-1]{"filter"} ref $_[-1]{"filter"} eq "CODE"
Truth table40%2/5
A and B and C and D
A= @_ > 1B= ref $_[-1] eq "HASH"C= exists $_[-1]{"filter"}D= ref $_[-1]{"filter"} eq "CODE"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1122 ref( $_[-1] ) eq 'HASH' &&
1123 exists( $_[-1]->{filter} ) &&
1124 ref( $_[-1]->{filter} ) eq 'CODE' )
1125 {
1126 0 $opts = pop( @_ );
1127 0 ▶ if( $self->_load_class( 'Data::Pretty' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_load_class('Data::Pretty')) { } 0 0 0
elsif ($self->_load_class('Data::Dump')) { } 0 0 0
1128 {
1129 0 return( Data::Pretty::dumpf( @_, $opts->{filter} ) );
1130 }
1131 elsif( $self->_load_class( 'Data::Dump' ) )
1132 {
1133 0 return( Data::Dump::dumpf( @_, $opts->{filter} ) );
1134 }
1135 else
1136 {
1137 0 return( "# Neither Data::Pretty or Data::Dump are installed." );
1138 }
1139 }
1140 else
1141 {
1142 0 ▶ if( $self->_load_class( 'Data::Pretty' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_load_class('Data::Pretty')) { } 0 0 0
elsif ($self->_load_class('Data::Dump')) { } 0 0 0
1143 {
1144 0 return( Data::Pretty::dump( @_ ) );
1145 }
1146 elsif( $self->_load_class( 'Data::Dump' ) )
1147 {
1148 0 return( Data::Dump::dump( @_ ) );
1149 }
1150 else
1151 {
1152 0 return( "# Neither Data::Pretty or Data::Dump are installed." );
1153 }
1154 }
1155 }
1156  
1157 {
1158 84 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
1159 33 *dumpto = \&dumpto_dumper;
1160 }
1161  
1162 sub error
1163 408 ▶{
Subroutine error: called CC=114 SCAR=71.7
Pod documented
1164 408 my $self = shift( @_ );
1165 408 ▶ my $class = CORE::ref( $self ) || $self;
Condition100%3/3
ref $self || $self
l!l&&r!l&&!r
372381
MC/DC100%2/2
ref $self || $self
ref $self $self
Truth table100%3/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1166 408 our $MOD_PERL;
1167 408 my $this = $self->_obj2h;
1168 408 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 7 401 408
1169 408 ▶ my $i_am_blessed = Scalar::Util::blessed( $self ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) ? : 370 38 408
1170 408 my $o;
1171 176 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1172 176 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
1173 my $want_return =
1174 {
1175 array => sub
1176 1 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
1177 1 return( [] );
1178 },
1179 code => sub
1180 1 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
1181 1 ▶ return( sub{} );
Subroutine __ANON__: called CC=1 SCAR=0.0
1182 },
1183 'glob' => sub
1184 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1185 0 my $dummy = '';
1186 0 open( my $tmp, '>', \$dummy );
1187 0 return( $tmp );
1188 },
1189 hash => sub
1190 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1191 0 return( {} );
1192 },
1193 object => sub
1194 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1195 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or die "Unable to load Module::Generic::Null" 0 0 0
1196 die( "Unable to load Module::Generic::Null" );
1197 0 my $null = Module::Generic::Null->new( $o, { debug => $this->{debug}, has_error => 1, wants => 'object' });
1198 0 return( $null );
1199 },
1200 'scalar' => sub
1201 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1202 0 my $dummy = undef;
1203 0 return( \$dummy );
1204 },
1205 408 };
1206  
1207 408 my $want_what = Wanted::wantref();
1208  
1209 # Ensure this is lowercase and at the same time that this is defined
1210 408 ▶ $want_what = lc( $want_what // '' );
Condition66%2/3
$want_what // ""
l!l
40804
MC/DC0%0/1
$want_what // ""
$want_what
Truth table50%1/2
A
A= $want_what
Aresult
11
00
1211 # What type of expected value we support to prevent perl error upon undef.
1212 # By default: object
1213 408 my $want_ok = [qw( object )];
1214 408 ▶ my $err_key = HAS_THREADS ? join( ';', $class, $$, threads->tid ) : join( ';', $class, $$ );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 408 408
1215 408 my $repo = Module::Generic::Global->new( 'errors' => $class, key => $err_key );
1216  
1217 408 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 84 324 408
1218 {
1219 84 my $args = {};
1220 # We got an object as first argument. It could be a child from our exception package or from another package
1221 # Either way, we use it as it is
1222 84 ▶ if( ( Scalar::Util::blessed( $_[0] ) && $_[0]->isa( 'Module::Generic::Exception' ) ) ||
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($_[0]) and $_[0]->isa('Module::Generic::Exception') or builtin::blessed($_[0])) { } 0 84 84
elsif (ref $_[0] eq 'HASH') { } 8 76 84
Condition50%3/6
builtin::blessed($_[0]) and $_[0]->isa("Module::Generic::Exception") or builtin::blessed($_[0])
l!l&&r!l&&!r
5084
builtin::blessed($_[0]) and $_[0]->isa("Module::Generic::Exception")
!ll&&!rl&&r
8400
MC/DC0%0/3
builtin::blessed($_[0]) and $_[0]->isa("Module::Generic::Exception") or builtin::blessed($_[0])
builtin::blessed($_[0]) $_[0]->isa("Module::Generic::Exception") builtin::blessed($_[0])
Truth table20%1/5
A and B or C
A= builtin::blessed($_[0])B= $_[0]->isa("Module::Generic::Exception")C= builtin::blessed($_[0])
ABCresult
11X1
0X11
1011
0X00
1000
1223 Scalar::Util::blessed( $_[0] ) )
1224 {
1225 0 $o = shift( @_ );
1226 }
1227 elsif( ref( $_[0] ) eq 'HASH' )
1228 {
1229 8 $args = shift( @_ );
1230 }
1231 else
1232 {
1233 76 ▶ $args->{message} = join( '', map( ( ref( $_ ) eq 'CODE' && !$this->{_msg_no_exec_sub} ) ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' && !$this->{'_msg_no_exec_sub'} ? : 0 85 85
Condition33%1/3
ref $_ eq "CODE" and not $this->{"_msg_no_exec_sub"}
!ll&&!rl&&r
8500
MC/DC0%0/2
ref $_ eq "CODE" and not $this->{"_msg_no_exec_sub"}
ref $_ eq "CODE" not $this->{"_msg_no_exec_sub"}
Truth table33%1/3
A and not(B)
A= ref $_ eq "CODE"B= not $this->{"_msg_no_exec_sub"}
ABresult
0X0
100
111
1234 }
1235 84 ▶ $args->{class} //= '';
Condition66%2/3
$args->{"class"} //= ""
l!l
4830
MC/DC0%0/1
$args->{"class"} //= ""
$args->{"class"}
Truth table50%1/2
A
A= $args->{"class"}
Aresult
11
00
1236 my $max_len = ( CORE::exists( $this->{error_max_length} ) && $this->{error_max_length} =~ /^[-+]?\d+$/ )
1237 ? $this->{error_max_length}
1238 84 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $this->{'error_max_length'} && $this->{'error_max_length'} =~ /^[-+]?\d+$/ ? : 0 84 84
Condition33%1/3
exists $this->{"error_max_length"} and $this->{"error_max_length"} =~ /^[-+]?\d+$/
!ll&&!rl&&r
8700
MC/DC0%0/2
exists $this->{"error_max_length"} and $this->{"error_max_length"} =~ /^[-+]?\d+$/
exists $this->{"error_max_length"} $this->{"error_max_length"} =~ /^[-+]?\d+$/
Truth table33%1/3
A and B
A= exists $this->{"error_max_length"}B= $this->{"error_max_length"} =~ /^[-+]?\d+$/
ABresult
0X0
100
111
1239 84 ▶ $args->{message} = substr( $args->{message}, 0, $this->{error_max_length} ) if( $max_len > 0 && length( $args->{message} ) > $max_len );
Branch: 1 branch
BranchTrueFalseTotal
if $max_len > 0 and length $args->{"message"} > $max_len 0 84 84
Condition33%1/3
$max_len > 0 and length $args->{"message"} > $max_len
!ll&&!rl&&r
8400
MC/DC0%0/2
$max_len > 0 and length $args->{"message"} > $max_len
$max_len > 0 length $args->{"message"} > $max_len
Truth table33%1/3
A and B
A= $max_len > 0B= length $args->{"message"} > $max_len
ABresult
0X0
100
111
1240 # Reset it
1241 84 $this->{_msg_no_exec_sub} = 0;
1242 # Note Taken from Carp to find the right point in the stack to start from
1243 84 my $caller_func;
1244 0 ▶ $caller_func = \&{"CORE::GLOBAL::caller"} if( defined( &{"CORE::GLOBAL::caller"} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"CORE::GLOBAL::caller";} 0 84 84
1245 84 $self->__message( 105, "Called with error message '", $args->{message}, "'" );
1246 # What type of expected value we support to prevent perl error upon undef.
1247 # By default: object
1248 84 ▶ if( exists( $args->{want} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"want"} and builtin::reftype($args->{"want"} // "") eq "ARRAY") 3 81 84
Condition50%3/6
exists $args->{"want"} and builtin::reftype($args->{"want"} // "") eq "ARRAY"
!ll&&!rl&&r
8103
$args->{"want"} // ""
l!l
300
MC/DC50%1/2
exists $args->{"want"} and builtin::reftype($args->{"want"} // "") eq "ARRAY"
exists $args->{"want"} $args->{"want"}
Truth table66%2/3
A and B
A= exists $args->{"want"}B= $args->{"want"}
ABresult
0X0
100
111
1249 Scalar::Util::reftype( $args->{want} // '' ) eq 'ARRAY' )
1250 {
1251 3 $want_ok = CORE::delete( $args->{want} );
1252 }
1253  
1254 84 ▶ if( scalar( grep( $_ eq 'all', @$want_ok ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar grep(($_ eq "all"), @$want_ok)) 3 81 84
1255 {
1256 3 foreach my $t ( keys( %$want_return ) )
1257 {
1258 18 ▶ push( @$want_ok, $t ) unless( scalar( grep( /^$t$/i, @$want_ok ) ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar grep(/^$t$/i, @$want_ok) 18 0 18
1259 }
1260 }
1261  
1262 84 ▶ push( @$want_ok, 'OBJECT' ) unless( scalar( grep( /^object$/i, @$want_ok ) ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar grep(/^object$/i, @$want_ok) 0 84 84
1263  
1264 84 ▶ if( !defined( $o ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $o) 84 0 84
1265 {
1266 84 ▶ $args->{debug} = $self->debug unless( CORE::exists( $args->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"debug"} 84 0 84
1267 my $ex_class = CORE::length( $args->{class} )
1268 ? $args->{class}
1269 : ( CORE::exists( $this->{_exception_class} ) && CORE::length( $this->{_exception_class} ) )
1270 ? $this->{_exception_class}
1271 0 : ( defined( ${"${class}\::EXCEPTION_CLASS"} ) && CORE::length( ${"${class}\::EXCEPTION_CLASS"} ) )
1272 0 ▶ ? ${"${class}\::EXCEPTION_CLASS"}
Branch: 3 branches
BranchTrueFalseTotal
length $args->{'class'} ? : 1 83 84
exists $this->{'_exception_class'} && length $this->{'_exception_class'} ? : 76 7 83
defined ${"${class}::EXCEPTION_CLASS";} && length ${"${class}::EXCEPTION_CLASS";} ? : 0 7 7
Condition66%4/6
exists $this->{"_exception_class"} and length $this->{"_exception_class"}
!ll&&!rl&&r
7076
defined ${"${class}::EXCEPTION_CLASS";} and length ${"${class}::EXCEPTION_CLASS";}
!ll&&!rl&&r
730
MC/DC50%1/2
exists $this->{"_exception_class"} and length $this->{"_exception_class"}
exists $this->{"_exception_class"} length $this->{"_exception_class"}
MC/DC0%0/2
defined ${"${class}::EXCEPTION_CLASS";} and length ${"${class}::EXCEPTION_CLASS";}
defined ${"${class}::EXCEPTION_CLASS";} length ${"${class}::EXCEPTION_CLASS";}
Truth table66%2/3
A and B
A= exists $this->{"_exception_class"}B= length $this->{"_exception_class"}
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined ${"${class}::EXCEPTION_CLASS";}B= length ${"${class}::EXCEPTION_CLASS";}
ABresult
0X0
100
111
1273 : 'Module::Generic::Exception';
1274 84 ▶ unless( $self->_is_class_loaded( $ex_class ) || scalar( keys( %{"${ex_class}\::"} ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_class_loaded($ex_class) or scalar keys %{"${ex_class}::";}) 12 72 84
Condition66%2/3
$self->_is_class_loaded($ex_class) or scalar keys %{"${ex_class}::";}
l!l
75120
MC/DC100%1/1
$self->_is_class_loaded($ex_class) or scalar keys %{"${ex_class}::";}
$self->_is_class_loaded($ex_class)
Truth table100%2/2
A
A= $self->_is_class_loaded($ex_class)
Aresult
11
00
1275 {
1276 12 my $pl = "use $ex_class;";
1277 12 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=0.0
1278 12 local $@;
1279 12 ▶ eval( $pl );
Subroutine BEGIN: called CC=1 SCAR=0.0
1280 # We have to die, because we have an error within another error
1281 12 ▶ die( __PACKAGE__ . "::error() is unable to load exception class \"$ex_class\": $@" ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 12 12
1282 }
1283 84 $self->__message( 105, "Creating error object with class $ex_class" );
1284 84 $o = $ex_class->new( $args );
1285 }
1286  
1287 84 ▶ $self->__message( 105, "Storing exception object (", $self->_str_val( $o // 'undef' ), ") in our current object ", $self->_str_val( $self // 'undef' ) );
Condition50%3/6
$o // "undef"
l!l
8430
$self // "undef"
l!l
8700
MC/DC0%0/1
$o // "undef"
$o
MC/DC0%0/1
$self // "undef"
$self
Truth table50%1/2
A
A= $o
Aresult
11
00
Truth table50%1/2
A
A= $self
Aresult
11
00
1288 84 $this->{error} = $o;
1289 # We need to also store the object in the global $ERRORS repository, because when a class constructor fails, it may call 'error' using its newly instantiated object, but the caller can only get the error by calling 'error' as a class function, such as My::Module->error
1290 # my $rv = $self->_ensure_shared_elements;
1291 # $self->__message( 6, "Are we running under threads, switching to shared data ? ", ( $rv ? 'yes' : 'no' ) );
1292 84 ▶ $self->__message( 106, "Are we running under threads, switching to shared data ? ", ( HAS_THREADS ? 'yes' : 'no' ) );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 84 84
1293 84 $self->__message( 106, "Storing the error object in the global \$ERRORS" );
1294 84 $repo->set( $o );
1295 # For backward compatibility, so the user can access $My::Module::ERROR
1296 # ${ $class . '::ERROR' } = $o;
1297 # $self->__message( 106, "Entry in \$ERRORS for key '$err_key' is ", CORE::length( $repo->get // 'undef' ), " bytes big, and \$${class}\::ERROR is '", $self->_str_val( ${ $class . '::ERROR' } // 'undef' ), "'" );
1298  
1299 84 my $err_callback = $self->_on_error;
1300 84 ▶ if( !defined( $err_callback ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $err_callback and exists $args->{"callback"} and ref $args->{"callback"} eq "CODE") 0 84 84
Condition50%3/6
not defined $err_callback and exists $args->{"callback"} and ref $args->{"callback"} eq "CODE"
!ll&&!rl&&r
8700
not defined $err_callback and exists $args->{"callback"}
!ll&&!rl&&r
3840
MC/DC0%0/3
not defined $err_callback and exists $args->{"callback"} and ref $args->{"callback"} eq "CODE"
not defined $err_callback exists $args->{"callback"} ref $args->{"callback"} eq "CODE"
Truth table25%1/4
not(A) and B and C
A= not defined $err_callbackB= exists $args->{"callback"}C= ref $args->{"callback"} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
1301 CORE::exists( $args->{callback} ) &&
1302 ref( $args->{callback} ) eq 'CODE' )
1303 {
1304 0 $err_callback = $args->{callback};
1305 }
1306  
1307 84 ▶ if( defined( $err_callback ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err_callback and ref $err_callback eq "CODE") 0 84 84
Condition33%1/3
defined $err_callback and ref $err_callback eq "CODE"
!ll&&!rl&&r
8700
MC/DC0%0/2
defined $err_callback and ref $err_callback eq "CODE"
defined $err_callback ref $err_callback eq "CODE"
Truth table33%1/3
A and B
A= defined $err_callbackB= ref $err_callback eq "CODE"
ABresult
0X0
100
111
1308 ref( $err_callback ) eq 'CODE' )
1309 {
1310 0 ▶ local $SIG{__WARN__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
1311 0 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
1312 0 local $@;
1313 eval
1314 0 {
1315 0 $err_callback->( $self, $o );
1316 };
1317 }
1318  
1319 84 ▶ my $err_callbacks = [ reverse( @{$self->_error_callbacks || []} ) ];
Condition33%1/3
$self->_error_callbacks || []
l!l
8700
MC/DC0%0/1
$self->_error_callbacks || []
$self->_error_callbacks
Truth table50%1/2
A
A= $self->_error_callbacks
Aresult
11
00
1320 84 ▶ if( scalar( @$err_callbacks ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$err_callbacks) 0 84 84
1321 {
1322 0 ▶ local $SIG{__WARN__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
1323 0 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
1324 0 local $@;
1325 0 foreach my $ref ( @$err_callbacks )
1326 {
1327 0 ▶ $self->__message( 112, "Executing error callback '", ( $ref->{name} // 'undef' ), "'" );
Condition33%1/3
$ref->{"name"} // "undef"
l!l
300
MC/DC0%0/1
$ref->{"name"} // "undef"
$ref->{"name"}
Truth table50%1/2
A
A= $ref->{"name"}
Aresult
11
00
1328 0 my $code = $ref->{cb};
1329 0 ▶ if( !defined( $code ) || ref( $code ) ne 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $code or ref $code ne "CODE") 0 0 0
Condition0%0/3
not defined $code or ref $code ne "CODE"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $code or ref $code ne "CODE"
not defined $code ref $code ne "CODE"
Truth table0%0/3
not(A) or B
A= not defined $codeB= ref $code ne "CODE"
ABresult
1X1
011
000
1330 {
1331 0 next;
1332 }
1333 0 eval{ $code->( $self, $o ) };
1334 }
1335 }
1336  
1337 # Get the warnings status of the caller. We use caller(1) to skip one frame further, ie our caller's caller
1338 # This can be changed by using 'no warnings'
1339 84 my $should_display_warning = 0;
1340 84 my $no_use_warnings = 1;
1341 84 ▶ unless( $this->{quiet} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->{"quiet"}) 84 0 84
1342 {
1343 # Try to get the warnings status if is enabled at all.
1344 84 $should_display_warning = $self->_warnings_is_enabled;
1345 84 $no_use_warnings = 0;
1346  
1347 # If no warnings are registered for our package, we display warnings.
1348 84 ▶ if( $no_use_warnings && !defined( $warnings::Bits{ $class } ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($no_use_warnings and not defined $warnings::Bits{$class}) 0 84 84
Condition33%1/3
$no_use_warnings and not defined $warnings::Bits{$class}
!ll&&!rl&&r
8400
MC/DC0%0/2
$no_use_warnings and not defined $warnings::Bits{$class}
$no_use_warnings not defined $warnings::Bits{$class}
Truth table33%1/3
A and not(B)
A= $no_use_warningsB= not defined $warnings::Bits{$class}
ABresult
0X0
100
111
1349 {
1350 0 $no_use_warnings = 0;
1351 0 $should_display_warning = 1;
1352 }
1353 }
1354  
1355 84 ▶ if( $no_use_warnings )
Branch: 1 branch
BranchTrueFalseTotal
if ($no_use_warnings) 0 84 84
1356 {
1357 0 my $call_offset = 0;
1358 0 ▶ while( my @call_data = $caller_func ? $caller_func->( $call_offset ) : caller( $call_offset ) )
Branch: 2 branches
BranchTrueFalseTotal
if (my(@call_data) = $caller_func ? &$caller_func($call_offset) : caller $call_offset) 0 0 0
$caller_func ? : 0 0 0
1359 {
1360 0 ▶ my @prev_stack = $caller_func ? $caller_func->( $call_offset - 1 ) : caller( $call_offset - 1 );
Branch: 1 branch
BranchTrueFalseTotal
$caller_func ? : 0 0 0
1361 0 ▶ unless( $call_offset > 0 && $call_data[0] ne $class && $prev_stack[0] eq $class )
Branch: 1 branch
BranchTrueFalseTotal
unless ($call_offset > 0 and $call_data[0] ne $class and $prev_stack[0] eq $class) 0 0 0
Condition0%0/6
$call_offset > 0 and $call_data[0] ne $class and $prev_stack[0] eq $class
!ll&&!rl&&r
000
$call_offset > 0 and $call_data[0] ne $class
!ll&&!rl&&r
000
MC/DC0%0/3
$call_offset > 0 and $call_data[0] ne $class and $prev_stack[0] eq $class
$call_offset > 0 $call_data[0] ne $class $prev_stack[0] eq $class
Truth table0%0/4
A and B and C
A= $call_offset > 0B= $call_data[0] ne $classC= $prev_stack[0] eq $class
ABCresult
0XX0
10X0
1100
1111
1362 {
1363 0 $call_offset++;
1364 0 next;
1365 }
1366 0 ▶ last if( $call_data[9] || ( $call_offset > 0 && $prev_stack[0] ne $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if $call_data[9] or $call_offset > 0 and $prev_stack[0] ne $class 0 0 0
Condition33%2/6
$call_data[9] or $call_offset > 0 and $prev_stack[0] ne $class
l!l&&r!l&&!r
300
$call_offset > 0 and $prev_stack[0] ne $class
!ll&&!rl&&r
300
MC/DC0%0/3
$call_data[9] or $call_offset > 0 and $prev_stack[0] ne $class
$call_data[9] $call_offset > 0 $prev_stack[0] ne $class
Truth table25%1/4
A or B and C
A= $call_data[9]B= $call_offset > 0C= $prev_stack[0] ne $class
ABCresult
1XX1
0111
00X0
0100
1367 0 $call_offset++;
1368 }
1369 0 ▶ my $bitmask = $caller_func ? ($caller_func->( $call_offset ))[9] : ( caller( $call_offset ) )[9];
Branch: 1 branch
BranchTrueFalseTotal
$caller_func ? : 0 0 0
1370 0 my $offset = $warnings::Offsets{uninitialized};
1371 0 $should_display_warning = vec( $bitmask, $offset, 1 );
1372 }
1373  
1374 84 my $r;
1375 84 ▶ if( $MOD_PERL )
Branch: 1 branch
BranchTrueFalseTotal
if ($MOD_PERL) 0 84 84
1376 {
1377 # try-catch
1378 0 local $@;
1379 eval
1380 0 {
1381 0 $r = Apache2::RequestUtil->request;
1382 0 ▶ $r->warn( $o->as_string ) if( $r );
Branch: 1 branch
BranchTrueFalseTotal
if $r 0 0 0
1383 };
1384 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1385 {
1386 0 print( STDERR "Error trying to get the global Apache2::ApacheRec: $@\n" );
1387 }
1388 }
1389  
1390 84 my $err_handler = $self->error_handler;
1391 84 ▶ if( $err_handler && ref( $err_handler ) eq 'CODE' )
Branch: 4 branches
BranchTrueFalseTotal
if ($err_handler and ref $err_handler eq 'CODE') { } 0 84 84
elsif ($r) { } 0 84 84
elsif ($this->{'fatal'} or $args->{'fatal'} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}) { } 3 81 84
elsif ($should_display_warning) { } 0 81 81
Condition33%1/3
$err_handler and ref $err_handler eq "CODE"
!ll&&!rl&&r
8700
MC/DC0%0/2
$err_handler and ref $err_handler eq "CODE"
$err_handler ref $err_handler eq "CODE"
Truth table33%1/3
A and B
A= $err_handlerB= ref $err_handler eq "CODE"
ABresult
0X0
100
111
1392 {
1393 0 $err_handler->( $o );
1394 }
1395 elsif( $r )
1396 {
1397 0 ▶ if( my $log_handler = $r->get_handlers( 'PerlPrivateErrorHandler' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $log_handler = $r->get_handlers('PerlPrivateErrorHandler')) { } 0 0 0
1398 {
1399 0 $log_handler->( $o );
1400 }
1401 else
1402 {
1403 0 ▶ $r->warn( $o->as_string ) if( $should_display_warning );
Branch: 1 branch
BranchTrueFalseTotal
if $should_display_warning 0 0 0
1404 }
1405 }
1406 0 ▶ elsif( $this->{fatal} || $args->{fatal} || ( defined( ${"${class}\::FATAL_ERROR"} ) && ${"${class}\::FATAL_ERROR"} ) )
Condition55%5/9
$this->{"fatal"} or $args->{"fatal"} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
l!l&&r!l&&!r
6081
$this->{"fatal"} or $args->{"fatal"}
l!l&&r!l&&!r
3081
defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
!ll&&!rl&&r
8100
MC/DC25%1/4
$this->{"fatal"} or $args->{"fatal"} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
$this->{"fatal"} $args->{"fatal"} defined ${"${class}::FATAL_ERROR";} ${"${class}::FATAL_ERROR";}
Truth table40%2/5
A or B or C and D
A= $this->{"fatal"}B= $args->{"fatal"}C= defined ${"${class}::FATAL_ERROR";}D= ${"${class}::FATAL_ERROR";}
ABCDresult
1XXX1
01XX1
00111
000X0
00100
1407 {
1408 3 ▶ $self->__message( 105, "We are instructed to die with the newly created exception object ", $self->_str_val( $o // 'undef' ) );
Condition66%2/3
$o // "undef"
l!l
330
MC/DC0%0/1
$o // "undef"
$o
Truth table50%1/2
A
A= $o
Aresult
11
00
1409 # my $enc_str = eval{ Encode::encode( 'UTF-8', "$o", Encode::FB_CROAK ) };
1410 # die( $@ ? $o : $enc_str );
1411 3 die( $o );
1412 }
1413 elsif( $should_display_warning )
1414 {
1415 0 ▶ if( $r )
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 0 0 0
1416 {
1417 0 $r->warn( $o->as_string );
1418 }
1419 else
1420 {
1421 0 local $@;
1422 0 $self->__message( 106, "Encoding error string '$o' (", $o->message, ")" );
1423 0 require Encode;
1424 0 my $enc_str = eval{ Encode::encode( 'UTF-8', "$o", Encode::FB_CROAK ) };
1425 # Display warnings if warnings for this class is registered and enabled or if not registered
1426 0 $self->__message( 106, "Encoded error string is '$enc_str'" );
1427 0 ▶ warn( $@ ? $o : $enc_str );
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
1428 }
1429 }
1430  
1431 81 ▶ if( overload::Overloaded( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (overload::Overloaded($self)) 81 0 81
1432 {
1433 81 my $overload_meth_ref = overload::Method( $self, '""' );
1434 81 my $overload_meth_name = '';
1435 81 require Sub::Util;
1436 81 ▶ $overload_meth_name = Sub::Util::subname( $overload_meth_ref ) if( ref( $overload_meth_ref ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $overload_meth_ref 6 75 81
1437 # use Sub::Identify ();
1438 # my( $over_file, $over_line ) = Sub::Identify::get_code_location( $overload_meth_ref );
1439 # my( $over_call_pack, $over_call_file, $over_call_line ) = caller();
1440 81 ▶ my $call_sub = $caller_func ? ($caller_func->(1))[3] : (caller(1))[3];
Branch: 1 branch
BranchTrueFalseTotal
$caller_func ? : 0 81 81
1441 # overloaded method name can be, for example: My::Package::as_string
1442 # or, for anonymous sub: My::Package::__ANON__[lib/My/Package.pm:12]
1443 # caller sub will reliably be the same, so we use it to check if we are called from an overloaded stringification and return undef right here.
1444 # Wanted::want check of being called in an OBJECT context triggers a perl segmentation fault
1445 81 ▶ if( length( $overload_meth_name ) && $overload_meth_name eq $call_sub )
Branch: 1 branch
BranchTrueFalseTotal
if (length $overload_meth_name and $overload_meth_name eq $call_sub) 2 79 81
Condition100%3/3
length $overload_meth_name and $overload_meth_name eq $call_sub
!ll&&!rl&&r
75468
MC/DC100%2/2
length $overload_meth_name and $overload_meth_name eq $call_sub
length $overload_meth_name $overload_meth_name eq $call_sub
Truth table100%3/3
A and B
A= length $overload_meth_nameB= $overload_meth_name eq $call_sub
ABresult
0X0
100
111
1446 {
1447 2 return;
1448 }
1449 }
1450  
1451 # When used inside an lvalue method
1452 79 ▶ if( $args->{lvalue} && $args->{assign} )
Branch: 3 branches
BranchTrueFalseTotal
if ($args->{'lvalue'} and $args->{'assign'}) { } 0 79 79
elsif (not $args->{'no_return_null_object'} and $want_what && exists $want_return->{$want_what} && scalar grep(/^$want_what$/i, @$want_ok) || $args->{'object'}) { } 2 77 79
elsif ($args->{'lvalue'} and want('RVALUE')) { } 0 154 154
Condition66%2/3
$args->{"lvalue"} and $args->{"assign"}
!ll&&!rl&&r
79066
MC/DC0%0/2
$args->{"lvalue"} and $args->{"assign"}
$args->{"lvalue"} $args->{"assign"}
Truth table33%1/3
A and B
A= $args->{"lvalue"}B= $args->{"assign"}
ABresult
0X0
100
111
1453 {
1454 0 return( $data->{__dummy} = 'dummy' );
1455 }
1456 # https://metacpan.org/pod/Perl::Critic::Policy::Subroutines::ProhibitExplicitReturnUndef
1457 # https://perlmonks.org/index.pl?node_id=741847
1458 # Because in list context this would create a lit with one element undef()
1459 # A bare return will return an empty list or an undef scalar
1460 # return( undef() );
1461 # return;
1462 # As of 2019-10-13, Module::Generic version 0.6, we use this special package Module::Generic::Null to be returned in chain without perl causing the error that a method was called on an undefined value
1463 # 2020-05-12: Added the no_return_null_object to instruct not to return a null object
1464 # This is especially needed when an error is called from TIEHASH that returns a special object.
1465 # A Null object would trigger a fatal perl segmentation fault
1466 ▶ elsif( !$args->{no_return_null_object} &&
Condition83%10/12
not $args->{"no_return_null_object"} and $want_what && exists $want_return->{$want_what} && scalar grep(/^$want_what$/i, @$want_ok) || $args->{"object"}
!ll&&!rl&&r
07768
$want_what and exists $want_return->{$want_what} and scalar grep(/^$want_what$/i, @$want_ok) or $args->{"object"}
l!l&&r!l&&!r
20143
$want_what and exists $want_return->{$want_what} and scalar grep(/^$want_what$/i, @$want_ok)
!ll
75466
$want_what and exists $want_return->{$want_what}
!ll&&!rl&&r
75664
MC/DC25%1/4
not $args->{"no_return_null_object"} and $want_what && exists $want_return->{$want_what} && scalar grep(/^$want_what$/i, @$want_ok) || $args->{"object"}
not $args->{"no_return_null_object"} $want_what exists $want_return->{$want_what} $args->{"object"}
Truth table33%2/6
not(A) and B and C or D
A= not $args->{"no_return_null_object"}B= $want_whatC= exists $want_return->{$want_what}D= $args->{"object"}
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
1467 (
1468 ( $want_what && CORE::exists( $want_return->{ $want_what } ) && scalar( grep( /^$want_what$/i, @$want_ok ) ) ) ||
1469 $args->{object}
1470 ) )
1471 {
1472 2 ▶ if( $args->{object} )
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'object'}) { } 0 2 2
1473 {
1474 0 $self->__message( 105, "Caller is in object context, returning a Null object to caller ", [caller]->[0], " at line ", [caller]->[2] );
1475 0 rreturn( $want_return->{object}->() );
1476 }
1477 else
1478 {
1479 2 $self->__message( 106, "The caller (", [caller]->[0], " at line ", [caller]->[2], ") context is ${want_what}. Returning now with appropriate value to caller ", [caller]->[0], " at line ", [caller]->[2] );
1480 2 rreturn( $want_return->{ $want_what }->() );
1481 }
1482 }
1483 ▶ elsif( $args->{lvalue} && want( 'RVALUE' ) )
Condition33%1/3
$args->{"lvalue"} and want("RVALUE")
!ll&&!rl&&r
8000
MC/DC0%0/2
$args->{"lvalue"} and want("RVALUE")
$args->{"lvalue"} want("RVALUE")
Truth table33%1/3
A and B
A= $args->{"lvalue"}B= want("RVALUE")
ABresult
0X0
100
111
1484 {
1485 0 $self->__message( 105, "Caller is in rvalue context, returning nothing (undef or empty list to caller ", [caller]->[0], " at line ", [caller]->[2] );
1486 0 rreturn;
1487 }
1488 77 $self->__message( 105, "Returning nothing (undef or empty list) to caller ", [caller]->[0], " at line ", [caller]->[2] );
1489 77 return;
1490 }
1491 # Done with mutator mode
1492  
1493 324 ▶ $self->__message( 104, "Called in accessor mode from ", [caller]->[0], " from line ", [caller]->[2], " for class $class and object \$self ", $self->_str_val( $self // 'undef' ), ". Called as a class function ? ", ( $i_am_blessed ? 'no' : 'yes' ), ". Do we have an error on record ? ", ( $this->{error} ? 'yes' : 'no' ) );
Branch: 2 branches
BranchTrueFalseTotal
$i_am_blessed ? : 287 37 324
$this->{'error'} ? : 26 298 324
Condition50%1/2
$self // "undef"
l!l
3240
MC/DC0%0/1
$self // "undef"
$self
Truth table50%1/2
A
A= $self
Aresult
11
00
1494 # $self->__message( 105, "Returning error object -> ", $self->_str_val( ref( $self ) ? ( $this->{error} // '' ) : ( ${ $class . '::ERROR' } // '' ) ) );
1495 324 ▶ if( $i_am_blessed )
Branch: 1 branch
BranchTrueFalseTotal
if ($i_am_blessed) 287 37 324
1496 {
1497 # To avoid the perl error of 'called on undefined value' and so the user can do
1498 # $o->error->__message for example without concerning himself/herself whether an exception object is actually set
1499 287 ▶ if( !$this->{error} )
Branch: 1 branch
BranchTrueFalseTotal
if (not $this->{'error'}) { } 261 26 287
1500 {
1501 261 ▶ $self->__message( 106, "There is no error object in our object (", $self->_str_val( $self // 'undef' ), "), and caller (", [caller]->[0], " at line ", [caller]->[2], ") context is ${want_what}. Returning now with appropriate value." );
Condition50%1/2
$self // "undef"
l!l
2610
MC/DC0%0/1
$self // "undef"
$self
Truth table50%1/2
A
A= $self
Aresult
11
00
1502 261 ▶ if( $want_what &&
Branch: 1 branch
BranchTrueFalseTotal
if ($want_what and exists $want_return->{$want_what} and scalar grep(/^$want_what$/i, @$want_ok)) 0 261 261
Condition40%2/5
$want_what and exists $want_return->{$want_what} and scalar grep(/^$want_what$/i, @$want_ok)
!ll
2610
$want_what and exists $want_return->{$want_what}
!ll&&!rl&&r
26100
MC/DC0%0/2
$want_what and exists $want_return->{$want_what} and scalar grep(/^$want_what$/i, @$want_ok)
$want_what exists $want_return->{$want_what}
Truth table33%1/3
A and B
A= $want_whatB= exists $want_return->{$want_what}
ABresult
0X0
100
111
1503 CORE::exists( $want_return->{ $want_what } ) &&
1504 scalar( grep( /^$want_what$/i, @$want_ok ) ) )
1505 {
1506 0 rreturn( $want_return->{ $want_what }->() );
1507 }
1508 }
1509 else
1510 {
1511 26 ▶ $self->__message( 105, "Returning error object (", $self->_str_val( $this->{error} // 'undef' ), ") found within our object (", $self->_str_val( $self // 'undef' ), ")." );
Condition50%2/4
$this->{"error"} // "undef"
l!l
260
$self // "undef"
l!l
260
MC/DC0%0/1
$this->{"error"} // "undef"
$this->{"error"}
MC/DC0%0/1
$self // "undef"
$self
Truth table50%1/2
A
A= $this->{"error"}
Aresult
11
00
Truth table50%1/2
A
A= $self
Aresult
11
00
1512 26 return( $this->{error} );
1513 }
1514 }
1515  
1516 298 ▶ $self->__message( 106, "Do we have an entry for the key '$err_key' in the global \$ERRORS ? ", ( $repo->exists ? 'yes' : 'no' ), ". \$ERRORS contains ", $repo->length, " errors." );
Branch: 1 branch
BranchTrueFalseTotal
$repo->exists ? : 37 261 298
1517 298 $o = $repo->get;
1518 298 ▶ if( CORE::defined( $o ) && CORE::length( $o ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $o and length $o) { } 37 261 298
elsif (not &CAN_THREADS() and defined ${$class . '::ERROR';} and length ${$class . '::ERROR';}) { } 0 522 522
Condition66%2/3
defined $o and length $o
!ll&&!rl&&r
261037
MC/DC50%1/2
defined $o and length $o
defined $o length $o
Truth table66%2/3
A and B
A= defined $oB= length $o
ABresult
0X0
100
111
1519 {
1520 # Found an exception object using Module::Generic::Global
1521 37 ▶ $self->__message( 106, "Object retrieved is '", $self->_str_val( $o // 'undef' ), "'" );
Condition50%1/2
$o // "undef"
l!l
370
MC/DC0%0/1
$o // "undef"
$o
Truth table50%1/2
A
A= $o
Aresult
11
00
1522 }
1523 ▶ elsif( !CAN_THREADS &&
Condition33%2/6
not &CAN_THREADS() and defined ${$class . '::ERROR';} and length ${$class . '::ERROR';}
!ll&&!rl&&r
26100
not &CAN_THREADS() and defined ${$class . '::ERROR';}
!ll&&!rl&&r
02610
MC/DC0%0/3
not &CAN_THREADS() and defined ${$class . '::ERROR';} and length ${$class . '::ERROR';}
not &CAN_THREADS() defined ${$class . '::ERROR';} length ${$class . '::ERROR';}
Truth table25%1/4
not(A) and B and C
A= not &CAN_THREADS()B= defined ${$class . '::ERROR';}C= length ${$class . '::ERROR';}
ABCresult
0XX0
10X0
1100
1111
1524 261 CORE::defined( ${ $class . '::ERROR' } ) &&
1525 # clear_error() set this to an empty string, so it is no undefined
1526 # Other inheriting moduls might do the same
1527 0 CORE::length( ${ $class . '::ERROR' } ) )
1528 {
1529 0 $self->__message( 106, "Retrieving the stored object as-is (not frozen) from the global variable \$ERROR from package $class" );
1530 # $o = ${ $class . '::ERROR' };
1531 0 ▶ warn( "Accessing ${class}::ERROR is deprecated; use ${class}->error instead" ) if( $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled 0 0 0
1532 }
1533 298 return( $o );
1534 }
1535  
1536 84 ▶sub error_handler { return( shift->_set_get_code( '_error_handler', @_ ) ); }
Subroutine error_handler: called CC=1 SCAR=0.0
Pod documented
1537  
1538 {
1539 113 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
1540 35 *errstr = \&error;
1541 }
1542  
1543 5 ▶sub fatal { return( shift->_set_get_boolean( 'fatal', @_ ) ); }
Subroutine fatal: called CC=1 SCAR=0.0
Pod documented
1544  
1545 sub get
1546 0 ▶{
Subroutine get: not called CC=3 SCAR=24.8
Pod documented
1547 0 my $self = shift( @_ );
1548 0 my $this = $self->_obj2h;
1549 0 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 0 0
1550 0 my @data = map{ $data->{ $_ } } @_;
1551 0 ▶ return( wantarray() ? @data : $data[ 0 ] );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1552 }
1553  
1554 sub init
1555 1374 ▶{
Subroutine init: called CC=96 SCAR=75.0
Pod documented
1556 1374 my $self = shift( @_ );
1557 1374 my $pkg = ref( $self );
1558 119 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1559 116 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
1560 1374 my $this = $self->_obj2h;
1561 34 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1562 1374 ▶ $this->{verbose} = defined( ${ $pkg . '::VERBOSE' } ) ? ${ $pkg . '::VERBOSE' } : 0 if( !length( $this->{verbose} ) );
Branch: 2 branches
BranchTrueFalseTotal
unless length $this->{"verbose"} 1374 0 1374
defined ${$pkg . '::VERBOSE';} ? : 23 1351 1374
1563 1374 ▶ $this->{debug} = defined( ${ $pkg . '::DEBUG' } ) ? ${ $pkg . '::DEBUG' } : 0 if( !length( $this->{debug} ) );
Branch: 2 branches
BranchTrueFalseTotal
unless length $this->{"debug"} 1149 225 1374
defined ${$pkg . '::DEBUG';} ? : 85 1064 1149
1564 1374 ▶ $this->{version} = ${ $pkg . '::VERSION' } if( !defined( $this->{version} ) && defined( ${ $pkg . '::VERSION' } ) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $this->{"version"} and defined ${$pkg . '::VERSION';} 1370 4 1374
Condition66%2/3
not defined $this->{"version"} and defined ${$pkg . '::VERSION';}
!ll&&!rl&&r
041370
MC/DC50%1/2
not defined $this->{"version"} and defined ${$pkg . '::VERSION';}
not defined $this->{"version"} defined ${$pkg . '::VERSION';}
Truth table66%2/3
not(A) and B
A= not defined $this->{"version"}B= defined ${$pkg . '::VERSION';}
ABresult
0X0
100
111
1565 # $this->{level} = 0;
1566 1374 ▶ $this->{_colour_open} = undef unless( CORE::exists( $this->{_colour_open} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $this->{"_colour_open"} 1374 0 1374
1567 1374 ▶ $this->{_colour_close} = undef unless( CORE::exists( $this->{_colour_close} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $this->{"_colour_close"} 1374 0 1374
1568 1374 ▶ $this->{_exception_class} = 'Module::Generic::Exception' unless( CORE::defined( $this->{_exception_class} ) && CORE::length( $this->{_exception_class} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this->{"_exception_class"} and length $this->{"_exception_class"} 1373 1 1374
Condition66%2/3
defined $this->{"_exception_class"} and length $this->{"_exception_class"}
!ll&&!rl&&r
137301
MC/DC50%1/2
defined $this->{"_exception_class"} and length $this->{"_exception_class"}
defined $this->{"_exception_class"} length $this->{"_exception_class"}
Truth table66%2/3
A and B
A= defined $this->{"_exception_class"}B= length $this->{"_exception_class"}
ABresult
0X0
100
111
1569 1374 ▶ $this->{_init_params_order} = [] unless( ref( $this->{_init_params_order} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this->{"_init_params_order"} 1374 0 1374
1570 # If no debug level was provided when calling message, this level will be assumed
1571 # Example: message( "Hello" );
1572 # If __message_default_level was set to 3, this would be equivalent to message( 3, "Hello" )
1573 1374 ▶ $this->{_init_strict_use_sub} = 0 unless( length( $this->{_init_strict_use_sub} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $this->{"_init_strict_use_sub"} 90 1284 1374
1574 1374 ▶ $this->{_log_handler} = '' unless( length( $this->{_log_handler} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $this->{"_log_handler"} 1374 0 1374
1575 1374 $this->{_message_default_level} = 0;
1576 1374 ▶ $this->{_msg_no_exec_sub} = 0 unless( length( $this->{_msg_no_exec_sub} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $this->{"_msg_no_exec_sub"} 1374 0 1374
1577 1374 ▶ $this->{_error_max_length} = '' unless( length( $this->{_error_max_length} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $this->{"_error_max_length"} 1374 0 1374
1578 1374 my $data = $this;
1579 1374 ▶ if( $this->{_data_repo} )
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"_data_repo"}) 0 1374 1374
1580 {
1581 0 ▶ $this->{ $this->{_data_repo} } = {} if( !$this->{ $this->{_data_repo} } );
Branch: 1 branch
BranchTrueFalseTotal
unless $$this{$this->{"_data_repo"}} 0 0 0
1582 0 $data = $this->{ $this->{_data_repo} };
1583 }
1584  
1585 # If the calling module wants to set up object cleanup
1586 1374 ▶ if( $this->{_mod_perl_cleanup} && $MOD_PERL )
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"_mod_perl_cleanup"} and $MOD_PERL) 0 1374 1374
Condition33%1/3
$this->{"_mod_perl_cleanup"} and $MOD_PERL
!ll&&!rl&&r
137400
MC/DC0%0/2
$this->{"_mod_perl_cleanup"} and $MOD_PERL
$this->{"_mod_perl_cleanup"} $MOD_PERL
Truth table33%1/3
A and B
A= $this->{"_mod_perl_cleanup"}B= $MOD_PERL
ABresult
0X0
100
111
1587 {
1588 # try-catch
1589 0 local $@;
1590 eval
1591 0 {
1592 0 local $SIG{__DIE__};
1593 # Must enable GlobalRequest for this to work.
1594 0 my $r = Apache2::RequestUtil->request;
1595 0 ▶ if( $r )
Branch: 1 branch
BranchTrueFalseTotal
if ($r) 0 0 0
1596 {
1597 $r->pool->cleanup_register(sub
1598 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1599 0 map{ delete( $this->{ $_ } ) } keys( %$this );
1600 0 undef( %$this );
1601 0 return(1);
1602 0 });
1603 }
1604 };
1605 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1606 {
1607 0 print( STDERR "Error trying to get the global Apache2::ApacheRec object and setting up a cleanup handler: $@\n" );
1608 }
1609 }
1610  
1611 1374 ▶ @_ = () if( @_ == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and not defined $_[0] 0 1374 1374
Condition66%2/3
@_ == 1 and not defined $_[0]
!ll&&!rl&&r
1325490
MC/DC0%0/2
@_ == 1 and not defined $_[0]
@_ == 1 not defined $_[0]
Truth table66%2/3
A and not(B)
A= @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
1612 1374 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 482 892 1374
1613 {
1614 482 my @args = @_;
1615 0 ▶ $self->__message( 105, "Args (\@args) provided is -> ", sub{ $self->Module::Generic::dump( \@args ) } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
1616 482 my $vals;
1617 482 ▶ if( ref( $args[0] ) eq 'HASH' ||
Branch: 4 branches
BranchTrueFalseTotal
if (ref $args[0] eq 'HASH' or builtin::blessed($args[0]) and $args[0]->isa('Module::Generic::Hash')) { } 49 433 482
elsif (ref $args[0] eq 'ARRAY') { } 0 433 433
elsif (scalar @args == 1 and not defined $args[0]) { } 0 433 433
elsif (scalar(@args) % 2) { } 0 433 433
Condition50%3/6
ref $args[0] eq "HASH" or builtin::blessed($args[0]) and $args[0]->isa("Module::Generic::Hash")
l!l&&r!l&&!r
490433
builtin::blessed($args[0]) and $args[0]->isa("Module::Generic::Hash")
!ll&&!rl&&r
43300
MC/DC33%1/3
ref $args[0] eq "HASH" or builtin::blessed($args[0]) and $args[0]->isa("Module::Generic::Hash")
ref $args[0] eq "HASH" builtin::blessed($args[0]) $args[0]->isa("Module::Generic::Hash")
Truth table50%2/4
A or B and C
A= ref $args[0] eq "HASH"B= builtin::blessed($args[0])C= $args[0]->isa("Module::Generic::Hash")
ABCresult
1XX1
0111
00X0
0100
1618 ( Scalar::Util::blessed( $args[0] ) && $args[0]->isa( 'Module::Generic::Hash' ) ) )
1619 {
1620 49 my $h = shift( @args );
1621 49 my $debug_value;
1622 49 ▶ $debug_value = CORE::delete( $h->{debug} ) if( CORE::exists( $h->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $h->{"debug"} 12 37 49
1623 49 $vals = [ %$h ];
1624 49 ▶ unshift( @$vals, debug => $debug_value ) if( CORE::defined( $debug_value ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $debug_value 4 45 49
1625 }
1626 elsif( ref( $args[0] ) eq 'ARRAY' )
1627 {
1628 # $self->__message( 103, "Got an array ref" );
1629 0 $vals = $args[0];
1630 }
1631 # Special case when there is an undefined value passed (null) even though it is declared as a hash or object
1632 ▶ elsif( scalar( @args ) == 1 && !defined( $args[0] ) )
Condition33%1/3
scalar @args == 1 and not defined $args[0]
!ll&&!rl&&r
43300
MC/DC0%0/2
scalar @args == 1 and not defined $args[0]
scalar @args == 1 not defined $args[0]
Truth table33%1/3
A and not(B)
A= scalar @args == 1B= not defined $args[0]
ABresult
0X0
100
111
1633 {
1634 0 return( $self->error( "Only argument is provided to init ", ref( $self ), " object and its value is undefined." ) );
1635 }
1636 elsif( ( scalar( @args ) % 2 ) )
1637 {
1638 0 return( $self->error( sprintf( "Uneven number of parameters provided (%d). Should receive key => value pairs. Parameters provided are: %s", scalar( @args ), join( ', ', @args ) ) ) );
1639 }
1640 else
1641 {
1642 433 $vals = \@args;
1643 }
1644  
1645 482 ▶ my $order = ( CORE::exists( $this->{_init_params_order} ) && Scalar::Util::reftype( $this->{_init_params_order} ) eq 'ARRAY' ) ? $this->{_init_params_order} : [];
Branch: 1 branch
BranchTrueFalseTotal
exists $this->{'_init_params_order'} && builtin::reftype($this->{'_init_params_order'}) eq 'ARRAY' ? : 482 0 482
Condition33%1/3
exists $this->{"_init_params_order"} and builtin::reftype($this->{"_init_params_order"}) eq "ARRAY"
!ll&&!rl&&r
00482
MC/DC0%0/2
exists $this->{"_init_params_order"} and builtin::reftype($this->{"_init_params_order"}) eq "ARRAY"
exists $this->{"_init_params_order"} builtin::reftype($this->{"_init_params_order"}) eq "ARRAY"
Truth table33%1/3
A and B
A= exists $this->{"_init_params_order"}B= builtin::reftype($this->{"_init_params_order"}) eq "ARRAY"
ABresult
0X0
100
111
1646 482 ▶ if( scalar( @$order ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$order) 0 482 482
1647 {
1648 0 my $new = [];
1649 0 foreach my $param ( @$order )
1650 {
1651 0 ▶ for( my $i = 0; $i < scalar( @$vals ); $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$vals) 0 0 0
1652 {
1653 0 ▶ if( defined( $vals->[$i] ) && $vals->[$i] eq $param )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $vals->[$i] and $vals->[$i] eq $param) 0 0 0
Condition0%0/3
defined $vals->[$i] and $vals->[$i] eq $param
!ll&&!rl&&r
000
MC/DC0%0/2
defined $vals->[$i] and $vals->[$i] eq $param
defined $vals->[$i] $vals->[$i] eq $param
Truth table0%0/3
A and B
A= defined $vals->[$i]B= $vals->[$i] eq $param
ABresult
0X0
100
111
1654 {
1655 0 push( @$new, splice( @$vals, $i, 2 ) );
1656 }
1657 }
1658 }
1659 0 ▶ if( scalar( @$new ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$new) 0 0 0
1660 {
1661 0 push( @$new, @$vals );
1662 0 @$vals = @$new;
1663 }
1664 }
1665  
1666 482 ▶ if( CORE::exists( $this->{_init_preprocess} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $this->{"_init_preprocess"} and ref $this->{"_init_preprocess"} eq "CODE") 0 482 482
Condition33%1/3
exists $this->{"_init_preprocess"} and ref $this->{"_init_preprocess"} eq "CODE"
!ll&&!rl&&r
48200
MC/DC0%0/2
exists $this->{"_init_preprocess"} and ref $this->{"_init_preprocess"} eq "CODE"
exists $this->{"_init_preprocess"} ref $this->{"_init_preprocess"} eq "CODE"
Truth table33%1/3
A and B
A= exists $this->{"_init_preprocess"}B= ref $this->{"_init_preprocess"} eq "CODE"
ABresult
0X0
100
111
1667 ref( $this->{_init_preprocess} ) eq 'CODE' )
1668 {
1669 0 $self->__message( 112, "Init pre-process found, executing callback with an array containing ", scalar( @$vals ), " elements." );
1670 $vals = eval
1671 0 {
1672 0 $this->{_init_preprocess}->( $vals );
1673 };
1674 # try-catch
1675 0 local $@;
1676 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (builtin::reftype($vals // '') ne 'ARRAY') { } 0 0 0
1677 {
1678 0 die( "Pre-processing of init data failed: $@" );
1679 }
1680 ▶ elsif( Scalar::Util::reftype( $vals // '' ) ne 'ARRAY' )
Condition0%0/2
$vals // ""
l!l
00
MC/DC0%0/1
$vals // ""
$vals
Truth table0%0/2
A
A= $vals
Aresult
11
00
1681 {
1682 0 ▶ die( "Pre-processing of init data returned a ", ( ref( $vals ) // 'string' ), ", but was expecting an array reference." );
Condition0%0/2
ref $vals // "string"
l!l
00
MC/DC0%0/1
ref $vals // "string"
ref $vals
Truth table0%0/2
A
A= ref $vals
Aresult
11
00
1683 }
1684 0 ▶ $self->__message( 112, "Init pre-process returned an array containing ", scalar( @$vals ), " elements -> ", sub{ $self->Module::Generic::dump( $vals ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1685 }
1686  
1687 # Check if there is a debug parameter, and if we find one, set it first so that that
1688 # calls to the package subroutines can produce verbose feedback as necessary
1689 482 ▶ for( my $i = 0; $i < scalar( @$vals ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$vals) 1457 482 1939
1690 {
1691 1457 ▶ next if( !defined( $vals->[$i] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vals->[$i] 113 1344 1457
1692 1344 ▶ if( $vals->[$i] eq 'debug' )
Branch: 1 branch
BranchTrueFalseTotal
if ($vals->[$i] eq "debug") 387 957 1344
1693 {
1694 387 my $v = $vals->[$i + 1];
1695 387 $self->debug( $v );
1696 387 CORE::splice( @$vals, $i, 2 );
1697 }
1698 }
1699  
1700 482 ▶ for( my $i = 0; $i < scalar( @$vals ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$vals) 589 482 1071
1701 {
1702 589 my $name = $vals->[ $i ];
1703 589 my $val = $vals->[ ++$i ];
1704 # Ensure the name has any dash ("-") converted to underscore ("_")
1705 589 my $orig = $name;
1706 589 my $transformed = ( $name =~ tr/-/_/ );
1707 589 my $meth = $self->can( $name );
1708 589 ▶ $self->__message( 112, "Initialising field $name with value '", ( $val // 'undef' ), "' (", $self->_str_val( $val // 'undef' ), "). Is method $name defined? ", ( defined( $meth ) ? 'yes' : 'no' ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $meth ? : 585 4 589
Condition100%4/4
$val // "undef"
l!l
476113
$val // "undef"
l!l
476113
MC/DC100%1/1
$val // "undef"
$val
MC/DC100%1/1
$val // "undef"
$val
Truth table100%2/2
A
A= $val
Aresult
11
00
Truth table100%2/2
A
A= $val
Aresult
11
00
1709 589 ▶ if( defined( $meth ) )
Branch: 3 branches
BranchTrueFalseTotal
if (defined $meth) { } 585 4 589
elsif ($this->{'_init_strict_use_sub'}) { } 4 0 4
elsif (exists $data->{$name} or exists $data->{$orig}) { } 0 0 0
1710 {
1711 # if( !defined( $self->$name( $val ) ) )
1712 585 ▶ $self->__message( 114, "Calling method '$name' ($meth) with value '", $self->_str_val( $val // 'undef' ), "'" );
Condition100%2/2
$val // "undef"
l!l
472113
MC/DC100%1/1
$val // "undef"
$val
Truth table100%2/2
A
A= $val
Aresult
11
00
1713 585 ▶ if( !defined( $meth->( $self, $val ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &$meth($self, $val)) 113 472 585
1714 {
1715 113 my $err = $self->error;
1716 113 ▶ if( defined( $val ) && $err )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $err) 0 113 113
Condition33%1/3
defined $val and $err
!ll&&!rl&&r
11300
MC/DC0%0/2
defined $val and $err
defined $val $err
Truth table33%1/3
A and B
A= defined $valB= $err
ABresult
0X0
100
111
1717 {
1718 0 $self->__message( 104, "Error while instantiating object for class '", ref( $self ), "': ", $self->error );
1719 0 ▶ warn( "Warning: method $name returned undef while initialising object ", ref( $self ), ": ", ( $err ? $err->message : '' ), "\n" );
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 0 0 0
1720 0 return;
1721 }
1722 }
1723 585 next;
1724 }
1725 elsif( $this->{_init_strict_use_sub} )
1726 {
1727 0 ▶ $self->__message( 103, "Unknown method '$name' in class $pkg -> ", sub{ $self->_get_stack_trace->as_string });
Subroutine __ANON__: not called CC=1 SCAR=1.2
1728 4 $self->error( "Unknown method $name in class $pkg" );
1729 4 next;
1730 }
1731 ▶ elsif( exists( $data->{ $name } ) ||
Condition0%0/3
exists $data->{$name} or exists $data->{$orig}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $data->{$name} or exists $data->{$orig}
exists $data->{$name} exists $data->{$orig}
Truth table0%0/3
A or B
A= exists $data->{$name}B= exists $data->{$orig}
ABresult
1X1
011
000
1732 exists( $data->{ $orig } ) )
1733 {
1734 # Pre-existing field value looks like a module package and that package is already loaded
1735 0 ▶ if( ( index( $data->{ $name }, '::' ) != -1 || $data->{ $name } =~ /^[a-zA-Z][a-zA-Z\_]*[a-zA-Z]$/ ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (index($data->{$name}, '::') != -1 || $data->{$name} =~ /^[a-zA-Z][a-zA-Z\_]*[a-zA-Z]$/ and $self->_is_class_loaded($data->{$name})) { } 0 0 0
elsif ($this->{'_init_strict'}) { } 0 0 0
Condition0%0/6
index($data->{$name}, "::") != -1 || $data->{$name} =~ /^[a-zA-Z][a-zA-Z\_]*[a-zA-Z]$/ and $self->_is_class_loaded($data->{$name})
!ll&&!rl&&r
000
index($data->{$name}, "::") != -1 or $data->{$name} =~ /^[a-zA-Z][a-zA-Z\_]*[a-zA-Z]$/
l!l&&r!l&&!r
000
MC/DC0%0/3
index($data->{$name}, "::") != -1 || $data->{$name} =~ /^[a-zA-Z][a-zA-Z\_]*[a-zA-Z]$/ and $self->_is_class_loaded($data->{$name})
index($data->{$name}, "::") != -1 $data->{$name} =~ /^[a-zA-Z][a-zA-Z\_]*[a-zA-Z]$/ $self->_is_class_loaded($data->{$name})
Truth table0%0/5
A or B and C
A= index($data->{$name}, "::") != -1B= $data->{$name} =~ /^[a-zA-Z][a-zA-Z\_]*[a-zA-Z]$/C= $self->_is_class_loaded($data->{$name})
ABCresult
00X0
1X00
0100
1X11
0111
1736 $self->_is_class_loaded( $data->{ $name } ) )
1737 {
1738 0 my $thisPack = $data->{ $name };
1739 0 ▶ if( !Scalar::Util::blessed( $val ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not builtin::blessed($val)) { } 0 0 0
elsif (not $val->isa($thisPack)) { } 0 0 0
1740 {
1741 0 return( $self->error( "$name parameter expects a package $thisPack object, but instead got '$val'." ) );
1742 }
1743 elsif( !$val->isa( $thisPack ) )
1744 {
1745 0 return( $self->error( "$name parameter expects a package $thisPack object, but instead got an object from package '", ref( $val ), "'." ) );
1746 }
1747 }
1748 elsif( $this->{_init_strict} )
1749 {
1750 0 ▶ if( exists( $data->{ $orig } ) && ref( $data->{ $orig } ) eq 'ARRAY' )
Branch: 4 branches
BranchTrueFalseTotal
if (exists $data->{$orig} and ref $data->{$orig} eq 'ARRAY') { } 0 0 0
elsif (exists $data->{$orig} and ref $data->{$orig} eq 'HASH') { } 0 0 0
elsif (exists $data->{$orig} and ref $data->{$orig} eq 'SCALAR') { } 0 0 0
elsif ($transformed) { } 0 0 0
Condition0%0/3
exists $data->{$orig} and ref $data->{$orig} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $data->{$orig} and ref $data->{$orig} eq "ARRAY"
exists $data->{$orig} ref $data->{$orig} eq "ARRAY"
Truth table0%0/3
A and B
A= exists $data->{$orig}B= ref $data->{$orig} eq "ARRAY"
ABresult
0X0
100
111
1751 {
1752 0 ▶ return( $self->error( "$orig parameter expects an array reference, but instead got '$val'." ) ) if( ( Scalar::Util::reftype( $val ) // '' ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($val) // "") ne "ARRAY" 0 0 0
Condition0%0/2
builtin::reftype($val) // ""
l!l
00
MC/DC0%0/1
builtin::reftype($val) // ""
builtin::reftype($val)
Truth table0%0/2
A
A= builtin::reftype($val)
Aresult
11
00
1753 }
1754 ▶ elsif( exists( $data->{ $orig } ) && ref( $data->{ $orig } ) eq 'HASH' )
Condition0%0/3
exists $data->{$orig} and ref $data->{$orig} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $data->{$orig} and ref $data->{$orig} eq "HASH"
exists $data->{$orig} ref $data->{$orig} eq "HASH"
Truth table0%0/3
A and B
A= exists $data->{$orig}B= ref $data->{$orig} eq "HASH"
ABresult
0X0
100
111
1755 {
1756 0 ▶ return( $self->error( "$orig parameter expects an hash reference, but instead got '$val'." ) ) if( ( Scalar::Util::reftype( $val ) // '' ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($val) // "") ne "HASH" 0 0 0
Condition0%0/2
builtin::reftype($val) // ""
l!l
00
MC/DC0%0/1
builtin::reftype($val) // ""
builtin::reftype($val)
Truth table0%0/2
A
A= builtin::reftype($val)
Aresult
11
00
1757 }
1758 ▶ elsif( exists( $data->{ $orig } ) && ref( $data->{ $orig } ) eq 'SCALAR' )
Condition0%0/3
exists $data->{$orig} and ref $data->{$orig} eq "SCALAR"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $data->{$orig} and ref $data->{$orig} eq "SCALAR"
exists $data->{$orig} ref $data->{$orig} eq "SCALAR"
Truth table0%0/3
A and B
A= exists $data->{$orig}B= ref $data->{$orig} eq "SCALAR"
ABresult
0X0
100
111
1759 {
1760 0 ▶ return( $self->error( "$orig parameter expects a scalar reference, but instead got '$val'." ) ) if( ( Scalar::Util::reftype( $val ) // '' ) ne 'SCALAR' );
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($val) // "") ne "SCALAR" 0 0 0
Condition0%0/2
builtin::reftype($val) // ""
l!l
00
MC/DC0%0/1
builtin::reftype($val) // ""
builtin::reftype($val)
Truth table0%0/2
A
A= builtin::reftype($val)
Aresult
11
00
1761 }
1762 elsif( $transformed )
1763 {
1764 0 ▶ if( exists( $data->{ $name } ) && ref( $data->{ $name } ) eq 'ARRAY' )
Branch: 3 branches
BranchTrueFalseTotal
if (exists $data->{$name} and ref $data->{$name} eq 'ARRAY') { } 0 0 0
elsif (exists $data->{$name} and ref $data->{$name} eq 'HASH') { } 0 0 0
elsif (exists $data->{$name} and ref $data->{$name} eq 'SCALAR') { } 0 0 0
Condition0%0/3
exists $data->{$name} and ref $data->{$name} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $data->{$name} and ref $data->{$name} eq "ARRAY"
exists $data->{$name} ref $data->{$name} eq "ARRAY"
Truth table0%0/3
A and B
A= exists $data->{$name}B= ref $data->{$name} eq "ARRAY"
ABresult
0X0
100
111
1765 {
1766 0 ▶ return( $self->error( "$name parameter expects an array reference, but instead got '$val'." ) ) if( ( Scalar::Util::reftype( $val ) // '' ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($val) // "") ne "ARRAY" 0 0 0
Condition0%0/2
builtin::reftype($val) // ""
l!l
00
MC/DC0%0/1
builtin::reftype($val) // ""
builtin::reftype($val)
Truth table0%0/2
A
A= builtin::reftype($val)
Aresult
11
00
1767 }
1768 ▶ elsif( exists( $data->{ $name } ) && ref( $data->{ $name } ) eq 'HASH' )
Condition0%0/3
exists $data->{$name} and ref $data->{$name} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $data->{$name} and ref $data->{$name} eq "HASH"
exists $data->{$name} ref $data->{$name} eq "HASH"
Truth table0%0/3
A and B
A= exists $data->{$name}B= ref $data->{$name} eq "HASH"
ABresult
0X0
100
111
1769 {
1770 0 ▶ return( $self->error( "$name parameter expects an hash reference, but instead got '$val'." ) ) if( ( Scalar::Util::reftype( $val ) // '' ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($val) // "") ne "HASH" 0 0 0
Condition0%0/2
builtin::reftype($val) // ""
l!l
00
MC/DC0%0/1
builtin::reftype($val) // ""
builtin::reftype($val)
Truth table0%0/2
A
A= builtin::reftype($val)
Aresult
11
00
1771 }
1772 ▶ elsif( exists( $data->{ $name } ) && ref( $data->{ $name } ) eq 'SCALAR' )
Condition0%0/3
exists $data->{$name} and ref $data->{$name} eq "SCALAR"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $data->{$name} and ref $data->{$name} eq "SCALAR"
exists $data->{$name} ref $data->{$name} eq "SCALAR"
Truth table0%0/3
A and B
A= exists $data->{$name}B= ref $data->{$name} eq "SCALAR"
ABresult
0X0
100
111
1773 {
1774 0 ▶ return( $self->error( "$name parameter expects a scalar reference, but instead got '$val'." ) ) if( ( Scalar::Util::reftype( $val ) // '' ) ne 'SCALAR' );
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($val) // "") ne "SCALAR" 0 0 0
Condition0%0/2
builtin::reftype($val) // ""
l!l
00
MC/DC0%0/1
builtin::reftype($val) // ""
builtin::reftype($val)
Truth table0%0/2
A
A= builtin::reftype($val)
Aresult
11
00
1775 }
1776 }
1777 }
1778 }
1779 # The name parameter does not exist
1780 else
1781 {
1782 # If we are strict, we reject
1783 0 ▶ next if( $this->{_init_strict} );
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"_init_strict"} 0 0 0
1784 }
1785 # We passed all tests
1786 0 $data->{ $name } = $val;
1787 }
1788 }
1789 1374 return( $self );
1790 }
1791  
1792 0 ▶sub log_handler { return( shift->_set_get_code( '_log_handler', @_ ) ); }
Subroutine log_handler: not called CC=1 SCAR=6.9
Pod documented
1793  
1794 {
1795 34 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
1796 # NOTE: aliasing message to __message
1797 35 *message = \&__message;
1798  
1799 # NOTE: aliasing messagec to message_colour
1800 53 *messagec = \&message_colour;
1801  
1802 # NOTE: aliasing message_check to _message_check
1803 53 *message_check = \&_message_check;
1804  
1805 # NOTE: aliasing message_color to message_colour
1806 53 *message_color = \&message_colour;
1807  
1808 # NOTE: aliasing message_frame to _message_frame
1809 53 *message_frame = \&_message_frame;
1810  
1811 # NOTE: aliasing message_log to _message_log
1812 53 *message_log = \&_message_log;
1813  
1814 # NOTE: aliasing message_log_io to _message_log_io
1815 53 *message_log_io = \&_message_log_io;
1816  
1817 # NOTE: aliasing messagef to __messagef
1818 37 *messagef = \&__messagef;
1819 }
1820  
1821 sub new_array
1822 694 ▶{
Subroutine new_array: called CC=3 SCAR=11.3
Pod documented
1823 694 my $self = shift( @_ );
1824 694 ▶ $self->_load_class( 'Module::Generic::Array' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Array") or return $self->pass_error 694 0 694
1825 694 my $v = Module::Generic::Array->new( @_ );
1826 694 ▶ return( $self->pass_error( Module::Generic::Array->error ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 694 694
1827 694 return( $v );
1828 }
1829  
1830 sub new_datetime
1831 0 ▶{
Subroutine new_datetime: not called CC=3 SCAR=24.8
Pod documented
1832 0 my $self = shift( @_ );
1833 0 ▶ $self->_load_class( 'Module::Generic::DateTime' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::DateTime") or return $self->pass_error 0 0 0
1834 0 my $v = Module::Generic::DateTime->new( @_ );
1835 0 ▶ return( $self->pass_error( Module::Generic::DateTime->error ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
1836 0 return( $v );
1837 }
1838  
1839 sub new_file
1840 1 ▶{
Subroutine new_file: called CC=3 SCAR=11.3
Pod documented
1841 1 my $self = shift( @_ );
1842 1 ▶ $self->_load_class( 'Module::Generic::File' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::File") or return $self->pass_error 1 0 1
1843 1 my $v = Module::Generic::File->new( @_ );
1844 1 ▶ return( $self->pass_error( Module::Generic::File->error ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 1 1
1845 1 return( $v );
1846 }
1847  
1848 sub new_hash
1849 1 ▶{
Subroutine new_hash: called CC=3 SCAR=11.3
Pod documented
1850 1 my $self = shift( @_ );
1851 1 ▶ $self->_load_class( 'Module::Generic::Hash' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Hash") or return $self->pass_error 1 0 1
1852 1 my $v = Module::Generic::Hash->new( @_ );
1853 1 ▶ return( $self->pass_error( Module::Generic::Hash->error ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 1 1
1854 1 return( $v );
1855 }
1856  
1857 sub new_json
1858 0 ▶{
Subroutine new_json: not called CC=8 SCAR=42.8
Pod documented
1859 0 my $self = shift( @_ );
1860 0 my $opts = $self->_get_args_as_hash( @_ );
1861 0 ▶ $self->_load_class( 'JSON' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("JSON") or return $self->pass_error 0 0 0
1862 # 'allow_tags' is a real trouble-maker
1863 # my $j = JSON->new->allow_nonref->allow_blessed->convert_blessed->allow_tags->relaxed;
1864 0 my $j = JSON->new->allow_nonref->allow_blessed->convert_blessed->relaxed;
1865 # my $j = JSON->new->allow_nonref->allow_blessed->convert_blessed->relaxed;
1866 # Same as in Module::Generic::File::unload_json()
1867 0 my $equi =
1868 {
1869 order => 'canonical',
1870 ordered => 'canonical',
1871 sorted => 'canonical',
1872 sort => 'canonical',
1873 };
1874  
1875 0 foreach my $opt ( keys( %$opts ) )
1876 {
1877 0 my $ref;
1878 $ref = $j->can( exists( $equi->{ $opt } ) ? $equi->{ $opt } : $opt ) || do
1879 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
exists $equi->{$opt} ? : 0 0 0
Condition0%0/3
$j->can(exists $equi->{$opt} ? $equi->{$opt} : $opt) || do { warn "Unknown JSON option '${opt}'\n" if $self->_warnings_is_enabled; next }
l!l&&r!l&&!r
000
MC/DC0%0/2
$j->can(exists $equi->{$opt} ? $equi->{$opt} : $opt) || do { warn "Unknown JSON option '${opt}'\n" if $self->_warnings_is_enabled; next }
$j->can(exists $equi->{$opt} ? $equi->{$opt} : $opt) do { warn "Unknown JSON option '${opt}'\n" if $self->_warnings_is_enabled; next }
Truth table0%0/3
A || B
A= $j->can(exists $equi->{$opt} ? $equi->{$opt} : $opt)B= do { warn "Unknown JSON option '${opt}'\n" if $self->_warnings_is_enabled; next }
ABresult
1X1
011
000
1880 0 ▶ warn( "Unknown JSON option '${opt}'\n" ) if( $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled 0 0 0
1881 0 next;
1882 };
1883  
1884 # try-catch
1885 0 local $@;
1886 eval
1887 0 {
1888 0 $ref->( $j, $opts->{ $opt } );
1889 };
1890 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1891 {
1892 0 ▶ if( $@ =~ /perl[[:blank:]\h]+structure[[:blank:]\h]+exceeds[[:blank:]\h]+maximum[[:blank:]\h]+nesting[[:blank:]\h]+level/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /perl[[:blank:]\h]+structure[[:blank:]\h]+exceeds[[:blank:]\h]+maximum[[:blank:]\h]+nesting[[:blank:]\h]+level/i) { } 0 0 0
1893 {
1894 0 my $max = $j->get_max_depth;
1895 0 return( $self->error( "Unable to set json option ${opt}: $@ (max_depth value is ${max})" ) );
1896 }
1897 else
1898 {
1899 0 return( $self->error( "Unable to set json option ${opt}: $@" ) );
1900 }
1901 }
1902 }
1903 0 return( $j );
1904 }
1905  
1906 sub new_json_safe
1907 0 ▶{
Subroutine new_json_safe: not called CC=6 SCAR=37.4
Pod documented
1908 0 my $self = shift( @_ );
1909 0 my $opts = $self->_get_args_as_hash( @_ );
1910 0 ▶ $self->_load_class( 'Module::Generic::JSON' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::JSON") or return $self->pass_error 0 0 0
1911 0 my $defaults =
1912 {
1913 allow_nonref => 1,
1914 allow_blessed => 1,
1915 convert_blessed => 1,
1916 # allow_tags => 1,
1917 relaxed => 1,
1918 };
1919 0 foreach my $opt ( keys( %$defaults ) )
1920 {
1921 0 ▶ if( !exists( $opts->{ $opt } ) || !defined( $opts->{ $opt } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{$opt} and defined $opts->{$opt}) 0 0 0
Condition0%0/3
exists $opts->{$opt} and defined $opts->{$opt}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{$opt} and defined $opts->{$opt}
exists $opts->{$opt} defined $opts->{$opt}
Truth table0%0/3
A and B
A= exists $opts->{$opt}B= defined $opts->{$opt}
ABresult
0X0
100
111
1922 {
1923 0 $opts->{ $opt } = $defaults->{ $opt };
1924 }
1925 }
1926 0 ▶ my $j = Module::Generic::JSON->new( %$opts ) ||
Condition0%0/2
'Module::Generic::JSON'->new(%$opts) || (return $self->pass_error('Module::Generic::JSON'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::JSON'->new(%$opts) || (return $self->pass_error('Module::Generic::JSON'->error))
'Module::Generic::JSON'->new(%$opts)
Truth table0%0/2
A
A= 'Module::Generic::JSON'->new(%$opts)
Aresult
11
00
1927 return( $self->pass_error( Module::Generic::JSON->error ) );
1928 0 return( $j );
1929 }
1930  
1931 sub new_null
1932 56 ▶{
Subroutine new_null: called CC=11 SCAR=36.0
Pod documented
1933 56 my $self = shift( @_ );
1934 56 my $opts = $self->_get_args_as_hash( @_ );
1935 56 my $what;
1936 56 ▶ if( CORE::exists( $opts->{type} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'type'} and length($opts->{'type'} // '') and $opts->{'type'} =~ /^(array|code|hash|object|refscalar)$/i) { } 0 56 56
Condition25%2/8
exists $opts->{"type"} and length($opts->{"type"} // "") and $opts->{"type"} =~ /^(array|code|hash|object|refscalar)$/i
!ll&&!rl&&r
5600
exists $opts->{"type"} and length($opts->{"type"} // "")
!ll&&!rl&&r
5600
$opts->{"type"} // ""
l!l
00
MC/DC0%0/3
exists $opts->{"type"} and length($opts->{"type"} // "") and $opts->{"type"} =~ /^(array|code|hash|object|refscalar)$/i
exists $opts->{"type"} $opts->{"type"} $opts->{"type"} =~ /^(array|code|hash|object|refscalar)$/i
Truth table25%1/4
A and B and C
A= exists $opts->{"type"}B= $opts->{"type"}C= $opts->{"type"} =~ /^(array|code|hash|object|refscalar)$/i
ABCresult
0XX0
10X0
1100
1111
1937 CORE::length( $opts->{type} // '' ) &&
1938 $opts->{type} =~ /^(array|code|hash|object|refscalar)$/i )
1939 {
1940 0 $what = $opts->{type};
1941 }
1942 else
1943 {
1944 56 $what = Wanted::context();
1945 }
1946  
1947 56 ▶ if( $what eq 'OBJECT' )
Branch: 5 branches
BranchTrueFalseTotal
if ($what eq 'OBJECT') { } 0 56 56
elsif ($what eq 'ARRAY') { } 0 56 56
elsif ($what eq 'HASH') { } 0 56 56
elsif ($what eq 'CODE') { } 0 56 56
elsif ($what eq 'REFSCALAR') { } 0 56 56
1948 {
1949 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or die "Unable to load Module::Generic::Null" 0 0 0
1950 die( "Unable to load Module::Generic::Null" );
1951 0 return( Module::Generic::Null->new( @_ ) );
1952 }
1953 elsif( $what eq 'ARRAY' )
1954 {
1955 0 return( [] );
1956 }
1957 elsif( $what eq 'HASH' )
1958 {
1959 0 return( {} );
1960 }
1961 elsif( $what eq 'CODE' )
1962 {
1963 0 ▶ return( sub{ return; } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1964 }
1965 elsif( $what eq 'REFSCALAR' )
1966 {
1967 0 return( \undef );
1968 }
1969 else
1970 {
1971 56 return;
1972 }
1973 }
1974  
1975 sub new_number
1976 100 ▶{
Subroutine new_number: called CC=3 SCAR=11.3
Pod documented
1977 100 my $self = shift( @_ );
1978 100 ▶ $self->_load_class( 'Module::Generic::Number' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Number") or return $self->pass_error 100 0 100
1979 100 my $v = Module::Generic::Number->new( @_ );
1980 100 ▶ return( $self->pass_error( Module::Generic::Number->error ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 100 100
1981 100 return( $v );
1982 }
1983  
1984 sub new_scalar
1985 42 ▶{
Subroutine new_scalar: called CC=3 SCAR=11.3
Pod documented
1986 42 my $self = shift( @_ );
1987 42 ▶ $self->_load_class( 'Module::Generic::Scalar' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or return $self->pass_error 42 0 42
1988 42 my $v = Module::Generic::Scalar->new( @_ );
1989 42 ▶ return( $self->pass_error( Module::Generic::Scalar->error ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 42 42
1990 42 return( $v );
1991 }
1992  
1993 sub new_tempdir
1994 0 ▶{
Subroutine new_tempdir: not called CC=2 SCAR=17.9
Pod documented
1995 0 my $self = shift( @_ );
1996 0 ▶ $self->_load_class( 'Module::Generic::File' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::File") or return $self->pass_error 0 0 0
1997 0 return( Module::Generic::File::tempdir( @_ ) );
1998 }
1999  
2000 sub new_tempfile
2001 0 ▶{
Subroutine new_tempfile: not called CC=2 SCAR=17.9
Pod documented
2002 0 my $self = shift( @_ );
2003 0 ▶ $self->_load_class( 'Module::Generic::File' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::File") or return $self->pass_error 0 0 0
2004 0 return( Module::Generic::File::tempfile( @_ ) );
2005 }
2006  
2007 sub new_version
2008 0 ▶{
Subroutine new_version: not called CC=4 SCAR=30.0
Pod documented
2009 0 my $self = shift( @_ );
2010 0 my $v = shift( @_ );
2011 0 ▶ if( !defined( $v ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $v) { } 0 0 0
elsif (not length "$v") { } 0 0 0
2012 {
2013 0 return( $self->error( "No version was provided." ) );
2014 }
2015 elsif( !CORE::length( "$v" ) )
2016 {
2017 0 return( $self->error( "Value provided, to create a version object, is empty." ) );
2018 }
2019  
2020 0 my $vers;
2021 # try-catch
2022 0 local $@;
2023 eval
2024 0 {
2025 0 $vers = version->parse( "$v" );
2026 };
2027 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2028 {
2029 0 return( $self->error( "Unable to create a version object from '$v': $@" ) );
2030 }
2031 0 return( $vers );
2032 }
2033  
2034 0 ▶sub noexec { $_[0]->{_msg_no_exec_sub} = 1; return( $_[0] ); }
Subroutine noexec: not called CC=1 SCAR=6.9
Pod documented
2035  
2036 # Purpose is to get an error object thrown from, possibly another package,
2037 # and make it ours and pass it along
2038 # e.g.:
2039 # $self->pass_error
2040 # $self->pass_error( 'Some error that will be passed to error()' );
2041 # $self->pass_error( $error_object );
2042 # $self->pass_error( $error_object, { class => 'Some::ExceptionClass', code => 400 } );
2043 # $self->pass_error({ class => 'Some::ExceptionClass' });
2044 sub pass_error
2045 8 ▶{
Subroutine pass_error: called CC=64 SCAR=65.3
Pod documented
2046 8 my $self = shift( @_ );
2047 8 ▶ my $class = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
800
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
2048 8 my $this = $self->_obj2h;
2049 8 my $opts = {};
2050 8 my $err;
2051 my $ex_class;
2052 8 my $code;
2053 8 my $callback;
2054 35 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
2055 8 ▶ my $err_key = HAS_THREADS() ? join( ';', $class, $$, threads->tid ) : join( ';', $class, $$ );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 8 8
2056 8 my $repo = Module::Generic::Global->new( 'errors' => $class, key => $err_key );
2057  
2058 8 ▶ if( scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 2 6 8
2059 {
2060 # Either an hash defining a new error and this will be passed along to error(); or
2061 # an hash with a single property: { class => 'Some::ExceptionClass' }
2062 2 ▶ if( scalar( @_ ) == 1 && ref( $_[0] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and ref $_[0] eq 'HASH') { } 0 2 2
Condition33%1/3
scalar @_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
020
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
2063 {
2064 0 $opts = $_[0];
2065 }
2066 else
2067 {
2068 # $self->pass_error( $error_object, { class => 'Some::ExceptionClass' } );
2069 2 ▶ if( scalar( @_ ) > 1 && ref( $_[-1] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1 and ref $_[-1] eq "HASH") 0 2 2
Condition33%1/3
scalar @_ > 1 and ref $_[-1] eq "HASH"
!ll&&!rl&&r
200
MC/DC0%0/2
scalar @_ > 1 and ref $_[-1] eq "HASH"
scalar @_ > 1 ref $_[-1] eq "HASH"
Truth table33%1/3
A and B
A= scalar @_ > 1B= ref $_[-1] eq "HASH"
ABresult
0X0
100
111
2070 {
2071 0 $opts = pop( @_ );
2072 }
2073 2 $err = $_[0];
2074 }
2075 }
2076 8 ▶ $err = $opts->{error} if( !defined( $err ) && CORE::exists( $opts->{error} ) && defined( $opts->{error} ) && CORE::length( $opts->{error} ) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"} 0 8 8
Condition44%4/9
not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"}
!ll&&!rl&&r
800
not defined $err and exists $opts->{"error"} and defined $opts->{"error"}
!ll&&!rl&&r
800
not defined $err and exists $opts->{"error"}
!ll&&!rl&&r
260
MC/DC0%0/4
not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"}
not defined $err exists $opts->{"error"} defined $opts->{"error"} length $opts->{"error"}
Truth table40%2/5
not(A) and B and C and D
A= not defined $errB= exists $opts->{"error"}C= defined $opts->{"error"}D= length $opts->{"error"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2077 # We set $ex_class only if the hash provided is a one-element hash and not an error-defining hash
2078 # $class = CORE::delete( $opts->{class} ) if( scalar( keys( %$opts ) ) == 1 && [keys( %$opts )]->[0] eq 'class' );
2079 8 ▶ $ex_class = $opts->{class} if( CORE::exists( $opts->{class} ) && defined( $opts->{class} ) && CORE::length( $opts->{class} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"} 0 8 8
Condition33%2/6
exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}
!ll&&!rl&&r
800
exists $opts->{"class"} and defined $opts->{"class"}
!ll&&!rl&&r
800
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
2080 8 ▶ $code = $opts->{code} if( CORE::exists( $opts->{code} ) && defined( $opts->{code} ) && CORE::length( $opts->{code} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"} 0 8 8
Condition33%2/6
exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"}
!ll&&!rl&&r
800
exists $opts->{"code"} and defined $opts->{"code"}
!ll&&!rl&&r
800
MC/DC0%0/3
exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"}
exists $opts->{"code"} defined $opts->{"code"} length $opts->{"code"}
Truth table25%1/4
A and B and C
A= exists $opts->{"code"}B= defined $opts->{"code"}C= length $opts->{"code"}
ABCresult
0XX0
10X0
1100
1111
2081 8 ▶ $callback = $opts->{callback} if( CORE::exists( $opts->{callback} ) && defined( $opts->{callback} ) && ref( $opts->{callback} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"callback"} and defined $opts->{"callback"} and ref $opts->{"callback"} 0 8 8
Condition33%2/6
exists $opts->{"callback"} and defined $opts->{"callback"} and ref $opts->{"callback"}
!ll&&!rl&&r
800
exists $opts->{"callback"} and defined $opts->{"callback"}
!ll&&!rl&&r
800
MC/DC0%0/3
exists $opts->{"callback"} and defined $opts->{"callback"} and ref $opts->{"callback"}
exists $opts->{"callback"} defined $opts->{"callback"} ref $opts->{"callback"}
Truth table25%1/4
A and B and C
A= exists $opts->{"callback"}B= defined $opts->{"callback"}C= ref $opts->{"callback"}
ABCresult
0XX0
10X0
1100
1111
2082  
2083 # called with no argument, most likely from the same class to pass on an error
2084 # set up earlier by another method; or
2085 # with an hash containing just one argument class => 'Some::ExceptionClass'
2086 8 ▶ if( !defined( $err ) && ( !scalar( @_ ) || defined( $ex_class ) || defined( $code ) || defined( $callback ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $err and !scalar(@_) || defined $ex_class || defined $code || defined $callback) { } 6 2 8
elsif (defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $ex_class) { } 2 0 2
Condition41%5/12
not defined $err and !scalar(@_) || defined $ex_class || defined $code || defined $callback
!ll&&!rl&&r
206
not scalar @_ or defined $ex_class or defined $code or defined $callback
l!l&&r!l&&!r
600
not scalar @_ or defined $ex_class or defined $code
l!l&&r!l&&!r
600
not scalar @_ or defined $ex_class
l!l&&r!l&&!r
600
MC/DC20%1/5
not defined $err and !scalar(@_) || defined $ex_class || defined $code || defined $callback
not defined $err not scalar @_ defined $ex_class defined $code defined $callback
Truth table33%2/6
not(A) and not(B) or C or D or E
A= not defined $errB= not scalar @_C= defined $ex_classD= defined $codeE= defined $callback
ABCDEresult
0XXXX0
100000
11XXX1
101XX1
1001X1
100011
2087 {
2088 6 $self->__message( 106, "Passing on error..." );
2089 6 my $error;
2090 6 ▶ if( Scalar::Util::blessed( $self ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($self) and exists $this->{'error'} and defined $this->{'error'} and length $self->_str_val($this->{'error'})) { } 6 0 6
elsif ($repo->exists) { } 0 0 0
Condition33%3/9
builtin::blessed($self) and exists $this->{"error"} and defined $this->{"error"} and length $self->_str_val($this->{"error"})
!ll&&!rl&&r
006
builtin::blessed($self) and exists $this->{"error"} and defined $this->{"error"}
!ll&&!rl&&r
006
builtin::blessed($self) and exists $this->{"error"}
!ll&&!rl&&r
006
MC/DC0%0/4
builtin::blessed($self) and exists $this->{"error"} and defined $this->{"error"} and length $self->_str_val($this->{"error"})
builtin::blessed($self) exists $this->{"error"} defined $this->{"error"} length $self->_str_val($this->{"error"})
Truth table20%1/5
A and B and C and D
A= builtin::blessed($self)B= exists $this->{"error"}C= defined $this->{"error"}D= length $self->_str_val($this->{"error"})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2091 CORE::exists( $this->{error} ) &&
2092 defined( $this->{error} ) &&
2093 # Avoid overloaded stringification
2094 CORE::length( $self->_str_val( $this->{error} ) ) )
2095 {
2096 6 $error = $this->{error};
2097 6 ▶ $self->__message( 106, "Error found from within our object: ", $self->_str_val( $error // 'undef' ) );
Condition50%1/2
$error // "undef"
l!l
60
MC/DC0%0/1
$error // "undef"
$error
Truth table50%1/2
A
A= $error
Aresult
11
00
2098 }
2099 elsif( $repo->exists )
2100 {
2101 0 $error = $repo->get;
2102 }
2103  
2104 6 ▶ if( !defined( $error ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $error) { } 0 6 6
2105 {
2106 0 warn( "No error object provided and no previous error set either! It seems the previous method call returned a simple undef\n", $self->_get_stack_trace );
2107 }
2108 else
2109 {
2110 6 ▶ $err = ( defined( $ex_class ) ? bless( $error => $ex_class ) : $error );
Branch: 1 branch
BranchTrueFalseTotal
defined $ex_class ? : 0 6 6
2111 6 ▶ $err->code( $code ) if( defined( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code 0 6 6
2112 # Here, we do not:
2113 # my $err_callback = $self->_on_error;
2114 # because this callback is for new errors, whereas here, we just pass along existing error.
2115 # We would not want to trigger the error callback twice.
2116 6 ▶ if( defined( $callback ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $callback and ref $callback eq "CODE") 0 6 6
Condition33%1/3
defined $callback and ref $callback eq "CODE"
!ll&&!rl&&r
600
MC/DC0%0/2
defined $callback and ref $callback eq "CODE"
defined $callback ref $callback eq "CODE"
Truth table33%1/3
A and B
A= defined $callbackB= ref $callback eq "CODE"
ABresult
0X0
100
111
2117 CORE::ref( $callback ) eq 'CODE' )
2118 {
2119 0 ▶ local $SIG{__WARN__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
2120 0 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
2121 0 local $@;
2122 eval
2123 0 {
2124 0 $callback->( $self, $err );
2125 };
2126 }
2127 }
2128 }
2129 # An error object was provided
2130 ▶ elsif( defined( $err ) &&
Condition25%3/12
defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $ex_class
!ll&&!rl&&r
002
defined $err and builtin::blessed($err)
!ll&&!rl&&r
002
scalar @_ == 1 or scalar @_ == 2 and defined $ex_class
l!l&&r!l&&!r
200
scalar @_ == 2 and defined $ex_class
!ll&&!rl&&r
000
MC/DC0%0/5
defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $ex_class
defined $err builtin::blessed($err) scalar @_ == 1 scalar @_ == 2 defined $ex_class
Truth table16%1/6
A and B and C or D and E
A= defined $errB= builtin::blessed($err)C= scalar @_ == 1D= scalar @_ == 2E= defined $ex_class
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
2131 Scalar::Util::blessed( $err ) &&
2132 ( scalar( @_ ) == 1 ||
2133 ( scalar( @_ ) == 2 && defined( $ex_class ) )
2134 ) )
2135 {
2136 2 ▶ $self->__message( 106, "Received exception object ", $self->_str_val( $err // 'undef' ), " from caller ", [caller]->[0], " at line ", [caller]->[2] );
Condition50%1/2
$err // "undef"
l!l
20
MC/DC0%0/1
$err // "undef"
$err
Truth table50%1/2
A
A= $err
Aresult
11
00
2137 # If necessary, we re-bless the error object to the designated class
2138 2 ▶ my $o = ( defined( $ex_class ) ? bless( $err => $ex_class ) : $err );
Branch: 1 branch
BranchTrueFalseTotal
defined $ex_class ? : 0 2 2
2139 2 ▶ $self->__message( 106, "Storing the error object provided", ( defined( $ex_class ) ? " after having blessed it with class $ex_class" : '' ), ' ', $self->_str_val( $o // 'undef' ), " in our current object (", $self->_str_val( $self // 'undef' ), ")" );
Branch: 1 branch
BranchTrueFalseTotal
defined $ex_class ? : 0 2 2
Condition50%2/4
$o // "undef"
l!l
20
$self // "undef"
l!l
20
MC/DC0%0/1
$o // "undef"
$o
MC/DC0%0/1
$self // "undef"
$self
Truth table50%1/2
A
A= $o
Aresult
11
00
Truth table50%1/2
A
A= $self
Aresult
11
00
2140 2 $this->{error} = $o;
2141 # We ned to be backward compatible, and allow the user to access $My::Module::ERROR
2142 2 $self->__message( 106, "pass_error() was called as a class function $class->pass_error, storing the provided error object in the global \$ERRORS" );
2143 2 ▶ $self->__message( 106, "Are we running under threads, switching to shared data ? ", ( HAS_THREADS ? 'yes' : 'no' ) );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 2 2
2144 2 $repo->set( $o );
2145 # ${ $class . '::ERROR' } = $o;
2146 2 ▶ $this->{error}->code( $code ) if( defined( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code 0 2 2
2147 2 my $err_callback = $self->_on_error;
2148 2 ▶ $err_callback = $callback if( !defined( $err_callback ) && defined( $callback ) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $err_callback and defined $callback 0 2 2
Condition33%1/3
not defined $err_callback and defined $callback
!ll&&!rl&&r
020
MC/DC0%0/2
not defined $err_callback and defined $callback
not defined $err_callback defined $callback
Truth table33%1/3
not(A) and B
A= not defined $err_callbackB= defined $callback
ABresult
0X0
100
111
2149 2 ▶ if( defined( $err_callback ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err_callback and ref $err_callback eq "CODE") 0 2 2
Condition33%1/3
defined $err_callback and ref $err_callback eq "CODE"
!ll&&!rl&&r
200
MC/DC0%0/2
defined $err_callback and ref $err_callback eq "CODE"
defined $err_callback ref $err_callback eq "CODE"
Truth table33%1/3
A and B
A= defined $err_callbackB= ref $err_callback eq "CODE"
ABresult
0X0
100
111
2150 CORE::ref( $err_callback ) eq 'CODE' )
2151 {
2152 0 ▶ local $SIG{__WARN__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
2153 0 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
2154 0 local $@;
2155 eval
2156 0 {
2157 0 $err_callback->( $self, $this->{error} );
2158 };
2159 }
2160  
2161 2 ▶ my $err_callbacks = [ reverse( @{$self->_error_callbacks || []} ) ];
Condition50%1/2
$self->_error_callbacks || []
l!l
20
MC/DC0%0/1
$self->_error_callbacks || []
$self->_error_callbacks
Truth table50%1/2
A
A= $self->_error_callbacks
Aresult
11
00
2162 2 ▶ if( scalar( @$err_callbacks ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$err_callbacks) 0 2 2
2163 {
2164 0 ▶ local $SIG{__WARN__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
2165 0 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
2166 0 local $@;
2167 0 foreach my $ref ( @$err_callbacks )
2168 {
2169 0 ▶ $self->__message( 112, "Executing error callback '", ( $ref->{name} // 'undef' ), "'" );
Condition0%0/2
$ref->{"name"} // "undef"
l!l
00
MC/DC0%0/1
$ref->{"name"} // "undef"
$ref->{"name"}
Truth table0%0/2
A
A= $ref->{"name"}
Aresult
11
00
2170 0 my $code = $ref->{cb};
2171 0 ▶ if( !defined( $code ) || ref( $code ) ne 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $code or ref $code ne "CODE") 0 0 0
Condition0%0/3
not defined $code or ref $code ne "CODE"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $code or ref $code ne "CODE"
not defined $code ref $code ne "CODE"
Truth table0%0/3
not(A) or B
A= not defined $codeB= ref $code ne "CODE"
ABresult
1X1
011
000
2172 {
2173 0 next;
2174 }
2175 0 eval{ $code->( $self, $this->{error} ) };
2176 }
2177 }
2178  
2179 0 ▶ if( $this->{fatal} || ( defined( ${"${class}\::FATAL_ERROR"} ) && ${"${class}\::FATAL_ERROR"} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"fatal"} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}) 0 2 2
Condition33%2/6
$this->{"fatal"} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
l!l&&r!l&&!r
002
defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
!ll&&!rl&&r
200
MC/DC0%0/3
$this->{"fatal"} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
$this->{"fatal"} defined ${"${class}::FATAL_ERROR";} ${"${class}::FATAL_ERROR";}
Truth table25%1/4
A or B and C
A= $this->{"fatal"}B= defined ${"${class}::FATAL_ERROR";}C= ${"${class}::FATAL_ERROR";}
ABCresult
1XX1
0111
00X0
0100
2180 {
2181 0 die( $this->{error} );
2182 }
2183 }
2184 # If the error provided is not an object, we call error to create one
2185 else
2186 {
2187 0 $self->__message( 106, "Creating an object from the arguments provided." );
2188 0 return( $self->error( @_ ) );
2189 }
2190  
2191 8 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want("OBJECT")) 0 8 8
2192 {
2193 0 $self->__message( 106, "We are in object context, returning a Module::Generic::Null object." );
2194 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or die "Unable to load Module::Generic::Null" 0 0 0
2195 die( "Unable to load Module::Generic::Null" );
2196 0 my $null = Module::Generic::Null->new( $err, { debug => $this->{debug}, has_error => 1 });
2197 0 rreturn( $null );
2198 }
2199 8 $self->__message( 106, "Simply returning undef or an empty list with to caller ", [caller]->[0], " from line ", [caller]->[2] );
2200 8 return;
2201 }
2202  
2203 0 ▶sub quiet { return( shift->_set_get( 'quiet', @_ ) ); }
Subroutine quiet: not called CC=1 SCAR=6.9
Pod documented
2204  
2205 sub serialise
2206 1 ▶{
Subroutine serialise: called CC=141 SCAR=96.2
Pod documented
2207 1 my $self = shift( @_ );
2208 1 my $data = shift( @_ );
2209 1 ▶ return( $self->error( "No data to serialise was provided." ) ) if( !defined( $data ) || !length( $data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data and length $data 0 1 1
Condition33%1/3
defined $data and length $data
!ll&&!rl&&r
001
MC/DC0%0/2
defined $data and length $data
defined $data length $data
Truth table33%1/3
A and B
A= defined $dataB= length $data
ABresult
0X0
100
111
2210 1 my $opts = $self->_get_args_as_hash( @_ );
2211 1 ▶ my $class = $opts->{serialiser} || $opts->{serializer} || $SERIALISER;
Condition33%2/6
$opts->{'serialiser'} || $opts->{'serializer'} || $SERIALISER
l!l&&r!l&&!r
100
$opts->{"serialiser"} or $opts->{"serializer"}
l!l&&r!l&&!r
100
MC/DC0%0/3
$opts->{'serialiser'} || $opts->{'serializer'} || $SERIALISER
$opts->{"serialiser"} $opts->{"serializer"} $SERIALISER
Truth table25%1/4
A or B || C
A= $opts->{"serialiser"}B= $opts->{"serializer"}C= $SERIALISER
ABCresult
1XX1
01X1
0011
0000
2212 1 ▶ return( $self->error( "No serialiser class was provided nor set in \$Module::Generic::SERIALISER" ) ) if( !defined( $class ) || !length( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $class and length $class 0 1 1
Condition33%1/3
defined $class and length $class
!ll&&!rl&&r
001
MC/DC0%0/2
defined $class and length $class
defined $class length $class
Truth table33%1/3
A and B
A= defined $classB= length $class
ABresult
0X0
100
111
2213 1 ▶ $opts->{base64} //= '';
Condition50%1/2
$opts->{"base64"} //= ""
l!l
01
MC/DC0%0/1
$opts->{"base64"} //= ""
$opts->{"base64"}
Truth table50%1/2
A
A= $opts->{"base64"}
Aresult
11
00
2214 1 $self->__message( 104, "Serialising data using serialiser $class" );
2215  
2216 1 ▶ if( $class eq 'CBOR' || $class eq 'CBOR::XS' )
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq 'CBOR' or $class eq 'CBOR::XS') { } 0 1 1
Condition33%1/3
$class eq "CBOR" or $class eq "CBOR::XS"
l!l&&r!l&&!r
001
MC/DC0%0/2
$class eq "CBOR" or $class eq "CBOR::XS"
$class eq "CBOR" $class eq "CBOR::XS"
Truth table33%1/3
A or B
A= $class eq "CBOR"B= $class eq "CBOR::XS"
ABresult
1X1
011
000
2217 {
2218 0 ▶ $self->_load_class( 'CBOR::XS' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("CBOR::XS") or return $self->pass_error 0 0 0
2219 }
2220 else
2221 {
2222 1 ▶ $self->_load_class( $class ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($class) or return $self->pass_error 1 0 1
2223 1 ▶ if( $class eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "Sereal") 0 1 1
2224 {
2225 0 ▶ $self->_load_class( 'Sereal::Encoder' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Sereal::Encoder") or return $self->pass_error 0 0 0
2226 }
2227 }
2228  
2229 # This should be an array with two entries: encoder and decoder handler code reference
2230 1 my $base64;
2231 1 ▶ if( defined( $opts->{base64} ) && $opts->{base64} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"base64"} and $opts->{"base64"}) 0 1 1
Condition33%1/3
defined $opts->{"base64"} and $opts->{"base64"}
!ll&&!rl&&r
010
MC/DC0%0/2
defined $opts->{"base64"} and $opts->{"base64"}
defined $opts->{"base64"} $opts->{"base64"}
Truth table33%1/3
A and B
A= defined $opts->{"base64"}B= $opts->{"base64"}
ABresult
0X0
100
111
2232 {
2233 0 $self->__message( 104, "Base64 is required." );
2234 0 $base64 = $self->_has_base64( $opts->{base64} );
2235 0 ▶ return( $self->error( "base64 option '$opts->{base64}' has been provided for deserialising, but could not get handlers." ) ) if( !$base64 );
Branch: 1 branch
BranchTrueFalseTotal
unless $base64 0 0 0
2236 0 ▶ if( ref( $base64 ) ne 'ARRAY' ||
Branch: 1 branch
BranchTrueFalseTotal
if (ref $base64 ne "ARRAY" or scalar @$base64 < 2 or not defined $base64->[0] or not defined $base64->[1] or ref $base64->[0] ne "CODE" or ref $base64->[1] ne "CODE") 0 0 0
Condition0%0/15
ref $base64 ne "ARRAY" or scalar @$base64 < 2 or not defined $base64->[0] or not defined $base64->[1] or ref $base64->[0] ne "CODE" or ref $base64->[1] ne "CODE"
l!l&&r!l&&!r
000
ref $base64 ne "ARRAY" or scalar @$base64 < 2 or not defined $base64->[0] or not defined $base64->[1] or ref $base64->[0] ne "CODE"
l!l&&r!l&&!r
000
ref $base64 ne "ARRAY" or scalar @$base64 < 2 or not defined $base64->[0] or not defined $base64->[1]
l!l&&r!l&&!r
000
ref $base64 ne "ARRAY" or scalar @$base64 < 2 or not defined $base64->[0]
l!l&&r!l&&!r
000
ref $base64 ne "ARRAY" or scalar @$base64 < 2
l!l&&r!l&&!r
000
MC/DC0%0/6
ref $base64 ne "ARRAY" or scalar @$base64 < 2 or not defined $base64->[0] or not defined $base64->[1] or ref $base64->[0] ne "CODE" or ref $base64->[1] ne "CODE"
ref $base64 ne "ARRAY" scalar @$base64 < 2 not defined $base64->[0] not defined $base64->[1] ref $base64->[0] ne "CODE" ref $base64->[1] ne "CODE"
Truth table0%0/7
A or B or not(C) or not(D) or E or F
A= ref $base64 ne "ARRAY"B= scalar @$base64 < 2C= not defined $base64->[0]D= not defined $base64->[1]E= ref $base64->[0] ne "CODE"F= ref $base64->[1] ne "CODE"
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
2237 scalar( @$base64 ) < 2 ||
2238 !defined( $base64->[0] ) ||
2239 !defined( $base64->[1] ) ||
2240 ref( $base64->[0] ) ne 'CODE' ||
2241 ref( $base64->[1] ) ne 'CODE' )
2242 {
2243 0 return( $self->error( "Value returned by _has_base64 is not an array reference containing two code references." ) );
2244 }
2245 }
2246  
2247 # NOTE: serialise with CBOR or CBOR::XS
2248 1 ▶ if( $class eq 'CBOR' || $class eq 'CBOR::XS' )
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "CBOR" or $class eq "CBOR::XS") 0 1 1
Condition33%1/3
$class eq "CBOR" or $class eq "CBOR::XS"
l!l&&r!l&&!r
001
MC/DC0%0/2
$class eq "CBOR" or $class eq "CBOR::XS"
$class eq "CBOR" $class eq "CBOR::XS"
Truth table33%1/3
A or B
A= $class eq "CBOR"B= $class eq "CBOR::XS"
ABresult
1X1
011
000
2249 {
2250 0 my @options = qw(
2251 max_depth max_size allow_unknown allow_sharing allow_cycles forbid_objects
2252 pack_strings text_keys text_strings validate_utf8 filter
2253 );
2254 0 my $cbor = CBOR::XS->new;
2255 0 for( @options )
2256 {
2257 0 ▶ next unless( CORE::exists( $opts->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{$_} 0 0 0
2258 0 ▶ if( my $code = $cbor->can( $_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $cbor->can($_)) 0 0 0
2259 {
2260 0 $code->( $cbor, $opts->{ $_ } );
2261 }
2262 }
2263  
2264 # try-catch
2265 0 local $@;
2266 my $serialised = eval
2267 0 {
2268 0 $cbor->encode( $data );
2269 };
2270 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2271 {
2272 0 $self->__message( 104, "Error serialising data using $class: $@" );
2273 0 return( $self->error( "Error trying to serialise data with $class: $@" ) );
2274 }
2275  
2276 0 $self->__message( 104, CORE::length( $serialised ), " bytes of serialised data was produced by $class" );
2277 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) 0 0 0
2278 {
2279 0 $serialised = $base64->[0]->( $serialised );
2280 0 $self->__message( 104, "Serialised data is in base64 and is now ", CORE::length( $serialised ), " bytes." );
2281 }
2282  
2283 0 ▶ if( exists( $opts->{file} ) && $opts->{file} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"file"} and $opts->{"file"}) 0 0 0
Condition0%0/3
exists $opts->{"file"} and $opts->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"file"} and $opts->{"file"}
exists $opts->{"file"} $opts->{"file"}
Truth table0%0/3
A and B
A= exists $opts->{"file"}B= $opts->{"file"}
ABresult
0X0
100
111
2284 {
2285 0 $self->__message( 104, "A file was provided to unload serialised data -> '$opts->{file}'" );
2286 0 ▶ my $f = $self->new_file( $opts->{file} ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($opts->{'file'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($opts->{'file'}) || (return $self->pass_error)
$self->new_file($opts->{'file'})
Truth table0%0/2
A
A= $self->new_file($opts->{'file'})
Aresult
11
00
2287 0 my $cache_dir = $f->parent;
2288 0 ▶ my $tmp = $self->new_tempfile(
Branch: 1 branch
BranchTrueFalseTotal
$cache_dir->can_write ? : 0 0 0
Condition0%0/2
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin') || (return $self->pass_error($f->error))
l!l
00
MC/DC0%0/1
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin') || (return $self->pass_error($f->error))
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin')
Truth table0%0/2
A
A= $self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin')
Aresult
11
00
2289 ( $cache_dir->can_write ? ( dir => $cache_dir ) : () ),
2290 suffix => 'bin',
2291 ) || return( $self->pass_error( $f->error ) );
2292 # Need to open the file to lock it.
2293 0 ▶ $f->open( '>', { binmode => ':raw' } ) || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$f->open(">", {"binmode", ":raw"}) or return $self->pass_error($f->error) 0 0 0
2294 0 ▶ $f->lock( exclusive => 1 ) || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$f->lock("exclusive", 1) or return $self->pass_error($f->error) 0 0 0
2295 0 ▶ if( !$tmp->unload( $serialised, { binmode => 'raw' } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp->unload($serialised, {"binmode", "raw"})) 0 0 0
2296 {
2297 0 $f->unlock;
2298 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2299 0 return( $self->pass_error( $f->error ) );
2300 }
2301 0 ▶ if( !$tmp->rename( $f, overwrite => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp->rename($f, "overwrite", 1)) 0 0 0
2302 {
2303 0 $f->unlock;
2304 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2305 0 return( $self->error( "Could not replace cache file '$f' with '$tmp': ", $tmp->error ) );
2306 }
2307 0 $f->unlock;
2308 }
2309 0 return( $serialised );
2310 }
2311 # NOTE: serialise with CBOR::Free
2312 1 ▶ if( $class eq 'CBOR::Free' )
Branch: 4 branches
BranchTrueFalseTotal
if ($class eq 'CBOR::Free') { } 0 1 1
elsif ($class eq 'JSON') { } 0 1 1
elsif ($class eq 'Sereal') { } 0 1 1
elsif ($class eq 'Storable::Improved' or $class eq 'Storable') { } 1 0 1
2313 {
2314 0 my @options = qw(
2315 canonical string_encode_mode preserve_references scalar_references
2316 );
2317 0 my $params = {};
2318 0 for( @options )
2319 {
2320 0 ▶ next unless( CORE::exists( $opts->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{$_} 0 0 0
2321 0 $params->{ $_ } = $opts->{ $_ };
2322 }
2323  
2324 # try-catch
2325 0 local $@;
2326 my $serialised = eval
2327 0 {
2328 0 ▶ CBOR::Free::encode( $data, ( scalar( keys( %$params ) ) ? %$params : () ) );
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %$params ? : 0 0 0
2329 };
2330 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2331 {
2332 0 $self->__message( 104, "Error serialising data using $class: $@" );
2333 0 return( $self->error( "Error trying to serialise data with $class: $@" ) );
2334 }
2335  
2336 0 $self->__message( 104, CORE::length( $serialised ), " bytes of serialised data was produced by $class" );
2337 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) 0 0 0
2338 {
2339 0 $serialised = $base64->[0]->( $serialised );
2340 0 $self->__message( 104, "Serialised data is in base64 and is now ", CORE::length( $serialised ), " bytes." );
2341 }
2342  
2343 0 ▶ if( exists( $opts->{file} ) && $opts->{file} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"file"} and $opts->{"file"}) 0 0 0
Condition0%0/3
exists $opts->{"file"} and $opts->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"file"} and $opts->{"file"}
exists $opts->{"file"} $opts->{"file"}
Truth table0%0/3
A and B
A= exists $opts->{"file"}B= $opts->{"file"}
ABresult
0X0
100
111
2344 {
2345 0 $self->__message( 104, "A file was provided to unload serialised data -> '$opts->{file}'" );
2346 0 ▶ my $f = $self->new_file( $opts->{file} ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($opts->{'file'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($opts->{'file'}) || (return $self->pass_error)
$self->new_file($opts->{'file'})
Truth table0%0/2
A
A= $self->new_file($opts->{'file'})
Aresult
11
00
2347 0 my $cache_dir = $f->parent;
2348 # $f->unload( $serialised, { binmode => 'raw' } ) || return( $self->pass_error( $f->error ) );
2349 0 ▶ my $tmp = $self->new_tempfile(
Branch: 1 branch
BranchTrueFalseTotal
$cache_dir->can_write ? : 0 0 0
Condition0%0/2
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin') || (return $self->pass_error($f->error))
l!l
00
MC/DC0%0/1
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin') || (return $self->pass_error($f->error))
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin')
Truth table0%0/2
A
A= $self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin')
Aresult
11
00
2350 ( $cache_dir->can_write ? ( dir => $cache_dir ) : () ),
2351 suffix => 'bin',
2352 ) || return( $self->pass_error( $f->error ) );
2353 # Need to open the file to lock it.
2354 0 ▶ $f->open( '>', { binmode => ':raw' } ) || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$f->open(">", {"binmode", ":raw"}) or return $self->pass_error($f->error) 0 0 0
2355 0 ▶ $f->lock( exclusive => 1 ) || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$f->lock("exclusive", 1) or return $self->pass_error($f->error) 0 0 0
2356 0 ▶ if( !$tmp->unload( $serialised, { binmode => 'raw' } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp->unload($serialised, {"binmode", "raw"})) 0 0 0
2357 {
2358 0 $f->unlock;
2359 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2360 0 return( $self->pass_error( $f->error ) );
2361 }
2362 0 ▶ if( !$tmp->rename( $f, overwrite => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp->rename($f, "overwrite", 1)) 0 0 0
2363 {
2364 0 $f->unlock;
2365 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2366 0 return( $self->error( "Could not replace cache file '$f' with '$tmp': ", $tmp->error ) );
2367 }
2368 0 $f->unlock;
2369 }
2370 0 return( $serialised );
2371 }
2372 # NOTE: serialise with JSON
2373 elsif( $class eq 'JSON' )
2374 {
2375 0 my @options = qw(
2376 allow_blessed allow_nonref allow_unknown allow_tags ascii boolean_values
2377 canonical convert_blessed filter_json_object filter_json_single_key_object
2378 indent latin1 max_depth max_size pretty relaxed space_after space_before utf8
2379 );
2380 0 my $json = JSON->new;
2381 0 for( @options )
2382 {
2383 0 ▶ next unless( CORE::exists( $opts->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{$_} 0 0 0
2384 0 ▶ if( my $code = $json->can( $_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $json->can($_)) 0 0 0
2385 {
2386 0 $code->( $json, $opts->{ $_ } );
2387 }
2388 }
2389  
2390 # try-catch
2391 0 local $@;
2392 my $serialised = eval
2393 0 {
2394 0 $json->encode( $data );
2395 };
2396 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2397 {
2398 0 $self->__message( 104, "Error serialising data using $class: $@" );
2399 0 return( $self->error( "Error trying to serialise data with $class: $@" ) );
2400 }
2401  
2402 0 $self->__message( 104, CORE::length( $serialised ), " bytes of serialised data was produced by $class" );
2403 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) 0 0 0
2404 {
2405 0 $serialised = $base64->[0]->( $serialised );
2406 0 $self->__message( 104, "Serialised data is in base64 and is now ", CORE::length( $serialised ), " bytes." );
2407 }
2408  
2409 0 ▶ if( exists( $opts->{file} ) && $opts->{file} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"file"} and $opts->{"file"}) 0 0 0
Condition0%0/3
exists $opts->{"file"} and $opts->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"file"} and $opts->{"file"}
exists $opts->{"file"} $opts->{"file"}
Truth table0%0/3
A and B
A= exists $opts->{"file"}B= $opts->{"file"}
ABresult
0X0
100
111
2410 {
2411 0 $self->__message( 104, "A file was provided to unload serialised data -> '$opts->{file}'" );
2412 0 ▶ my $f = $self->new_file( $opts->{file} ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($opts->{'file'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($opts->{'file'}) || (return $self->pass_error)
$self->new_file($opts->{'file'})
Truth table0%0/2
A
A= $self->new_file($opts->{'file'})
Aresult
11
00
2413 0 my $cache_dir = $f->parent;
2414 # $f->unload( $serialised, { binmode => 'raw' } ) || return( $self->pass_error( $f->error ) );
2415 0 ▶ my $tmp = $self->new_tempfile(
Branch: 1 branch
BranchTrueFalseTotal
$cache_dir->can_write ? : 0 0 0
Condition0%0/2
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin') || (return $self->pass_error($f->error))
l!l
00
MC/DC0%0/1
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin') || (return $self->pass_error($f->error))
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin')
Truth table0%0/2
A
A= $self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin')
Aresult
11
00
2416 ( $cache_dir->can_write ? ( dir => $cache_dir ) : () ),
2417 suffix => 'bin',
2418 ) || return( $self->pass_error( $f->error ) );
2419 # Need to open the file to lock it.
2420 0 ▶ $f->open( '>', { binmode => ':raw' } ) || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$f->open(">", {"binmode", ":raw"}) or return $self->pass_error($f->error) 0 0 0
2421 0 ▶ $f->lock( exclusive => 1 ) || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$f->lock("exclusive", 1) or return $self->pass_error($f->error) 0 0 0
2422 0 ▶ if( !$tmp->unload( $serialised, { binmode => 'raw' } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp->unload($serialised, {"binmode", "raw"})) 0 0 0
2423 {
2424 0 $f->unlock;
2425 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2426 0 return( $self->pass_error( $f->error ) );
2427 }
2428 0 ▶ if( !$tmp->rename( $f, overwrite => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp->rename($f, "overwrite", 1)) 0 0 0
2429 {
2430 0 $f->unlock;
2431 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2432 0 return( $self->error( "Could not replace cache file '$f' with '$tmp': ", $tmp->error ) );
2433 }
2434 0 $f->unlock;
2435 }
2436 0 return( $serialised );
2437 }
2438 # NOTE: serialise with Sereal
2439 elsif( $class eq 'Sereal' )
2440 {
2441 0 my @options = qw( compress compress_threshold compress_level snappy snappy_incr snappy_threshold croak_on_bless freeze_callbacks no_bless_objects undef_unknown stringify_unknown warn_unknown max_recursion_depth canonical canonical_refs sort_keys no_shared_hashkeys dedupe_strings aliased_dedupe_strings protocol_version use_protocol_v1 );
2442 0 my $ref = {};
2443 0 for( @options )
2444 {
2445 0 ▶ $ref->{ $_ } = $opts->{ $_ } if( exists( $opts->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{$_} 0 0 0
2446 }
2447  
2448 0 my $enc = Sereal::Encoder->new( $ref );
2449 0 ▶ if( exists( $opts->{file} ) && $opts->{file} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'file'} and $opts->{'file'}) { } 0 0 0
Condition0%0/3
exists $opts->{"file"} and $opts->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"file"} and $opts->{"file"}
exists $opts->{"file"} $opts->{"file"}
Truth table0%0/3
A and B
A= exists $opts->{"file"}B= $opts->{"file"}
ABresult
0X0
100
111
2450 {
2451 0 $self->__message( 104, "A file was provided to unload serialised data -> '$opts->{file}'" );
2452 0 ▶ my $f = $self->new_file( $opts->{file} ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($opts->{'file'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($opts->{'file'}) || (return $self->pass_error)
$self->new_file($opts->{'file'})
Truth table0%0/2
A
A= $self->new_file($opts->{'file'})
Aresult
11
00
2453 0 my $cache_dir = $f->parent;
2454 0 ▶ my $tmp = $self->new_tempfile(
Branch: 1 branch
BranchTrueFalseTotal
$cache_dir->can_write ? : 0 0 0
Condition0%0/2
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin') || (return $self->pass_error($f->error))
l!l
00
MC/DC0%0/1
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin') || (return $self->pass_error($f->error))
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin')
Truth table0%0/2
A
A= $self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin')
Aresult
11
00
2455 ( $cache_dir->can_write ? ( dir => $cache_dir ) : () ),
2456 suffix => 'bin',
2457 ) || return( $self->pass_error( $f->error ) );
2458 # Need to open the file to lock it.
2459 0 ▶ $f->open( '>', { binmode => ':raw' } ) || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$f->open(">", {"binmode", ":raw"}) or return $self->pass_error($f->error) 0 0 0
2460 0 ▶ $f->lock( exclusive => 1 ) || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$f->lock("exclusive", 1) or return $self->pass_error($f->error) 0 0 0
2461 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) { } 0 0 0
2462 {
2463 0 my $serialised = $enc->encode( $data );
2464 0 $self->__message( 104, CORE::length( $serialised ), " bytes of serialised data was produced by $class" );
2465 0 $serialised = $base64->[0]->( $serialised );
2466 0 $self->__message( 104, "Serialised data is in base64 and is now ", CORE::length( $serialised ), " bytes." );
2467 # $f->unload( $serialised, { binmode => 'raw' } ) || return( $self->pass_error( $f->error ) );
2468 0 ▶ if( !$tmp->unload( $serialised, { binmode => 'raw' } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp->unload($serialised, {"binmode", "raw"})) 0 0 0
2469 {
2470 0 $f->unlock;
2471 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2472 0 return( $self->pass_error( $f->error ) );
2473 }
2474 0 ▶ if( !$tmp->rename( $f, overwrite => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp->rename($f, "overwrite", 1)) 0 0 0
2475 {
2476 0 $f->unlock;
2477 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2478 0 return( $self->error( "Could not replace cache file '$f' with '$tmp': ", $tmp->error ) );
2479 }
2480 0 $f->unlock;
2481 0 return( $serialised );
2482 }
2483 else
2484 {
2485 # try-catch
2486 0 local $@;
2487 my $rv = eval
2488 0 {
2489 0 ▶ $enc->encode_to_file( "$tmp", $data, ( exists( $opts->{append} ) ? $opts->{append} : 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'append'} ? : 0 0 0
2490 };
2491 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2492 {
2493 0 $f->unlock;
2494 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2495 0 $self->__message( 104, "Error serialising data using $class: $@" );
2496 0 return( $self->error( "Error trying to serialise data with $class: $@" ) );
2497 }
2498 0 $self->__message( 104, CORE::length( $rv ), " bytes of serialised data was produced by $class" );
2499 0 ▶ if( !$tmp->rename( $f, overwrite => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp->rename($f, "overwrite", 1)) 0 0 0
2500 {
2501 0 $f->unlock;
2502 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2503 0 return( $self->error( "Could not replace cache file '$f' with '$tmp': ", $tmp->error ) );
2504 }
2505 0 $f->unlock;
2506 0 return( $rv );
2507 }
2508 }
2509 else
2510 {
2511 # try-catch
2512 0 local $@;
2513 my $serialised = eval
2514 0 {
2515 0 $enc->encode( $data );
2516 };
2517 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2518 {
2519 0 $self->__message( 104, "Error serialising data using $class: $@" );
2520 0 return( $self->error( "Error trying to serialise data with $class: $@" ) );
2521 }
2522  
2523 0 $self->__message( 104, CORE::length( $serialised ), " bytes of serialised data was produced by $class" );
2524 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) 0 0 0
2525 {
2526 0 $self->__message( 104, "Serialised data to base64." );
2527 0 return( $base64->[0]->( $serialised ) );
2528 }
2529 0 return( $serialised );
2530 }
2531 }
2532 # NOTE: serialise with Storable::Improved or Storable
2533 ▶ elsif( $class eq 'Storable::Improved' || $class eq 'Storable' )
Condition33%1/3
$class eq "Storable::Improved" or $class eq "Storable"
l!l&&r!l&&!r
100
MC/DC0%0/2
$class eq "Storable::Improved" or $class eq "Storable"
$class eq "Storable::Improved" $class eq "Storable"
Truth table33%1/3
A or B
A= $class eq "Storable::Improved"B= $class eq "Storable"
ABresult
1X1
011
000
2534 {
2535 1 ▶ if( exists( $opts->{file} ) && $opts->{file} )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opts->{'file'} and $opts->{'file'}) { } 0 1 1
elsif (exists $opts->{'io'}) { } 0 1 1
Condition33%1/3
exists $opts->{"file"} and $opts->{"file"}
!ll&&!rl&&r
100
MC/DC0%0/2
exists $opts->{"file"} and $opts->{"file"}
exists $opts->{"file"} $opts->{"file"}
Truth table33%1/3
A and B
A= exists $opts->{"file"}B= $opts->{"file"}
ABresult
0X0
100
111
2536 {
2537 0 $self->__message( 104, "A file was provided to unload serialised data -> '$opts->{file}'" );
2538 0 ▶ if( defined( $base64 ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $base64) { } 0 0 0
elsif ($opts->{'lock'}) { } 0 0 0
2539 {
2540 0 my $serialised;
2541 0 ▶ if( defined( my $code = $class->can( 'freeze' ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $code = $class->can('freeze'))) { } 0 0 0
2542 {
2543 0 $serialised = $code->( $data );
2544 }
2545 else
2546 {
2547 0 return( $self->error( "The class $class does not support the method 'freeze'." ) );
2548 }
2549 0 $serialised = $base64->[0]->( $serialised );
2550 0 $self->__message( 104, "Serialised data is in base64 and is now ", CORE::length( $serialised ), " bytes." );
2551 0 ▶ my $f = $self->new_file( $opts->{file} ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($opts->{'file'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($opts->{'file'}) || (return $self->pass_error)
$self->new_file($opts->{'file'})
Truth table0%0/2
A
A= $self->new_file($opts->{'file'})
Aresult
11
00
2552 # $f->unload( $serialised, { binmode => 'raw' } ) || return( $self->pass_error( $f->error ) );
2553 0 my $cache_dir = $f->parent;
2554 0 ▶ my $tmp = $self->new_tempfile(
Branch: 1 branch
BranchTrueFalseTotal
$cache_dir->can_write ? : 0 0 0
Condition0%0/2
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin') || (return $self->pass_error($f->error))
l!l
00
MC/DC0%0/1
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin') || (return $self->pass_error($f->error))
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin')
Truth table0%0/2
A
A= $self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin')
Aresult
11
00
2555 ( $cache_dir->can_write ? ( dir => $cache_dir ) : () ),
2556 suffix => 'bin',
2557 ) || return( $self->pass_error( $f->error ) );
2558 # Need to open the file to lock it.
2559 0 ▶ $f->open( '>', { binmode => ':raw' } ) || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$f->open(">", {"binmode", ":raw"}) or return $self->pass_error($f->error) 0 0 0
2560 0 ▶ $f->lock( exclusive => 1 ) || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$f->lock("exclusive", 1) or return $self->pass_error($f->error) 0 0 0
2561 0 ▶ if( !$tmp->unload( $serialised, { binmode => 'raw' } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp->unload($serialised, {"binmode", "raw"})) 0 0 0
2562 {
2563 0 $f->unlock;
2564 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2565 0 return( $self->pass_error( $f->error ) );
2566 }
2567 0 ▶ if( !$tmp->rename( $f, overwrite => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp->rename($f, "overwrite", 1)) 0 0 0
2568 {
2569 0 $f->unlock;
2570 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2571 0 return( $self->error( "Could not replace cache file '$f' with '$tmp': ", $tmp->error ) );
2572 }
2573 0 $f->unlock;
2574 0 return( $serialised );
2575 }
2576 elsif( $opts->{lock} )
2577 {
2578 0 ▶ my $f = $self->new_file( $opts->{file} ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($opts->{'file'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($opts->{'file'}) || (return $self->pass_error)
$self->new_file($opts->{'file'})
Truth table0%0/2
A
A= $self->new_file($opts->{'file'})
Aresult
11
00
2579 0 my $cache_dir = $f->parent;
2580 0 ▶ my $tmp = $self->new_tempfile(
Branch: 1 branch
BranchTrueFalseTotal
$cache_dir->can_write ? : 0 0 0
Condition0%0/2
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin') || (return $self->pass_error($f->error))
l!l
00
MC/DC0%0/1
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin') || (return $self->pass_error($f->error))
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin')
Truth table0%0/2
A
A= $self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin')
Aresult
11
00
2581 ( $cache_dir->can_write ? ( dir => $cache_dir ) : () ),
2582 suffix => 'bin',
2583 ) || return( $self->pass_error( $f->error ) );
2584 # try-catch
2585 0 local $@;
2586 my $rv = eval
2587 0 {
2588 0 my $code = $class->can( 'lock_store' );
2589 0 ▶ if( !defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 0 0
2590 {
2591 0 die( "The class $class does not support the method 'lock_store'." );
2592 }
2593 0 return( $code->( $data => "$tmp" ) );
2594 };
2595 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2596 {
2597 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2598 0 $self->__message( 104, "Error serialising data using $class: $@" );
2599 0 return( $self->error( "Error trying to serialise data with $class: $@" ) );
2600 }
2601 0 ▶ if( !$tmp->rename( $f, overwrite => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp->rename($f, "overwrite", 1)) 0 0 0
2602 {
2603 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2604 0 return( $self->error( "Could not replace cache file '$f' with '$tmp': ", $tmp->error ) );
2605 }
2606 0 return( $rv );
2607 }
2608 else
2609 {
2610 0 ▶ my $f = $self->new_file( $opts->{file} ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($opts->{'file'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($opts->{'file'}) || (return $self->pass_error)
$self->new_file($opts->{'file'})
Truth table0%0/2
A
A= $self->new_file($opts->{'file'})
Aresult
11
00
2611 0 my $cache_dir = $f->parent;
2612 0 ▶ my $tmp = $self->new_tempfile(
Branch: 1 branch
BranchTrueFalseTotal
$cache_dir->can_write ? : 0 0 0
Condition0%0/2
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin') || (return $self->pass_error($f->error))
l!l
00
MC/DC0%0/1
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin') || (return $self->pass_error($f->error))
$self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin')
Truth table0%0/2
A
A= $self->new_tempfile($cache_dir->can_write ? ('dir', $cache_dir) : (), 'suffix', 'bin')
Aresult
11
00
2613 ( $cache_dir->can_write ? ( dir => $cache_dir ) : () ),
2614 suffix => 'bin',
2615 ) || return( $self->pass_error( $f->error ) );
2616 # try-catch
2617 0 local $@;
2618 my $rv = eval
2619 0 {
2620 0 my $code = $class->can( 'store' );
2621 0 ▶ if( !defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 0 0
2622 {
2623 0 die( "The class $class does not support the method 'store'." );
2624 }
2625 0 return( $code->( $data => "$opts->{file}" ) );
2626 };
2627 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2628 {
2629 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2630 0 $self->__message( 104, "Error serialising data using $class: $@" );
2631 0 return( $self->error( "Error trying to serialise data with $class: $@" ) );
2632 }
2633 0 $self->__message( 104, CORE::length( $rv ), " bytes of serialised data was produced by $class" );
2634 0 ▶ if( !$tmp->rename( $f, overwrite => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp->rename($f, "overwrite", 1)) 0 0 0
2635 {
2636 0 ▶ $tmp->unlink if( $tmp->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->exists 0 0 0
2637 0 return( $self->error( "Could not replace cache file '$f' with '$tmp': ", $tmp->error ) );
2638 }
2639 0 return( $rv );
2640 }
2641 }
2642 elsif( exists( $opts->{io} ) )
2643 {
2644 0 $self->__message( 104, "Serialising using class $class and file handle '$opts->{io}'" );
2645 0 ▶ return( $self->error( "File handle provided ($opts->{io}) is not an actual file handle to serialise data to." ) ) if( ( Scalar::Util::reftype( $opts->{io} ) // '' ) ne 'GLOB' );
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($opts->{"io"}) // "") ne "GLOB" 0 0 0
Condition0%0/2
builtin::reftype($opts->{"io"}) // ""
l!l
00
MC/DC0%0/1
builtin::reftype($opts->{"io"}) // ""
builtin::reftype($opts->{"io"})
Truth table0%0/2
A
A= builtin::reftype($opts->{"io"})
Aresult
11
00
2646 0 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) { } 0 0 0
2647 {
2648 0 my $serialised;
2649 0 ▶ if( my $code = $class->can( 'freeze' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $class->can('freeze')) { } 0 0 0
2650 {
2651 0 $serialised = $code->( $data );
2652 }
2653 else
2654 {
2655 0 return( $self->error( "The class $class does not support the method 'freeze'." ) );
2656 }
2657 0 $self->__message( 104, CORE::length( $serialised ), " bytes of serialised data was produced by $class" );
2658 0 $serialised = $base64->[0]->( $serialised );
2659 0 $self->__message( 104, "Serialised data is in base64 and is now ", CORE::length( $serialised ), " bytes." );
2660  
2661 0 my $bytes = syswrite( $opts->{io}, $serialised );
2662 0 ▶ return( $self->error( "Unable to write ", CORE::length( $serialised ), " bytes of Storable serialised data to file handle '$opts->{io}': $!" ) ) if( !defined( $bytes ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 0 0
2663 0 ▶ $self->__message( 104, "Wrote ", ( $bytes // 'undef' ), " bytes of data to file handle $opts->{io}" );
Condition0%0/2
$bytes // "undef"
l!l
00
MC/DC0%0/1
$bytes // "undef"
$bytes
Truth table0%0/2
A
A= $bytes
Aresult
11
00
2664 0 return( $serialised );
2665 }
2666 else
2667 {
2668 # try-catch
2669 0 local $@;
2670 my $rv = eval
2671 0 {
2672 0 my $code = $class->can( 'store_fd' );
2673 0 ▶ if( !defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 0 0
2674 {
2675 0 die( "Class $class does not support the method 'store_fd'." );
2676 }
2677 0 $self->__message( 104, "Calling subroutine 'store_fd' to serialise data from file handle $opts->{io}" );
2678 0 return( $code->( $data => $opts->{io} ) );
2679 };
2680 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2681 {
2682 0 $self->__message( 104, "Error serialising data using $class: $@" );
2683 0 return( $self->error( "Error trying to serialise data with $class: $@" ) );
2684 }
2685 0 return( $rv );
2686 }
2687 }
2688 else
2689 {
2690 # try-catch
2691 1 local $@;
2692 my $serialised = eval
2693 1 {
2694 1 my $code = $class->can( 'freeze' );
2695 1 ▶ if( !defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 1 1
2696 {
2697 0 die( "Class $class has no method 'freeze' to serialise data." );
2698 }
2699 1 $self->__message( 104, "Calling subroutine 'freeze' to serialise ", CORE::length( $data ), " bytes of data." );
2700 1 return( $code->( $data ) );
2701 };
2702 1 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
2703 {
2704 0 $self->__message( 104, "Error serialising data using $class: $@" );
2705 0 return( $self->error( "Error trying to serialise data with $class: $@" ) );
2706 }
2707  
2708 1 ▶ if( defined( $base64 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base64) 0 1 1
2709 {
2710 0 $self->__message( 104, "Serialised data to base64." );
2711 0 return( $base64->[0]->( $serialised ) );
2712 }
2713 1 return( $serialised );
2714 }
2715 }
2716 else
2717 {
2718 0 return( $self->error( "Unsupporterd serialiser \"$class\"." ) );
2719 }
2720 }
2721  
2722 0 ▶sub serialize { return( shift->serialise( @_ ) ); }
Subroutine serialize: not called CC=1 SCAR=6.9
Pod documented
2723  
2724 sub set
2725 0 ▶{
Subroutine set: not called CC=3 SCAR=24.8
Pod documented
2726 0 my $self = shift( @_ );
2727 0 my %arg = ();
2728 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
2729 {
2730 0 %arg = ( @_ );
2731 0 my $this = $self->_obj2h;
2732 0 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 0 0
2733 0 my @keys = keys( %arg );
2734 0 @$data{ @keys } = @arg{ @keys };
2735 }
2736 0 return( scalar( keys( %arg ) ) );
2737 }
2738  
2739 9 ▶sub true { return( $Module::Generic::Boolean::true ); }
Subroutine true: called CC=1 SCAR=0.0
Pod documented
2740  
2741 10 ▶sub false { return( $Module::Generic::Boolean::false ); }
Subroutine false: called CC=1 SCAR=0.0
Pod documented
2742  
2743 sub verbose
2744 0 ▶{
Subroutine verbose: not called CC=2 SCAR=17.9
Pod documented
2745 0 my $self = shift( @_ );
2746 0 my $this = $self->_obj2h;
2747 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
2748 {
2749 0 my $flag = shift( @_ );
2750 0 $this->{verbose} = $flag;
2751 }
2752 0 return( $this->{verbose} );
2753 }
2754  
2755 sub will
2756 0 ▶{
Subroutine will: not called CC=21 SCAR=60.3
Pod documented
2757 0 ▶ ( @_ >= 2 && @_ <= 3 ) || die( 'Usage: $obj->can( "method" ) or Module::Generic::will( $obj, "method" )' );
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 and @_ <= 3 or die "Usage: \$obj->can( \"method\" ) or Module::Generic::will( \$obj, \"method\" )" 0 0 0
Condition0%0/3
@_ >= 2 and @_ <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
@_ >= 2 and @_ <= 3
@_ >= 2 @_ <= 3
Truth table0%0/3
A and B
A= @_ >= 2B= @_ <= 3
ABresult
0X0
100
111
2758 0 my( $obj, $meth, $level );
2759 0 ▶ if( @_ == 3 && ref( $_[ 1 ] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 3 and ref $_[1]) { } 0 0 0
Condition0%0/3
@_ == 3 and ref $_[1]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 3 and ref $_[1]
@_ == 3 ref $_[1]
Truth table0%0/3
A and B
A= @_ == 3B= ref $_[1]
ABresult
0X0
100
111
2760 {
2761 0 $obj = $_[ 1 ];
2762 0 $meth = $_[ 2 ];
2763 }
2764 else
2765 {
2766 0 ( $obj, $meth, $level ) = @_;
2767 }
2768 0 ▶ return if( !ref( $obj ) && index( $obj, '::' ) == -1 );
Branch: 1 branch
BranchTrueFalseTotal
if not ref $obj and index($obj, "::") == -1 0 0 0
Condition0%0/3
not ref $obj and index($obj, "::") == -1
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $obj and index($obj, "::") == -1
not ref $obj index($obj, "::") == -1
Truth table0%0/3
not(A) and B
A= not ref $objB= index($obj, "::") == -1
ABresult
0X0
100
111
2769 34 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
2770 # Give a chance to UNIVERSAL::can
2771 0 my $ref = undef;
2772 0 ▶ if( Scalar::Util::blessed( $obj ) && ( $ref = $obj->can( $meth ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($obj) and $ref = $obj->can($meth)) 0 0 0
Condition0%0/3
builtin::blessed($obj) and $ref = $obj->can($meth)
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($obj) and $ref = $obj->can($meth)
builtin::blessed($obj) $ref = $obj->can($meth)
Truth table0%0/3
A and B
A= builtin::blessed($obj)B= $ref = $obj->can($meth)
ABresult
0X0
100
111
2773 {
2774 0 return( $ref );
2775 }
2776 0 ▶ my $class = ref( $obj ) || $obj;
Condition0%0/3
ref $obj || $obj
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $obj || $obj
ref $obj $obj
Truth table0%0/3
A || B
A= ref $objB= $obj
ABresult
1X1
011
000
2777 0 my $origi = $class;
2778 0 ▶ if( index( $meth, '::' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($meth, "::") != -1) 0 0 0
2779 {
2780 0 $origi = substr( $meth, 0, rindex( $meth, '::' ) );
2781 0 $meth = substr( $meth, rindex( $meth, '::' ) + 2 );
2782 }
2783 0 ▶ $ref = \&{ "$class\::$meth" } if( defined( &{ "$class\::$meth" } ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"${class}::$meth";} 0 0 0
2784 0 ▶ return( $ref ) if( defined( $ref ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $ref 0 0 0
2785 # We do not go further down the rabbit hole if level is greater or equal to 10
2786 0 ▶ $level ||= 0;
Condition0%0/2
$level ||= 0
l!l
00
MC/DC0%0/1
$level ||= 0
$level
Truth table0%0/2
A
A= $level
Aresult
11
00
2787 0 ▶ return if( $level >= 10 );
Branch: 1 branch
BranchTrueFalseTotal
if $level >= 10 0 0 0
2788 0 $level++;
2789 # Let's see what Alice has got for us... :-)
2790 # We look in the @ISA to see if the method exists in the package from which we
2791 # possibly inherited
2792 0 ▶ if( @{ "$class\::ISA" } )
Branch: 1 branch
BranchTrueFalseTotal
if (@{"${class}::ISA";}) 0 0 0
2793 {
2794 0 foreach my $pack ( @{ "$class\::ISA" } )
2795 {
2796 0 my $ref = &will( $pack, "$origi\::$meth", $level );
2797 0 ▶ return( $ref ) if( defined( $ref ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $ref 0 0 0
2798 }
2799 }
2800 # Then, maybe there is an AUTOLOAD to trap undefined routine?
2801 # But, we do not want any loop, do we?
2802 # Since will() is called from Module::Generic::AUTOLOAD to check if EXTRA_AUTOLOAD exists
2803 # we are not going to call Module::Generic::AUTOLOAD for EXTRA_AUTOLOAD...
2804 0 ▶ if( $class ne 'Module::Generic' && $meth ne 'EXTRA_AUTOLOAD' && defined( &{ "$class\::AUTOLOAD" } ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($class ne "Module::Generic" and $meth ne "EXTRA_AUTOLOAD" and defined &{"${class}::AUTOLOAD";}) 0 0 0
Condition0%0/6
$class ne "Module::Generic" and $meth ne "EXTRA_AUTOLOAD" and defined &{"${class}::AUTOLOAD";}
!ll&&!rl&&r
000
$class ne "Module::Generic" and $meth ne "EXTRA_AUTOLOAD"
!ll&&!rl&&r
000
MC/DC0%0/3
$class ne "Module::Generic" and $meth ne "EXTRA_AUTOLOAD" and defined &{"${class}::AUTOLOAD";}
$class ne "Module::Generic" $meth ne "EXTRA_AUTOLOAD" defined &{"${class}::AUTOLOAD";}
Truth table0%0/4
A and B and C
A= $class ne "Module::Generic"B= $meth ne "EXTRA_AUTOLOAD"C= defined &{"${class}::AUTOLOAD";}
ABCresult
0XX0
10X0
1100
1111
2805 {
2806 my $sub = sub
2807 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2808 0 $class::AUTOLOAD = "$origi\::$meth";
2809 0 &{ "$class::AUTOLOAD" }( @_ );
2810 0 };
2811 0 return( $sub );
2812 }
2813 0 return;
2814 }
2815  
2816 sub __instantiate_object
2817 53 ▶{
Subroutine __instantiate_object: called CC=31 SCAR=49.1
2818 53 my $self = shift( @_ );
2819 53 my $field = shift( @_ );
2820 53 ▶ my $class = shift( @_ ) ||
Condition50%1/2
shift @_ || (return $self->error('No object class name was provided to instantiate a new object.'))
l!l
530
MC/DC0%0/1
shift @_ || (return $self->error('No object class name was provided to instantiate a new object.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
2821 return( $self->error( "No object class name was provided to instantiate a new object." ) );
2822 53 my $this = $self->_obj2h;
2823 53 my $o;
2824 my $callback;
2825 53 my $def = {};
2826 53 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 37 16 53
2827 {
2828 37 $def = $field;
2829 37 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 37 0 37
Condition33%2/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
0037
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
0037
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table25%1/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
2830 defined( $def->{field} ) &&
2831 CORE::length( $def->{field} ) )
2832 {
2833 37 $field = $def->{field};
2834 }
2835 else
2836 {
2837 0 $field = undef;
2838 }
2839 37 ▶ return( $self->error( "No property 'field' was provided in the parameters of _set_get_object" ) ) if( !length( $field // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($field // "") 0 37 37
Condition50%1/2
$field // ""
l!l
370
MC/DC0%0/1
$field // ""
$field
Truth table50%1/2
A
A= $field
Aresult
11
00
2840 37 ▶ if( CORE::exists( $def->{callback} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE") 0 37 37
Condition33%2/6
exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE"
!ll&&!rl&&r
3700
exists $def->{"callback"} and defined $def->{"callback"}
!ll&&!rl&&r
3700
MC/DC0%0/3
exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE"
exists $def->{"callback"} defined $def->{"callback"} ref $def->{"callback"} eq "CODE"
Truth table25%1/4
A and B and C
A= exists $def->{"callback"}B= defined $def->{"callback"}C= ref $def->{"callback"} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
2841 defined( $def->{callback} ) &&
2842 ref( $def->{callback} ) eq 'CODE' )
2843 {
2844 0 $callback = $def->{callback};
2845 }
2846 }
2847  
2848 53 ▶ if( ref( $class ) && $self->_can_overload( $class => '""' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class and $self->_can_overload($class, "\"\"")) 0 53 53
Condition33%1/3
ref $class and $self->_can_overload($class, "\"\"")
!ll&&!rl&&r
5300
MC/DC0%0/2
ref $class and $self->_can_overload($class, "\"\"")
ref $class $self->_can_overload($class, "\"\"")
Truth table33%1/3
A and B
A= ref $classB= $self->_can_overload($class, "\"\"")
ABresult
0X0
100
111
2849 {
2850 0 $class = "$class";
2851 }
2852  
2853 # If the $class value is not a string or a stringifyable value, AND there is no callback to handle it, then we return an error
2854 53 ▶ if( ref( $class ) && !defined( $callback ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class and not defined $callback) 0 53 53
Condition33%1/3
ref $class and not defined $callback
!ll&&!rl&&r
5300
MC/DC0%0/2
ref $class and not defined $callback
ref $class not defined $callback
Truth table33%1/3
A and not(B)
A= ref $classB= not defined $callback
ABresult
0X0
100
111
2855 {
2856 0 return( $self->error( "The class name used to instantiate a new object must be a string, but you provided '", $self->_str_val( $class ), "'." ) );
2857 }
2858  
2859 # try-catch
2860 53 local $@;
2861 eval
2862 53 {
2863 # https://stackoverflow.com/questions/32608504/how-to-check-if-perl-module-is-available#comment53081298_32608860
2864 # require $class unless( defined( *{"${class}::"} ) );
2865 # Either it passes and returns the class loaded or it raises an error trapped in catch
2866 # 2025-06-29: $class can be an array of classes passed down from _set_get_object_without_init or _set_get_object_array_object
2867 53 ▶ if( $self->_is_array( $class ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($class)) { } 0 53 53
2868 {
2869 0 ▶ for( my $i = 0; $i < scalar( @$class ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$class) 0 0 0
2870 {
2871 0 ▶ $self->__message( 107, "Loading class '", ( $class->[0] // 'undef' ), "'." );
Condition0%0/2
$class->[0] // "undef"
l!l
00
MC/DC0%0/1
$class->[0] // "undef"
$class->[0]
Truth table0%0/2
A
A= $class->[0]
Aresult
11
00
2872 0 ▶ next unless( defined( $class->[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $class->[0] 0 0 0
2873 0 ▶ my $class_name = $self->_load_class( $class->[0] ) ||
Condition0%0/2
$self->_load_class($class->[0]) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_load_class($class->[0]) || (return $self->pass_error)
$self->_load_class($class->[0])
Truth table0%0/2
A
A= $self->_load_class($class->[0])
Aresult
11
00
2874 return( $self->pass_error );
2875 }
2876 }
2877 else
2878 {
2879 53 $self->__message( 107, "Loading class '$class'." );
2880 53 ▶ my $rc = $self->_load_class( $class ) || return( $self->pass_error );
Condition50%1/2
$self->_load_class($class) || (return $self->pass_error)
l!l
530
MC/DC0%0/1
$self->_load_class($class) || (return $self->pass_error)
$self->_load_class($class)
Truth table50%1/2
A
A= $self->_load_class($class)
Aresult
11
00
2881 }
2882 # $self->__message( 106, "Loading class ${class} resulted in return value '${rc}'" );
2883 53 ▶ @_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and not defined $_[0] 0 53 53
Condition66%2/3
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
37160
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
2884 53 ▶ if( defined( $callback ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $callback) { } 0 53 53
2885 {
2886 0 $self->__message( 107, "Calling callback to get new object." );
2887 0 local $_ = $self;
2888 0 $o = $callback->(
2889 $class => [@_],
2890 );
2891 }
2892 else
2893 {
2894 0 ▶ my $args = \@_; $self->__message( 107, "Creating a new ${class} object using arguments '", CORE::join( "', '", map( $self->_str_val( $_ // 'undef' ), @_ ) ), "': ", sub{ $self->Module::Generic::dump( $args) } );
Subroutine __ANON__: not called CC=1 SCAR=0.6
Condition50%1/2
$_ // "undef"
l!l
160
MC/DC0%0/1
$_ // "undef"
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
2895 53 ▶ $o = scalar( @_ ) ? $class->new( @_ ) : $class->new;
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ ? : 16 37 53
2896 }
2897 };
2898 53 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 53 53
2899 {
2900 0 $self->__message( 107, "Error instantiating new $class object: $@" );
2901 0 ▶ if( $self->_can( $@ => 'message' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_can($@, 'message')) { } 0 0 0
2902 {
2903 0 return( $self->error({ code => 500, message => $@->message }) );
2904 }
2905 else
2906 {
2907 0 return( $self->error({ code => 500, message => $@ }) );
2908 }
2909 }
2910 53 ▶ $self->__message( 107, "Unable to instantiate an object of class $class." ) if( !defined( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 53 53
2911 53 ▶ return( $self->error( "Unable to instantiate an object of class $class: ", $class->error ) ) if( !defined( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 53 53
2912 53 ▶ $o->debug( $this->{debug} ) if( $o->can( 'debug' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $o->can("debug") 16 37 53
2913 53 $self->__message( 107, "Returning new class $class object." );
2914 53 return( $o );
2915 }
2916  
2917 sub _can
2918 393 ▶{
Subroutine _can: called CC=7 SCAR=23.0
2919 393 my $self = shift( @_ );
2920 112 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
2921 # Nothing provided
2922 393 ▶ return if( !scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 0 393 393
2923 393 ▶ return if( !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 393 393
2924 393 ▶ return if( !Scalar::Util::blessed( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 332 61 393
2925 61 ▶ if( $self->_is_array( $_[1] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($_[1])) { } 0 61 61
2926 {
2927 0 foreach my $meth ( @{$_[1]} )
2928 {
2929 0 ▶ return(0) unless( $_[0]->can( $meth ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->can($meth) 0 0 0
2930 }
2931 0 return(1);
2932 }
2933 else
2934 {
2935 61 return( $_[0]->can( $_[1] ) );
2936 }
2937 }
2938  
2939 sub _get_args_as_hash
2940 1657 ▶{
Subroutine _get_args_as_hash: called CC=19 SCAR=46.6
2941 1657 my $self = shift( @_ );
2942 1657 ▶ return( {} ) if( !scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 1130 527 1657
2943 112 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
2944 527 my $ref = {};
2945 527 my $order = $self->new_array;
2946 527 ▶ my $need_list = Wanted::want( 'LIST' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
Wanted::want('LIST') ? : 0 527 527
2947 527 my $ok = {};
2948  
2949 my $process = sub
2950 161 ▶ {
Subroutine __ANON__: called CC=16 SCAR=49.0
2951 161 my $this = shift( @_ );
2952 # Check if among the parameters there is a special args_list one and its value is an array reference
2953 161 ▶ if( scalar( grep( !Scalar::Util::blessed( $_ ) && $_ eq 'args_list', @$this ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar grep((!builtin::blessed($_) && $_ eq "args_list"), @$this)) 0 161 161
Condition66%2/3
!builtin::blessed($_) && $_ eq 'args_list'
!ll&&!rl&&r
64840
MC/DC0%0/2
!builtin::blessed($_) && $_ eq 'args_list'
!builtin::blessed($_) $_ eq 'args_list'
Truth table66%2/3
not(A) && B
A= !builtin::blessed($_)B= $_ eq 'args_list'
ABresult
0X0
100
111
2954 {
2955 0 ▶ for( my $i = 0; $i < scalar( @$this ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$this) 0 0 0
2956 {
2957 0 ▶ if( defined( $this->[$i] ) && $this->[$i] eq 'args_list' &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this->[$i] and $this->[$i] eq "args_list" and defined $$this[$i + 1] and (builtin::reftype($$this[$i + 1]) // "") eq "ARRAY") 0 0 0
Condition0%0/11
defined $this->[$i] and $this->[$i] eq "args_list" and defined $$this[$i + 1] and (builtin::reftype($$this[$i + 1]) // "") eq "ARRAY"
!ll&&!rl&&r
000
defined $this->[$i] and $this->[$i] eq "args_list" and defined $$this[$i + 1]
!ll&&!rl&&r
000
defined $this->[$i] and $this->[$i] eq "args_list"
!ll&&!rl&&r
000
builtin::reftype($$this[$i + 1]) // ""
l!l
00
MC/DC0%0/4
defined $this->[$i] and $this->[$i] eq "args_list" and defined $$this[$i + 1] and (builtin::reftype($$this[$i + 1]) // "") eq "ARRAY"
defined $this->[$i] $this->[$i] eq "args_list" defined $$this[$i + 1] builtin::reftype($$this[$i + 1])
Truth table0%0/5
A and B and C and D
A= defined $this->[$i]B= $this->[$i] eq "args_list"C= defined $$this[$i + 1]D= builtin::reftype($$this[$i + 1])
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2958 defined( $this->[$i+1] ) && ( Scalar::Util::reftype( $this->[$i+1] ) // '' ) eq 'ARRAY' )
2959 {
2960 0 my $list = $this->[$i+1];
2961 0 @$ok{ @$list } = (1) x scalar( @$list );
2962 0 last;
2963 }
2964 }
2965 }
2966  
2967 # If we have a restricted list of parameters, obey it
2968 161 ▶ if( scalar( keys( %$ok ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (scalar keys %$ok) { } 0 161 161
elsif (not scalar(@$this) % 2) { } 161 0 161
2969 {
2970 0 ▶ for( my $i = 0; $i < scalar( @$this ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$this) 0 0 0
2971 {
2972 0 ▶ if( exists( $ok->{ $this->[$i] } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$ok{$this->[$i]}) 0 0 0
2973 {
2974 0 $ref->{ $this->[$i] } = $this->[$i+1];
2975 0 ▶ $order->push( $this->[$i] ) if( $need_list );
Branch: 1 branch
BranchTrueFalseTotal
if $need_list 0 0 0
2976 0 splice( @$this, $i, 2 );
2977 0 $i--;
2978 }
2979 }
2980 }
2981 # or, if we have simple a list of key-value pairs, take this and put it into an hash reference
2982 elsif( !( scalar( @$this ) % 2 ) )
2983 {
2984 161 $ref = { @$this };
2985 161 ▶ if( $need_list )
Branch: 1 branch
BranchTrueFalseTotal
if ($need_list) 0 161 161
2986 {
2987 0 ▶ for( my $i = 0; $i < scalar( @$this ); $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$this) 0 0 0
2988 {
2989 0 $order->push( $this->[$i] );
2990 }
2991 }
2992 }
2993 161 return( $ref, $order );
2994 527 };
2995  
2996 # A single hash reference was provided
2997 527 ▶ if( scalar( @_ ) == 1 && $self->_is_hash( $_[0] ) )
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1 and $self->_is_hash($_[0])) { } 366 161 527
elsif (scalar @_ == 1 and (builtin::reftype($_[0]) // '') eq 'ARRAY' or scalar @_ == 3 and (builtin::reftype($_[0]) // '') eq 'ARRAY' and defined $_[1] and $_[1] eq 'args_list' and defined $_[2] and (builtin::reftype($_[2]) // '') eq 'ARRAY') { } 0 161 161
Condition66%2/3
scalar @_ == 1 and $self->_is_hash($_[0])
!ll&&!rl&&r
1610366
MC/DC50%1/2
scalar @_ == 1 and $self->_is_hash($_[0])
scalar @_ == 1 $self->_is_hash($_[0])
Truth table66%2/3
A and B
A= scalar @_ == 1B= $self->_is_hash($_[0])
ABresult
0X0
100
111
2998 {
2999 366 $ref = shift( @_ );
3000 366 ▶ $order = $self->new_array( [sort( keys( %$ref ) )] ) if( $need_list );
Branch: 1 branch
BranchTrueFalseTotal
if $need_list 0 366 366
3001 }
3002 ▶ elsif( (
Condition25%7/27
scalar @_ == 1 and (builtin::reftype($_[0]) // "") eq "ARRAY" or scalar @_ == 3 and (builtin::reftype($_[0]) // "") eq "ARRAY" and defined $_[1] and $_[1] eq "args_list" and defined $_[2] and (builtin::reftype($_[2]) // "") eq "ARRAY"
l!l&&r!l&&!r
00161
scalar @_ == 1 and (builtin::reftype($_[0]) // "") eq "ARRAY"
!ll&&!rl&&r
16100
builtin::reftype($_[0]) // ""
l!l
00
scalar @_ == 3 and (builtin::reftype($_[0]) // "") eq "ARRAY" and defined $_[1] and $_[1] eq "args_list" and defined $_[2] and (builtin::reftype($_[2]) // "") eq "ARRAY"
!ll&&!rl&&r
16100
scalar @_ == 3 and (builtin::reftype($_[0]) // "") eq "ARRAY" and defined $_[1] and $_[1] eq "args_list" and defined $_[2]
!ll&&!rl&&r
16100
scalar @_ == 3 and (builtin::reftype($_[0]) // "") eq "ARRAY" and defined $_[1] and $_[1] eq "args_list"
!ll&&!rl&&r
16100
scalar @_ == 3 and (builtin::reftype($_[0]) // "") eq "ARRAY" and defined $_[1]
!ll&&!rl&&r
16100
scalar @_ == 3 and (builtin::reftype($_[0]) // "") eq "ARRAY"
!ll&&!rl&&r
16100
builtin::reftype($_[0]) // ""
l!l
00
builtin::reftype($_[2]) // ""
l!l
00
MC/DC0%0/8
scalar @_ == 1 and (builtin::reftype($_[0]) // "") eq "ARRAY" or scalar @_ == 3 and (builtin::reftype($_[0]) // "") eq "ARRAY" and defined $_[1] and $_[1] eq "args_list" and defined $_[2] and (builtin::reftype($_[2]) // "") eq "ARRAY"
scalar @_ == 1 builtin::reftype($_[0]) scalar @_ == 3 builtin::reftype($_[0]) defined $_[1] $_[1] eq "args_list" defined $_[2] builtin::reftype($_[2])
Truth table6%1/15
A and B or C and D and E and F and G and H
A= scalar @_ == 1B= builtin::reftype($_[0])C= scalar @_ == 3D= builtin::reftype($_[0])E= defined $_[1]F= $_[1] eq "args_list"G= defined $_[2]H= builtin::reftype($_[2])
ABCDEFGHresult
11XXXXXX1
0X1111111
101111111
0X0XXXXX0
0X10XXXX0
0X110XXX0
0X1110XX0
0X11110X0
0X1111100
100XXXXX0
1010XXXX0
10110XXX0
101110XX0
1011110X0
101111100
3003 scalar( @_ ) == 1 &&
3004 ( Scalar::Util::reftype( $_[0] ) // '' ) eq 'ARRAY'
3005 ) ||
3006 (
3007 scalar( @_ ) == 3 &&
3008 ( Scalar::Util::reftype( $_[0] ) // '' ) eq 'ARRAY' &&
3009 defined( $_[1] ) &&
3010 $_[1] eq 'args_list' &&
3011 defined( $_[2] ) &&
3012 ( Scalar::Util::reftype( $_[2] ) // '' ) eq 'ARRAY'
3013 ) )
3014 {
3015 0 ▶ if( @_ > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
3016 {
3017 0 my $list = $_[2];
3018 0 @$ok{ @$list } = (1) x scalar( @$list );
3019 }
3020 0 ( $ref, $order ) = $process->( $_[0] );
3021 }
3022 else
3023 {
3024 161 ( $ref, $order ) = $process->( \@_ );
3025 }
3026 527 ▶ return( $need_list ? ( $ref, $order ) : $ref );
Branch: 1 branch
BranchTrueFalseTotal
$need_list ? : 0 527 527
3027 }
3028  
3029 sub _get_stack_trace
3030 1 ▶{
Subroutine _get_stack_trace: called CC=2 SCAR=7.0
3031 1 my $self = shift( @_ );
3032 1 my $opts = $self->_get_args_as_hash( @_ );
3033 1 ▶ $opts->{skip_frames} //= 0;
Condition50%1/2
$opts->{"skip_frames"} //= 0
l!l
01
MC/DC0%0/1
$opts->{"skip_frames"} //= 0
$opts->{"skip_frames"}
Truth table50%1/2
A
A= $opts->{"skip_frames"}
Aresult
11
00
3034 1 require Devel::StackTrace;
3035 1 my $trace = Devel::StackTrace->new( skip_frames => ( 1 + $opts->{skip_frames} ), indent => 1 );
3036 1 return( $trace );
3037 }
3038  
3039 # Call to the actual method doing the work
3040 # The reason for doing so is because _instantiate_object() may be inherited, but
3041 # _set_get_class or _set_get_hash_as_object created dynamic class which requires to call _instantiate_object
3042 # If _instantiate_object is inherited, it will yield unpredictable results
3043 37 ▶sub _instantiate_object { return( shift->__instantiate_object( @_ ) ); }
Subroutine _instantiate_object: called CC=1 SCAR=0.0
3044  
3045 sub _is_a
3046 1612 ▶{
Subroutine _is_a: called CC=9 SCAR=22.3
3047 1612 my $self = shift( @_ );
3048 1612 my $obj = shift( @_ );
3049 1612 my $pkg = shift( @_ );
3050 34 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
3051 1612 ▶ return if( !$obj || !$pkg );
Branch: 1 branch
BranchTrueFalseTotal
unless $obj and $pkg 133 1479 1612
Condition66%2/3
$obj and $pkg
!ll&&!rl&&r
13301479
MC/DC50%1/2
$obj and $pkg
$obj $pkg
Truth table66%2/3
A and B
A= $objB= $pkg
ABresult
0X0
100
111
3052 1479 ▶ return if( !$self->_is_object( $obj ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($obj) 167 1312 1479
3053 1312 ▶ if( $self->_is_array( $pkg ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($pkg)) { } 21 1291 1312
3054 {
3055 21 for( @$pkg )
3056 {
3057 42 ▶ if( $_ !~ /^\w+(?:\:\:\w+)*$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ =~ /^\w+(?:\:\:\w+)*$/) 0 42 42
3058 {
3059 0 warn( "Warning only: package name provided \"$_\" contains illegal characters.\n" );
3060 }
3061 42 ▶ return(1) if( $obj->isa( $_ ) );
Branch: 1 branch
BranchTrueFalseTotal
if $obj->isa($_) 20 22 42
3062 }
3063 1 return(0);
3064 }
3065 else
3066 {
3067 1291 ▶ if( $pkg !~ /^\w+(?:\:\:\w+)*$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($pkg =~ /^\w+(?:\:\:\w+)*$/) 0 1291 1291
3068 {
3069 0 warn( "Warning only: package name provided \"$pkg\" contains illegal characters.\n" );
3070 }
3071 1291 return( $obj->isa( $pkg ) );
3072 }
3073 }
3074  
3075 sub _is_class_loadable
3076 20 ▶{
Subroutine _is_class_loadable: called CC=11 SCAR=26.5
3077 20 my $self = shift( @_ );
3078 20 ▶ my $class = shift( @_ ) || return(0);
Condition50%1/2
shift @_ || (return 0)
l!l
200
MC/DC0%0/1
shift @_ || (return 0)
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
3079 20 my $version = shift( @_ );
3080 111 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
3081 20 require File::Spec;
3082 20 my $file = File::Spec->catfile( split( /::/, $class ) ) . '.pm';
3083 20 my $inc = File::Spec::Unix->catfile( split( /::/, $class ) ) . '.pm';
3084 20 ▶ if( defined( $INC{ $inc } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $INC{$inc}) 17 3 20
3085 {
3086 17 ▶ if( defined( $version ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $version) { } 1 16 17
3087 {
3088 1 my $alter_version = ${"${class}\::VERSION"};
3089 # try-catch
3090 1 local $@;
3091 1 my $rv;
3092 eval
3093 1 {
3094 1 $rv = version->parse( $alter_version ) >= version->parse( $version );
3095 };
3096 1 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
3097 {
3098 0 return( $self->error( "An unexpected error occurred while trying to check if module \"$class\" with version '$version' is loadable: $@" ) );
3099 }
3100 1 return( $rv );
3101 }
3102 else
3103 {
3104 16 return(1);
3105 }
3106 }
3107  
3108 3 require Module::Metadata;
3109 3 foreach my $dir ( @INC )
3110 {
3111 23 my $fpath = File::Spec->catfile( $dir, $file );
3112 23 ▶ next if( !-e( $fpath ) || !-r( $fpath ) || -z( $fpath ) );
Branch: 1 branch
BranchTrueFalseTotal
if not -e $fpath && -r $fpath or -z $fpath 22 1 23
Condition66%4/6
not -e $fpath && -r $fpath or -z $fpath
l!l&&r!l&&!r
2201
-e $fpath && -r $fpath
!ll&&!rl&&r
2201
MC/DC33%1/3
not -e $fpath && -r $fpath or -z $fpath
-e $fpath -r $fpath -z $fpath
Truth table50%2/4
not(A && B) or C
A= -e $fpathB= -r $fpathC= -z $fpath
ABCresult
0XX1
10X1
1111
1100
3113 1 ▶ if( defined( $version ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $version) 0 1 1
3114 {
3115 0 my $info = Module::Metadata->new_from_file( $fpath );
3116 0 my $alter_version = $info->version;
3117  
3118 # try-catch
3119 0 local $@;
3120 0 my $rv;
3121 eval
3122 0 {
3123 0 $rv = version->parse( $alter_version ) >= version->parse( $version );
3124 };
3125 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3126 {
3127 0 return( $self->error( "An unexpected error occurred while trying to check if module \"$class\" with version '$version' is loadable: $@" ) );
3128 }
3129 0 return( $rv );
3130 }
3131 1 return(1);
3132 }
3133 2 return(0);
3134 }
3135  
3136 sub _is_class_loaded
3137 2848 ▶{
Subroutine _is_class_loaded: called CC=11 SCAR=25.1
3138 2848 my $self = shift( @_ );
3139 2848 ▶ my $class = shift( @_ ) || return(0);
Condition50%1/2
shift @_ || (return 0)
l!l
28480
MC/DC0%0/1
shift @_ || (return 0)
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
3140 2848 ▶ my $key = HAS_THREADS ? join( ';', $class, threads->tid() ) : $class;
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 2848 2848
3141 2848 ▶ my $repo = Module::Generic::Global->new( 'loaded_classes' => ( ref( $self ) || $self ), key => $key );
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
26921560
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
3142 2848 ▶ $self->__message( 106, "Are we running under threads, switching to shared data ? ", ( HAS_THREADS ? 'yes' : 'no' ) );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 2848 2848
3143 2848 ▶ if( $MOD_PERL )
Branch: 2 branches
BranchTrueFalseTotal
if ($MOD_PERL) { } 0 2848 2848
elsif ($repo->exists) { } 2704 144 2848
3144 {
3145 # https://perl.apache.org/docs/2.0/api/Apache2/Module.html#C_loaded_
3146 0 my $rv = Apache2::Module::loaded( $class );
3147 0 ▶ return(1) if( $rv );
Branch: 1 branch
BranchTrueFalseTotal
if $rv 0 0 0
3148 }
3149 # elsif( HAS_THREADS && $repo->exists )
3150 elsif( $repo->exists )
3151 {
3152 2704 ▶ $self->__message( 112, "Class $class is already loaded under threads -> ", ( $repo->get // 'undef' ) );
Condition50%1/2
$repo->get // "undef"
l!l
27040
MC/DC0%0/1
$repo->get // "undef"
$repo->get
Truth table50%1/2
A
A= $repo->get
Aresult
11
00
3153 2704 return(1);
3154 }
3155  
3156 144 $self->__message( 112, "Checking if class $class is loaded using \%INC." );
3157 # NOTE: Strict check via %INC first
3158 144 ( my $pm = $class ) =~ s{::}{/}gs;
3159 144 $pm .= '.pm';
3160 144 ▶ if( CORE::exists( $INC{ $pm } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $INC{$pm}) 56 88 144
3161 {
3162 56 $self->__message( 112, "Found class $class already loaded using \%INC." );
3163 56 $repo->set(1);
3164 56 return(1);
3165 }
3166  
3167 88 $self->__message( 112, "Checking if class $class is loaded using XS function __is_class_loaded." );
3168 88 ▶ if( $self->_is_class_loaded_xs( $class ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_class_loaded_xs($class)) 7 81 88
3169 {
3170 7 $self->__message( 112, "Found class $class already loaded using class namespace." );
3171 7 $repo->set(1);
3172 7 return(1);
3173 }
3174 81 $self->__message( 112, "Class $class is not loaded yet." );
3175 81 return(0);
3176 }
3177  
3178 sub _is_ip
3179 52 ▶{
Subroutine _is_ip: called CC=6 SCAR=19.1
3180 52 my $self = shift( @_ );
3181 52 my $ip = shift( @_ );
3182 52 ▶ return(0) if( !defined( $ip ) || !length( $ip ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ip and length $ip 0 52 52
Condition33%1/3
defined $ip and length $ip
!ll&&!rl&&r
0052
MC/DC0%0/2
defined $ip and length $ip
defined $ip length $ip
Truth table33%1/3
A and B
A= defined $ipB= length $ip
ABresult
0X0
100
111
3183 52 ▶ $self->__message( 112, "Regexp IPv4 is: ", ( $IPV4_RE // 'undef' ) );
Condition50%1/2
$IPV4_RE // "undef"
l!l
520
MC/DC0%0/1
$IPV4_RE // "undef"
$IPV4_RE
Truth table50%1/2
A
A= $IPV4_RE
Aresult
11
00
3184 52 ▶ $self->__message( 112, "Regexp IPv6 is: ", ( $IPV6_RE // 'undef' ) );
Condition50%1/2
$IPV6_RE // "undef"
l!l
520
MC/DC0%0/1
$IPV6_RE // "undef"
$IPV6_RE
Truth table50%1/2
A
A= $IPV6_RE
Aresult
11
00
3185  
3186 # We need to return either 1 or 0. By default, perl return undef for false
3187 # supports IPv4 and IPv6 in CIDR notation or not
3188 52 my $ip4or6 = qr/($IPV4_RE(\/(3[0-2]|[1-2][0-9]|[0-9]))?)|($IPV6_RE(\/(12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))?)/;
3189 52 ▶ return( $ip =~ /^$ip4or6$/ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$ip =~ /^$ip4or6$/ ? : 30 22 52
3190 }
3191  
3192 sub _is_uuid
3193 7 ▶{
Subroutine _is_uuid: called CC=5 SCAR=17.8
3194 7 ▶ return(0) if( scalar( @_ ) < 2 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ < 2 0 7 7
3195 7 ▶ return(0) if( !defined( $_[1] ) || !length( $_[1] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] and length $_[1] 0 7 7
Condition33%1/3
defined $_[1] and length $_[1]
!ll&&!rl&&r
007
MC/DC0%0/2
defined $_[1] and length $_[1]
defined $_[1] length $_[1]
Truth table33%1/3
A and B
A= defined $_[1]B= length $_[1]
ABresult
0X0
100
111
3196 7 ▶ return( $_[1] =~ /^[a-fA-F0-9]{8}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{12}$/ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$_[1] =~ /^[a-fA-F0-9]{8}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{12}$/ ? : 3 4 7
3197 }
3198  
3199 1 ▶sub _is_warnings_enabled { return( shift->_warnings_is_enabled( @_ ) ); }
Subroutine _is_warnings_enabled: called CC=1 SCAR=0.0
3200  
3201 sub _load_class
3202 2670 ▶{
Subroutine _load_class: called CC=33 SCAR=36.8
3203 2670 my $self = shift( @_ );
3204 2670 ▶ my $class = shift( @_ ) || return( $self->error( "No package name was provided to load." ) );
Condition50%1/2
shift @_ || (return $self->error('No package name was provided to load.'))
l!l
26700
MC/DC0%0/1
shift @_ || (return $self->error('No package name was provided to load.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
3205 2670 $self->__message( 112, "Loading class '$class'" );
3206  
3207 # Rigorous validation
3208 2670 ▶ return( $self->error( "Class name is empty." ) ) unless( length( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $class 0 2670 2670
3209  
3210 2670 my $opts = {};
3211 2670 ▶ $opts = pop( @_ ) if ( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 14 2656 2670
3212 #$self->__message( 112, "Using the parameters to load class $class: ", sub{ $self->dump( $opts ) } );
3213  
3214 # Validate options
3215 2670 my %valid_opts = map{ $_ => 1 } qw( caller force no_import no_warning version );
3216 2670 foreach my $key ( keys( %$opts ) )
3217 {
3218 14 ▶ return( $self->error( "Invalid option: $key" ) ) unless ( exists( $valid_opts{ $key } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $valid_opts{$key} 0 14 14
3219 }
3220 2670 ▶ if( exists( $opts->{version} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"version"}) 12 2658 2670
3221 {
3222 12 ▶ return( $self->error( "Version must be defined and non-empty." ) ) unless( defined( $opts->{version} ) && length( $opts->{version} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"version"} and length $opts->{"version"} 0 12 12
Condition33%1/3
defined $opts->{"version"} and length $opts->{"version"}
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $opts->{"version"} and length $opts->{"version"}
defined $opts->{"version"} length $opts->{"version"}
Truth table33%1/3
A and B
A= defined $opts->{"version"}B= length $opts->{"version"}
ABresult
0X0
100
111
3223 }
3224  
3225 2670 my $args = $self->_get_args_as_array( @_ );
3226 #$self->__message( 112, "Using the arguments to load class $class: ", sub{ $self->dump( $args ) } );
3227  
3228 # Get the caller's package so we load the module in context
3229 2670 ▶ my $caller_class = $opts->{caller} || CORE::caller;
Condition66%2/3
$opts->{'caller'} || caller
l!l&&r!l&&!r
126690
MC/DC0%0/2
$opts->{'caller'} || caller
$opts->{'caller'} caller
Truth table66%2/3
A || B
A= $opts->{'caller'}B= caller
ABresult
1X1
011
000
3230 2670 $self->__message( 112, "Loading class $class into caller's namespace $caller_class" );
3231  
3232 # Return if already loaded (threads aware)
3233 2670 my $is_loaded = $self->_is_class_loaded( $class );
3234 2670 ▶ if( $is_loaded && !$opts->{force} )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_loaded and not $opts->{"force"}) 2605 65 2670
Condition66%2/3
$is_loaded and not $opts->{"force"}
!ll&&!rl&&r
6502605
MC/DC50%1/2
$is_loaded and not $opts->{"force"}
$is_loaded not $opts->{"force"}
Truth table66%2/3
A and not(B)
A= $is_loadedB= not $opts->{"force"}
ABresult
0X0
100
111
3235 {
3236 2605 $self->__message( 112, "Class $class is already loaded." );
3237 2605 ▶ if( scalar( @$args ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args) 1 2604 2605
3238 {
3239 1 $self->__message( 112, "Importing $class with ", scalar( @$args ), " arguments." );
3240 1 ▶ my $pl = "package ${caller_class}; $class->import(" . ( scalar( @$args ) ? "'" . join( "', '", @$args ) . "'" : '' ) . ");";
Branch: 1 branch
BranchTrueFalseTotal
scalar @$args ? : 1 0 1
3241 1 $self->__message( 112, "Executing: $pl" );
3242 1 eval( $pl );
3243 1 ▶ $self->__message( 112, "Error importing class $class into caller's namespace ${caller_class}: $@" ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
3244 1 ▶ return( $self->error( "Error importing class $class into caller's namespace ${caller_class}: $@" ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
3245 }
3246 2605 return( $class );
3247 }
3248 # Use a shared variable for locking in threaded environments
3249 # What we retrieved from _is_class_loaded is not a threaded shared value, so we have to do this instead:
3250 65 ▶ $self->__message( 106, "Are we running under threads, switching to shared data ? ", ( HAS_THREADS ? 'yes' : 'no' ) );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 65 65
3251 65 ▶ my $key = HAS_THREADS ? join( ';', $class, threads->tid() ) : $class;
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 65 65
3252 65 ▶ my $repo = Module::Generic::Global->new( 'loaded_classes' => ( ref( $self ) || $self ), key => $key );
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
6320
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
3253  
3254 # Load the module with thread safety
3255 {
3256 65 ▶ my $has_version = ( CORE::exists( $opts->{version} ) && CORE::length( $opts->{version} // '' ) ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'version'} && length($opts->{'version'} // '') ? : 3 62 65
Condition60%3/5
exists $opts->{"version"} and length($opts->{"version"} // "")
!ll&&!rl&&r
6203
$opts->{"version"} // ""
l!l
30
MC/DC50%1/2
exists $opts->{"version"} and length($opts->{"version"} // "")
exists $opts->{"version"} $opts->{"version"}
Truth table66%2/3
A and B
A= exists $opts->{"version"}B= $opts->{"version"}
ABresult
0X0
100
111
3257 65 ▶ local $SIG{__WARN__} = sub{} if( $opts->{no_warning} );
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"no_warning"} 1 64 65
3258 65 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: called CC=1 SCAR=0.0
3259 65 local $@;
3260 65 my $pl = "package ${caller_class}; require $class;";
3261 65 $self->__message( 112, "Evaluating code '$pl' under threads." );
3262 65 eval( $pl );
3263 65 ▶ $self->__message( 112, "Error loading class: $@" ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 5 60 65
3264 65 ▶ return( $self->error( "Unable to load package ${class}: $@\nCode executed was:\n${pl}" ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 5 60 65
3265 60 ▶ $self->__message( 112, "Checking for version ? ", ( $has_version ? "yes -> $opts->{version}" : 'no' ) );
Branch: 1 branch
BranchTrueFalseTotal
$has_version ? : 3 57 60
3266 60 ▶ if( $has_version )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_version) 3 57 60
3267 {
3268 3 eval{ $class->VERSION( $opts->{version} ) };
3269 3 ▶ return( $self->error( "Insufficient version ", $class->VERSION(), ", for class $class. $opts->{version} minimum is required." ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
3270 }
3271  
3272 60 ▶ unless( $opts->{no_import} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"no_import"}) 60 0 60
3273 {
3274 60 $self->__message( 112, "Importing $class with ", scalar( @$args ), " arguments." );
3275 60 ▶ $pl = "package ${caller_class}; $class->import(" . ( scalar( @$args ) ? "'" . join( "', '", @$args ) . "'" : '' ) . ");";
Branch: 1 branch
BranchTrueFalseTotal
scalar @$args ? : 0 60 60
3276 60 $self->__message( 112, "Executing: $pl" );
3277 60 eval( $pl );
3278 60 ▶ $self->__message( 112, "Error importing class $class into caller's namespace ${caller_class}: $@" ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 60 60
3279 60 ▶ return( $self->error( "Error importing class $class into caller's namespace ${caller_class}: $@" ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 60 60
3280 }
3281 60 $repo->set(1);
3282 60 $self->__message( 112, "Class $class successfully loaded." );
3283 }
3284  
3285 60 ▶ return( $self->_is_class_loaded( $class ) ? $class : '' );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_class_loaded($class) ? : 60 0 60
3286 }
3287  
3288 sub _load_classes
3289 0 ▶{
Subroutine _load_classes: not called CC=5 SCAR=34.0
3290 0 my $self = shift( @_ );
3291 0 ▶ my $ref = shift( @_ ) || return( $self->error( "No array reference of classes to load was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No array reference of classes to load was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No array reference of classes to load was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
3292 0 ▶ return( $self->error( "Value provided is not an array reference." ) ) if( !$self->_is_array( $ref ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($ref) 0 0 0
3293 0 my $opts = $self->_get_args_as_hash( @_ );
3294 0 for( @$ref )
3295 {
3296 0 ▶ $self->_load_class( $_, $opts ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($_, $opts) or return $self->pass_error 0 0 0
3297 }
3298 0 return( $self );
3299 }
3300  
3301 sub _look_like_number
3302 0 ▶{
Subroutine _look_like_number: not called CC=6 SCAR=33.6
3303 0 ▶ return(0) if( scalar( @_ ) < 2 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ < 2 0 0 0
3304 0 my( $self, $num ) = @_;
3305 0 ▶ return(0) if( !defined( $num ) || !length( $num ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num and length $num 0 0 0
Condition0%0/3
defined $num and length $num
!ll&&!rl&&r
000
MC/DC0%0/2
defined $num and length $num
defined $num length $num
Truth table0%0/3
A and B
A= defined $numB= length $num
ABresult
0X0
100
111
3306 0 ▶ if( my $isok = Scalar::Util::looks_like_number( $num ) )
Branch: 2 branches
BranchTrueFalseTotal
if (my $isok = &Scalar::Util::looks_like_number($num)) { } 0 0 0
elsif ($num =~ /^0x[0-9A-F]+$/i) { } 0 0 0
3307 {
3308 0 return(1);
3309 }
3310 # If the hexadecimal value is a string, it will return false, so we use regular expression.
3311 elsif( $num =~ /^0x[0-9A-F]+$/i )
3312 {
3313 0 return(1);
3314 }
3315 111 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
3316 0 return( $num =~ /^$NUMBER_REAL_RE$/ );
3317 }
3318  
3319 8 ▶sub _lvalue : lvalue { return( shift->_set_get_callback( @_ ) ); }
Subroutine _lvalue: called CC=1 SCAR=0.0
3320  
3321 sub __message
3322 101939 ▶{
Subroutine __message: called CC=64 SCAR=78.3
3323 101939 my $self = shift( @_ );
3324 101939 ▶ my $class = ref( $self ) || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
1010099300
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
3325 101939 my $this = $self->_obj2h;
3326 111 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
3327 176 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
3328 101939 ▶ if( $this->{verbose} ||
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"verbose"} or $this->{"debug"} or ${$class . '::DEBUG';} or scalar @_ and ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and $_[-1]{"debug"}) 224 101715 101939
Condition66%6/9
$this->{"verbose"} or $this->{"debug"} or ${$class . '::DEBUG';} or scalar @_ and ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and $_[-1]{"debug"}
l!l&&r!l&&!r
2240101715
$this->{"verbose"} or $this->{"debug"} or ${$class . '::DEBUG';}
l!l&&r!l&&!r
2240101715
$this->{"verbose"} or $this->{"debug"}
l!l&&r!l&&!r
0224101715
MC/DC0%0/4
$this->{"verbose"} or $this->{"debug"} or ${$class . '::DEBUG';} or scalar @_ and ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and $_[-1]{"debug"}
$this->{"verbose"} $this->{"debug"} ${$class . '::DEBUG';} scalar @_ and ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and $_[-1]{"debug"}
Truth table40%2/5
A or B or C or D
A= $this->{"verbose"}B= $this->{"debug"}C= ${$class . '::DEBUG';}D= scalar @_ and ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and $_[-1]{"debug"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
3329 $this->{debug} ||
3330 101715 ▶ ${ $class . '::DEBUG' } ||
Condition33%3/9
scalar @_ and ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and $_[-1]{"debug"}
!ll&&!rl&&r
10171500
scalar @_ and ref $_[-1] eq "HASH" and exists $_[-1]{"debug"}
!ll&&!rl&&r
10171500
scalar @_ and ref $_[-1] eq "HASH"
!ll&&!rl&&r
01017150
MC/DC0%0/4
scalar @_ and ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and $_[-1]{"debug"}
scalar @_ ref $_[-1] eq "HASH" exists $_[-1]{"debug"} $_[-1]{"debug"}
Truth table0%0/5
A and B and C and D
A= scalar @_B= ref $_[-1] eq "HASH"C= exists $_[-1]{"debug"}D= $_[-1]{"debug"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
3331 # Last parameter is an hash and there is a debug property
3332 ( scalar( @_ ) && ref( $_[-1] ) eq 'HASH' && CORE::exists( $_[-1]->{debug} ) && $_[-1]->{debug} ) )
3333 {
3334 224 my $r;
3335 # We check which phase we are in, because in destruction phase, Apache2::ApacheRec is not available.
3336 224 ▶ if( $MOD_PERL && !&_in_global_destruction() )
Branch: 1 branch
BranchTrueFalseTotal
if ($MOD_PERL and not &_in_global_destruction()) 0 224 224
Condition33%1/3
$MOD_PERL and not &_in_global_destruction()
!ll&&!rl&&r
22400
MC/DC0%0/2
$MOD_PERL and not &_in_global_destruction()
$MOD_PERL not &_in_global_destruction()
Truth table33%1/3
A and not(B)
A= $MOD_PERLB= not &_in_global_destruction()
ABresult
0X0
100
111
3337 {
3338 # try-catch
3339 0 local $@;
3340 eval
3341 0 {
3342 0 ▶ local $SIG{__WARN__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
3343 0 $r = Apache2::RequestUtil->request;
3344 };
3345 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3346 {
3347 0 print( STDERR "Error trying to get the global Apache2::ApacheRec: $@\n" );
3348 }
3349 }
3350  
3351 224 local $Module::Generic::TieHash::PAUSED = 1;
3352 224 my $ref;
3353 224 $ref = $self->_message_check( @_ );
3354 224 ▶ return(1) if( !$ref );
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 224 0 224
3355  
3356 0 my $opts = {};
3357 # NOTE: make sure to update this if there is use of additional parameters
3358 0 ▶ if( ref( $ref->[-1] ) eq 'HASH' &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref->[-1] eq "HASH" and scalar grep(/^(caller_info|colour|color|level|message|no_encoding|no_exec|prefix|skip_frames|type)$/, keys %{$$ref[-1];})) 0 0 0
Condition0%0/2
ref $ref->[-1] eq "HASH" and scalar grep(/^(caller_info|colour|color|level|message|no_encoding|no_exec|prefix|skip_frames|type)$/, keys %{$$ref[-1];})
!ll
00
MC/DC0%0/1
ref $ref->[-1] eq "HASH" and scalar grep(/^(caller_info|colour|color|level|message|no_encoding|no_exec|prefix|skip_frames|type)$/, keys %{$$ref[-1];})
ref $ref->[-1] eq "HASH"
Truth table0%0/2
A
A= ref $ref->[-1] eq "HASH"
Aresult
00
11
3359 0 scalar( grep( /^(caller_info|colour|color|level|message|no_encoding|no_exec|prefix|skip_frames|type)$/, keys( %{$ref->[-1]} ) ) ) )
3360 {
3361 0 $opts = pop( @$ref );
3362 }
3363  
3364 0 ▶ my $stackFrame = $self->_message_frame( (caller(1))[3] ) || 0;
Condition0%0/2
$self->_message_frame((caller 1)[3]) || 0
l!l
00
MC/DC0%0/1
$self->_message_frame((caller 1)[3]) || 0
$self->_message_frame((caller 1)[3])
Truth table0%0/2
A
A= $self->_message_frame((caller 1)[3])
Aresult
11
00
3365 0 ▶ $stackFrame = 0 unless( $stackFrame =~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $stackFrame =~ /^\d+$/ 0 0 0
3366 0 ▶ $stackFrame += int( $opts->{skip_frames} ) if( CORE::exists( $opts->{skip_frames} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"skip_frames"} 0 0 0
3367 0 ▶ while( ( (caller( $stackFrame + 1 ))[3] // '' ) =~ /^Module::Generic::(?:_)?(messagef|message|messagec|message_color|message_colour|AUTOLOAD)/ )
Branch: 1 branch
BranchTrueFalseTotal
if (((caller $stackFrame + 1)[3] // "") =~ /^Module::Generic::(?:_)?(messagef|message|messagec|message_color|message_colour|AUTOLOAD)/) 0 0 0
Condition0%0/2
(caller $stackFrame + 1)[3] // ""
l!l
00
MC/DC0%0/1
(caller $stackFrame + 1)[3] // ""
(caller $stackFrame + 1)[3]
Truth table0%0/2
A
A= (caller $stackFrame + 1)[3]
Aresult
11
00
3368 {
3369 0 $stackFrame++;
3370 }
3371  
3372 0 my( $pkg, $file, $line, @otherInfo ) = caller( $stackFrame );
3373 0 ▶ my $sub = ( caller( $stackFrame + 1 ) )[3] // '';
Condition0%0/2
(caller $stackFrame + 1)[3] // ""
l!l
00
MC/DC0%0/1
(caller $stackFrame + 1)[3] // ""
(caller $stackFrame + 1)[3]
Truth table0%0/2
A
A= (caller $stackFrame + 1)[3]
Aresult
11
00
3374 0 my $sub2 = substr( $sub, rindex( $sub, '::' ) + 2 );
3375 0 ▶ if( ref( $this->{_message_frame} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this->{"_message_frame"} eq "HASH") 0 0 0
3376 {
3377 0 ▶ if( CORE::exists( $this->{_message_frame}->{ $sub2 } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $this->{"_message_frame"}{$sub2}) 0 0 0
3378 {
3379 0 my $frameNo = int( $this->{_message_frame}->{ $sub2 } );
3380 0 ▶ if( $frameNo > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($frameNo > 0) 0 0 0
3381 {
3382 0 ( $pkg, $file, $line, $sub ) = caller( $frameNo );
3383 0 $sub2 = substr( $sub, rindex( $sub, '::' ) + 2 );
3384 }
3385 }
3386 }
3387  
3388 0 require Encode;
3389 0 my $txt;
3390 0 ▶ if( $opts->{message} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'message'}) { } 0 0 0
3391 {
3392 0 ▶ if( ref( $opts->{message} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts->{'message'} eq 'ARRAY') { } 0 0 0
3393 {
3394 0 ▶ $txt = join( '', map{ Encode::is_utf8( $_ ) ? $_ : Encode::decode_utf8( $_ ) } map{ ( ref( $_ ) eq 'CODE' && !$this->{_msg_no_exec_sub} ) ? $_->() : ( $_ // '' ) } @{$opts->{message}} );
Branch: 2 branches
BranchTrueFalseTotal
&Encode::is_utf8($_) ? : 0 0 0
ref $_ eq 'CODE' && !$this->{'_msg_no_exec_sub'} ? : 0 0 0
Condition0%0/5
ref $_ eq "CODE" and not $this->{"_msg_no_exec_sub"}
!ll&&!rl&&r
000
$_ // ""
l!l
00
MC/DC0%0/2
ref $_ eq "CODE" and not $this->{"_msg_no_exec_sub"}
ref $_ eq "CODE" not $this->{"_msg_no_exec_sub"}
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/3
A and not(B)
A= ref $_ eq "CODE"B= not $this->{"_msg_no_exec_sub"}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $_
Aresult
11
00
3395 }
3396 else
3397 {
3398 0 ▶ $txt = Encode::is_utf8( $opts->{message} ) ? $opts->{message} : Encode::decode_utf8( $opts->{message} );
Branch: 1 branch
BranchTrueFalseTotal
&Encode::is_utf8($opts->{'message'}) ? : 0 0 0
3399 }
3400 }
3401 else
3402 {
3403 0 ▶ $txt = join( '', map{ Encode::is_utf8( $_ ) ? $_ : Encode::decode_utf8( $_ ) } map{ ( ref( $_ ) eq 'CODE' && !$this->{_msg_no_exec_sub} && !$opts->{no_exec} ) ? $_->() : ( $_ // '' ) } @$ref );
Branch: 2 branches
BranchTrueFalseTotal
&Encode::is_utf8($_) ? : 0 0 0
ref $_ eq 'CODE' && !$this->{'_msg_no_exec_sub'} && !$opts->{'no_exec'} ? : 0 0 0
Condition0%0/8
ref $_ eq "CODE" and not $this->{"_msg_no_exec_sub"} and not $opts->{"no_exec"}
!ll&&!rl&&r
000
ref $_ eq "CODE" and not $this->{"_msg_no_exec_sub"}
!ll&&!rl&&r
000
$_ // ""
l!l
00
MC/DC0%0/3
ref $_ eq "CODE" and not $this->{"_msg_no_exec_sub"} and not $opts->{"no_exec"}
ref $_ eq "CODE" not $this->{"_msg_no_exec_sub"} not $opts->{"no_exec"}
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/4
A and not(B) and not(C)
A= ref $_ eq "CODE"B= not $this->{"_msg_no_exec_sub"}C= not $opts->{"no_exec"}
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/2
A
A= $_
Aresult
11
00
3404 }
3405 # Reset it
3406 0 $this->{_msg_no_exec_sub} = 0;
3407  
3408 # Process colours if needed
3409 0 ▶ if( $opts->{colour} || $opts->{color} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"colour"} or $opts->{"color"}) 0 0 0
Condition0%0/3
$opts->{"colour"} or $opts->{"color"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"colour"} or $opts->{"color"}
$opts->{"colour"} $opts->{"color"}
Truth table0%0/3
A or B
A= $opts->{"colour"}B= $opts->{"color"}
ABresult
1X1
011
000
3410 {
3411 0 $txt = $self->colour_parse( $txt );
3412 }
3413  
3414 0 ▶ my $prefix = CORE::length( $opts->{prefix} ) ? $opts->{prefix} : '##';
Branch: 1 branch
BranchTrueFalseTotal
length $opts->{'prefix'} ? : 0 0 0
3415 58 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
3416 0 ▶ $opts->{caller_info} = 1 if( !CORE::exists( $opts->{caller_info} ) || !CORE::length( $opts->{caller_info} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"caller_info"} and length $opts->{"caller_info"} 0 0 0
Condition0%0/3
exists $opts->{"caller_info"} and length $opts->{"caller_info"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"caller_info"} and length $opts->{"caller_info"}
exists $opts->{"caller_info"} length $opts->{"caller_info"}
Truth table0%0/3
A and B
A= exists $opts->{"caller_info"}B= length $opts->{"caller_info"}
ABresult
0X0
100
111
3417 0 my $proc_info = " [PID: $$]";
3418 0 ▶ if( HAS_THREADS )
Branch: 1 branch
BranchTrueFalseTotal
if (&HAS_THREADS()) 0 0 0
3419 {
3420 0 my $tid = threads->tid;
3421 0 ▶ $proc_info .= ' -> [thread id ' . $tid . ']' if( $tid );
Branch: 1 branch
BranchTrueFalseTotal
if $tid 0 0 0
3422 }
3423 0 ▶ my $mesg_raw = $opts->{caller_info} ? ( "${pkg}::${sub2}( " . $self->_str_val( $self // 'undef' ) . " ) [$line]${proc_info}: " . $txt ) : $txt;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'caller_info'} ? : 0 0 0
Condition0%0/2
$self // "undef"
l!l
00
MC/DC0%0/1
$self // "undef"
$self
Truth table0%0/2
A
A= $self
Aresult
11
00
3424 0 $mesg_raw =~ s/\n$//gs;
3425 0 my $mesg = "${prefix} " . join( "\n${prefix} ", split( /\n/, $mesg_raw ) );
3426  
3427 my $info =
3428 {
3429 'formatted' => $mesg,
3430 'message' => $txt,
3431 'file' => $file,
3432 'line' => $line,
3433 'package' => $class,
3434 'sub' => $sub2,
3435 0 ▶ 'level' => ( $_[0] =~ /^\d+$/ ? $_[0] : CORE::exists( $opts->{level} ) ? $opts->{level} : 0 ),
Branch: 2 branches
BranchTrueFalseTotal
$_[0] =~ /^\d+$/ ? : 0 0 0
exists $opts->{'level'} ? : 0 0 0
3436 };
3437 0 ▶ $info->{type} = $opts->{type} if( $opts->{type} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"type"} 0 0 0
3438  
3439 # If Mod perl is activated AND we are not using a private log
3440 0 ▶ if( $r && !${ "${class}::LOG_DEBUG" } )
Branch: 5 branches
BranchTrueFalseTotal
if ($r and not ${"${class}::LOG_DEBUG";}) { } 0 0 0
elsif ($MOD_PERL and not ${"${class}::LOG_DEBUG";}) { } 0 0 0
elsif (not -t STDIN and $this->{'_log_handler'} and ref $this->{'_log_handler'} eq 'CODE') { } 0 0 0
elsif (not -t STDIN and ${$class . '::MESSAGE_HANDLER';} and ref ${$class . '::MESSAGE_HANDLER';} eq 'CODE') { } 0 0 0
elsif ($self->_message_log($mesg, "\n")) { } 0 0 0
Condition0%0/3
$r and not ${"${class}::LOG_DEBUG";}
!ll&&!rl&&r
000
MC/DC0%0/2
$r and not ${"${class}::LOG_DEBUG";}
$r not ${"${class}::LOG_DEBUG";}
Truth table0%0/3
A and not(B)
A= $rB= not ${"${class}::LOG_DEBUG";}
ABresult
0X0
100
111
3441 {
3442 0 ▶ if( my $log_handler = $r->get_handlers( 'PerlPrivateLogHandler' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (my $log_handler = $r->get_handlers('PerlPrivateLogHandler')) { } 0 0 0
elsif ($this->{'_log_handler'} and ref $this->{'_log_handler'} eq 'CODE') { } 0 0 0
3443 {
3444 0 $log_handler->( $mesg_raw );
3445 }
3446 ▶ elsif( $this->{_log_handler} && ref( $this->{_log_handler} ) eq 'CODE' )
Condition0%0/3
$this->{"_log_handler"} and ref $this->{"_log_handler"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$this->{"_log_handler"} and ref $this->{"_log_handler"} eq "CODE"
$this->{"_log_handler"} ref $this->{"_log_handler"} eq "CODE"
Truth table0%0/3
A and B
A= $this->{"_log_handler"}B= ref $this->{"_log_handler"} eq "CODE"
ABresult
0X0
100
111
3447 {
3448 0 $this->{_log_handler}->( $info );
3449 }
3450 else
3451 {
3452 0 $r->log->debug( $mesg_raw );
3453 }
3454 }
3455 # Using ModPerl Server to log
3456 0 ▶ elsif( $MOD_PERL && !${ "${class}::LOG_DEBUG" } )
Condition0%0/3
$MOD_PERL and not ${"${class}::LOG_DEBUG";}
!ll&&!rl&&r
000
MC/DC0%0/2
$MOD_PERL and not ${"${class}::LOG_DEBUG";}
$MOD_PERL not ${"${class}::LOG_DEBUG";}
Truth table0%0/3
A and not(B)
A= $MOD_PERLB= not ${"${class}::LOG_DEBUG";}
ABresult
0X0
100
111
3457 {
3458 0 ▶ $self->_load_class( 'Apache2::ServerUtil' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Apache2::ServerUtil") or return $self->pass_error 0 0 0
3459 0 my $s = Apache2::ServerUtil->server;
3460 0 $s->log->debug( $mesg );
3461 }
3462 # e.g. in our package, we could set the handler using the curry module like $self->{_log_handler} = $self->curry::log
3463 ▶ elsif( !-t( STDIN ) && $this->{_log_handler} && ref( $this->{_log_handler} ) eq 'CODE' )
Condition0%0/6
not -t STDIN and $this->{"_log_handler"} and ref $this->{"_log_handler"} eq "CODE"
!ll&&!rl&&r
000
not -t STDIN and $this->{"_log_handler"}
!ll&&!rl&&r
000
MC/DC0%0/3
not -t STDIN and $this->{"_log_handler"} and ref $this->{"_log_handler"} eq "CODE"
not -t STDIN $this->{"_log_handler"} ref $this->{"_log_handler"} eq "CODE"
Truth table0%0/4
not(A) and B and C
A= not -t STDINB= $this->{"_log_handler"}C= ref $this->{"_log_handler"} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
3464 {
3465 0 $this->{_log_handler}->( $info );
3466 }
3467 0 ▶ elsif( !-t( STDIN ) && ${ $class . '::MESSAGE_HANDLER' } && ref( ${ $class . '::MESSAGE_HANDLER' } ) eq 'CODE' )
Condition0%0/6
not -t STDIN and ${$class . '::MESSAGE_HANDLER';} and ref ${$class . '::MESSAGE_HANDLER';} eq "CODE"
!ll&&!rl&&r
000
not -t STDIN and ${$class . '::MESSAGE_HANDLER';}
!ll&&!rl&&r
000
MC/DC0%0/3
not -t STDIN and ${$class . '::MESSAGE_HANDLER';} and ref ${$class . '::MESSAGE_HANDLER';} eq "CODE"
not -t STDIN ${$class . '::MESSAGE_HANDLER';} ref ${$class . '::MESSAGE_HANDLER';} eq "CODE"
Truth table0%0/4
not(A) and B and C
A= not -t STDINB= ${$class . '::MESSAGE_HANDLER';}C= ref ${$class . '::MESSAGE_HANDLER';} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
3468 {
3469 0 my $h = ${ $class . '::MESSAGE_HANDLER' };
3470 0 $h->( $info );
3471 }
3472 # Or maybe then into a private log file?
3473 # This way, even if the log method is superseeded, we can keep using ours without interfering with the other one
3474 elsif( $self->_message_log( $mesg, "\n" ) )
3475 {
3476 0 return(1);
3477 }
3478 # Otherwise just on the stderr
3479 else
3480 {
3481 0 ▶ if( $opts->{no_encoding} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'no_encoding'}) { } 0 0 0
3482 {
3483 0 $stderr_raw->print( $mesg, "\n" );
3484 }
3485 else
3486 {
3487 0 $stderr->print( $mesg, "\n" );
3488 }
3489 }
3490 }
3491 101715 return(1);
3492 }
3493  
3494 sub _message_check
3495 224 ▶{
Subroutine _message_check: called CC=34 SCAR=57.5
3496 224 my $self = shift( @_ );
3497 224 ▶ my $class = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
22400
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
3498 224 my $this = $self->_obj2h;
3499 176 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
3500 176 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
3501 224 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 224 0 224
3502 {
3503 224 local $Module::Generic::TieHash::PAUSED = 1;
3504 224 ▶ if( $_[0] !~ /^\d/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[0] =~ /^\d/) 0 224 224
3505 {
3506 # The last parameter is an options parameter which has the level property set
3507 0 ▶ if( ref( $_[-1] ) eq 'HASH' && CORE::exists( $_[-1]->{level} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[-1] eq 'HASH' and exists $_[-1]{'level'}) { } 0 0 0
elsif ($this->{'_message_default_level'} =~ /^\d+$/ and $this->{'_message_default_level'} > 0) { } 0 0 0
Condition0%0/3
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
ref $_[-1] eq "HASH" exists $_[-1]{"level"}
Truth table0%0/3
A and B
A= ref $_[-1] eq "HASH"B= exists $_[-1]{"level"}
ABresult
0X0
100
111
3508 {
3509 # Then let's use this
3510 }
3511 ▶ elsif( $this->{_message_default_level} =~ /^\d+$/ &&
Condition0%0/3
$this->{"_message_default_level"} =~ /^\d+$/ and $this->{"_message_default_level"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$this->{"_message_default_level"} =~ /^\d+$/ and $this->{"_message_default_level"} > 0
$this->{"_message_default_level"} =~ /^\d+$/ $this->{"_message_default_level"} > 0
Truth table0%0/3
A and B
A= $this->{"_message_default_level"} =~ /^\d+$/B= $this->{"_message_default_level"} > 0
ABresult
0X0
100
111
3512 $this->{_message_default_level} > 0 )
3513 {
3514 0 unshift( @_, $this->{_message_default_level} );
3515 }
3516 else
3517 {
3518 0 unshift( @_, 1 );
3519 }
3520 }
3521 # If the first argument looks line a number, and there is more than 1 argument
3522 # and it is greater than 1, and greater than our current debug level
3523 # well, we do not output anything then...
3524 224 ▶ if( ( $_[0] =~ /^\d+$/ ||
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/ || ref $_[-1] eq "HASH" && exists $_[-1]{"level"} && $_[-1]{"level"} =~ /^\d+$/ and @_ > 1) 224 0 224
Condition16%2/12
$_[0] =~ /^\d+$/ || ref $_[-1] eq "HASH" && exists $_[-1]{"level"} && $_[-1]{"level"} =~ /^\d+$/ and @_ > 1
!ll&&!rl&&r
00224
$_[0] =~ /^\d+$/ or ref $_[-1] eq "HASH" and exists $_[-1]{"level"} and $_[-1]{"level"} =~ /^\d+$/
l!l&&r!l&&!r
22400
ref $_[-1] eq "HASH" and exists $_[-1]{"level"} and $_[-1]{"level"} =~ /^\d+$/
!ll&&!rl&&r
000
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
!ll&&!rl&&r
000
MC/DC0%0/5
$_[0] =~ /^\d+$/ || ref $_[-1] eq "HASH" && exists $_[-1]{"level"} && $_[-1]{"level"} =~ /^\d+$/ and @_ > 1
$_[0] =~ /^\d+$/ ref $_[-1] eq "HASH" exists $_[-1]{"level"} $_[-1]{"level"} =~ /^\d+$/ @_ > 1
Truth table14%1/7
A or B and C and D and E
A= $_[0] =~ /^\d+$/B= ref $_[-1] eq "HASH"C= exists $_[-1]{"level"}D= $_[-1]{"level"} =~ /^\d+$/E= @_ > 1
ABCDEresult
00XXX0
010XX0
0110X0
1XXX00
011100
1XXX11
011111
3525 ( ref( $_[-1] ) eq 'HASH' &&
3526 CORE::exists( $_[-1]->{level} ) &&
3527 $_[-1]->{level} =~ /^\d+$/
3528 )
3529 ) && @_ > 1 )
3530 {
3531 224 my $message_level = 0;
3532 224 ▶ if( $_[0] =~ /^\d+$/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/) { } 224 0 224
elsif (ref $_[-1] eq 'HASH' and exists $_[-1]{'level'}) { } 0 0 0
3533 {
3534 224 $message_level = shift( @_ );
3535 }
3536 ▶ elsif( ref( $_[-1] ) eq 'HASH' && CORE::exists( $_[-1]->{level} ) )
Condition0%0/3
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
ref $_[-1] eq "HASH" exists $_[-1]{"level"}
Truth table0%0/3
A and B
A= ref $_[-1] eq "HASH"B= exists $_[-1]{"level"}
ABresult
0X0
100
111
3537 {
3538 0 $message_level = $_[-1]->{level};
3539 }
3540 224 my $target_re = '';
3541 224 ▶ if( ref( ${ "${class}::DEBUG_TARGET" } ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref ${"${class}::DEBUG_TARGET";} eq "ARRAY") 0 224 224
3542 {
3543 0 ▶ $target_re = scalar( @${ "${class}::DEBUG_TARGET" } ) ? join( '|', @${ "${class}::DEBUG_TARGET" } ) : '';
Branch: 1 branch
BranchTrueFalseTotal
scalar @${"${class}::DEBUG_TARGET";} ? : 0 0 0
3544 }
3545 224 ▶ if( ( exists( $this->{debug} ) && int( $this->{debug} ) >= $message_level ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (exists $this->{'debug'} and int $this->{'debug'} >= $message_level or exists $this->{'verbose'} and int $this->{'verbose'} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or ref $_[-1] eq 'HASH' and exists $_[-1]{'debug'} and defined $_[-1]{'debug'} and $_[-1]{'debug'} >= $message_level or exists $this->{'debug_level'} and int $this->{'debug_level'} >= $message_level or int $this->{'debug'} >= 100 or length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level) { } 0 224 224
Condition33%9/27
exists $this->{"debug"} and int $this->{"debug"} >= $message_level or exists $this->{"verbose"} and int $this->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and defined $_[-1]{"debug"} and $_[-1]{"debug"} >= $message_level or exists $this->{"debug_level"} and int $this->{"debug_level"} >= $message_level or int $this->{"debug"} >= 100 or length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
l!l&&r!l&&!r
00224
exists $this->{"debug"} and int $this->{"debug"} >= $message_level or exists $this->{"verbose"} and int $this->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and defined $_[-1]{"debug"} and $_[-1]{"debug"} >= $message_level or exists $this->{"debug_level"} and int $this->{"debug_level"} >= $message_level or int $this->{"debug"} >= 100
l!l&&r!l&&!r
00224
exists $this->{"debug"} and int $this->{"debug"} >= $message_level or exists $this->{"verbose"} and int $this->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and defined $_[-1]{"debug"} and $_[-1]{"debug"} >= $message_level or exists $this->{"debug_level"} and int $this->{"debug_level"} >= $message_level
l!l&&r!l&&!r
00224
exists $this->{"debug"} and int $this->{"debug"} >= $message_level or exists $this->{"verbose"} and int $this->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and defined $_[-1]{"debug"} and $_[-1]{"debug"} >= $message_level
l!l&&r!l&&!r
00224
exists $this->{"debug"} and int $this->{"debug"} >= $message_level or exists $this->{"verbose"} and int $this->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level
l!l&&r!l&&!r
00224
exists $this->{"debug"} and int $this->{"debug"} >= $message_level or exists $this->{"verbose"} and int $this->{"verbose"} >= $message_level
l!l&&r!l&&!r
00224
exists $this->{"debug"} and int $this->{"debug"} >= $message_level
!ll&&!rl&&r
02240
exists $this->{"verbose"} and int $this->{"verbose"} >= $message_level
!ll&&!rl&&r
22400
defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level
!ll&&!rl&&r
22400
MC/DC0%0/10
exists $this->{"debug"} and int $this->{"debug"} >= $message_level or exists $this->{"verbose"} and int $this->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and defined $_[-1]{"debug"} and $_[-1]{"debug"} >= $message_level or exists $this->{"debug_level"} and int $this->{"debug_level"} >= $message_level or int $this->{"debug"} >= 100 or length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
exists $this->{"debug"} int $this->{"debug"} >= $message_level exists $this->{"verbose"} int $this->{"verbose"} >= $message_level defined ${$class . '::DEBUG';} ${$class . '::DEBUG';} >= $message_level ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and defined $_[-1]{"debug"} and $_[-1]{"debug"} >= $message_level exists $this->{"debug_level"} and int $this->{"debug_level"} >= $message_level int $this->{"debug"} >= 100 length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
Truth table0%0/47
A and B or C and D or E and F or G or H or I or J
A= exists $this->{"debug"}B= int $this->{"debug"} >= $message_levelC= exists $this->{"verbose"}D= int $this->{"verbose"} >= $message_levelE= defined ${$class . '::DEBUG';}F= ${$class . '::DEBUG';} >= $message_levelG= ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and defined $_[-1]{"debug"} and $_[-1]{"debug"} >= $message_levelH= exists $this->{"debug_level"} and int $this->{"debug_level"} >= $message_levelI= int $this->{"debug"} >= 100J= length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
ABCDEFGHIJresult
11XXXXXXXX1
0X11XXXXXX1
1011XXXXXX1
0X0X11XXXX1
0X1011XXXX1
100X11XXXX1
101011XXXX1
0X0X0X1XXX1
0X0X101XXX1
0X100X1XXX1
0X10101XXX1
100X0X1XXX1
100X101XXX1
10100X1XXX1
1010101XXX1
0X0X0X01XX1
0X0X1001XX1
0X100X01XX1
0X101001XX1
100X0X01XX1
100X1001XX1
10100X01XX1
10101001XX1
0X0X0X001X1
0X0X10001X1
0X100X001X1
0X1010001X1
100X0X001X1
100X10001X1
10100X001X1
101010001X1
0X0X0X00011
0X0X1000011
0X100X00011
0X101000011
100X0X00011
100X1000011
10100X00011
10101000011
0X0X0X00000
0X0X1000000
0X100X00000
0X101000000
100X0X00000
100X1000000
10100X00000
10101000000
3546 ( exists( $this->{verbose} ) && int( $this->{verbose} ) >= $message_level ) ||
3547 0 ▶ ( defined( ${ $class . '::DEBUG' } ) && ${ $class . '::DEBUG' } >= $message_level ) ||
Condition33%6/18
ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and defined $_[-1]{"debug"} and $_[-1]{"debug"} >= $message_level
!ll&&!rl&&r
22400
ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and defined $_[-1]{"debug"}
!ll&&!rl&&r
22400
ref $_[-1] eq "HASH" and exists $_[-1]{"debug"}
!ll&&!rl&&r
22400
exists $this->{"debug_level"} and int $this->{"debug_level"} >= $message_level
!ll&&!rl&&r
02240
length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
!ll&&!rl&&r
22400
length $target_re and $class =~ /^$target_re$/
!ll&&!rl&&r
22400
MC/DC0%0/4
ref $_[-1] eq "HASH" and exists $_[-1]{"debug"} and defined $_[-1]{"debug"} and $_[-1]{"debug"} >= $message_level
ref $_[-1] eq "HASH" exists $_[-1]{"debug"} defined $_[-1]{"debug"} $_[-1]{"debug"} >= $message_level
MC/DC0%0/2
exists $this->{"debug_level"} and int $this->{"debug_level"} >= $message_level
exists $this->{"debug_level"} int $this->{"debug_level"} >= $message_level
MC/DC0%0/3
length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
length $target_re $class =~ /^$target_re$/ ${$class . '::GLOBAL_DEBUG';} >= $message_level
Truth table0%0/5
A and B and C and D
A= ref $_[-1] eq "HASH"B= exists $_[-1]{"debug"}C= defined $_[-1]{"debug"}D= $_[-1]{"debug"} >= $message_level
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table33%1/3
A and B
A= exists $this->{"debug_level"}B= int $this->{"debug_level"} >= $message_level
ABresult
0X0
100
111
Truth table0%0/4
A and B and C
A= length $target_reB= $class =~ /^$target_re$/C= ${$class . '::GLOBAL_DEBUG';} >= $message_level
ABCresult
0XX0
10X0
1100
1111
3548 ( ref( $_[-1] ) eq 'HASH' && CORE::exists( $_[-1]->{debug} ) && defined( $_[-1]->{debug} ) && $_[-1]->{debug} >= $message_level ) ||
3549 ( exists( $this->{debug_level} ) && int( $this->{debug_level} ) >= $message_level ) ||
3550 int( $this->{debug} ) >= 100 ||
3551 0 ( length( $target_re ) && $class =~ /^$target_re$/ && ${ $class . '::GLOBAL_DEBUG' } >= $message_level ) )
3552 {
3553 0 return( [ @_ ] );
3554 }
3555 else
3556 {
3557 224 return(0);
3558 }
3559 }
3560 }
3561 0 return(0);
3562 }
3563  
3564 sub _message_frame
3565 0 ▶{
Subroutine _message_frame: not called CC=8 SCAR=42.8
3566 0 my $self = shift( @_ );
3567 0 my $this = $self->_obj2h;
3568 0 my $mf;
3569 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
3570 {
3571 0 ▶ $this->{_message_frame } = {} if( !exists( $this->{_message_frame} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $this->{"_message_frame"} 0 0 0
3572 0 $mf = $this->{_message_frame};
3573 0 my $args = {};
3574 0 ▶ if( ref( $_[0] ) eq 'HASH' )
Branch: 3 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
elsif (not @_ % 2) { } 0 0 0
elsif (scalar @_ == 1) { } 0 0 0
3575 {
3576 0 $args = shift( @_ );
3577 0 my @k = keys( %$args );
3578 0 @$mf{ @k } = @$args{ @k };
3579 }
3580 elsif( !( @_ % 2 ) )
3581 {
3582 0 $args = { @_ };
3583 0 my @k = keys( %$args );
3584 0 @$mf{ @k } = @$args{ @k };
3585 }
3586 elsif( scalar( @_ ) == 1 )
3587 {
3588 0 my $sub = shift( @_ );
3589 0 ▶ $sub = substr( $sub, rindex( $sub, '::' ) + 2 ) if( index( $sub, '::' ) != -1 );
Branch: 1 branch
BranchTrueFalseTotal
if (index($sub, "::") != -1) 0 0 0
3590 0 return( $mf->{ $sub } );
3591 }
3592 else
3593 {
3594 0 return( $self->error( "I was expecting a key => value pair such as routine => stack frame (integer)" ) );
3595 }
3596 }
3597 0 ▶ return( $mf // {} );
Condition0%0/2
$mf // {}
l!l
00
MC/DC0%0/1
$mf // {}
$mf
Truth table0%0/2
A
A= $mf
Aresult
11
00
3598 }
3599  
3600 sub _message_log
3601 0 ▶{
Subroutine _message_log: not called CC=6 SCAR=37.4
3602 0 my $self = shift( @_ );
3603 0 my $io = $self->_message_log_io;
3604 0 ▶ return if( !$io );
Branch: 1 branch
BranchTrueFalseTotal
unless $io 0 0 0
3605 0 ▶ return if( !Scalar::Util::openhandle( $io ) && $io );
Branch: 1 branch
BranchTrueFalseTotal
if not &Scalar::Util::openhandle($io) and $io 0 0 0
Condition0%0/3
not &Scalar::Util::openhandle($io) and $io
!ll&&!rl&&r
000
MC/DC0%0/2
not &Scalar::Util::openhandle($io) and $io
not &Scalar::Util::openhandle($io) $io
Truth table0%0/3
not(A) and B
A= not &Scalar::Util::openhandle($io)B= $io
ABresult
0X0
100
111
3606 0 ▶ my $repo = Module::Generic::Global->new( 'debug_log_io' => ( ref( $self ) || $self ) );
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
3607 0 $repo->lock;
3608  
3609 # 2019-06-14: I decided to remove this test, because if a log is provided it should print to it
3610 # If we are on the command line, we can easily just do tail -f log_file.txt for example and get the same result as
3611 # if it were printed directly on the console
3612 0 ▶ my $rc = $io->print( scalar( localtime( time() ) ), " [$$]: ", @_ ) ||
Condition0%0/2
$io->print(scalar localtime time, " [${$}]: ", @_) || (return $self->error("Unable to print to log file: $!"))
l!l
00
MC/DC0%0/1
$io->print(scalar localtime time, " [${$}]: ", @_) || (return $self->error("Unable to print to log file: $!"))
$io->print(scalar localtime time, " [${$}]: ", @_)
Truth table0%0/2
A
A= $io->print(scalar localtime time, " [${$}]: ", @_)
Aresult
11
00
3613 return( $self->error( "Unable to print to log file: $!" ) );
3614 0 return( $rc );
3615 }
3616  
3617 sub _message_log_io
3618 0 ▶{
Subroutine _message_log_io: not called CC=10 SCAR=45.1
3619 #return( shift->_set_get( 'log_io', @_ ) );
3620 0 my $self = shift( @_ );
3621 0 ▶ my $class = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
3622 0 my $this = $self->_obj2h;
3623 33 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
3624 0 ▶ if( @_ )
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 0 0 0
elsif (${"${class}::LOG_DEBUG";} and not $self->_set_get('log_io') and ${"${class}::DEB_LOG";}) { } 0 0 0
3625 {
3626 0 my $io = shift( @_ );
3627 0 $self->_set_get( 'log_io', $io );
3628 }
3629 0 ▶ elsif( ${ "${class}::LOG_DEBUG" } &&
Condition0%0/6
${"${class}::LOG_DEBUG";} and not $self->_set_get("log_io") and ${"${class}::DEB_LOG";}
!ll&&!rl&&r
000
${"${class}::LOG_DEBUG";} and not $self->_set_get("log_io")
!ll&&!rl&&r
000
MC/DC0%0/3
${"${class}::LOG_DEBUG";} and not $self->_set_get("log_io") and ${"${class}::DEB_LOG";}
${"${class}::LOG_DEBUG";} not $self->_set_get("log_io") ${"${class}::DEB_LOG";}
Truth table0%0/4
A and not(B) and C
A= ${"${class}::LOG_DEBUG";}B= not $self->_set_get("log_io")C= ${"${class}::DEB_LOG";}
ABCresult
0XX0
10X0
1100
1111
3630 !$self->_set_get( 'log_io' ) &&
3631 0 ${ "${class}::DEB_LOG" } )
3632 {
3633 0 our $DEB_LOG = ${ "${class}::DEB_LOG" };
3634 0 ▶ my $repo = Module::Generic::Global->new( 'debug_log_io' => ( ref( $self ) || $self ) );
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
3635 0 $repo->lock;
3636  
3637 0 ▶ unless( $DEBUG_LOG_IO )
Branch: 1 branch
BranchTrueFalseTotal
unless ($DEBUG_LOG_IO) 0 0 0
3638 {
3639 0 ▶ $self->_load_class( 'Module::Generic::File' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::File") or return $self->pass_error 0 0 0
3640 0 $DEB_LOG = Module::Generic::File::file( $DEB_LOG );
3641 0 ▶ $DEBUG_LOG_IO = $DEB_LOG->open( '>>', { binmode => 'utf-8', autoflush => 1 }) ||
Condition0%0/2
$DEB_LOG->open('>>', {'binmode', 'utf-8', 'autoflush', 1}) || die("Unable to open debug log file $DEB_LOG in append mode: $!\n")
l!l
00
MC/DC0%0/1
$DEB_LOG->open('>>', {'binmode', 'utf-8', 'autoflush', 1}) || die("Unable to open debug log file $DEB_LOG in append mode: $!\n")
$DEB_LOG->open('>>', {'binmode', 'utf-8', 'autoflush', 1})
Truth table0%0/2
A
A= $DEB_LOG->open('>>', {'binmode', 'utf-8', 'autoflush', 1})
Aresult
11
00
3642 die( "Unable to open debug log file $DEB_LOG in append mode: $!\n" );
3643 }
3644 0 $repo->unlock;
3645 0 $self->_set_get( 'log_io', $DEBUG_LOG_IO );
3646 }
3647 0 return( $self->_set_get( 'log_io' ) );
3648 }
3649  
3650 sub __messagef
3651 0 ▶{
Subroutine __messagef: not called CC=22 SCAR=61.2
3652 0 my $self = shift( @_ );
3653 0 ▶ my $class = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
3654 0 my $this = $self->_obj2h;
3655 36 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
3656 0 ▶ if( $this->{verbose} || $this->{debug} || ${ $class . '::DEBUG' } )
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"verbose"} or $this->{"debug"} or ${$class . '::DEBUG';}) 0 0 0
Condition0%0/6
$this->{"verbose"} or $this->{"debug"} or ${$class . '::DEBUG';}
l!l&&r!l&&!r
000
$this->{"verbose"} or $this->{"debug"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$this->{"verbose"} or $this->{"debug"} or ${$class . '::DEBUG';}
$this->{"verbose"} $this->{"debug"} ${$class . '::DEBUG';}
Truth table0%0/4
A or B or C
A= $this->{"verbose"}B= $this->{"debug"}C= ${$class . '::DEBUG';}
ABCresult
1XX1
01X1
0011
0000
3657 {
3658 0 ▶ my $level = ( $_[0] =~ /^\d+$/ ? shift( @_ ) : undef() );
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^\d+$/ ? : 0 0 0
3659 0 my $opts = {};
3660 0 ▶ if( scalar( @_ ) > 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1 and ref $_[-1] eq "HASH" and exists $_[-1]{"level"} || exists $_[-1]{"type"} || exists $_[-1]{"message"} || exists $_[-1]{"colour"}) 0 0 0
Condition0%0/15
scalar @_ > 1 and ref $_[-1] eq "HASH" and exists $_[-1]{"level"} || exists $_[-1]{"type"} || exists $_[-1]{"message"} || exists $_[-1]{"colour"}
!ll&&!rl&&r
000
scalar @_ > 1 and ref $_[-1] eq "HASH"
!ll&&!rl&&r
000
exists $_[-1]{"level"} or exists $_[-1]{"type"} or exists $_[-1]{"message"} or exists $_[-1]{"colour"}
l!l&&r!l&&!r
000
exists $_[-1]{"level"} or exists $_[-1]{"type"} or exists $_[-1]{"message"}
l!l&&r!l&&!r
000
exists $_[-1]{"level"} or exists $_[-1]{"type"}
l!l&&r!l&&!r
000
MC/DC0%0/6
scalar @_ > 1 and ref $_[-1] eq "HASH" and exists $_[-1]{"level"} || exists $_[-1]{"type"} || exists $_[-1]{"message"} || exists $_[-1]{"colour"}
scalar @_ > 1 ref $_[-1] eq "HASH" exists $_[-1]{"level"} exists $_[-1]{"type"} exists $_[-1]{"message"} exists $_[-1]{"colour"}
Truth table0%0/7
A and B and C or D or E or F
A= scalar @_ > 1B= ref $_[-1] eq "HASH"C= exists $_[-1]{"level"}D= exists $_[-1]{"type"}E= exists $_[-1]{"message"}F= exists $_[-1]{"colour"}
ABCDEFresult
0XXXXX0
10XXXX0
1100000
111XXX1
1101XX1
11001X1
1100011
3661 ref( $_[-1] ) eq 'HASH' &&
3662 (
3663 CORE::exists( $_[-1]->{level} ) ||
3664 CORE::exists( $_[-1]->{type} ) ||
3665 CORE::exists( $_[-1]->{message} ) ||
3666 CORE::exists( $_[-1]->{colour} )
3667 ) )
3668 {
3669 0 $opts = pop( @_ );
3670 }
3671 0 ▶ $level = $opts->{level} if( !defined( $level ) && CORE::exists( $opts->{level} ) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $level and exists $opts->{"level"} 0 0 0
Condition0%0/3
not defined $level and exists $opts->{"level"}
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $level and exists $opts->{"level"}
not defined $level exists $opts->{"level"}
Truth table0%0/3
not(A) and B
A= not defined $levelB= exists $opts->{"level"}
ABresult
0X0
100
111
3672 0 my( $ref, $fmt );
3673 0 ▶ if( $opts->{message} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'message'}) { } 0 0 0
3674 {
3675 0 ▶ if( ref( $opts->{message} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts->{'message'} eq 'ARRAY') { } 0 0 0
3676 {
3677 0 $ref = $opts->{message};
3678 0 $fmt = shift( @$ref );
3679 }
3680 else
3681 {
3682 0 $fmt = $opts->{message};
3683 0 $ref = \@_;
3684 }
3685 }
3686 else
3687 {
3688 0 $ref = \@_;
3689 0 $fmt = shift( @$ref );
3690 }
3691 0 ▶ my $txt = sprintf( $fmt, map( ( ref( $_ ) eq 'CODE' && !$this->{_msg_no_exec_sub} ) ? $_->() : $_, @$ref ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' && !$this->{'_msg_no_exec_sub'} ? : 0 0 0
Condition0%0/3
ref $_ eq "CODE" and not $this->{"_msg_no_exec_sub"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ eq "CODE" and not $this->{"_msg_no_exec_sub"}
ref $_ eq "CODE" not $this->{"_msg_no_exec_sub"}
Truth table0%0/3
A and not(B)
A= ref $_ eq "CODE"B= not $this->{"_msg_no_exec_sub"}
ABresult
0X0
100
111
3692 0 ▶ $txt = $self->colour_parse( $txt ) if( $opts->{colour} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"colour"} 0 0 0
3693 0 $opts->{message} = $txt;
3694 0 ▶ $opts->{skip_frames} = 1 unless( exists( $opts->{skip_frames} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"skip_frames"} 0 0 0
3695 0 ▶ $opts->{level} = $level if( defined( $level ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $level 0 0 0
3696 0 ▶ return( $self->__message( ( $level || 0 ), $opts ) );
Condition0%0/2
$level || 0
l!l
00
MC/DC0%0/1
$level || 0
$level
Truth table0%0/2
A
A= $level
Aresult
11
00
3697 }
3698 0 return(1);
3699 }
3700  
3701 sub _set_get
3702 321 ▶{
Subroutine _set_get: called CC=30 SCAR=60.8
3703 321 my $self = shift( @_ );
3704 321 my $field = shift( @_ );
3705 321 my $this = $self->_obj2h;
3706 321 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 321 321
3707  
3708 321 my $callbacks = {};
3709 321 my $check;
3710 321 my $def = {};
3711 321 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 321 321
3712 {
3713 0 $def = $field;
3714 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
3715 defined( $def->{field} ) &&
3716 CORE::length( $def->{field} ) )
3717 {
3718 0 $field = $def->{field};
3719 }
3720 else
3721 {
3722 0 return( $self->error( "No field name was provided." ) );
3723 }
3724 # Should have been 'callbacks', but we catch it anyway.
3725 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
3726 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
3727 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
3728 }
3729  
3730 321 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 56 265 321
3731 {
3732 56 ▶ my $val = ( @_ == 1 ) ? shift( @_ ) : [ @_ ];
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 56 0 56
3733 56 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 56 56
3734 {
3735 # try-catch
3736 0 local $@;
3737 0 my $rv = eval{ $check->( $self, $val ) };
3738 0 ▶ 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
3739 {
3740 0 return( $self->pass_error );
3741 }
3742 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
3743 }
3744 56 $data->{ $field } = $val;
3745 56 $self->clear_error;
3746 56 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 56 56
Condition16%1/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
5600
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table25%1/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
3747 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
3748 {
3749 0 my $coderef;
3750 0 foreach my $t ( qw( add set ) )
3751 {
3752 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
3753 {
3754 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
3755 ? $callbacks->{ $t }
3756 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
3757 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
3758 }
3759 }
3760 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
3761 {
3762 0 $coderef->( $self, $data->{ $field } );
3763 }
3764 }
3765 }
3766 321 ▶ if( wantarray() )
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 321 321
3767 {
3768 0 ▶ if( ref( $data->{ $field } ) eq 'ARRAY' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data->{$field} eq 'ARRAY') { } 0 0 0
elsif (ref $data->{$field} eq 'HASH') { } 0 0 0
3769 {
3770 0 return( @{ $data->{ $field } } );
3771 }
3772 elsif( ref( $data->{ $field } ) eq 'HASH' )
3773 {
3774 0 return( %{ $data->{ $field } } );
3775 }
3776 else
3777 {
3778 0 return( ( $data->{ $field } ) );
3779 }
3780 }
3781 else
3782 {
3783 321 return( $data->{ $field } );
3784 }
3785 }
3786  
3787 sub _set_get_array
3788 2 ▶{
Subroutine _set_get_array: called CC=35 SCAR=64.3
3789 2 my $self = shift( @_ );
3790 2 my $field = shift( @_ );
3791 2 my $this = $self->_obj2h;
3792 2 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 2 2
3793  
3794 2 my $callbacks = {};
3795 2 my $check;
3796 2 my $def = {};
3797 2 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 2 2
3798 {
3799 0 $def = $field;
3800 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
3801 defined( $def->{field} ) &&
3802 CORE::length( $def->{field} ) )
3803 {
3804 0 $field = $def->{field};
3805 }
3806 else
3807 {
3808 0 return( $self->error( "No field name was provided." ) )
3809 }
3810 # Should have been 'callbacks', but we catch it anyway.
3811 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
3812 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
3813 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
3814 }
3815  
3816 2 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
3817 {
3818 1 ▶ my $val = ( @_ == 1 && ( ( Scalar::Util::blessed( $_[0] ) && $_[0]->isa( 'ARRAY' ) ) || ref( $_[0] ) eq 'ARRAY' ) ) ? shift( @_ ) : [ @_ ];
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && (builtin::blessed($_[0]) && $_[0]->isa('ARRAY') || ref $_[0] eq 'ARRAY') ? : 0 1 1
Condition11%1/9
@_ == 1 and builtin::blessed($_[0]) && $_[0]->isa("ARRAY") || ref $_[0] eq "ARRAY"
!ll&&!rl&&r
100
builtin::blessed($_[0]) and $_[0]->isa("ARRAY") or ref $_[0] eq "ARRAY"
l!l&&r!l&&!r
000
builtin::blessed($_[0]) and $_[0]->isa("ARRAY")
!ll&&!rl&&r
000
MC/DC0%0/4
@_ == 1 and builtin::blessed($_[0]) && $_[0]->isa("ARRAY") || ref $_[0] eq "ARRAY"
@_ == 1 builtin::blessed($_[0]) $_[0]->isa("ARRAY") ref $_[0] eq "ARRAY"
Truth table16%1/6
A and B and C or D
A= @_ == 1B= builtin::blessed($_[0])C= $_[0]->isa("ARRAY")D= ref $_[0] eq "ARRAY"
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
3819 1 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 1 1
3820 {
3821 # try-catch
3822 0 local $@;
3823 0 my $rv = eval{ $check->( $self, $val ) };
3824 0 ▶ 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
3825 {
3826 0 return( $self->pass_error );
3827 }
3828 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
3829 }
3830 1 ▶ if( !defined( $data->{ $field } ) && want( 'ARRAY' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $data->{$field} and want("ARRAY")) 0 1 1
Condition33%1/3
not defined $data->{$field} and want("ARRAY")
!ll&&!rl&&r
010
MC/DC0%0/2
not defined $data->{$field} and want("ARRAY")
not defined $data->{$field} want("ARRAY")
Truth table33%1/3
not(A) and B
A= not defined $data->{$field}B= want("ARRAY")
ABresult
0X0
100
111
3831 {
3832 # The call context is an array reference.
3833 # To avoid the perl of 'Not an ARRAY reference', we return an empty array
3834 0 return( [] );
3835 }
3836 1 $data->{ $field } = $val;
3837 1 $self->clear_error;
3838 1 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 1 1
Condition16%1/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
100
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table25%1/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
3839 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
3840 {
3841 0 my $coderef;
3842 0 foreach my $t ( qw( add set ) )
3843 {
3844 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
3845 {
3846 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
3847 ? $callbacks->{ $t }
3848 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
3849 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
3850 }
3851 }
3852 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
3853 {
3854 # try-catch
3855 0 local $@;
3856 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
3857 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
3858 {
3859 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
3860 }
3861 ▶ elsif( !defined( $rv ) && $self->error )
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
3862 {
3863 0 return( $self->pass_error );
3864 }
3865 0 $data->{ $field } = $rv;
3866 }
3867 }
3868 }
3869 2 return( $data->{ $field } );
3870 }
3871  
3872 118 ▶sub _set_get_array_as_object : lvalue
Subroutine _set_get_array_as_object: called CC=13 SCAR=40.4
3873 {
3874 118 my $self = shift( @_ );
3875 118 my $field = shift( @_ );
3876 118 my $this = $self->_obj2h;
3877 118 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 9 109 118
3878 # {
3879  
3880 118 my $callbacks = {};
3881 118 my $check;
3882 118 my $def = {};
3883 # If this is set to true, this method will return a list in list context
3884 118 ▶ $def->{wantlist} //= 0;
Condition50%1/2
$def->{"wantlist"} //= 0
l!l
0118
MC/DC0%0/1
$def->{"wantlist"} //= 0
$def->{"wantlist"}
Truth table50%1/2
A
A= $def->{"wantlist"}
Aresult
11
00
3885 118 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 118 118
3886 {
3887 0 $def = $field;
3888 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
3889 defined( $def->{field} ) &&
3890 CORE::length( $def->{field} ) )
3891 {
3892 0 $field = $def->{field};
3893 }
3894 else
3895 {
3896 0 $field = undef;
3897 }
3898 # Should have been 'callbacks', but we catch it anyway.
3899 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
3900 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
3901 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
3902 }
3903  
3904 return( $self->_set_get_callback({
3905 get => sub
3906 91 ▶ {
Subroutine __ANON__: called CC=20 SCAR=45.3
3907 91 my $self = shift( @_ );
3908 91 my $ctx = $_;
3909 91 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 91 91
3910 91 ▶ if( !$data->{ $field } || !$self->_is_object( $data->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($data->{$field} and $self->_is_object($data->{$field})) 16 75 91
Condition66%2/3
$data->{$field} and $self->_is_object($data->{$field})
!ll&&!rl&&r
01675
MC/DC50%1/2
$data->{$field} and $self->_is_object($data->{$field})
$data->{$field} $self->_is_object($data->{$field})
Truth table66%2/3
A and B
A= $data->{$field}B= $self->_is_object($data->{$field})
ABresult
0X0
100
111
3911 {
3912 16 ▶ $self->_load_class( 'Module::Generic::Array' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Array") or return $self->pass_error 16 0 16
3913 16 ▶ my $o = Module::Generic::Array->new( ( defined( $data->{ $field } ) && CORE::length( $data->{ $field } ) ) ? $data->{ $field } : [] );
Branch: 1 branch
BranchTrueFalseTotal
defined $data->{$field} && length $data->{$field} ? : 16 0 16
Condition33%1/3
defined $data->{$field} and length $data->{$field}
!ll&&!rl&&r
0016
MC/DC0%0/2
defined $data->{$field} and length $data->{$field}
defined $data->{$field} length $data->{$field}
Truth table33%1/3
A and B
A= defined $data->{$field}B= length $data->{$field}
ABresult
0X0
100
111
3914 16 $data->{ $field } = $o;
3915 16 ▶ if( scalar( keys( %$callbacks ) ) && !$o->has_callback )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and not $o->has_callback) 0 16 16
Condition33%1/3
scalar keys %$callbacks and not $o->has_callback
!ll&&!rl&&r
1600
MC/DC0%0/2
scalar keys %$callbacks and not $o->has_callback
scalar keys %$callbacks not $o->has_callback
Truth table33%1/3
A and not(B)
A= scalar keys %$callbacksB= not $o->has_callback
ABresult
0X0
100
111
3916 {
3917 0 foreach my $t ( qw( add remove ) )
3918 {
3919 0 ▶ if( CORE::exists( $callbacks->{ "array_${t}" } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$callbacks{"array_$t"} and defined $$callbacks{"array_$t"}) 0 0 0
Condition0%0/3
exists $$callbacks{"array_$t"} and defined $$callbacks{"array_$t"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $$callbacks{"array_$t"} and defined $$callbacks{"array_$t"}
exists $$callbacks{"array_$t"} defined $$callbacks{"array_$t"}
Truth table0%0/3
A and B
A= exists $$callbacks{"array_$t"}B= defined $$callbacks{"array_$t"}
ABresult
0X0
100
111
3920 defined( $callbacks->{ "array_${t}" } ) )
3921 {
3922 my $coderef = ref( $callbacks->{ "array_${t}" } ) eq 'CODE'
3923 ? $callbacks->{ "array_${t}" }
3924 0 ▶ : $self->can( $callbacks->{ "array_${t}" } );
Branch: 1 branch
BranchTrueFalseTotal
ref $$callbacks{"array_$t"} eq 'CODE' ? : 0 0 0
3925 0 ▶ if( defined( $coderef ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef) 0 0 0
3926 {
3927 0 $o->callback( $t => $coderef );
3928 }
3929 }
3930 }
3931 }
3932 }
3933 # If we are required to weaken the reference, and this is an object, and it is not already weakened, then we weaken it now.
3934 91 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 91 91
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
9100
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
9100
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
3935  
3936 91 ▶ if( $def->{wantlist} && $ctx->{list} )
Branch: 1 branch
BranchTrueFalseTotal
if ($def->{'wantlist'} and $ctx->{'list'}) { } 0 91 91
Condition33%1/3
$def->{"wantlist"} and $ctx->{"list"}
!ll&&!rl&&r
9100
MC/DC0%0/2
$def->{"wantlist"} and $ctx->{"list"}
$def->{"wantlist"} $ctx->{"list"}
Truth table33%1/3
A and B
A= $def->{"wantlist"}B= $ctx->{"list"}
ABresult
0X0
100
111
3937 {
3938 0 ▶ return( $data->{ $field } ? $data->{ $field }->list : () );
Branch: 1 branch
BranchTrueFalseTotal
$data->{$field} ? : 0 0 0
3939 }
3940 else
3941 {
3942 91 return( $data->{ $field } );
3943 }
3944 },
3945 set => sub
3946 28 ▶ {
Subroutine __ANON__: called CC=45 SCAR=63.8
3947 28 my $self = shift( @_ );
3948 28 my $ctx = $_;
3949 28 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 28 28
3950 28 ▶ my $val = ( @_ == 1 && ( ( Scalar::Util::blessed( $_[0] ) && $_[0]->isa( 'ARRAY' ) ) || ref( $_[0] ) eq 'ARRAY' ) ) ? shift( @_ ) : [ @_ ];
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && (builtin::blessed($_[0]) && $_[0]->isa('ARRAY') || ref $_[0] eq 'ARRAY') ? : 28 0 28
Condition55%5/9
@_ == 1 and builtin::blessed($_[0]) && $_[0]->isa("ARRAY") || ref $_[0] eq "ARRAY"
!ll&&!rl&&r
0028
builtin::blessed($_[0]) and $_[0]->isa("ARRAY") or ref $_[0] eq "ARRAY"
l!l&&r!l&&!r
1270
builtin::blessed($_[0]) and $_[0]->isa("ARRAY")
!ll&&!rl&&r
2701
MC/DC0%0/4
@_ == 1 and builtin::blessed($_[0]) && $_[0]->isa("ARRAY") || ref $_[0] eq "ARRAY"
@_ == 1 builtin::blessed($_[0]) $_[0]->isa("ARRAY") ref $_[0] eq "ARRAY"
Truth table33%2/6
A and B and C or D
A= @_ == 1B= builtin::blessed($_[0])C= $_[0]->isa("ARRAY")D= ref $_[0] eq "ARRAY"
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
3951 28 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 28 28
3952 {
3953 # try-catch
3954 0 local $@;
3955 0 my $rv = eval{ $check->( $self, $val ) };
3956 0 ▶ 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
3957 {
3958 0 return( $self->pass_error );
3959 }
3960 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
3961 }
3962 28 ▶ $self->_load_class( 'Module::Generic::Array' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Array") or return $self->pass_error 28 0 28
3963 28 my $o = $data->{ $field };
3964 # Some existing data, like maybe default value
3965 28 ▶ if( $o )
Branch: 1 branch
BranchTrueFalseTotal
if ($o) { } 13 15 28
3966 {
3967 13 ▶ if( !$self->_is_object( $o ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_object($o)) 11 2 13
3968 {
3969 11 my $tmp = $o;
3970 11 $o = Module::Generic::Array->new( $tmp );
3971 }
3972 13 $o->set( $val );
3973 }
3974 else
3975 {
3976 15 $o = Module::Generic::Array->new( $val );
3977 15 $data->{ $field } = $o;
3978 }
3979  
3980 28 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 28 28
Condition16%1/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
2800
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table25%1/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
3981 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
3982 {
3983 0 my $coderef;
3984 0 foreach my $t ( qw( add set ) )
3985 {
3986 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
3987 {
3988 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
3989 ? $callbacks->{ $t }
3990 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
3991 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
3992 }
3993 }
3994 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
3995 {
3996 # try-catch
3997 0 local $@;
3998 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
3999 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
4000 {
4001 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
4002 }
4003 ▶ elsif( !defined( $rv ) && $self->error )
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
4004 {
4005 0 return( $self->pass_error );
4006 }
4007 0 $data->{ $field } = $rv;
4008 }
4009 }
4010  
4011 28 ▶ if( !$data->{ $field } ||
Branch: 1 branch
BranchTrueFalseTotal
if (not $data->{$field} && $self->_is_object($data->{$field}) or $self->_is_object($data->{$field}) and ref $data->{$field} ne ref $self) 28 0 28
Condition33%3/9
not $data->{$field} && $self->_is_object($data->{$field}) or $self->_is_object($data->{$field}) and ref $data->{$field} ne ref $self
l!l&&r!l&&!r
0280
$data->{$field} && $self->_is_object($data->{$field})
!ll&&!rl&&r
0028
$self->_is_object($data->{$field}) and ref $data->{$field} ne ref $self
!ll&&!rl&&r
0028
MC/DC0%0/4
not $data->{$field} && $self->_is_object($data->{$field}) or $self->_is_object($data->{$field}) and ref $data->{$field} ne ref $self
$data->{$field} $self->_is_object($data->{$field}) $self->_is_object($data->{$field}) ref $data->{$field} ne ref $self
Truth table20%1/5
not(A && B) or C and D
A= $data->{$field}B= $self->_is_object($data->{$field})C= $self->_is_object($data->{$field})D= ref $data->{$field} ne ref $self
ABCDresult
0XXX1
10XX1
11111
110X0
11100
4012 !$self->_is_object( $data->{ $field } ) ||
4013 ( $self->_is_object( $data->{ $field } ) && ref( $data->{ $field } ) ne ref( $self ) ) )
4014 {
4015 28 ▶ $self->_load_class( 'Module::Generic::Array' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Array") or return $self->pass_error 28 0 28
4016 return( $self->pass_error );
4017 28 ▶ my $o = Module::Generic::Array->new( ( defined( $data->{ $field } ) && CORE::length( $data->{ $field } ) ) ? $data->{ $field } : [] );
Branch: 1 branch
BranchTrueFalseTotal
defined $data->{$field} && length $data->{$field} ? : 28 0 28
Condition33%1/3
defined $data->{$field} and length $data->{$field}
!ll&&!rl&&r
0028
MC/DC0%0/2
defined $data->{$field} and length $data->{$field}
defined $data->{$field} length $data->{$field}
Truth table33%1/3
A and B
A= defined $data->{$field}B= length $data->{$field}
ABresult
0X0
100
111
4018 28 $data->{ $field } = $o;
4019 }
4020 28 $self->clear_error;
4021  
4022 # Now, set the array callbacks if any
4023 28 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and $data->{$field}) 0 28 28
Condition33%1/3
scalar keys %$callbacks and $data->{$field}
!ll&&!rl&&r
2800
MC/DC0%0/2
scalar keys %$callbacks and $data->{$field}
scalar keys %$callbacks $data->{$field}
Truth table33%1/3
A and B
A= scalar keys %$callbacksB= $data->{$field}
ABresult
0X0
100
111
4024 $data->{ $field } )
4025 {
4026 0 foreach my $t ( qw( add remove ) )
4027 {
4028 0 ▶ if( CORE::exists( $callbacks->{ "array_${t}" } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$callbacks{"array_$t"} and defined $$callbacks{"array_$t"}) 0 0 0
Condition0%0/3
exists $$callbacks{"array_$t"} and defined $$callbacks{"array_$t"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $$callbacks{"array_$t"} and defined $$callbacks{"array_$t"}
exists $$callbacks{"array_$t"} defined $$callbacks{"array_$t"}
Truth table0%0/3
A and B
A= exists $$callbacks{"array_$t"}B= defined $$callbacks{"array_$t"}
ABresult
0X0
100
111
4029 defined( $callbacks->{ "array_${t}" } ) )
4030 {
4031 my $coderef = ref( $callbacks->{ "array_${t}" } ) eq 'CODE'
4032 ? $callbacks->{ "array_${t}" }
4033 0 ▶ : $self->can( $callbacks->{ "array_${t}" } );
Branch: 1 branch
BranchTrueFalseTotal
ref $$callbacks{"array_$t"} eq 'CODE' ? : 0 0 0
4034 0 ▶ if( defined( $coderef ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef) 0 0 0
4035 {
4036 0 $data->{ $field }->callback( $t => $coderef );
4037 }
4038 }
4039 }
4040 }
4041 28 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 28 28
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
2800
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
2800
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
4042  
4043 28 ▶ if( $def->{wantlist} && $ctx->{list} )
Branch: 1 branch
BranchTrueFalseTotal
if ($def->{'wantlist'} and $ctx->{'list'}) { } 0 28 28
Condition33%1/3
$def->{"wantlist"} and $ctx->{"list"}
!ll&&!rl&&r
2800
MC/DC0%0/2
$def->{"wantlist"} and $ctx->{"list"}
$def->{"wantlist"} $ctx->{"list"}
Truth table33%1/3
A and B
A= $def->{"wantlist"}B= $ctx->{"list"}
ABresult
0X0
100
111
4044 {
4045 0 ▶ return( $data->{ $field } ? $data->{ $field }->list : () );
Branch: 1 branch
BranchTrueFalseTotal
$data->{$field} ? : 0 0 0
4046 }
4047 else
4048 {
4049 28 return( $data->{ $field } );
4050 }
4051 },
4052 118 field => $field,
4053 }, @_ ) );
4054 }
4055  
4056 878 ▶sub _set_get_boolean : lvalue
Subroutine _set_get_boolean: called CC=15 SCAR=46.4
4057 {
4058 878 my $self = shift( @_ );
4059 878 my $field = shift( @_ );
4060 878 my $this = $self->_obj2h;
4061 878 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 12 866 878
4062  
4063 878 my $callbacks = {};
4064 878 my $check;
4065 my $bool_class;
4066 878 my $def = {};
4067 878 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 878 878
4068 {
4069 0 $def = $field;
4070 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
4071 defined( $def->{field} ) &&
4072 CORE::length( $def->{field} ) )
4073 {
4074 0 $field = $def->{field};
4075 }
4076 else
4077 {
4078 0 $field = undef;
4079 }
4080 # Should have been 'callbacks', but we catch it anyway.
4081 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
4082 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
4083 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
4084 0 ▶ $bool_class = $def->{class} if( CORE::exists( $def->{class} ) && length( $def->{class} // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"class"} and length($def->{"class"} // "") 0 0 0
Condition0%0/5
exists $def->{"class"} and length($def->{"class"} // "")
!ll&&!rl&&r
000
$def->{"class"} // ""
l!l
00
MC/DC0%0/2
exists $def->{"class"} and length($def->{"class"} // "")
exists $def->{"class"} $def->{"class"}
Truth table0%0/3
A and B
A= exists $def->{"class"}B= $def->{"class"}
ABresult
0X0
100
111
4085 }
4086  
4087 return( $self->_set_get_callback({
4088 get => sub
4089 589 ▶ {
Subroutine __ANON__: called CC=31 SCAR=53.9
4090 589 my $self = shift( @_ );
4091 589 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 589 589
4092 # If there is a value set, like a default value and it is not an object or at least not one we recognise
4093 # We transform it into a Module::Generic::Boolean object
4094 589 ▶ if( defined( $data->{ $field } ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (defined $data->{$field} and length $data->{$field} and !builtin::blessed($data->{$field}) || builtin::blessed($data->{$field}) && !$data->{$field}->isa('Module::Generic::Boolean') && !$data->{$field}->isa('JSON::PP::Boolean') && (defined $bool_class && !$data->{$field}->isa($bool_class))) { } 358 231 589
elsif (defined $data->{$field} and length $data->{$field} and builtin::reftype($data->{$field} // '') eq 'SCALAR') { } 223 16 239
Condition57%12/21
defined $data->{$field} and length $data->{$field} and !builtin::blessed($data->{$field}) || builtin::blessed($data->{$field}) && !$data->{$field}->isa("Module::Generic::Boolean") && !$data->{$field}->isa("JSON::PP::Boolean") && (defined $bool_class && !$data->{$field}->isa($bool_class))
!ll&&!rl&&r
8223358
defined $data->{$field} and length $data->{$field}
!ll&&!rl&&r
80581
not builtin::blessed($data->{$field}) or builtin::blessed($data->{$field}) and not $data->{$field}->isa("Module::Generic::Boolean") and not $data->{$field}->isa("JSON::PP::Boolean") and (defined $bool_class and not $data->{$field}->isa($bool_class))
l!l&&r!l&&!r
3580223
builtin::blessed($data->{$field}) and not $data->{$field}->isa("Module::Generic::Boolean") and not $data->{$field}->isa("JSON::PP::Boolean") and (defined $bool_class and not $data->{$field}->isa($bool_class))
!ll&&!rl&&r
22300
builtin::blessed($data->{$field}) and not $data->{$field}->isa("Module::Generic::Boolean") and not $data->{$field}->isa("JSON::PP::Boolean")
!ll&&!rl&&r
22210
builtin::blessed($data->{$field}) and not $data->{$field}->isa("Module::Generic::Boolean")
!ll&&!rl&&r
02221
defined $bool_class and not $data->{$field}->isa($bool_class)
!ll&&!rl&&r
000
MC/DC25%2/8
defined $data->{$field} and length $data->{$field} and !builtin::blessed($data->{$field}) || builtin::blessed($data->{$field}) && !$data->{$field}->isa("Module::Generic::Boolean") && !$data->{$field}->isa("JSON::PP::Boolean") && (defined $bool_class && !$data->{$field}->isa($bool_class))
defined $data->{$field} length $data->{$field} not builtin::blessed($data->{$field}) builtin::blessed($data->{$field}) not $data->{$field}->isa("Module::Generic::Boolean") not $data->{$field}->isa("JSON::PP::Boolean") defined $bool_class not $data->{$field}->isa($bool_class)
Truth table44%4/9
A and B and not(C) or D and not(E) and not(F) and G and not(H)
A= defined $data->{$field}B= length $data->{$field}C= not builtin::blessed($data->{$field})D= builtin::blessed($data->{$field})E= not $data->{$field}->isa("Module::Generic::Boolean")F= not $data->{$field}->isa("JSON::PP::Boolean")G= defined $bool_classH= not $data->{$field}->isa($bool_class)
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
1100XXXX0
11010XXX0
110110XX0
1101110X0
110111100
111XXXXX1
110111111
4095 CORE::length( $data->{ $field } ) &&
4096 (
4097 !Scalar::Util::blessed( $data->{ $field } ) ||
4098 (
4099 Scalar::Util::blessed( $data->{ $field } ) &&
4100 !$data->{ $field }->isa( 'Module::Generic::Boolean' ) &&
4101 !$data->{ $field }->isa( 'JSON::PP::Boolean' ) &&
4102 ( defined( $bool_class ) && !$data->{ $field }->isa( $bool_class ) )
4103 )
4104 ) )
4105 {
4106 358 my $val = $data->{ $field };
4107 358 ▶ if( defined( $bool_class ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bool_class) { } 0 358 358
4108 {
4109 0 ▶ $self->_load_class( $bool_class ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($bool_class) or return $self->pass_error 0 0 0
4110 return( $self->pass_error );
4111 0 ▶ if( $bool_class->can( 'true' ) && $bool_class->can( 'false' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($bool_class->can('true') and $bool_class->can('false')) { } 0 0 0
Condition0%0/3
$bool_class->can("true") and $bool_class->can("false")
!ll&&!rl&&r
000
MC/DC0%0/2
$bool_class->can("true") and $bool_class->can("false")
$bool_class->can("true") $bool_class->can("false")
Truth table0%0/3
A and B
A= $bool_class->can("true")B= $bool_class->can("false")
ABresult
0X0
100
111
4112 {
4113 0 ▶ $data->{ $field } = $val ? $bool_class->true : $bool_class->false;
Branch: 1 branch
BranchTrueFalseTotal
$val ? : 0 0 0
4114 }
4115 else
4116 {
4117 # try-catch
4118 0 local $@;
4119 0 $data->{ $field } = eval{ $bool_class->new( $val ) };
4120 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
4121 {
4122 0 return( $self->error( "Unable to instantiate a new $bool_class boolean object with value '", $self->_str_val( $val ), "': $@" ) );
4123 }
4124 }
4125 }
4126 else
4127 {
4128 358 ▶ $data->{ $field } = $val ? Module::Generic::Boolean->true : Module::Generic::Boolean->false;
Branch: 1 branch
BranchTrueFalseTotal
$val ? : 42 316 358
4129 }
4130 }
4131 ▶ elsif( defined( $data->{ $field } ) &&
Condition62%5/8
defined $data->{$field} and length $data->{$field} and builtin::reftype($data->{$field} // "") eq "SCALAR"
!ll&&!rl&&r
80223
defined $data->{$field} and length $data->{$field}
!ll&&!rl&&r
80223
$data->{$field} // ""
l!l
2230
MC/DC33%1/3
defined $data->{$field} and length $data->{$field} and builtin::reftype($data->{$field} // "") eq "SCALAR"
defined $data->{$field} length $data->{$field} $data->{$field}
Truth table50%2/4
A and B and C
A= defined $data->{$field}B= length $data->{$field}C= $data->{$field}
ABCresult
0XX0
10X0
1100
1111
4132 CORE::length( $data->{ $field } ) &&
4133 Scalar::Util::reftype( $data->{ $field } // '' ) eq 'SCALAR' )
4134 {
4135 223 my $val = $data->{ $field };
4136 223 ▶ if( defined( $bool_class ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bool_class) { } 0 223 223
4137 {
4138 0 ▶ $self->_load_class( $bool_class ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($bool_class) or return $self->pass_error 0 0 0
4139 return( $self->pass_error );
4140 0 ▶ if( $bool_class->can( 'true' ) && $bool_class->can( 'false' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($bool_class->can('true') and $bool_class->can('false')) { } 0 0 0
Condition0%0/3
$bool_class->can("true") and $bool_class->can("false")
!ll&&!rl&&r
000
MC/DC0%0/2
$bool_class->can("true") and $bool_class->can("false")
$bool_class->can("true") $bool_class->can("false")
Truth table0%0/3
A and B
A= $bool_class->can("true")B= $bool_class->can("false")
ABresult
0X0
100
111
4141 {
4142 0 ▶ $data->{ $field } = $$val ? $bool_class->true : $bool_class->false;
Branch: 1 branch
BranchTrueFalseTotal
$$val ? : 0 0 0
4143 }
4144 else
4145 {
4146 # try-catch
4147 0 local $@;
4148 0 $data->{ $field } = eval{ $bool_class->new( $$val ) };
4149 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
4150 {
4151 0 return( $self->error( "Unable to instantiate a new $bool_class boolean object with value '", $self->_str_val( $$val ), "': $@" ) );
4152 }
4153 }
4154 }
4155 else
4156 {
4157 223 ▶ $data->{ $field } = $$val ? Module::Generic::Boolean->true : Module::Generic::Boolean->false;
Branch: 1 branch
BranchTrueFalseTotal
$$val ? : 167 56 223
4158 }
4159 }
4160 589 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 589 589
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
58900
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
58900
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
4161 589 return( $data->{ $field } );
4162 },
4163 set => sub
4164 289 ▶ {
Subroutine __ANON__: called CC=68 SCAR=77.8
4165 289 my $self = shift( @_ );
4166 289 my $val = shift( @_ );
4167 289 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 289 289
4168 289 ▶ $val //= '';
Condition50%1/2
$val //= ""
l!l
2890
MC/DC0%0/1
$val //= ""
$val
Truth table50%1/2
A
A= $val
Aresult
11
00
4169 289 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 289 289
4170 {
4171 # try-catch
4172 0 local $@;
4173 0 my $rv = eval{ $check->( $self, $val ) };
4174 0 ▶ 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
4175 {
4176 0 return( $self->pass_error );
4177 }
4178 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
4179 }
4180 36 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
4181 289 ▶ if( Scalar::Util::blessed( $val ) &&
Branch: 3 branches
BranchTrueFalseTotal
if (builtin::blessed($val) and $val->isa('JSON::PP::Boolean') || $val->isa('Module::Generic::Boolean') || defined $bool_class && $val->isa($bool_class)) { } 26 263 289
elsif ((builtin::reftype($val) // '') eq 'SCALAR') { } 0 263 263
elsif (lc $val eq 'true' or lc $val eq 'false') { } 0 263 263
Condition41%5/12
builtin::blessed($val) and $val->isa("JSON::PP::Boolean") || $val->isa("Module::Generic::Boolean") || defined $bool_class && $val->isa($bool_class)
!ll&&!rl&&r
263026
$val->isa("JSON::PP::Boolean") or $val->isa("Module::Generic::Boolean") or defined $bool_class and $val->isa($bool_class)
l!l&&r!l&&!r
2600
$val->isa("JSON::PP::Boolean") or $val->isa("Module::Generic::Boolean")
l!l&&r!l&&!r
1250
defined $bool_class and $val->isa($bool_class)
!ll&&!rl&&r
000
MC/DC20%1/5
builtin::blessed($val) and $val->isa("JSON::PP::Boolean") || $val->isa("Module::Generic::Boolean") || defined $bool_class && $val->isa($bool_class)
builtin::blessed($val) $val->isa("JSON::PP::Boolean") $val->isa("Module::Generic::Boolean") defined $bool_class $val->isa($bool_class)
Truth table50%3/6
A and B or C or D and E
A= builtin::blessed($val)B= $val->isa("JSON::PP::Boolean")C= $val->isa("Module::Generic::Boolean")D= defined $bool_classE= $val->isa($bool_class)
ABCDEresult
0XXXX0
1000X0
100100
11XXX1
101XX1
100111
4182 (
4183 $val->isa( 'JSON::PP::Boolean' ) ||
4184 $val->isa( 'Module::Generic::Boolean' ) ||
4185 ( defined( $bool_class ) && $val->isa( $bool_class ) )
4186 ) )
4187 {
4188 26 $data->{ $field } = $val;
4189 }
4190 ▶ elsif( ( Scalar::Util::reftype( $val ) // '' ) eq 'SCALAR' )
Condition50%1/2
builtin::reftype($val) // ""
l!l
0263
MC/DC0%0/1
builtin::reftype($val) // ""
builtin::reftype($val)
Truth table50%1/2
A
A= builtin::reftype($val)
Aresult
11
00
4191 {
4192 0 ▶ if( defined( $bool_class ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bool_class) { } 0 0 0
4193 {
4194 0 ▶ $self->_load_class( $bool_class ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($bool_class) or return $self->pass_error 0 0 0
4195 return( $self->pass_error );
4196 0 ▶ if( $bool_class->can( 'true' ) && $bool_class->can( 'false' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($bool_class->can('true') and $bool_class->can('false')) { } 0 0 0
Condition0%0/3
$bool_class->can("true") and $bool_class->can("false")
!ll&&!rl&&r
000
MC/DC0%0/2
$bool_class->can("true") and $bool_class->can("false")
$bool_class->can("true") $bool_class->can("false")
Truth table0%0/3
A and B
A= $bool_class->can("true")B= $bool_class->can("false")
ABresult
0X0
100
111
4197 {
4198 0 ▶ $data->{ $field } = defined( $$val )
Branch: 2 branches
BranchTrueFalseTotal
defined $$val ? : 0 0 0
$$val ? : 0 0 0
4199 ? $$val
4200 ? $bool_class->true
4201 : $bool_class->false
4202 : $bool_class->false;
4203 }
4204 else
4205 {
4206 # try-catch
4207 0 local $@;
4208 0 $data->{ $field } = eval{ $bool_class->new( $$val ) };
4209 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
4210 {
4211 0 return( $self->error( "Unable to instantiate a new $bool_class boolean object with value '", $self->_str_val( $$val ), "': $@" ) );
4212 }
4213 }
4214 }
4215 else
4216 {
4217 0 ▶ $data->{ $field } = defined( $$val )
Branch: 2 branches
BranchTrueFalseTotal
defined $$val ? : 0 0 0
$$val ? : 0 0 0
4218 ? $$val
4219 ? Module::Generic::Boolean->true
4220 : Module::Generic::Boolean->false
4221 : Module::Generic::Boolean->false;
4222 }
4223 }
4224 ▶ elsif( lc( $val ) eq 'true' || lc( $val ) eq 'false' )
Condition33%1/3
lc $val eq "true" or lc $val eq "false"
l!l&&r!l&&!r
00263
MC/DC0%0/2
lc $val eq "true" or lc $val eq "false"
lc $val eq "true" lc $val eq "false"
Truth table33%1/3
A or B
A= lc $val eq "true"B= lc $val eq "false"
ABresult
1X1
011
000
4225 {
4226 0 ▶ if( defined( $bool_class ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bool_class) { } 0 0 0
4227 {
4228 0 ▶ $self->_load_class( $bool_class ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($bool_class) or return $self->pass_error 0 0 0
4229 return( $self->pass_error );
4230 0 ▶ if( $bool_class->can( 'true' ) && $bool_class->can( 'false' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($bool_class->can('true') and $bool_class->can('false')) { } 0 0 0
Condition0%0/3
$bool_class->can("true") and $bool_class->can("false")
!ll&&!rl&&r
000
MC/DC0%0/2
$bool_class->can("true") and $bool_class->can("false")
$bool_class->can("true") $bool_class->can("false")
Truth table0%0/3
A and B
A= $bool_class->can("true")B= $bool_class->can("false")
ABresult
0X0
100
111
4231 {
4232 0 ▶ $data->{ $field } = lc( $val ) eq 'true' ? $bool_class->true : $bool_class->false;
Branch: 1 branch
BranchTrueFalseTotal
lc $val eq 'true' ? : 0 0 0
4233 }
4234 else
4235 {
4236 # try-catch
4237 0 local $@;
4238 0 $data->{ $field } = eval{ $bool_class->new( $val ) };
4239 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
4240 {
4241 0 return( $self->error( "Unable to instantiate a new $bool_class boolean object with value '", $self->_str_val( $val ), "': $@" ) );
4242 }
4243 }
4244 }
4245 else
4246 {
4247 0 ▶ $data->{ $field } = lc( $val ) eq 'true' ? Module::Generic::Boolean->true : Module::Generic::Boolean->false;
Branch: 1 branch
BranchTrueFalseTotal
lc $val eq 'true' ? : 0 0 0
4248 }
4249 }
4250 else
4251 {
4252 263 ▶ if( defined( $bool_class ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bool_class) { } 0 263 263
4253 {
4254 0 ▶ $self->_load_class( $bool_class ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($bool_class) or return $self->pass_error 0 0 0
4255 return( $self->pass_error );
4256 0 ▶ if( $bool_class->can( 'true' ) && $bool_class->can( 'false' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($bool_class->can('true') and $bool_class->can('false')) { } 0 0 0
Condition0%0/3
$bool_class->can("true") and $bool_class->can("false")
!ll&&!rl&&r
000
MC/DC0%0/2
$bool_class->can("true") and $bool_class->can("false")
$bool_class->can("true") $bool_class->can("false")
Truth table0%0/3
A and B
A= $bool_class->can("true")B= $bool_class->can("false")
ABresult
0X0
100
111
4257 {
4258 0 ▶ $data->{ $field } = $val ? $bool_class->true : $bool_class->false;
Branch: 1 branch
BranchTrueFalseTotal
$val ? : 0 0 0
4259 }
4260 else
4261 {
4262 # try-catch
4263 0 local $@;
4264 0 $data->{ $field } = eval{ $bool_class->new( $val ) };
4265 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
4266 {
4267 0 return( $self->error( "Unable to instantiate a new $bool_class boolean object with value '", $self->_str_val( $val ), "': $@" ) );
4268 }
4269 }
4270 }
4271 else
4272 {
4273 263 ▶ $data->{ $field } = $val
Branch: 1 branch
BranchTrueFalseTotal
$val ? : 226 37 263
4274 ? Module::Generic::Boolean->true
4275 : Module::Generic::Boolean->false;
4276 }
4277 }
4278 289 $self->clear_error;
4279  
4280 289 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 289 289
Condition16%1/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
28900
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table25%1/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
4281 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
4282 {
4283 0 my $coderef;
4284 0 foreach my $t ( qw( add set ) )
4285 {
4286 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
4287 {
4288 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
4289 ? $callbacks->{ $t }
4290 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
4291 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
4292 }
4293 }
4294 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
4295 {
4296 # try-catch
4297 0 local $@;
4298 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
4299 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
4300 {
4301 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
4302 }
4303 ▶ elsif( !defined( $rv ) && $self->error )
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
4304 {
4305 0 return( $self->pass_error );
4306 }
4307 0 $data->{ $field } = $rv;
4308 }
4309 }
4310  
4311 # If there is a value set, like a default value and it is not an object or at least not one we recognise
4312 # We transform it into a Module::Generic::Boolean object
4313 289 ▶ if( CORE::length( $data->{ $field } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (length $data->{$field} and !builtin::blessed($data->{$field}) || builtin::blessed($data->{$field}) && !$data->{$field}->isa("Module::Generic::Boolean") && !$data->{$field}->isa("JSON::PP::Boolean") && (defined $bool_class && !$data->{$field}->isa($bool_class))) 0 289 289
Condition38%7/18
length $data->{$field} and !builtin::blessed($data->{$field}) || builtin::blessed($data->{$field}) && !$data->{$field}->isa("Module::Generic::Boolean") && !$data->{$field}->isa("JSON::PP::Boolean") && (defined $bool_class && !$data->{$field}->isa($bool_class))
!ll&&!rl&&r
02890
not builtin::blessed($data->{$field}) or builtin::blessed($data->{$field}) and not $data->{$field}->isa("Module::Generic::Boolean") and not $data->{$field}->isa("JSON::PP::Boolean") and (defined $bool_class and not $data->{$field}->isa($bool_class))
l!l&&r!l&&!r
00289
builtin::blessed($data->{$field}) and not $data->{$field}->isa("Module::Generic::Boolean") and not $data->{$field}->isa("JSON::PP::Boolean") and (defined $bool_class and not $data->{$field}->isa($bool_class))
!ll&&!rl&&r
28900
builtin::blessed($data->{$field}) and not $data->{$field}->isa("Module::Generic::Boolean") and not $data->{$field}->isa("JSON::PP::Boolean")
!ll&&!rl&&r
28810
builtin::blessed($data->{$field}) and not $data->{$field}->isa("Module::Generic::Boolean")
!ll&&!rl&&r
02881
defined $bool_class and not $data->{$field}->isa($bool_class)
!ll&&!rl&&r
000
MC/DC0%0/7
length $data->{$field} and !builtin::blessed($data->{$field}) || builtin::blessed($data->{$field}) && !$data->{$field}->isa("Module::Generic::Boolean") && !$data->{$field}->isa("JSON::PP::Boolean") && (defined $bool_class && !$data->{$field}->isa($bool_class))
length $data->{$field} not builtin::blessed($data->{$field}) builtin::blessed($data->{$field}) not $data->{$field}->isa("Module::Generic::Boolean") not $data->{$field}->isa("JSON::PP::Boolean") defined $bool_class not $data->{$field}->isa($bool_class)
Truth table25%2/8
A and not(B) or C and not(D) and not(E) and F and not(G)
A= length $data->{$field}B= not builtin::blessed($data->{$field})C= builtin::blessed($data->{$field})D= not $data->{$field}->isa("Module::Generic::Boolean")E= not $data->{$field}->isa("JSON::PP::Boolean")F= defined $bool_classG= not $data->{$field}->isa($bool_class)
ABCDEFGresult
0XXXXXX0
100XXXX0
1010XXX0
10110XX0
101110X0
10111100
11XXXXX1
10111111
4314 (
4315 !Scalar::Util::blessed( $data->{ $field } ) ||
4316 (
4317 Scalar::Util::blessed( $data->{ $field } ) &&
4318 !$data->{ $field }->isa( 'Module::Generic::Boolean' ) &&
4319 !$data->{ $field }->isa( 'JSON::PP::Boolean' ) &&
4320 ( defined( $bool_class ) && !$data->{ $field }->isa( $bool_class ) )
4321 )
4322 ) )
4323 {
4324 0 my $val = $data->{ $field };
4325 0 ▶ if( defined( $bool_class ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bool_class) { } 0 0 0
4326 {
4327 0 ▶ $self->_load_class( $bool_class ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($bool_class) or return $self->pass_error 0 0 0
4328 return( $self->pass_error );
4329 0 ▶ if( $bool_class->can( 'true' ) && $bool_class->can( 'false' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($bool_class->can('true') and $bool_class->can('false')) { } 0 0 0
Condition0%0/3
$bool_class->can("true") and $bool_class->can("false")
!ll&&!rl&&r
000
MC/DC0%0/2
$bool_class->can("true") and $bool_class->can("false")
$bool_class->can("true") $bool_class->can("false")
Truth table0%0/3
A and B
A= $bool_class->can("true")B= $bool_class->can("false")
ABresult
0X0
100
111
4330 {
4331 0 ▶ $data->{ $field } = $val ? $bool_class->true : $bool_class->false;
Branch: 1 branch
BranchTrueFalseTotal
$val ? : 0 0 0
4332 }
4333 else
4334 {
4335 # try-catch
4336 0 local $@;
4337 0 $data->{ $field } = eval{ $bool_class->new( $val ) };
4338 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
4339 {
4340 0 return( $self->error( "Unable to instantiate a new $bool_class boolean object with value '", $self->_str_val( $val ), "': $@" ) );
4341 }
4342 }
4343 }
4344 else
4345 {
4346 0 ▶ $data->{ $field } = $val ? Module::Generic::Boolean->true : Module::Generic::Boolean->false;
Branch: 1 branch
BranchTrueFalseTotal
$val ? : 0 0 0
4347 }
4348 }
4349 289 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 289 289
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
28900
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
28900
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
4350 289 return( $data->{ $field } );
4351 },
4352 878 field => $field,
4353 }, @_ ) );
4354 }
4355  
4356 5879 ▶sub _set_get_callback : lvalue
Subroutine _set_get_callback: called CC=70 SCAR=54.5
4357 {
4358 5879 my $self = shift( @_ );
4359 5879 my $def = shift( @_ );
4360 5879 my $this = $self->_obj2h;
4361 5879 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 136 5743 5879
4362 5879 my( $getter, $setter, $field ) = @$def{qw( get set field )};
4363  
4364 5879 ▶ if( defined( $getter ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $getter) { } 5879 0 5879
4365 {
4366 5879 ▶ die( "Getter code value provided is actually not a code reference." ) if( ref( $getter ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $getter ne "CODE" 0 5879 5879
4367 }
4368 else
4369 {
4370 0 ▶ $getter = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
4371 }
4372  
4373 5879 ▶ if( defined( $setter ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $setter) { } 5879 0 5879
4374 {
4375 5879 ▶ die( "Setter code value provided is actually not a code reference." ) if( ref( $setter ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $setter ne "CODE" 0 5879 5879
4376 }
4377 else
4378 {
4379 0 ▶ $setter = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
4380 }
4381 5879 ▶ die( "Field value specified is empty." ) if( defined( $field ) && !CORE::length( "$field" ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $field and not length "$field" 0 5879 5879
Condition66%2/3
defined $field and not length "$field"
!ll&&!rl&&r
858710
MC/DC0%0/2
defined $field and not length "$field"
defined $field not length "$field"
Truth table66%2/3
A and not(B)
A= defined $fieldB= not length "$field"
ABresult
0X0
100
111
4382  
4383 5879 my $context = {};
4384 # <https://perldoc.perl.org/threads#THREAD-CONTEXT>
4385 5879 ▶ my $wantarray = HAS_THREADS ? threads->wantarray() : wantarray();
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 5879 5879
4386 5879 ▶ $context->{wantarray} = defined( $wantarray ) ? $wantarray ? 'LIST' : 'SCALAR' : 'VOID';
Branch: 2 branches
BranchTrueFalseTotal
defined $wantarray ? : 4432 1447 5879
$wantarray ? : 415 4017 4432
4387 5879 ▶ $context->{wantarray0} = defined( wantarray() ) ? wantarray() ? 'LIST' : 'SCALAR' : 'VOID';
Branch: 2 branches
BranchTrueFalseTotal
defined wantarray ? : 4432 1447 5879
wantarray ? : 415 4017 4432
4388 5879 ▶ $self->__message( 112, "Determining caller context with Wanted for field '", ( $field // 'undef' ), "' and wantarray() wants $context->{wantarray} and regular wantarray wants $context->{wantarray0}." );
Condition100%2/2
$field // "undef"
l!l
58718
MC/DC100%1/1
$field // "undef"
$field
Truth table100%2/2
A
A= $field
Aresult
11
00
4389 5879 my $args;
4390 my @rv;
4391 5879 ▶ if( want( qw( LVALUE ASSIGN ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want(('LVALUE', 'ASSIGN'))) { } 26 5853 5879
4392 {
4393 26 ▶ $self->__message( 112, "Caller expects LVALUE ASSIGN with value '", $self->_str_val( $args // 'undef' ), "'" );
Condition50%1/2
$args // "undef"
l!l
026
MC/DC0%0/1
$args // "undef"
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
4394 26 $args = [want( 'ASSIGN' )];
4395 26 $context->{assign}++;
4396 26 $context->{lvalue}++;
4397 }
4398 else
4399 {
4400 5853 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1667 4186 5853
4401 {
4402 1667 $args = [@_];
4403 }
4404  
4405 5853 ▶ $self->__message( 112, "Caller is not in a LVALUE ASSIGN context, and there are ", scalar( @$args ), " argument(s) provided: '", join( "', '", map( $self->_str_val( $_ // 'undef' ), @$args ) ), "'" );
Condition100%2/2
$_ // "undef"
l!l
1528145
MC/DC100%1/1
$_ // "undef"
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
4406 5853 $self->__message( 112, "Checking for LVALUE or RVALUE context." );
4407 5853 ▶ if( want( 'LVALUE' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (want('LVALUE')) { } 16 5837 5853
elsif (want('RVALUE')) { } 5837 0 5837
4408 {
4409 16 $self->__message( 112, "Caller is in a LVALUE context." );
4410 16 $context->{lvalue}++;
4411 }
4412 elsif( want( 'RVALUE' ) )
4413 {
4414 5837 $self->__message( 112, "Caller is in a RVALUE context." );
4415 5837 $context->{rvalue}++;
4416 }
4417  
4418 5853 $self->__message( 112, "Checking other context in non lvalue-assign context." );
4419 5853 my $expect = Wanted::context();
4420 5853 $self->__message( 112, "Caller expects $expect" );
4421 5853 ▶ $context->{ lc( $expect ) }++ if( length( $expect ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $expect 5853 0 5853
4422 5853 $context->{count} = Wanted::want( 'COUNT' );
4423 }
4424 5879 $context->{eval} = $^S;
4425 0 ▶ $self->__message( 112, "_set_get_callback called with ", ( defined( $field ) ? "field $field and " : "no field and " ), "context is -> ", sub{ $self->Module::Generic::dump( $context ) } );
Subroutine __ANON__: not called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
defined $field ? : 5871 8 5879
4426  
4427 5879 ▶ if( CORE::defined( $args ) && scalar( @$args ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args and scalar @$args) 1693 4186 5879
Condition50%1/2
defined $args and scalar @$args
!ll
05879
MC/DC0%0/1
defined $args and scalar @$args
defined $args
Truth table50%1/2
A
A= defined $args
Aresult
00
11
4428 {
4429 1693 $self->__message( 112, "Called for mutator callback with ", scalar( @$args ), " arguments." );
4430 # try-catch
4431 1693 local $@;
4432 1693 local $_ = $context;
4433 1693 ▶ if( $context->{list} )
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{'list'}) { } 0 1693 1693
4434 {
4435 0 eval{ @rv = $setter->( $self, @$args ) };
4436 }
4437 else
4438 {
4439 1693 eval{ $rv[0] = $setter->( $self, @$args ) };
4440 }
4441 1693 ▶ $self->__message( 104, "Mutator triggered an exception: $@" ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 1692 1693
4442  
4443 1693 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 1692 1693
4444 {
4445 1 my $err;
4446 1 ▶ if( !ref( $@ ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $@) { } 0 1 1
elsif (builtin::blessed($@) and overload::Method($@, '""')) { } 1 0 1
elsif (builtin::blessed($@) and $@->can('as_string')) { } 0 0 0
4447 {
4448 0 $err = $@;
4449 }
4450 ▶ elsif( Scalar::Util::blessed( $@ ) && overload::Method( $@, '""' ) )
Condition33%1/3
builtin::blessed($@) and overload::Method($@, "\"\"")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($@) and overload::Method($@, "\"\"")
builtin::blessed($@) overload::Method($@, "\"\"")
Truth table33%1/3
A and B
A= builtin::blessed($@)B= overload::Method($@, "\"\"")
ABresult
0X0
100
111
4451 {
4452 1 $err = "$@";
4453 }
4454 ▶ elsif( Scalar::Util::blessed( $@ ) && $@->can( 'as_string' ) )
Condition0%0/3
builtin::blessed($@) and $@->can("as_string")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($@) and $@->can("as_string")
builtin::blessed($@) $@->can("as_string")
Truth table0%0/3
A and B
A= builtin::blessed($@)B= $@->can("as_string")
ABresult
0X0
100
111
4455 {
4456 0 $err = $@->as_string;
4457 }
4458 else
4459 {
4460 0 $err = $@;
4461 }
4462 1 $self->error( $err );
4463 }
4464  
4465 0 ▶ $self->__message( 112, "Mutator callback returned -> ", sub{ $self->Module::Generic::dump( \@rv ) } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
4466 1692 ▶ if( ( !scalar( @rv ) || ( scalar( @rv ) == 1 && !defined( $rv[0] ) ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (!scalar(@rv) || scalar @rv == 1 && !defined($rv[0]) and my $has_error = $self->error) { } 4 1688 1692
Condition77%7/9
!scalar(@rv) || scalar @rv == 1 && !defined($rv[0]) and my $has_error = $self->error
!ll&&!rl&&r
15431454
not scalar @rv or scalar @rv == 1 and not defined $rv[0]
l!l&&r!l&&!r
01491543
scalar @rv == 1 and not defined $rv[0]
!ll&&!rl&&r
01543149
MC/DC50%2/4
!scalar(@rv) || scalar @rv == 1 && !defined($rv[0]) and my $has_error = $self->error
not scalar @rv scalar @rv == 1 not defined $rv[0] my $has_error = $self->error
Truth table50%3/6
not(A) or B and not(C) and D
A= not scalar @rvB= scalar @rv == 1C= not defined $rv[0]D= my $has_error = $self->error
ABCDresult
00XX0
010X0
1XX00
01100
1XX11
01111
4467 ( my $has_error = $self->error ) )
4468 {
4469 4 $self->__message( 112, "Callback returned nothing, but found an error set." );
4470 4 ▶ if( $context->{assign} )
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{'assign'}) { } 3 1 4
4471 {
4472 3 $self->__message( 112, "We are in assign, returning a private property (__lvalue_error) of our object with value undef." );
4473 3 $data->{__lvalue_error} = undef;
4474 3 return( $data->{__lvalue_error} );
4475 }
4476 else
4477 {
4478 1 $self->__message( 112, "Not in assign context, passing the error." );
4479 1 return( $self->pass_error );
4480 }
4481 }
4482 else
4483 {
4484 1688 ▶ if( $context->{assign} || $context->{lvalue} )
Branch: 2 branches
BranchTrueFalseTotal
if ($context->{'assign'} or $context->{'lvalue'}) { } 22 1666 1688
elsif ($context->{'list'}) { } 0 1666 1666
Condition66%2/3
$context->{"assign"} or $context->{"lvalue"}
l!l&&r!l&&!r
2201666
MC/DC50%1/2
$context->{"assign"} or $context->{"lvalue"}
$context->{"assign"} $context->{"lvalue"}
Truth table66%2/3
A or B
A= $context->{"assign"}B= $context->{"lvalue"}
ABresult
1X1
011
000
4485 {
4486 22 ▶ $self->__message( 112, "We are in assign or lvalue context with value -> ", $self->_str_val( $rv[0] // 'undef' ) );
Condition50%1/2
$rv[0] // "undef"
l!l
220
MC/DC0%0/1
$rv[0] // "undef"
$rv[0]
Truth table50%1/2
A
A= $rv[0]
Aresult
11
00
4487 22 ▶ if( defined( $field ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $field) { } 21 1 22
4488 {
4489 21 $self->__message( 112, "Field parameter is provided ($field), storing and returning its value." );
4490 21 $data->{ $field } = $rv[0]; # Store setter's result
4491 # return( $data->{ $field } );
4492 tie( my $scalar, 'Module::Generic::LvalueGuard',
4493 21 value => $data->{ $field },
4494 get => $getter,
4495 set => $setter,
4496 obj => $self
4497 );
4498 21 return( $scalar );
4499 }
4500 else
4501 {
4502 1 $self->__message( 112, "No field parameter, returning private property (__lvalue) with callback value." );
4503 1 return( $data->{__lvalue} = $rv[0] );
4504 }
4505 }
4506 elsif( $context->{list} )
4507 {
4508 0 $self->__message( 112, "We are in list context." );
4509 0 return( @rv );
4510 }
4511 else
4512 {
4513 1666 ▶ $self->__message( 112, "We are in some other context, probably rvalue (", ( $context->{rvalue} ? 'yes' : 'no' ), ")." );
Branch: 1 branch
BranchTrueFalseTotal
$context->{'rvalue'} ? : 1666 0 1666
4514 1666 ▶ if( !defined( $rv[0] ) && $context->{object} )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rv[0] and $context->{"object"}) 0 1666 1666
Condition66%2/3
not defined $rv[0] and $context->{"object"}
!ll&&!rl&&r
15211450
MC/DC0%0/2
not defined $rv[0] and $context->{"object"}
not defined $rv[0] $context->{"object"}
Truth table66%2/3
not(A) and B
A= not defined $rv[0]B= $context->{"object"}
ABresult
0X0
100
111
4515 {
4516 0 $self->__message( 112, "Empty value returned in object context, returning Null object." );
4517 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or return $self->pass_error 0 0 0
4518 return( $self->pass_error );
4519 0 rreturn( Module::Generic::Null->new( wants => 'OBJECT' ) );
4520 }
4521 1666 ▶ $self->__message( 112, "Returning callback single value -> ", $self->_str_val( $rv[0] // 'undef' ) );
Condition100%2/2
$rv[0] // "undef"
l!l
1521145
MC/DC100%1/1
$rv[0] // "undef"
$rv[0]
Truth table100%2/2
A
A= $rv[0]
Aresult
11
00
4522 1666 rreturn( $rv[0] );
4523 }
4524 }
4525 }
4526  
4527 4186 $self->__message( 112, "Callback for accessor callback." );
4528 # try-catch
4529 4186 local $@;
4530 4186 local $_ = $context;
4531 4186 ▶ if( $context->{list} )
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{'list'}) { } 375 3811 4186
4532 {
4533 375 eval{ @rv = $getter->( $self ) };
4534 }
4535 else
4536 {
4537 3811 eval{ $rv[0] = $getter->( $self ) };
4538 }
4539 4186 ▶ $self->error( $@ ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 4186 4186
4540  
4541 4186 ▶ if( !scalar( @rv ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (not scalar @rv and my $has_error = $self->error) { } 0 4186 4186
Condition33%1/3
not scalar @rv and my $has_error = $self->error
!ll&&!rl&&r
418600
MC/DC0%0/2
not scalar @rv and my $has_error = $self->error
not scalar @rv my $has_error = $self->error
Truth table33%1/3
not(A) and B
A= not scalar @rvB= my $has_error = $self->error
ABresult
0X0
100
111
4542 ( my $has_error = $self->error ) )
4543 {
4544 0 $self->__message( 112, "Callback returned nothing, but found an error set." );
4545 0 ▶ if( $context->{rvalue} )
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{'rvalue'}) { } 0 0 0
4546 {
4547 0 $self->__message( 112, "We are in rvalue context." );
4548 0 ▶ if( $context->{object} )
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{"object"}) 0 0 0
4549 {
4550 0 $self->__message( 112, "We are in rvalue and object context, returning a Null object." );
4551 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or return $self->pass_error 0 0 0
4552 return( $self->pass_error );
4553 0 rreturn( Module::Generic::Null->new( wants => 'OBJECT' ) );
4554 }
4555 0 $self->__message( 112, "Returning undef or empty list." );
4556 0 rreturn;
4557 }
4558 else
4559 {
4560 0 $self->__message( 112, "We are in some other context." );
4561 0 ▶ if( $context->{object} )
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{"object"}) 0 0 0
4562 {
4563 0 $self->__message( 112, "We are in object context, returning a Null object." );
4564 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or return $self->pass_error 0 0 0
4565 return( $self->pass_error );
4566 0 return( Module::Generic::Null->new( wants => 'OBJECT' ) );
4567 }
4568 0 $self->__message( 112, "Returning undef or empty list." );
4569 0 return;
4570 }
4571 }
4572 else
4573 {
4574 4186 $self->__message( 112, "No error, all is well, accessor callback returned ", scalar( @rv ), " value(s)." );
4575 4186 ▶ if( $context->{lvalue} && defined( $field ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($context->{'lvalue'} and defined $field) { } 14 4172 4186
elsif ($context->{'rvalue'}) { } 4170 2 4172
Condition100%3/3
$context->{"lvalue"} and defined $field
!ll&&!rl&&r
4170214
MC/DC100%2/2
$context->{"lvalue"} and defined $field
$context->{"lvalue"} defined $field
Truth table100%3/3
A and B
A= $context->{"lvalue"}B= defined $field
ABresult
0X0
100
111
4576 {
4577 14 $self->__message( 112, "In lvalue context without args, returning field $field for lvalue access." );
4578 tie( my $scalar, 'Module::Generic::LvalueGuard',
4579 14 value => $data->{ $field },
4580 get => $getter,
4581 set => $setter,
4582 obj => $self
4583 );
4584 14 return( $scalar );
4585 }
4586 elsif( $context->{rvalue} )
4587 {
4588 4170 $self->__message( 112, "We are in rvalue context." );
4589 4170 ▶ if( $context->{list} )
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{'list'}) { } 375 3795 4170
4590 {
4591 375 $self->__message( 112, "Returning a list." );
4592 375 rreturn( @rv );
4593 }
4594 else
4595 {
4596 3795 $self->__message( 112, "Returning a scalar." );
4597 3795 ▶ if( !defined( $rv[0] ) && $context->{object} )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rv[0] and $context->{"object"}) 0 3795 3795
Condition66%2/3
not defined $rv[0] and $context->{"object"}
!ll&&!rl&&r
35152800
MC/DC0%0/2
not defined $rv[0] and $context->{"object"}
not defined $rv[0] $context->{"object"}
Truth table66%2/3
not(A) and B
A= not defined $rv[0]B= $context->{"object"}
ABresult
0X0
100
111
4598 {
4599 0 $self->__message( 112, "Value returned is empty or undef and we are in object context, returning a Null object." );
4600 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or return $self->pass_error 0 0 0
4601 return( $self->pass_error );
4602 0 rreturn( Module::Generic::Null->new( wants => 'OBJECT' ) );
4603 }
4604 3795 ▶ $self->__message( 112, "Returning the single value returned by callback -> '", $self->_str_val( $rv[0] // 'undef' ), "'" );
Condition100%2/2
$rv[0] // "undef"
l!l
3515280
MC/DC100%1/1
$rv[0] // "undef"
$rv[0]
Truth table100%2/2
A
A= $rv[0]
Aresult
11
00
4605 3795 rreturn( $rv[0] );
4606 }
4607 }
4608 else
4609 {
4610 2 $self->__message( 112, "We are in some other context." );
4611 2 ▶ if( $context->{list} )
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{'list'}) { } 0 2 2
4612 {
4613 0 $self->__message( 112, "Returning a list." );
4614 0 return( @rv );
4615 }
4616 else
4617 {
4618 2 $self->__message( 112, "Returning a scalar." );
4619 2 ▶ if( !defined( $rv[0] ) && $context->{object} )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rv[0] and $context->{"object"}) 0 2 2
Condition66%2/3
not defined $rv[0] and $context->{"object"}
!ll&&!rl&&r
110
MC/DC0%0/2
not defined $rv[0] and $context->{"object"}
not defined $rv[0] $context->{"object"}
Truth table66%2/3
not(A) and B
A= not defined $rv[0]B= $context->{"object"}
ABresult
0X0
100
111
4620 {
4621 0 $self->__message( 112, "Value returned is empty or undef and we are in object context, returning a Null object." );
4622 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or return $self->pass_error 0 0 0
4623 return( $self->pass_error );
4624 0 return( Module::Generic::Null->new( wants => 'OBJECT' ) );
4625 }
4626 2 ▶ $self->__message( 112, "Returning the single value returned by callback -> ", ( $rv[0] // 'undef' ), " (", $self->_str_val( $rv[0] // 'undef' ), ")." );
Condition100%4/4
$rv[0] // "undef"
l!l
11
$rv[0] // "undef"
l!l
11
MC/DC100%1/1
$rv[0] // "undef"
$rv[0]
MC/DC100%1/1
$rv[0] // "undef"
$rv[0]
Truth table100%2/2
A
A= $rv[0]
Aresult
11
00
Truth table100%2/2
A
A= $rv[0]
Aresult
11
00
4627 2 return( $rv[0] );
4628 }
4629 }
4630 }
4631 0 return;
4632 }
4633  
4634 # $self->_set_get_class( 'my_field', {
4635 # _class => 'My::Class',
4636 # field1 => { type => 'datetime' },
4637 # field2 => { type => 'scalar' },
4638 # field3 => { type => 'boolean' },
4639 # field4 => { type => 'object', class => 'Some::Class' },
4640 # }, @_ );
4641 sub _set_get_class
4642 0 ▶{
Subroutine _set_get_class: not called CC=17 SCAR=57.2
4643 0 my $self = shift( @_ );
4644 0 my $field = shift( @_ );
4645 0 my $def = shift( @_ );
4646 0 my $this = $self->_obj2h;
4647 0 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 0 0
4648 0 ▶ @_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and not defined $_[0] 0 0 0
Condition0%0/3
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and not defined $_[0]
scalar @_ == 1 not defined $_[0]
Truth table0%0/3
A and not(B)
A= scalar @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
4649 0 ▶ if( ref( $def ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $def ne "HASH") 0 0 0
4650 {
4651 0 CORE::warn( "Warning only: dynamic class field definition hash ($def) for field \"$field\" is not a hash reference." );
4652 0 return;
4653 }
4654  
4655 0 my $weaken = CORE::delete( $def->{weaken} );
4656 0 ▶ $self->__message( 112, "Creating class for field $field with definition -> ", sub{ $self->Module::Generic::dump( $def ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
4657 0 ▶ my $class = $self->__create_class( $field, $def ) || die( "Failed to create the dynamic class for field \"$field\".\n" );
Condition0%0/2
$self->__create_class($field, $def) || die(qq[Failed to create the dynamic class for field "$field".\n])
l!l
00
MC/DC0%0/1
$self->__create_class($field, $def) || die(qq[Failed to create the dynamic class for field "$field".\n])
$self->__create_class($field, $def)
Truth table0%0/2
A
A= $self->__create_class($field, $def)
Aresult
11
00
4658  
4659 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
4660 {
4661 # my $hash = shift( @_ );
4662 0 my $hash = $self->_get_args_as_hash( @_ );
4663 0 ▶ $hash->{debug} = $self->debug if( ref( $hash ) eq 'HASH' && !exists( $hash->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $hash eq "HASH" and not exists $hash->{"debug"} 0 0 0
Condition0%0/3
ref $hash eq "HASH" and not exists $hash->{"debug"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $hash eq "HASH" and not exists $hash->{"debug"}
ref $hash eq "HASH" not exists $hash->{"debug"}
Truth table0%0/3
A and not(B)
A= ref $hash eq "HASH"B= not exists $hash->{"debug"}
ABresult
0X0
100
111
4664 # my $o = $class->new( $hash );
4665 # my $o = $self->__instantiate_object( $field, $class, ( %$hash, debug => $self->debug ) );
4666 0 ▶ my $o = $self->__instantiate_object( $field, $class, $hash ) || return( $self->pass_error );
Condition0%0/2
$self->__instantiate_object($field, $class, $hash) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->__instantiate_object($field, $class, $hash) || (return $self->pass_error)
$self->__instantiate_object($field, $class, $hash)
Truth table0%0/2
A
A= $self->__instantiate_object($field, $class, $hash)
Aresult
11
00
4667 0 $self->clear_error;
4668 0 $data->{ $field } = $o;
4669 }
4670  
4671 0 ▶ if( !$data->{ $field } )
Branch: 1 branch
BranchTrueFalseTotal
unless ($data->{$field}) 0 0 0
4672 {
4673 0 ▶ my $o = $self->__instantiate_object( $field, $class ) || return( $self->pass_error );
Condition0%0/2
$self->__instantiate_object($field, $class) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->__instantiate_object($field, $class) || (return $self->pass_error)
$self->__instantiate_object($field, $class)
Truth table0%0/2
A
A= $self->__instantiate_object($field, $class)
Aresult
11
00
4674 0 ▶ $o->debug( $self->debug ) if( $o && $o->can( 'debug' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $o and $o->can("debug") 0 0 0
Condition0%0/3
$o and $o->can("debug")
!ll&&!rl&&r
000
MC/DC0%0/2
$o and $o->can("debug")
$o $o->can("debug")
Truth table0%0/3
A and B
A= $oB= $o->can("debug")
ABresult
0X0
100
111
4675 0 $data->{ $field } = $o;
4676 }
4677 0 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $weaken && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $weaken and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 0 0
Condition0%0/6
$weaken and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
000
$weaken and $self->_is_object($data->{$field})
!ll&&!rl&&r
000
MC/DC0%0/3
$weaken and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$weaken $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table0%0/4
A and B and not(C)
A= $weakenB= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
4678 0 return( $data->{ $field } );
4679 }
4680  
4681 sub _set_get_class_array
4682 0 ▶{
Subroutine _set_get_class_array: not called CC=14 SCAR=53.5
4683 0 my $self = shift( @_ );
4684 0 my $field = shift( @_ );
4685 0 my $def = shift( @_ );
4686 0 my $this = $self->_obj2h;
4687 0 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 0 0
4688 0 ▶ if( ref( $def ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $def ne "HASH") 0 0 0
4689 {
4690 0 CORE::warn( "Warning only: dynamic class field definition hash ($def) for field \"$field\" is not a hash reference." );
4691 0 return;
4692 }
4693 0 ▶ @_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and not defined $_[0] 0 0 0
Condition0%0/3
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and not defined $_[0]
scalar @_ == 1 not defined $_[0]
Truth table0%0/3
A and not(B)
A= scalar @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
4694 0 ▶ my $class = $self->__create_class( $field, $def ) || die( "Failed to create the dynamic class for field \"$field\".\n" );
Condition0%0/2
$self->__create_class($field, $def) || die(qq[Failed to create the dynamic class for field "$field".\n])
l!l
00
MC/DC0%0/1
$self->__create_class($field, $def) || die(qq[Failed to create the dynamic class for field "$field".\n])
$self->__create_class($field, $def)
Truth table0%0/2
A
A= $self->__create_class($field, $def)
Aresult
11
00
4695 0 my $weaken = CORE::delete( $def->{weaken} );
4696 # return( $self->_set_get_object_array( $field, $class, @_ ) );
4697 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
4698 {
4699 0 my $ref = shift( @_ );
4700 0 ▶ return( $self->error( "I was expecting an array ref, but instead got '$ref'. _is_array returned: '", $self->_is_array( $ref ), "'" ) ) if( !$self->_is_array( $ref ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($ref) 0 0 0
4701 0 my $arr = [];
4702 0 ▶ for( my $i = 0; $i < scalar( @$ref ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$ref) 0 0 0
4703 {
4704 0 ▶ if( ref( $ref->[$i] ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref->[$i] ne "HASH") 0 0 0
4705 {
4706 0 return( $self->error( "Array offset $i is not a hash reference. I was expecting a hash reference to instantiate an object of class $class." ) );
4707 }
4708 0 ▶ my $o = $self->__instantiate_object( $field, $class, $ref->[$i] ) || return( $self->pass_error );
Condition0%0/2
$self->__instantiate_object($field, $class, $ref->[$i]) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->__instantiate_object($field, $class, $ref->[$i]) || (return $self->pass_error)
$self->__instantiate_object($field, $class, $ref->[$i])
Truth table0%0/2
A
A= $self->__instantiate_object($field, $class, $ref->[$i])
Aresult
11
00
4709 # If an error occurred, we report it to the caller and do not add it, since even if we did add it, it would be undef, because no object would have been created.
4710 # And the caller needs to know there has been some errors
4711 0 ▶ Scalar::Util::weaken( $o ) if( $weaken && $self->_is_object( $o ) && !Scalar::Util::isweak( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
if $weaken and $self->_is_object($o) and not builtin::is_weak($o) 0 0 0
Condition0%0/6
$weaken and $self->_is_object($o) and not builtin::is_weak($o)
!ll&&!rl&&r
000
$weaken and $self->_is_object($o)
!ll&&!rl&&r
000
MC/DC0%0/3
$weaken and $self->_is_object($o) and not builtin::is_weak($o)
$weaken $self->_is_object($o) not builtin::is_weak($o)
Truth table0%0/4
A and B and not(C)
A= $weakenB= $self->_is_object($o)C= not builtin::is_weak($o)
ABCresult
0XX0
10X0
1100
1111
4712 0 CORE::push( @$arr, $o );
4713 }
4714 0 $data->{ $field } = $arr;
4715 0 $self->clear_error;
4716 }
4717 0 return( $data->{ $field } );
4718 }
4719  
4720 178 ▶sub _set_get_code : lvalue
Subroutine _set_get_code: called CC=8 SCAR=27.2
4721 {
4722 178 my $self = shift( @_ );
4723 178 my $field = shift( @_ );
4724 178 my $this = $self->_obj2h;
4725 178 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 13 165 178
4726 178 my $opts = {};
4727  
4728 178 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 178 178
4729 {
4730 0 $opts = $field;
4731 0 ▶ if( CORE::exists( $opts->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'field'} and defined $opts->{'field'} and length $opts->{'field'}) { } 0 0 0
Condition0%0/6
exists $opts->{"field"} and defined $opts->{"field"} and length $opts->{"field"}
!ll&&!rl&&r
000
exists $opts->{"field"} and defined $opts->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $opts->{"field"} and defined $opts->{"field"} and length $opts->{"field"}
exists $opts->{"field"} defined $opts->{"field"} length $opts->{"field"}
Truth table0%0/4
A and B and C
A= exists $opts->{"field"}B= defined $opts->{"field"}C= length $opts->{"field"}
ABCresult
0XX0
10X0
1100
1111
4732 defined( $opts->{field} ) &&
4733 CORE::length( $opts->{field} ) )
4734 {
4735 0 $field = $opts->{field};
4736 }
4737 else
4738 {
4739 0 $field = undef;
4740 }
4741 }
4742 178 ▶ $opts->{undef_ok} //= 0;
Condition50%1/2
$opts->{"undef_ok"} //= 0
l!l
0178
MC/DC0%0/1
$opts->{"undef_ok"} //= 0
$opts->{"undef_ok"}
Truth table50%1/2
A
A= $opts->{"undef_ok"}
Aresult
11
00
4743 178 ▶ $opts->{return_undef} //= 0;
Condition50%1/2
$opts->{"return_undef"} //= 0
l!l
0178
MC/DC0%0/1
$opts->{"return_undef"} //= 0
$opts->{"return_undef"}
Truth table50%1/2
A
A= $opts->{"return_undef"}
Aresult
11
00
4744  
4745 return( $self->_set_get_callback({
4746 get => sub
4747 175 ▶ {
Subroutine __ANON__: called CC=10 SCAR=28.6
4748 175 my $self = shift( @_ );
4749 175 my $ctx = $_;
4750 175 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 175 175
4751 175 ▶ if( ( !defined( $data->{ $field } ) || !$data->{ $field } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $data->{$field} && $data->{$field} || $opts->{"return_undef"} and $ctx->{"object"}) 0 175 175
Condition66%6/9
not defined $data->{$field} && $data->{$field} || $opts->{"return_undef"} and $ctx->{"object"}
!ll&&!rl&&r
51700
defined $data->{$field} && $data->{$field} || $opts->{'return_undef'}
l!l&&r!l&&!r
50170
defined $data->{$field} and $data->{$field}
!ll&&!rl&&r
17005
MC/DC0%0/4
not defined $data->{$field} && $data->{$field} || $opts->{"return_undef"} and $ctx->{"object"}
defined $data->{$field} $data->{$field} $opts->{'return_undef'} $ctx->{"object"}
Truth table28%2/7
not(A and B || C) and D
A= defined $data->{$field}B= $data->{$field}C= $opts->{'return_undef'}D= $ctx->{"object"}
ABCDresult
11XX0
0X1X0
101X0
0X000
10000
0X011
10011
4752 !$opts->{return_undef} &&
4753 $ctx->{object} )
4754 {
4755 0 ▶ return( sub{} );
Subroutine __ANON__: not called CC=1 SCAR=6.9
4756 }
4757 175 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $opts->{weaken} && defined( $data->{ $field } ) && ref( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field}) 0 175 175
Condition33%3/9
$opts->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
17500
$opts->{"weaken"} and defined $data->{$field} and ref $data->{$field}
!ll&&!rl&&r
17500
$opts->{"weaken"} and defined $data->{$field}
!ll&&!rl&&r
17500
MC/DC0%0/4
$opts->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
$opts->{"weaken"} defined $data->{$field} ref $data->{$field} not builtin::is_weak($data->{$field})
Truth table20%1/5
A and B and C and not(D)
A= $opts->{"weaken"}B= defined $data->{$field}C= ref $data->{$field}D= not builtin::is_weak($data->{$field})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
4758 175 return( $data->{ $field } );
4759 },
4760 set => sub
4761 4 ▶ {
Subroutine __ANON__: called CC=14 SCAR=36.5
4762 4 my $self = shift( @_ );
4763 4 my $arg = shift( @_ );
4764 4 my $ctx = $_;
4765 4 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 4 4
4766 4 my $v = $arg;
4767 4 ▶ if( ( ( $opts->{undef_ok} && defined( $v ) ) || !$opts->{undef_ok} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"undef_ok"} && defined $v || !$opts->{"undef_ok"} and ref $v ne "CODE") 0 4 4
Condition33%3/9
$opts->{"undef_ok"} && defined $v || !$opts->{"undef_ok"} and ref $v ne "CODE"
!ll&&!rl&&r
040
$opts->{"undef_ok"} and defined $v or not $opts->{"undef_ok"}
l!l&&r!l&&!r
040
$opts->{"undef_ok"} and defined $v
!ll&&!rl&&r
400
MC/DC0%0/4
$opts->{"undef_ok"} && defined $v || !$opts->{"undef_ok"} and ref $v ne "CODE"
$opts->{"undef_ok"} defined $v not $opts->{"undef_ok"} ref $v ne "CODE"
Truth table12%1/8
A and B or not(C) and D
A= $opts->{"undef_ok"}B= defined $vC= not $opts->{"undef_ok"}D= ref $v ne "CODE"
ABCDresult
0X0X0
100X0
11X00
0X100
10100
11X11
0X111
10111
4768 ref( $v ) ne 'CODE' )
4769 {
4770 0 return( $self->error( "Value provided for \"$field\" ($v) is not an anonymous subroutine (code). You can pass as argument something like \$self->curry::my_sub or something like sub { some_code_here; }" ) );
4771 }
4772 4 $data->{ $field } = $v;
4773 4 $self->clear_error;
4774  
4775 4 ▶ if( ( !defined( $data->{ $field } ) || !$data->{ $field } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $data->{$field} && $data->{$field} || $opts->{"return_undef"} and $ctx->{"object"}) 0 4 4
Condition33%3/9
not defined $data->{$field} && $data->{$field} || $opts->{"return_undef"} and $ctx->{"object"}
!ll&&!rl&&r
400
defined $data->{$field} && $data->{$field} || $opts->{'return_undef'}
l!l&&r!l&&!r
400
defined $data->{$field} and $data->{$field}
!ll&&!rl&&r
004
MC/DC0%0/4
not defined $data->{$field} && $data->{$field} || $opts->{"return_undef"} and $ctx->{"object"}
defined $data->{$field} $data->{$field} $opts->{'return_undef'} $ctx->{"object"}
Truth table14%1/7
not(A and B || C) and D
A= defined $data->{$field}B= $data->{$field}C= $opts->{'return_undef'}D= $ctx->{"object"}
ABCDresult
11XX0
0X1X0
101X0
0X000
10000
0X011
10011
4776 !$opts->{return_undef} &&
4777 $ctx->{object} )
4778 {
4779 0 ▶ return( sub{} );
Subroutine __ANON__: not called CC=1 SCAR=6.9
4780 }
4781 4 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $opts->{weaken} && defined( $data->{ $field } ) && ref( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field}) 0 4 4
Condition33%3/9
$opts->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
400
$opts->{"weaken"} and defined $data->{$field} and ref $data->{$field}
!ll&&!rl&&r
400
$opts->{"weaken"} and defined $data->{$field}
!ll&&!rl&&r
400
MC/DC0%0/4
$opts->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
$opts->{"weaken"} defined $data->{$field} ref $data->{$field} not builtin::is_weak($data->{$field})
Truth table20%1/5
A and B and C and not(D)
A= $opts->{"weaken"}B= defined $data->{$field}C= ref $data->{$field}D= not builtin::is_weak($data->{$field})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
4782 4 return( $data->{ $field } );
4783 },
4784 178 field => $field,
4785 }, @_ ) );
4786 }
4787  
4788 16 ▶sub _set_get_file : lvalue
Subroutine _set_get_file: called CC=12 SCAR=39.9
4789 {
4790 16 my $self = shift( @_ );
4791 16 my $field = shift( @_ );
4792 39 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
4793 16 my $this = $self->_obj2h;
4794 16 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 12 4 16
4795  
4796 16 my $callbacks = {};
4797 16 my $check;
4798 16 my $def = {};
4799 16 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 16 16
4800 {
4801 0 $def = $field;
4802 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
4803 defined( $def->{field} ) &&
4804 CORE::length( $def->{field} ) )
4805 {
4806 0 $field = $def->{field};
4807 }
4808 else
4809 {
4810 0 $field = undef;
4811 }
4812 # Should have been 'callbacks', but we catch it anyway.
4813 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
4814 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
4815 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
4816 }
4817  
4818 return( $self->_set_get_callback({
4819 get => sub
4820 10 ▶ {
Subroutine __ANON__: called CC=9 SCAR=32.0
4821 10 my $self = shift( @_ );
4822 10 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 10 10
4823 10 ▶ if( $data->{ $field } && !$self->_is_a( $data->{ $field } => 'Module::Generic::File' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{$field} and not $self->_is_a($data->{$field}, "Module::Generic::File")) 0 10 10
Condition33%1/3
$data->{$field} and not $self->_is_a($data->{$field}, "Module::Generic::File")
!ll&&!rl&&r
0100
MC/DC0%0/2
$data->{$field} and not $self->_is_a($data->{$field}, "Module::Generic::File")
$data->{$field} not $self->_is_a($data->{$field}, "Module::Generic::File")
Truth table33%1/3
A and not(B)
A= $data->{$field}B= not $self->_is_a($data->{$field}, "Module::Generic::File")
ABresult
0X0
100
111
4824 {
4825 0 ▶ $self->_load_class( 'Module::Generic::File' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::File") or return $self->pass_error 0 0 0
4826 return( $self->pass_error );
4827 0 ▶ $data->{ $field } = Module::Generic::File->new( $data->{ $field } . '' ) ||
Condition0%0/2
'Module::Generic::File'->new($data->{$field} . '') || (return $self->error('Module::Generic::File'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::File'->new($data->{$field} . '') || (return $self->error('Module::Generic::File'->error))
'Module::Generic::File'->new($data->{$field} . '')
Truth table0%0/2
A
A= 'Module::Generic::File'->new($data->{$field} . '')
Aresult
11
00
4828 return( $self->error( Module::Generic::File->error ) );
4829 }
4830 10 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 10 10
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
1000
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
1000
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
4831 10 return( $data->{ $field } )
4832 },
4833 set => sub
4834 7 ▶ {
Subroutine __ANON__: called CC=27 SCAR=55.6
4835 7 my $self = shift( @_ );
4836 7 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 7 7
4837 7 ▶ @_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and not defined $_[0] 0 7 7
Condition33%1/3
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
070
MC/DC0%0/2
scalar @_ == 1 and not defined $_[0]
scalar @_ == 1 not defined $_[0]
Truth table33%1/3
A and not(B)
A= scalar @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
4838 7 my $arg = shift( @_ );
4839  
4840 7 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 7 7
4841 {
4842 # try-catch
4843 0 local $@;
4844 0 my $rv = eval{ $check->( $self, $arg ) };
4845 0 ▶ 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
4846 {
4847 0 return( $self->pass_error );
4848 }
4849 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
4850 }
4851  
4852 7 ▶ $self->_load_class( 'Module::Generic::File' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::File") or return $self->pass_error 7 0 7
4853 return( $self->pass_error );
4854 7 my $val;
4855 7 ▶ if( $self->_is_a( $arg => 'Module::Generic::File' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($arg, 'Module::Generic::File')) { } 1 6 7
elsif (defined $arg) { } 6 0 6
4856 {
4857 1 $val = $arg;
4858 }
4859 elsif( defined( $arg ) )
4860 {
4861 6 ▶ $val = Module::Generic::File->new( $arg ) ||
Condition50%1/2
'Module::Generic::File'->new($arg) || (return $self->pass_error('Module::Generic::File'->error))
l!l
60
MC/DC0%0/1
'Module::Generic::File'->new($arg) || (return $self->pass_error('Module::Generic::File'->error))
'Module::Generic::File'->new($arg)
Truth table50%1/2
A
A= 'Module::Generic::File'->new($arg)
Aresult
11
00
4862 return( $self->pass_error( Module::Generic::File->error ) );
4863 }
4864 7 $data->{ $field } = $val;
4865 7 $self->clear_error;
4866 7 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 7 7
Condition16%1/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
700
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table25%1/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
4867 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
4868 {
4869 0 my $coderef;
4870 0 foreach my $t ( qw( add set ) )
4871 {
4872 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
4873 {
4874 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
4875 ? $callbacks->{ $t }
4876 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
4877 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
4878 }
4879 }
4880 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
4881 {
4882 # try-catch
4883 0 local $@;
4884 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
4885 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
4886 {
4887 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
4888 }
4889 ▶ elsif( !defined( $rv ) && $self->error )
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
4890 {
4891 0 return( $self->pass_error );
4892 }
4893 0 $data->{ $field } = $rv;
4894 }
4895 }
4896 7 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 7 7
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
700
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
700
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
4897 7 return( $data->{ $field } );
4898 },
4899 16 field => $field,
4900 }, @_ ) );
4901 }
4902  
4903 0 ▶sub _set_get_glob : lvalue
Subroutine _set_get_glob: not called CC=12 SCAR=50.5
4904 {
4905 0 my $self = shift( @_ );
4906 0 my $field = shift( @_ );
4907 0 my $this = $self->_obj2h;
4908 0 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 0 0
4909  
4910 0 my $callbacks = {};
4911 0 my $check;
4912 0 my $def = {};
4913 0 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 0 0
4914 {
4915 0 $def = $field;
4916 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
4917 defined( $def->{field} ) &&
4918 CORE::length( $def->{field} ) )
4919 {
4920 0 $field = $def->{field};
4921 }
4922 else
4923 {
4924 0 $field = undef;
4925 }
4926 # Should have been 'callbacks', but we catch it anyway.
4927 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
4928 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
4929 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
4930 }
4931  
4932 return( $self->_set_get_callback({
4933 get => sub
4934 0 ▶ {
Subroutine __ANON__: not called CC=5 SCAR=34.0
4935 0 my $self = shift( @_ );
4936 0 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 0 0
4937 0 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_glob( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_glob($data->{$field}) and not builtin::is_weak($data->{$field}) 0 0 0
Condition0%0/6
$def->{"weaken"} and $self->_is_glob($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
000
$def->{"weaken"} and $self->_is_glob($data->{$field})
!ll&&!rl&&r
000
MC/DC0%0/3
$def->{"weaken"} and $self->_is_glob($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_glob($data->{$field}) not builtin::is_weak($data->{$field})
Truth table0%0/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_glob($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
4938 0 return( $data->{ $field } );
4939 },
4940 set => sub
4941 0 ▶ {
Subroutine __ANON__: not called CC=27 SCAR=66.3
4942 0 my $self = shift( @_ );
4943 0 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 0 0
4944 0 ▶ @_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and not defined $_[0] 0 0 0
Condition0%0/3
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and not defined $_[0]
scalar @_ == 1 not defined $_[0]
Truth table0%0/3
A and not(B)
A= scalar @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
4945 0 my $arg = shift( @_ );
4946  
4947 0 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 0 0
4948 {
4949 # try-catch
4950 0 local $@;
4951 0 my $rv = eval{ $check->( $self, $arg ) };
4952 0 ▶ 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
4953 {
4954 0 return( $self->pass_error );
4955 }
4956 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
4957 }
4958  
4959 # Convoluted, but that's because reftype returns undef for false, and this would trigger the annoying warning 'Use of uninitialized value in string ne'
4960 0 ▶ if( defined( $arg ) && ( Scalar::Util::reftype( $arg // '' ) // '' ) ne 'GLOB' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg and (builtin::reftype($arg // "") // "") ne "GLOB") 0 0 0
Condition0%0/7
defined $arg and (builtin::reftype($arg // "") // "") ne "GLOB"
!ll&&!rl&&r
000
builtin::reftype($arg // "") // ""
l!l
00
$arg // ""
l!l
00
MC/DC0%0/2
defined $arg and (builtin::reftype($arg // "") // "") ne "GLOB"
defined $arg $arg
Truth table0%0/3
A and B
A= defined $argB= $arg
ABresult
0X0
100
111
4961 {
4962 0 $self->__message( 104, "Value being set ($arg) is not a glob." );
4963 0 return( $self->error( "Method $field takes only a glob, but value provided ($arg) is not supported" ) );
4964 }
4965  
4966 0 $data->{ $field } = $arg;
4967 0 $self->clear_error;
4968  
4969 0 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 0 0
Condition0%0/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
000
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table0%0/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
4970 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
4971 {
4972 0 my $coderef;
4973 0 foreach my $t ( qw( add set ) )
4974 {
4975 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
4976 {
4977 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
4978 ? $callbacks->{ $t }
4979 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
4980 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
4981 }
4982 }
4983 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
4984 {
4985 # try-catch
4986 0 local $@;
4987 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
4988 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
4989 {
4990 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
4991 }
4992 ▶ elsif( !defined( $rv ) && $self->error )
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
4993 {
4994 0 return( $self->pass_error );
4995 }
4996 0 $data->{ $field } = $rv;
4997 }
4998 }
4999  
5000 0 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_glob( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_glob($data->{$field}) and not builtin::is_weak($data->{$field}) 0 0 0
Condition0%0/6
$def->{"weaken"} and $self->_is_glob($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
000
$def->{"weaken"} and $self->_is_glob($data->{$field})
!ll&&!rl&&r
000
MC/DC0%0/3
$def->{"weaken"} and $self->_is_glob($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_glob($data->{$field}) not builtin::is_weak($data->{$field})
Truth table0%0/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_glob($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
5001 0 return( $data->{ $field } );
5002 },
5003 0 field => $field,
5004 }, @_ ) );
5005 }
5006  
5007 21 ▶sub _set_get_hash : lvalue
Subroutine _set_get_hash: called CC=12 SCAR=40.2
5008 {
5009 21 my $self = shift( @_ );
5010 21 my $field = shift( @_ );
5011 21 my $this = $self->_obj2h;
5012 21 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 21 21
5013  
5014 21 my $callbacks = {};
5015 21 my $check;
5016 21 my $def = {};
5017 21 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 21 21
5018 {
5019 0 $def = $field;
5020 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
5021 defined( $def->{field} ) &&
5022 CORE::length( $def->{field} ) )
5023 {
5024 0 $field = $def->{field};
5025 }
5026 else
5027 {
5028 0 $field = undef;
5029 }
5030 # Should have been 'callbacks', but we catch it anyway.
5031 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
5032 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
5033 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
5034 }
5035  
5036 return( $self->_set_get_callback({
5037 get => sub
5038 18 ▶ {
Subroutine __ANON__: called CC=9 SCAR=30.1
5039 18 my $self = shift( @_ );
5040 18 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 18 18
5041 18 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && defined( $data->{ $field } ) && ref( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field}) 0 18 18
Condition33%3/9
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
1800
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field}
!ll&&!rl&&r
1800
$def->{"weaken"} and defined $data->{$field}
!ll&&!rl&&r
1800
MC/DC0%0/4
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
$def->{"weaken"} defined $data->{$field} ref $data->{$field} not builtin::is_weak($data->{$field})
Truth table20%1/5
A and B and C and not(D)
A= $def->{"weaken"}B= defined $data->{$field}C= ref $data->{$field}D= not builtin::is_weak($data->{$field})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
5042 18 ▶ if( exists( $callbacks->{get} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{"get"} and $callbacks->{"get"} and ref $callbacks->{"get"} eq "CODE") 0 18 18
Condition33%2/6
exists $callbacks->{"get"} and $callbacks->{"get"} and ref $callbacks->{"get"} eq "CODE"
!ll&&!rl&&r
1800
exists $callbacks->{"get"} and $callbacks->{"get"}
!ll&&!rl&&r
1800
MC/DC0%0/3
exists $callbacks->{"get"} and $callbacks->{"get"} and ref $callbacks->{"get"} eq "CODE"
exists $callbacks->{"get"} $callbacks->{"get"} ref $callbacks->{"get"} eq "CODE"
Truth table25%1/4
A and B and C
A= exists $callbacks->{"get"}B= $callbacks->{"get"}C= ref $callbacks->{"get"} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
5043 $callbacks->{get} &&
5044 ref( $callbacks->{get} ) eq 'CODE' )
5045 {
5046 0 return( $callbacks->{get}->( $self ) );
5047 }
5048 18 return( $data->{ $field } );
5049 },
5050 set => sub
5051 4 ▶ {
Subroutine __ANON__: called CC=29 SCAR=56.8
5052 4 my $self = shift( @_ );
5053 4 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 4 4
5054 4 ▶ @_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and not defined $_[0] 0 4 4
Condition66%2/3
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
130
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
5055 4 my $arg;
5056 4 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 0 4
5057 {
5058 4 ▶ if( ref( $_[0] ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 3 1 4
elsif (not @_ % 2) { } 1 0 1
5059 {
5060 3 $arg = shift( @_ );
5061 }
5062 elsif( !( @_ % 2 ) )
5063 {
5064 1 $arg = { @_ };
5065 }
5066 else
5067 {
5068 0 $arg = shift( @_ );
5069 }
5070 }
5071  
5072 4 ▶ if( defined( $arg ) && ref( $arg ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg and ref $arg ne "HASH") 0 4 4
Condition33%1/3
defined $arg and ref $arg ne "HASH"
!ll&&!rl&&r
040
MC/DC0%0/2
defined $arg and ref $arg ne "HASH"
defined $arg ref $arg ne "HASH"
Truth table33%1/3
A and B
A= defined $argB= ref $arg ne "HASH"
ABresult
0X0
100
111
5073 {
5074 0 return( $self->error( "Method $field takes only a hash or reference to a hash, but value provided ($arg) is not supported" ) );
5075 }
5076  
5077 4 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 4 4
5078 {
5079 # try-catch
5080 0 local $@;
5081 0 my $rv = eval{ $check->( $self, $arg ) };
5082 0 ▶ 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
5083 {
5084 0 return( $self->pass_error );
5085 }
5086 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
5087 }
5088  
5089 4 $data->{ $field } = $arg;
5090 4 $self->clear_error;
5091  
5092 4 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 4 4
Condition16%1/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
400
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table25%1/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
5093 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
5094 {
5095 0 my $coderef;
5096 0 foreach my $t ( qw( add set ) )
5097 {
5098 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
5099 {
5100 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
5101 ? $callbacks->{ $t }
5102 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
5103 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
5104 }
5105 }
5106 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
5107 {
5108 # try-catch
5109 0 local $@;
5110 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
5111 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
5112 {
5113 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
5114 }
5115 ▶ elsif( !defined( $rv ) && $self->error )
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
5116 {
5117 0 return( $self->pass_error );
5118 }
5119 0 $data->{ $field } = $rv;
5120 }
5121 }
5122 4 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && defined( $data->{ $field } ) && ref( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field}) 0 4 4
Condition33%3/9
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
400
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field}
!ll&&!rl&&r
400
$def->{"weaken"} and defined $data->{$field}
!ll&&!rl&&r
400
MC/DC0%0/4
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
$def->{"weaken"} defined $data->{$field} ref $data->{$field} not builtin::is_weak($data->{$field})
Truth table20%1/5
A and B and C and not(D)
A= $def->{"weaken"}B= defined $data->{$field}C= ref $data->{$field}D= not builtin::is_weak($data->{$field})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
5123 4 return( $data->{ $field } );
5124 },
5125 21 field => $field,
5126 }, @_ ) );
5127 }
5128  
5129 55 ▶sub _set_get_hash_as_mix_object : lvalue
Subroutine _set_get_hash_as_mix_object: called CC=14 SCAR=43.3
5130 {
5131 55 my $self = shift( @_ );
5132 55 my $field = shift( @_ );
5133 55 my $this = $self->_obj2h;
5134 55 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 55 55
5135  
5136 55 my $callbacks = {};
5137 55 my $check;
5138 55 my $opts = {};
5139  
5140 55 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 55 55
5141 {
5142 0 $opts = $field;
5143 0 ▶ if( CORE::exists( $opts->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'field'} and defined $opts->{'field'} and length $opts->{'field'}) { } 0 0 0
Condition0%0/6
exists $opts->{"field"} and defined $opts->{"field"} and length $opts->{"field"}
!ll&&!rl&&r
000
exists $opts->{"field"} and defined $opts->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $opts->{"field"} and defined $opts->{"field"} and length $opts->{"field"}
exists $opts->{"field"} defined $opts->{"field"} length $opts->{"field"}
Truth table0%0/4
A and B and C
A= exists $opts->{"field"}B= defined $opts->{"field"}C= length $opts->{"field"}
ABCresult
0XX0
10X0
1100
1111
5144 defined( $opts->{field} ) &&
5145 CORE::length( $opts->{field} ) )
5146 {
5147 0 $field = $opts->{field};
5148 }
5149 else
5150 {
5151 0 $field = undef;
5152 }
5153 # Should have been 'callbacks', but we catch it anyway.
5154 0 ▶ $callbacks = $opts->{callback} if( CORE::exists( $opts->{callback} ) && ref( $opts->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"callback"} and ref $opts->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $opts->{"callback"} and ref $opts->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"callback"} and ref $opts->{"callback"} eq "HASH"
exists $opts->{"callback"} ref $opts->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $opts->{"callback"}B= ref $opts->{"callback"} eq "HASH"
ABresult
0X0
100
111
5155 0 ▶ $callbacks = $opts->{callbacks} if( CORE::exists( $opts->{callbacks} ) && ref( $opts->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"callbacks"} and ref $opts->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $opts->{"callbacks"} and ref $opts->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"callbacks"} and ref $opts->{"callbacks"} eq "HASH"
exists $opts->{"callbacks"} ref $opts->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $opts->{"callbacks"}B= ref $opts->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
5156 0 ▶ $check = $opts->{check} if( CORE::exists( $opts->{check} ) && ref( $opts->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"check"} and ref $opts->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $opts->{"check"} and ref $opts->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"check"} and ref $opts->{"check"} eq "CODE"
exists $opts->{"check"} ref $opts->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $opts->{"check"}B= ref $opts->{"check"} eq "CODE"
ABresult
0X0
100
111
5157 }
5158 55 ▶ $opts->{undef_ok} //= 0;
Condition50%1/2
$opts->{"undef_ok"} //= 0
l!l
055
MC/DC0%0/1
$opts->{"undef_ok"} //= 0
$opts->{"undef_ok"}
Truth table50%1/2
A
A= $opts->{"undef_ok"}
Aresult
11
00
5159 55 ▶ $opts->{return_undef} //= 0;
Condition50%1/2
$opts->{"return_undef"} //= 0
l!l
055
MC/DC0%0/1
$opts->{"return_undef"} //= 0
$opts->{"return_undef"}
Truth table50%1/2
A
A= $opts->{"return_undef"}
Aresult
11
00
5160  
5161 return( $self->_set_get_callback({
5162 get => sub
5163 49 ▶ {
Subroutine __ANON__: called CC=13 SCAR=37.0
5164 49 my $self = shift( @_ );
5165 49 my $ctx = $_;
5166 49 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 49 49
5167 49 ▶ if( !defined( $data->{ $field } ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $data->{$field}) { } 0 49 49
elsif ($data->{$field} and not $self->_is_object($data->{$field})) { } 11 38 49
5168 {
5169 # If the call context is either an hash or an object, we instantiate an empty object, and return it,
5170 # but we do not affect the current property value of our object
5171 0 ▶ if( $ctx->{object} || $ctx->{hash} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"object"} or $ctx->{"hash"}) 0 0 0
Condition0%0/3
$ctx->{"object"} or $ctx->{"hash"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ctx->{"object"} or $ctx->{"hash"}
$ctx->{"object"} $ctx->{"hash"}
Truth table0%0/3
A or B
A= $ctx->{"object"}B= $ctx->{"hash"}
ABresult
1X1
011
000
5172 {
5173 0 ▶ $self->_load_class( 'Module::Generic::Hash' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Hash") or return $self->pass_error 0 0 0
5174 return( $self->pass_error );
5175 0 local $Module::Generic::Hash::DEBUG = $self->debug;
5176 # my $o = Module::Generic::Hash->new( $data->{ $field } );
5177 0 ▶ my $o = Module::Generic::Hash->new ||
Condition0%0/2
'Module::Generic::Hash'->new || (return $self->pass_error('Module::Generic::Hash'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::Hash'->new || (return $self->pass_error('Module::Generic::Hash'->error))
'Module::Generic::Hash'->new
Truth table0%0/2
A
A= 'Module::Generic::Hash'->new
Aresult
11
00
5178 return( $self->pass_error( Module::Generic::Hash->error ) );
5179 0 return( $o );
5180 }
5181 0 return;
5182 }
5183 ▶ elsif( $data->{ $field } && !$self->_is_object( $data->{ $field } ) )
Condition66%2/3
$data->{$field} and not $self->_is_object($data->{$field})
!ll&&!rl&&r
03811
MC/DC50%1/2
$data->{$field} and not $self->_is_object($data->{$field})
$data->{$field} not $self->_is_object($data->{$field})
Truth table66%2/3
A and not(B)
A= $data->{$field}B= not $self->_is_object($data->{$field})
ABresult
0X0
100
111
5184 {
5185 11 ▶ $self->_load_class( 'Module::Generic::Hash' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Hash") or return $self->pass_error 11 0 11
5186 return( $self->pass_error );
5187 11 local $Module::Generic::Hash::DEBUG = $self->debug;
5188 11 my $o = Module::Generic::Hash->new( $data->{ $field } );
5189 11 $data->{ $field } = $o;
5190 }
5191 49 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $opts->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 49 49
Condition33%2/6
$opts->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
4900
$opts->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
4900
MC/DC0%0/3
$opts->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$opts->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $opts->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
5192 49 return( $data->{ $field } );
5193 },
5194 set => sub
5195 7 ▶ {
Subroutine __ANON__: called CC=45 SCAR=66.7
5196 7 my $self = shift( @_ );
5197 7 my $ctx = $_;
5198 7 my $arg;
5199 7 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 7 7
5200 7 ▶ @_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) && !$opts->{undef_ok} );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and not defined $_[0] and not $opts->{"undef_ok"} 0 7 7
Condition50%3/6
scalar @_ == 1 and not defined $_[0] and not $opts->{"undef_ok"}
!ll&&!rl&&r
700
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
160
MC/DC0%0/3
scalar @_ == 1 and not defined $_[0] and not $opts->{"undef_ok"}
scalar @_ == 1 not defined $_[0] not $opts->{"undef_ok"}
Truth table50%2/4
A and not(B) and not(C)
A= scalar @_ == 1B= not defined $_[0]C= not $opts->{"undef_ok"}
ABCresult
0XX0
10X0
1100
1111
5201 7 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 7 0 7
5202 {
5203 7 ▶ if( ref( $_[0] ) eq 'HASH' )
Branch: 5 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 6 1 7
elsif (ref $_[0] eq 'Module::Generic::Hash') { } 0 1 1
elsif ($self->_is_a($_[0], 'Module::Generic::Hash')) { } 0 1 1
elsif (not @_ % 2) { } 1 0 1
elsif (not defined $_[0] and $opts->{'undef_ok'}) { } 0 0 0
5204 {
5205 6 $arg = shift( @_ );
5206 }
5207 elsif( ref( $_[0] ) eq 'Module::Generic::Hash' )
5208 {
5209 0 $arg = $_[0]->clone;
5210 }
5211 # or, maybe this is a subclass of Module::Generic::Hash ?
5212 elsif( $self->_is_a( $_[0] => 'Module::Generic::Hash' ) )
5213 {
5214 0 $arg = $_[0];
5215 }
5216 elsif( !( @_ % 2 ) )
5217 {
5218 1 $arg = { @_ };
5219 }
5220 ▶ elsif( !defined( $_[0] ) && $opts->{undef_ok} )
Condition0%0/3
not defined $_[0] and $opts->{"undef_ok"}
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $_[0] and $opts->{"undef_ok"}
not defined $_[0] $opts->{"undef_ok"}
Truth table0%0/3
not(A) and B
A= not defined $_[0]B= $opts->{"undef_ok"}
ABresult
0X0
100
111
5221 {
5222 0 $arg = undef;
5223 }
5224 else
5225 {
5226 0 $arg = "'" . join( "', '", @_ ) . "'";
5227 0 return( $self->error( "Method $field takes only a hash or reference to a hash, but value provided ($arg) is not supported" ) );
5228 }
5229 }
5230 7 my $val = $arg;
5231  
5232 7 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 7 7
5233 {
5234 # try-catch
5235 0 local $@;
5236 0 my $rv = eval{ $check->( $self, $val ) };
5237 0 ▶ 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
5238 {
5239 0 return( $self->pass_error );
5240 }
5241 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
5242 }
5243  
5244 7 ▶ if( !defined( $val ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $val) { } 0 7 7
elsif (ref $val eq 'Module::Generic::Hash') { } 0 7 7
elsif ($self->_is_a($val, 'Module::Generic::Hash')) { } 0 7 7
5245 {
5246 0 $data->{ $field } = undef;
5247 }
5248 elsif( ref( $val ) eq 'Module::Generic::Hash' )
5249 {
5250 0 $self->clear_error;
5251 0 return( $data->{ $field } = $val );
5252 }
5253 # or, maybe this is a subclass of Module::Generic::Hash ?
5254 elsif( $self->_is_a( $val => 'Module::Generic::Hash' ) )
5255 {
5256 0 $self->clear_error;
5257 0 return( $data->{ $field } = $val );
5258 }
5259 else
5260 {
5261 7 ▶ $self->_load_class( 'Module::Generic::Hash' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Hash") or return $self->pass_error 7 0 7
5262 return( $self->pass_error );
5263 7 local $Module::Generic::Hash::DEBUG = $self->debug;
5264 7 ▶ $data->{ $field } = Module::Generic::Hash->new( $val ) ||
Condition50%1/2
'Module::Generic::Hash'->new($val) || (return $self->pass_error('Module::Generic::Hash'->error))
l!l
70
MC/DC0%0/1
'Module::Generic::Hash'->new($val) || (return $self->pass_error('Module::Generic::Hash'->error))
'Module::Generic::Hash'->new($val)
Truth table50%1/2
A
A= 'Module::Generic::Hash'->new($val)
Aresult
11
00
5265 return( $self->pass_error( Module::Generic::Hash->error ) );
5266 }
5267  
5268 7 ▶ if( !defined( $data->{ $field } ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $data->{$field}) { } 0 7 7
elsif ($data->{$field} and not $self->_is_object($data->{$field})) { } 0 7 7
5269 {
5270 # If the call context is either an hash or an object, we instantiate an empty object, and return it,
5271 # but we do not affect the current property value of our object
5272 0 ▶ if( $ctx->{object} || $ctx->{hash} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"object"} or $ctx->{"hash"}) 0 0 0
Condition0%0/3
$ctx->{"object"} or $ctx->{"hash"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ctx->{"object"} or $ctx->{"hash"}
$ctx->{"object"} $ctx->{"hash"}
Truth table0%0/3
A or B
A= $ctx->{"object"}B= $ctx->{"hash"}
ABresult
1X1
011
000
5273 {
5274 0 ▶ $self->_load_class( 'Module::Generic::Hash' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Hash") or return $self->pass_error 0 0 0
5275 return( $self->pass_error );
5276 0 local $Module::Generic::Hash::DEBUG = $self->debug;
5277 # my $o = Module::Generic::Hash->new( $data->{ $field } );
5278 0 ▶ my $o = Module::Generic::Hash->new ||
Condition0%0/2
'Module::Generic::Hash'->new || (return $self->pass_error('Module::Generic::Hash'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::Hash'->new || (return $self->pass_error('Module::Generic::Hash'->error))
'Module::Generic::Hash'->new
Truth table0%0/2
A
A= 'Module::Generic::Hash'->new
Aresult
11
00
5279 return( $self->pass_error( Module::Generic::Hash->error ) );
5280 0 $self->clear_error;
5281 0 return( $o );
5282 }
5283 0 $self->clear_error;
5284 0 return;
5285 }
5286 ▶ elsif( $data->{ $field } && !$self->_is_object( $data->{ $field } ) )
Condition33%1/3
$data->{$field} and not $self->_is_object($data->{$field})
!ll&&!rl&&r
070
MC/DC0%0/2
$data->{$field} and not $self->_is_object($data->{$field})
$data->{$field} not $self->_is_object($data->{$field})
Truth table33%1/3
A and not(B)
A= $data->{$field}B= not $self->_is_object($data->{$field})
ABresult
0X0
100
111
5287 {
5288 0 ▶ $self->_load_class( 'Module::Generic::Hash' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Hash") or return $self->pass_error 0 0 0
5289 return( $self->pass_error );
5290 0 local $Module::Generic::Hash::DEBUG = $self->debug;
5291 0 ▶ my $o = Module::Generic::Hash->new( $data->{ $field } ) ||
Condition0%0/2
'Module::Generic::Hash'->new($data->{$field}) || (return $self->pass_error('Module::Generic::Hash'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::Hash'->new($data->{$field}) || (return $self->pass_error('Module::Generic::Hash'->error))
'Module::Generic::Hash'->new($data->{$field})
Truth table0%0/2
A
A= 'Module::Generic::Hash'->new($data->{$field})
Aresult
11
00
5292 return( $self->pass_error( Module::Generic::Hash->error ) );
5293 0 $data->{ $field } = $o;
5294 }
5295 7 $self->clear_error;
5296  
5297 7 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 7 7
Condition16%1/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
700
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table25%1/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
5298 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
5299 {
5300 0 my $coderef;
5301 0 foreach my $t ( qw( add set ) )
5302 {
5303 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
5304 {
5305 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
5306 ? $callbacks->{ $t }
5307 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
5308 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
5309 }
5310 }
5311 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
5312 {
5313 # try-catch
5314 0 local $@;
5315 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
5316 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
5317 {
5318 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
5319 }
5320 ▶ elsif( !defined( $rv ) && $self->error )
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
5321 {
5322 0 return( $self->pass_error );
5323 }
5324 0 $data->{ $field } = $rv;
5325 }
5326 }
5327 7 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $opts->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 7 7
Condition33%2/6
$opts->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
700
$opts->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
700
MC/DC0%0/3
$opts->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$opts->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $opts->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
5328 7 return( $data->{ $field } );
5329 },
5330 55 field => $field,
5331 }, @_ ) );
5332 }
5333  
5334 # There is no lvalue here on purpose
5335 sub _set_get_hash_as_object
5336 30 ▶{
Subroutine _set_get_hash_as_object: called CC=24 SCAR=38.4
5337 30 my $self = shift( @_ );
5338 30 my $this = $self->_obj2h;
5339 30 ▶ my $field = shift( @_ ) || return( $self->error( "No field provided for _set_get_hash_as_object" ) );
Condition50%1/2
shift @_ || (return $self->error('No field provided for _set_get_hash_as_object'))
l!l
300
MC/DC0%0/1
shift @_ || (return $self->error('No field provided for _set_get_hash_as_object'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
5340 30 my $class;
5341 30 ▶ @_ = () if( @_ == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and not defined $_[0] 0 30 30
Condition66%2/3
@_ == 1 and not defined $_[0]
!ll&&!rl&&r
14160
MC/DC0%0/2
@_ == 1 and not defined $_[0]
@_ == 1 not defined $_[0]
Truth table66%2/3
A and not(B)
A= @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
5342 34 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
5343 30 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 16 14 30
5344 {
5345 # No class was provided
5346 16 ▶ if( ( Scalar::Util::reftype( $_[0] ) // '' ) eq 'HASH' )
Branch: 3 branches
BranchTrueFalseTotal
if ((builtin::reftype($_[0]) // '') eq 'HASH') { } 16 0 16
elsif (ref $_[0]) { } 0 0 0
elsif (length($_[0] // '')) { } 0 0 0
Condition50%1/2
builtin::reftype($_[0]) // ""
l!l
160
MC/DC0%0/1
builtin::reftype($_[0]) // ""
builtin::reftype($_[0])
Truth table50%1/2
A
A= builtin::reftype($_[0])
Aresult
11
00
5347 {
5348 16 my $new_class = $field;
5349 16 $new_class =~ tr/-/_/;
5350 16 $new_class =~ s/\_{2,}/_/g;
5351 16 $new_class = join( '', map( ucfirst( lc( $_ ) ), split( /\_/, $new_class ) ) );
5352 16 ▶ $class = ( ref( $self ) || $self ) . "\::${new_class}";
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
1600
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
5353 }
5354 elsif( ref( $_[0] ) )
5355 {
5356 0 ▶ return( $self->error( "Class name in _set_get_hash_as_object helper method cannot be a reference. Received: \"", $self->_str_val( $_[0] // 'undef' ), "\"." ) );
Condition0%0/2
$_[0] // "undef"
l!l
00
MC/DC0%0/1
$_[0] // "undef"
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
5357 }
5358 ▶ elsif( CORE::length( $_[0] // '' ) )
Condition0%0/2
$_[0] // ""
l!l
00
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
5359 {
5360 0 $class = shift( @_ );
5361 }
5362 }
5363 else
5364 {
5365 14 my $new_class = $field;
5366 14 $new_class =~ tr/-/_/;
5367 14 $new_class =~ s/\_{2,}/_/g;
5368 14 $new_class = join( '', map( ucfirst( lc( $_ ) ), split( /\_/, $new_class ) ) );
5369 14 ▶ $class = ( ref( $self ) || $self ) . "\::${new_class}";
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
1400
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
5370 }
5371 # my $class = shift( @_ );
5372 30 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 13 17 30
5373 30 ▶ unless( $self->_is_class_loaded( $class ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_class_loaded($class)) 1 29 30
5374 {
5375 1 $self->__message( 106, "Generating a new perl class ${class}" );
5376 1 my $perl .= <<EOT;
5377 package $class;
5378 BEGIN
5379 {
5380 use strict;
5381 use warnings::register;
5382 use Module::Generic;
5383 use parent qw( Module::Generic::Dynamic );
5384 };
5385  
5386 use strict;
5387 use warnings;
5388  
5389 1;
5390  
5391 EOT
5392 1 local $@;
5393 1 my $rc = eval( $perl );
5394 1 ▶ die( "Unable to dynamically create module \"$class\" for field \"$field\" based on our own class \"", ( ref( $self ) || $self ), "\": $@" ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
5395 }
5396  
5397 # $self->__message( 106, "Instantiating object from dynamic class ${class} with arguments: '", join( "', '", @_ ), "'" );
5398 30 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 16 14 30
5399 {
5400 16 my $hash = shift( @_ );
5401 34 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
5402 16 ▶ $Module::Generic::Dynamic::DEBUG = $self->debug unless( CORE::exists( $hash->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{"debug"} 16 0 16
5403 16 $self->__message( 107, "Instantiating a new $class object for field '$field' and hash reference $hash" );
5404 16 ▶ my $o = $self->__instantiate_object( $field, $class, $hash ) || return( $self->pass_error );
Condition50%1/2
$self->__instantiate_object($field, $class, $hash) || (return $self->pass_error)
l!l
160
MC/DC0%0/1
$self->__instantiate_object($field, $class, $hash) || (return $self->pass_error)
$self->__instantiate_object($field, $class, $hash)
Truth table50%1/2
A
A= $self->__instantiate_object($field, $class, $hash)
Aresult
11
00
5405 16 $self->clear_error;
5406 16 ▶ $self->__message( 107, "Associating resulting object ", $self->_str_val( $o // 'undef' ), " to \$data->{ $field }" );
Condition50%1/2
$o // "undef"
l!l
160
MC/DC0%0/1
$o // "undef"
$o
Truth table50%1/2
A
A= $o
Aresult
11
00
5407 16 $data->{ $field } = $o;
5408 }
5409  
5410 30 ▶ if( !$data->{ $field } || !$self->_is_object( $data->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($data->{$field} and $self->_is_object($data->{$field})) 0 30 30
Condition33%1/3
$data->{$field} and $self->_is_object($data->{$field})
!ll&&!rl&&r
0030
MC/DC0%0/2
$data->{$field} and $self->_is_object($data->{$field})
$data->{$field} $self->_is_object($data->{$field})
Truth table33%1/3
A and B
A= $data->{$field}B= $self->_is_object($data->{$field})
ABresult
0X0
100
111
5411 {
5412 0 ▶ $data->{ $field } = $self->__instantiate_object( $field, $class, $data->{ $field } ) ||
Condition0%0/2
$self->__instantiate_object($field, $class, $data->{$field}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->__instantiate_object($field, $class, $data->{$field}) || (return $self->pass_error)
$self->__instantiate_object($field, $class, $data->{$field})
Truth table0%0/2
A
A= $self->__instantiate_object($field, $class, $data->{$field})
Aresult
11
00
5413 return( $self->pass_error );
5414 }
5415 30 return( $data->{ $field } );
5416 }
5417  
5418 12 ▶sub _set_get_ip : lvalue
Subroutine _set_get_ip: called CC=12 SCAR=39.6
5419 {
5420 12 my $self = shift( @_ );
5421 12 my $field = shift( @_ );
5422 12 my $this = $self->_obj2h;
5423 12 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 6 6 12
5424  
5425 12 my $callbacks = {};
5426 12 my $check;
5427 12 my $def = {};
5428 12 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 12 12
5429 {
5430 0 $def = $field;
5431 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
5432 defined( $def->{field} ) &&
5433 CORE::length( $def->{field} ) )
5434 {
5435 0 $field = $def->{field};
5436 }
5437 else
5438 {
5439 0 $field = undef;
5440 }
5441 # Should have been 'callbacks', but we catch it anyway.
5442 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
5443 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
5444 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
5445 }
5446  
5447 return( $self->_set_get_callback({
5448 get => sub
5449 7 ▶ {
Subroutine __ANON__: called CC=7 SCAR=23.6
5450 7 my $self = shift( @_ );
5451 7 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 7 7
5452 7 my $v;
5453 7 ▶ if( $self->_is_a( $data->{ $field }, 'Module::Generic::Scalar' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($data->{$field}, 'Module::Generic::Scalar')) { } 7 0 7
5454 {
5455 7 $v = $data->{ $field };
5456 }
5457 else
5458 {
5459 0 $v = $data->{ $field } = $self->new_scalar( $data->{ $field } );
5460 }
5461 7 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 7 7
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
700
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
700
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
5462 7 ▶ if( !$v->defined )
Branch: 1 branch
BranchTrueFalseTotal
if (not $v->defined) { } 0 7 7
5463 {
5464 0 return;
5465 }
5466 else
5467 {
5468 7 return( $v );
5469 }
5470 },
5471 set => sub
5472 6 ▶ {
Subroutine __ANON__: called CC=32 SCAR=58.7
5473 6 my $self = shift( @_ );
5474 6 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 6 6
5475 6 my $arg = shift( @_ );
5476 6 my $ctx = $_;
5477 6 my $v = $arg;
5478 6 ▶ $self->__message( 112, "Setting value '", ( $arg // 'undef' ), "' to object field '$field'." );
Condition50%1/2
$arg // "undef"
l!l
60
MC/DC0%0/1
$arg // "undef"
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
5479  
5480 6 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 6 6
5481 {
5482 # try-catch
5483 0 local $@;
5484 0 my $rv = eval{ $check->( $self, $arg ) };
5485 0 ▶ 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
5486 {
5487 0 return( $self->pass_error );
5488 }
5489 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
5490 }
5491  
5492 # If the user wants to remove it
5493 6 ▶ if( !defined( $v ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $v) { } 0 6 6
elsif (length $v and not $self->_is_ip($v)) { } 1 5 6
5494 {
5495 0 $data->{ $field } = $v;
5496 }
5497 # If the user provided a string, let's check it
5498 ▶ elsif( length( $v ) && !$self->_is_ip( $v ) )
Condition66%2/3
length $v and not $self->_is_ip($v)
!ll&&!rl&&r
051
MC/DC50%1/2
length $v and not $self->_is_ip($v)
length $v not $self->_is_ip($v)
Truth table66%2/3
A and not(B)
A= length $vB= not $self->_is_ip($v)
ABresult
0X0
100
111
5499 {
5500 1 $self->__message( 106, "Value provided ($v) is not a valid IP." );
5501 1 return( $self->error( "Value provided ($v) is not a valid ip address." ) );
5502 }
5503 5 $data->{ $field } = $self->new_scalar( $v );
5504  
5505 5 ▶ if( $self->_is_a( $data->{ $field }, 'Module::Generic::Scalar' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($data->{$field}, 'Module::Generic::Scalar')) { } 5 0 5
5506 {
5507 5 $v = $data->{ $field };
5508 }
5509 else
5510 {
5511 0 $v = $data->{ $field } = $self->new_scalar( $data->{ $field } );
5512 }
5513 5 $self->clear_error;
5514  
5515 5 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 5 5
Condition16%1/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
500
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table25%1/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
5516 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
5517 {
5518 0 my $coderef;
5519 0 foreach my $t ( qw( add set ) )
5520 {
5521 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
5522 {
5523 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
5524 ? $callbacks->{ $t }
5525 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
5526 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
5527 }
5528 }
5529 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
5530 {
5531 0 ▶ $self->__message( 112, "Executing callback passing new value '", ( $v // 'undef' ), "'" );
Condition0%0/2
$v // "undef"
l!l
00
MC/DC0%0/1
$v // "undef"
$v
Truth table0%0/2
A
A= $v
Aresult
11
00
5532 # try-catch
5533 0 local $@;
5534 0 $v = eval{ $coderef->( $self, $v ) };
5535 0 ▶ $self->__message( 112, "Callback done. Object field $field value is now '", ( $v // 'undef' ), "'" );
Condition0%0/2
$v // "undef"
l!l
00
MC/DC0%0/1
$v // "undef"
$v
Truth table0%0/2
A
A= $v
Aresult
11
00
5536 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $v and $self->error) { } 0 0 0
5537 {
5538 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $v ), "': $@" ) );
5539 }
5540 ▶ elsif( !defined( $v ) && $self->error )
Condition0%0/3
not defined $v and $self->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $v and $self->error
not defined $v $self->error
Truth table0%0/3
not(A) and B
A= not defined $vB= $self->error
ABresult
0X0
100
111
5541 {
5542 0 return( $self->pass_error );
5543 }
5544 0 $data->{ $field } = $v;
5545 }
5546 }
5547 5 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 5 5
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
500
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
500
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
5548  
5549 5 ▶ if( defined( $data->{ $field } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{$field} and builtin::blessed($data->{$field}) and $data->{$field}->can('defined') and not $data->{$field}->defined) { } 0 5 5
Condition33%3/9
defined $data->{$field} and builtin::blessed($data->{$field}) and $data->{$field}->can("defined") and not $data->{$field}->defined
!ll&&!rl&&r
050
defined $data->{$field} and builtin::blessed($data->{$field}) and $data->{$field}->can("defined")
!ll&&!rl&&r
005
defined $data->{$field} and builtin::blessed($data->{$field})
!ll&&!rl&&r
005
MC/DC0%0/4
defined $data->{$field} and builtin::blessed($data->{$field}) and $data->{$field}->can("defined") and not $data->{$field}->defined
defined $data->{$field} builtin::blessed($data->{$field}) $data->{$field}->can("defined") not $data->{$field}->defined
Truth table20%1/5
A and B and C and not(D)
A= defined $data->{$field}B= builtin::blessed($data->{$field})C= $data->{$field}->can("defined")D= not $data->{$field}->defined
ABCDresult
0XXX0
10XX0
110X0
11100
11111
5550 Scalar::Util::blessed( $data->{ $field } ) &&
5551 $data->{ $field }->can( 'defined' ) &&
5552 !$data->{ $field }->defined )
5553 {
5554 0 return;
5555 }
5556 else
5557 {
5558 5 return( $data->{ $field } );
5559 }
5560 },
5561 12 field => $field,
5562 }, @_ ) );
5563 }
5564  
5565 2 ▶sub _set_get_lvalue : lvalue
Subroutine _set_get_lvalue: called CC=12 SCAR=42.7
5566 {
5567 2 my $self = shift( @_ );
5568 2 my $field = shift( @_ );
5569 2 my $this = $self->_obj2h;
5570 2 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 2 2
5571  
5572 2 my $callbacks = {};
5573 2 my $check;
5574 2 my $def = {};
5575 2 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 2 2
5576 {
5577 0 $def = $field;
5578 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
5579 defined( $def->{field} ) &&
5580 CORE::length( $def->{field} ) )
5581 {
5582 0 $field = $def->{field};
5583 }
5584 else
5585 {
5586 0 $field = undef;
5587 }
5588 # Should have been 'callbacks', but we catch it anyway.
5589 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
5590 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
5591 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
5592 }
5593  
5594 return( $self->_set_get_callback({
5595 get => sub
5596 2 ▶ {
Subroutine __ANON__: called CC=2 SCAR=7.1
5597 2 my $self = shift( @_ );
5598 2 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 2 2
5599 2 return( $data->{ $field } );
5600 },
5601 set => sub
5602 2 ▶ {
Subroutine __ANON__: called CC=20 SCAR=53.7
5603 2 my $self = shift( @_ );
5604 2 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 2 2
5605 2 ▶ @_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and not defined $_[0] 0 2 2
Condition33%1/3
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
020
MC/DC0%0/2
scalar @_ == 1 and not defined $_[0]
scalar @_ == 1 not defined $_[0]
Truth table33%1/3
A and not(B)
A= scalar @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
5606 2 my $val = shift( @_ );
5607  
5608 2 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 2 2
5609 {
5610 # try-catch
5611 0 local $@;
5612 0 my $rv = eval{ $check->( $self, $val ) };
5613 0 ▶ 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
5614 {
5615 0 return( $self->pass_error );
5616 }
5617 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
5618 }
5619  
5620 2 $data->{ $field } = $val;
5621 2 $self->clear_error;
5622  
5623 2 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 2 2
Condition16%1/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
200
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table25%1/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
5624 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
5625 {
5626 0 my $coderef;
5627 0 foreach my $t ( qw( add set ) )
5628 {
5629 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
5630 {
5631 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
5632 ? $callbacks->{ $t }
5633 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
5634 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
5635 }
5636 }
5637 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
5638 {
5639 # try-catch
5640 0 local $@;
5641 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
5642 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
5643 {
5644 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
5645 }
5646 ▶ elsif( !defined( $rv ) && $self->error )
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
5647 {
5648 0 return( $self->pass_error );
5649 }
5650 0 $data->{ $field } = $rv;
5651 }
5652 }
5653  
5654 # lnoreturn;
5655 2 return( $data->{ $field } );
5656 },
5657 2 field => $field,
5658 }, @_ ) );
5659 }
5660  
5661 387 ▶sub _set_get_number : lvalue
Subroutine _set_get_number: called CC=36 SCAR=62.2
5662 {
5663 387 my $self = shift( @_ );
5664 387 my $field = shift( @_ );
5665 387 my $this = $self->_obj2h;
5666 34 ▶ no overload;
Subroutine BEGIN: called CC=1 SCAR=0.0
5667 387 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 10 377 387
5668 387 my $opts = {};
5669  
5670 387 my $callbacks = {};
5671 387 my( $check, $constraint );
5672 # Standard constraints taken from Regexp::Common::number
5673 # What about short, and long ?
5674 387 my $standard_constraints =
5675 {
5676 'bin' => qr/(?i)
5677 (?:[-+]?)
5678 (?:
5679 (?=[.]?[01])
5680 (?:[01]*)
5681 (?:
5682 (?:[.])
5683 (?:[01]{0,})
5684 )?
5685 )
5686 (?:
5687 (?:[E])
5688 (?:
5689 (?:[-+]?)
5690 (?:[01]+)
5691 )
5692 |
5693 )/x,
5694 'hex' => qr/(?i)
5695 (?:[-+]?)
5696 (?:
5697 (?=[.]?[0-9A-F])
5698 (?:[0-9A-F]*)
5699 (?:
5700 (?:[.])
5701 (?:[0-9A-F]{0,})
5702 )?
5703 )
5704 (?:
5705 (?:[E])
5706 (?:
5707 (?:[-+]?)
5708 (?:[0-9A-F]+)
5709 )
5710 |
5711 )/x,
5712 'int' => qr/(?:[-+]?)(?:0|[1-9][0-9]*)/,
5713 long => qr/(?:[-+]?)(?:0|[1-9][0-9]{0,9})/,
5714 negative_int => qr/\-[1-9][0-9]*/,
5715 'oct' => qr/(?i)
5716 (?:[-+]?)
5717 (?:
5718 (?=[.]?[0-7])
5719 (?:[0-7]*)
5720 (?:
5721 (?:[.])
5722 (?:[0-7]{0,})
5723 )?
5724 )
5725 (?:
5726 (?:[E])
5727 (?:
5728 (?:[-+]?)
5729 (?:[0-7]+)
5730 )
5731 |
5732 )/x,
5733 # Should we alias 'double', decimal and 'float' to this ?
5734 real => qr/(?i)
5735 (?:[-+]?)
5736 (?:
5737 (?=[.]?[0-9])
5738 (?:[0-9]*)
5739 (?:
5740 (?:[.])
5741 (?:[0-9]{0,})
5742 )?
5743 )
5744 (?:
5745 (?:[E])
5746 (?:
5747 (?:[-+]?)
5748 (?:[0-9]+)
5749 )
5750 |
5751 )/x,
5752 short => qr/(?:[-+]?)(?:0|[1-9][0-9]{0,4})/,
5753 signed_byte => qr/(?:[-+]?)(?:0|[1-9][0-9]{0,2})/,
5754 unsigned_byte => qr/(?:0|[1-9][0-9]{0,2})/,
5755 unsigned_int => qr/(?:0|[1-9][0-9]*)/,
5756 unsigned_long => qr/(?:0|[1-9][0-9]{0,9})/,
5757 unsigned_real => qr/
5758 (?:
5759 (?=[.]?[0-9])
5760 (?:[0-9]*)
5761 (?:
5762 (?:[.])
5763 (?:[0-9]{0,})
5764 )?
5765 )
5766 (?:
5767 (?:[E])
5768 (?:
5769 (?:[-+]?)
5770 (?:[0-9]+)
5771 )
5772 |
5773 )/x,
5774 unsigned_short => qr/(?:0|[1-9][0-9]{0,4})/,
5775 };
5776 387 $standard_constraints->{byte} = $standard_constraints->{signed_byte};
5777 # Aliasing double, decimal, and float to real, since for Perl regexp pattern it would not make much difference.
5778 387 $standard_constraints->{dec} = $standard_constraints->{decimal} = $standard_constraints->{double} = $standard_constraints->{float} = $standard_constraints->{real};
5779 387 $standard_constraints->{integer} = $standard_constraints->{int};
5780 387 $standard_constraints->{positive_int} = $standard_constraints->{unsigned_integer} = $standard_constraints->{unsigned_int};
5781 387 $standard_constraints->{hexadecimal} = $standard_constraints->{hex};
5782 387 $standard_constraints->{binary} = $standard_constraints->{bin};
5783 387 $standard_constraints->{octal} = $standard_constraints->{oct};
5784 387 $standard_constraints->{unsigned_dec} = $standard_constraints->{unsigned_decimal} = $standard_constraints->{unsigned_double} = $standard_constraints->{unsigned_float} = $standard_constraints->{unsigned_real};
5785 387 $standard_constraints->{positive_dec} = $standard_constraints->{positive_decimal} = $standard_constraints->{positive_double} = $standard_constraints->{positive_float} = $standard_constraints->{positive_real} = $standard_constraints->{unsigned_real};
5786 387 $standard_constraints->{signed_byte_int} = $standard_constraints->{signed_byte};
5787 387 $standard_constraints->{unsigned_byte_int} = $standard_constraints->{unsigned_byte};
5788 # The constraint name for error reporting purposes.
5789 # If there is no entry, the key will be used as-is. For example 'real' -> 'real' and 'int' -> 'integer'
5790 387 my $constraint_names =
5791 {
5792 'bin' => 'binary',
5793 'decimal' => 'decimal number',
5794 'double' => 'double-precision number',
5795 'float' => 'floating-point number',
5796 'hex' => 'hexadecimal',
5797 'int' => 'integer',
5798 'long' => 'long integer',
5799 'oct' => 'octal',
5800 'negative_int' => 'negative integer',
5801 'positive_int' => 'positive integer',
5802 'positive_real' => 'positive real number',
5803 'positive_dec' => 'positive decimal number',
5804 'positive_double' => 'positive double-precision number',
5805 'positive_float' => 'positive floating-point number',
5806 'real' => 'real number',
5807 'signed_byte' => 'signed byte',
5808 'short' => 'short integer',
5809 'unsigned_byte' => 'unsigned byte',
5810 'unsigned_int' => 'unsigned integer',
5811 'unsigned_long' => 'unsigned long integer',
5812 # Yes, those below are made-up types
5813 'unsigned_real' => 'unsigned real number',
5814 'unsigned_dec' => 'unsigned decimal number',
5815 'unsigned_double' => 'unsigned double-precision number',
5816 'unsigned_float'=> 'unsigned floating-point number',
5817 # This one is a real type though
5818 'unsigned_short' => 'unsigned short integer',
5819 };
5820 387 $constraint_names->{byte} = $constraint_names->{signed_byte};
5821 387 $constraint_names->{positive_decimal} = $constraint_names->{positive_dec};
5822 387 $constraint_names->{signed_byte_int} = $constraint_names->{signed_byte};
5823 387 $constraint_names->{signed_byte_integer} = $constraint_names->{signed_byte};
5824 387 $constraint_names->{unsigned_byte_int} = $constraint_names->{unsigned_byte};
5825 387 $constraint_names->{unsigned_byte_integer} = $constraint_names->{unsigned_byte};
5826 387 $constraint_names->{unsigned_integer} = $constraint_names->{unsigned_int};
5827 387 $constraint_names->{unsigned_decimal} = $constraint_names->{unsigned_dec};
5828 387 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 387 387
5829 {
5830 0 $opts = $field;
5831 0 ▶ if( CORE::exists( $opts->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'field'} and defined $opts->{'field'} and length $opts->{'field'}) { } 0 0 0
Condition0%0/6
exists $opts->{"field"} and defined $opts->{"field"} and length $opts->{"field"}
!ll&&!rl&&r
000
exists $opts->{"field"} and defined $opts->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $opts->{"field"} and defined $opts->{"field"} and length $opts->{"field"}
exists $opts->{"field"} defined $opts->{"field"} length $opts->{"field"}
Truth table0%0/4
A and B and C
A= exists $opts->{"field"}B= defined $opts->{"field"}C= length $opts->{"field"}
ABCresult
0XX0
10X0
1100
1111
5832 defined( $opts->{field} ) &&
5833 CORE::length( $opts->{field} ) )
5834 {
5835 0 $field = $opts->{field};
5836 }
5837 else
5838 {
5839 0 $field = undef;
5840 }
5841 # Should have been 'callbacks', but we catch it anyway.
5842 0 ▶ $callbacks = $opts->{callback} if( CORE::exists( $opts->{callback} ) && ref( $opts->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"callback"} and ref $opts->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $opts->{"callback"} and ref $opts->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"callback"} and ref $opts->{"callback"} eq "HASH"
exists $opts->{"callback"} ref $opts->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $opts->{"callback"}B= ref $opts->{"callback"} eq "HASH"
ABresult
0X0
100
111
5843 0 ▶ $callbacks = $opts->{callbacks} if( CORE::exists( $opts->{callbacks} ) && ref( $opts->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"callbacks"} and ref $opts->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $opts->{"callbacks"} and ref $opts->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"callbacks"} and ref $opts->{"callbacks"} eq "HASH"
exists $opts->{"callbacks"} ref $opts->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $opts->{"callbacks"}B= ref $opts->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
5844 0 ▶ $check = $opts->{check} if( CORE::exists( $opts->{check} ) && ref( $opts->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"check"} and ref $opts->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $opts->{"check"} and ref $opts->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"check"} and ref $opts->{"check"} eq "CODE"
exists $opts->{"check"} ref $opts->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $opts->{"check"}B= ref $opts->{"check"} eq "CODE"
ABresult
0X0
100
111
5845 0 ▶ if( CORE::exists( $opts->{constraint} ) && CORE::length( $opts->{constraint} // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"constraint"} and length($opts->{"constraint"} // "")) 0 0 0
Condition0%0/5
exists $opts->{"constraint"} and length($opts->{"constraint"} // "")
!ll&&!rl&&r
000
$opts->{"constraint"} // ""
l!l
00
MC/DC0%0/2
exists $opts->{"constraint"} and length($opts->{"constraint"} // "")
exists $opts->{"constraint"} $opts->{"constraint"}
Truth table0%0/3
A and B
A= exists $opts->{"constraint"}B= $opts->{"constraint"}
ABresult
0X0
100
111
5846 {
5847 0 ▶ if( ref( $opts->{constraint} ) eq 'Regexp' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $opts->{'constraint'} eq 'Regexp') { } 0 0 0
elsif (exists $$standard_constraints{$opts->{'constraint'}}) { } 0 0 0
5848 {
5849 0 $constraint = $opts->{constraint};
5850 }
5851 elsif( CORE::exists( $standard_constraints->{ $opts->{constraint} } ) )
5852 {
5853 0 $constraint = $standard_constraints->{ $opts->{constraint} };
5854 # Special cases for 'short' and 'long'
5855 # Let's note that 'check' constraint are triggered before other constraints, and if failed, it stops there.
5856 0 ▶ unless( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $check) 0 0 0
5857 {
5858 # Validates short and long integers against 16-bit and 32-bit ranges
5859 0 my( $start_range, $end_range );
5860 0 ▶ if( $opts->{constraint} eq 'short' ||
Branch: 6 branches
BranchTrueFalseTotal
if ($opts->{'constraint'} eq 'short' or $opts->{'constraint'} eq 'short_int' or $opts->{'constraint'} eq 'short_integer') { } 0 0 0
elsif ($opts->{'constraint'} eq 'unsigned_short' or $opts->{'constraint'} eq 'unsigned_short_int' or $opts->{'constraint'} eq 'unsigned_short_integer') { } 0 0 0
elsif ($opts->{'constraint'} eq 'long' or $opts->{'constraint'} eq 'long_int' or $opts->{'constraint'} eq 'long_integer') { } 0 0 0
elsif ($opts->{'constraint'} eq 'unsigned_long' or $opts->{'constraint'} eq 'unsigned_long_int' or $opts->{'constraint'} eq 'unsigned_long_integer') { } 0 0 0
elsif ($opts->{'constraint'} =~ /^(signed_byte|byte|signed_byte_int|signed_byte_integer)$/) { } 0 0 0
elsif ($opts->{'constraint'} =~ /^(unsigned_byte|unsigned_byte_int|unsigned_byte_integer)$/) { } 0 0 0
Condition0%0/6
$opts->{"constraint"} eq "short" or $opts->{"constraint"} eq "short_int" or $opts->{"constraint"} eq "short_integer"
l!l&&r!l&&!r
000
$opts->{"constraint"} eq "short" or $opts->{"constraint"} eq "short_int"
l!l&&r!l&&!r
000
MC/DC0%0/3
$opts->{"constraint"} eq "short" or $opts->{"constraint"} eq "short_int" or $opts->{"constraint"} eq "short_integer"
$opts->{"constraint"} eq "short" $opts->{"constraint"} eq "short_int" $opts->{"constraint"} eq "short_integer"
Truth table0%0/4
A or B or C
A= $opts->{"constraint"} eq "short"B= $opts->{"constraint"} eq "short_int"C= $opts->{"constraint"} eq "short_integer"
ABCresult
1XX1
01X1
0011
0000
5861 $opts->{constraint} eq 'short_int' ||
5862 $opts->{constraint} eq 'short_integer' )
5863 {
5864 0 ( $start_range, $end_range ) = ( -32_768, 32_767 );
5865 }
5866 ▶ elsif( $opts->{constraint} eq 'unsigned_short' ||
Condition0%0/6
$opts->{"constraint"} eq "unsigned_short" or $opts->{"constraint"} eq "unsigned_short_int" or $opts->{"constraint"} eq "unsigned_short_integer"
l!l&&r!l&&!r
000
$opts->{"constraint"} eq "unsigned_short" or $opts->{"constraint"} eq "unsigned_short_int"
l!l&&r!l&&!r
000
MC/DC0%0/3
$opts->{"constraint"} eq "unsigned_short" or $opts->{"constraint"} eq "unsigned_short_int" or $opts->{"constraint"} eq "unsigned_short_integer"
$opts->{"constraint"} eq "unsigned_short" $opts->{"constraint"} eq "unsigned_short_int" $opts->{"constraint"} eq "unsigned_short_integer"
Truth table0%0/4
A or B or C
A= $opts->{"constraint"} eq "unsigned_short"B= $opts->{"constraint"} eq "unsigned_short_int"C= $opts->{"constraint"} eq "unsigned_short_integer"
ABCresult
1XX1
01X1
0011
0000
5867 $opts->{constraint} eq 'unsigned_short_int' ||
5868 $opts->{constraint} eq 'unsigned_short_integer' )
5869 {
5870 0 ( $start_range, $end_range ) = ( 0, 65_535 );
5871 }
5872 ▶ elsif( $opts->{constraint} eq 'long' ||
Condition0%0/6
$opts->{"constraint"} eq "long" or $opts->{"constraint"} eq "long_int" or $opts->{"constraint"} eq "long_integer"
l!l&&r!l&&!r
000
$opts->{"constraint"} eq "long" or $opts->{"constraint"} eq "long_int"
l!l&&r!l&&!r
000
MC/DC0%0/3
$opts->{"constraint"} eq "long" or $opts->{"constraint"} eq "long_int" or $opts->{"constraint"} eq "long_integer"
$opts->{"constraint"} eq "long" $opts->{"constraint"} eq "long_int" $opts->{"constraint"} eq "long_integer"
Truth table0%0/4
A or B or C
A= $opts->{"constraint"} eq "long"B= $opts->{"constraint"} eq "long_int"C= $opts->{"constraint"} eq "long_integer"
ABCresult
1XX1
01X1
0011
0000
5873 $opts->{constraint} eq 'long_int' ||
5874 $opts->{constraint} eq 'long_integer' )
5875 {
5876 0 ( $start_range, $end_range ) = ( -2_147_483_648, 2_147_483_647 );
5877 }
5878 ▶ elsif( $opts->{constraint} eq 'unsigned_long' ||
Condition0%0/6
$opts->{"constraint"} eq "unsigned_long" or $opts->{"constraint"} eq "unsigned_long_int" or $opts->{"constraint"} eq "unsigned_long_integer"
l!l&&r!l&&!r
000
$opts->{"constraint"} eq "unsigned_long" or $opts->{"constraint"} eq "unsigned_long_int"
l!l&&r!l&&!r
000
MC/DC0%0/3
$opts->{"constraint"} eq "unsigned_long" or $opts->{"constraint"} eq "unsigned_long_int" or $opts->{"constraint"} eq "unsigned_long_integer"
$opts->{"constraint"} eq "unsigned_long" $opts->{"constraint"} eq "unsigned_long_int" $opts->{"constraint"} eq "unsigned_long_integer"
Truth table0%0/4
A or B or C
A= $opts->{"constraint"} eq "unsigned_long"B= $opts->{"constraint"} eq "unsigned_long_int"C= $opts->{"constraint"} eq "unsigned_long_integer"
ABCresult
1XX1
01X1
0011
0000
5879 $opts->{constraint} eq 'unsigned_long_int' ||
5880 $opts->{constraint} eq 'unsigned_long_integer' )
5881 {
5882 0 ( $start_range, $end_range ) = ( 0, 4_294_967_295 );
5883 }
5884 # Existing code for short/long...
5885 elsif( $opts->{constraint} =~ /^(signed_byte|byte|signed_byte_int|signed_byte_integer)$/ )
5886 {
5887 0 ( $start_range, $end_range ) = ( -128, 127 );
5888 }
5889 elsif( $opts->{constraint} =~ /^(unsigned_byte|unsigned_byte_int|unsigned_byte_integer)$/ )
5890 {
5891 0 ( $start_range, $end_range ) = ( 0, 255 );
5892 }
5893  
5894 0 ▶ if( defined( $start_range ) && defined( $end_range ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start_range and defined $end_range) 0 0 0
Condition0%0/3
defined $start_range and defined $end_range
!ll&&!rl&&r
000
MC/DC0%0/2
defined $start_range and defined $end_range
defined $start_range defined $end_range
Truth table0%0/3
A and B
A= defined $start_rangeB= defined $end_range
ABresult
0X0
100
111
5895 {
5896 $check = sub
5897 0 ▶ {
Subroutine __ANON__: not called CC=5 SCAR=34.0
5898 0 my( $self, $val ) = @_;
5899 0 ▶ return(1) unless( defined( $val ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
5900 # Force numeric context
5901 0 my $num = $val + 0;
5902 0 ▶ unless( $num >= $start_range && $num <= $end_range )
Branch: 1 branch
BranchTrueFalseTotal
unless ($num >= $start_range and $num <= $end_range) 0 0 0
Condition0%0/3
$num >= $start_range and $num <= $end_range
!ll&&!rl&&r
000
MC/DC0%0/2
$num >= $start_range and $num <= $end_range
$num >= $start_range $num <= $end_range
Truth table0%0/3
A and B
A= $num >= $start_rangeB= $num <= $end_range
ABresult
0X0
100
111
5903 {
5904 0 ▶ return( $self->error( "Value for numeric field '$field' exceeds ", ( CORE::exists( $constraint_names->{ $opts->{constraint} } ) ? $constraint_names->{ $opts->{constraint} } : $opts->{constraint} ), " range" ) );
Branch: 1 branch
BranchTrueFalseTotal
exists $$constraint_names{$opts->{'constraint'}} ? : 0 0 0
5905 }
5906 0 return(1);
5907 0 };
5908 }
5909 }
5910 }
5911 else
5912 {
5913 0 ▶ warn( "Warning only: unknown constraint type '$opts->{constraint}' for this numeric field '$field'" ) if( $self->_is_warnings_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled 0 0 0
5914 }
5915 }
5916 }
5917 # $opts->{undef_ok} //= 0;
5918  
5919 my $do_callback = sub
5920 247 ▶ {
Subroutine __ANON__: called CC=13 SCAR=49.9
5921 247 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 247 247
Condition16%1/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
24700
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table25%1/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
5922 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
5923 {
5924 0 my $coderef;
5925 0 foreach my $t ( qw( add set ) )
5926 {
5927 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
5928 {
5929 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
5930 ? $callbacks->{ $t }
5931 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
5932 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
5933 }
5934 }
5935 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
5936 {
5937 # try-catch
5938 0 local $@;
5939 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
5940 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
5941 {
5942 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
5943 }
5944 ▶ elsif( !defined( $rv ) && $self->error )
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
5945 {
5946 0 return( $self->pass_error );
5947 }
5948 0 $data->{ $field } = $rv;
5949 }
5950 }
5951 387 };
5952  
5953 387 ▶ $self->_load_class( 'Module::Generic::Number' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Number") or return $self->pass_error 387 0 387
5954  
5955 return( $self->_set_get_callback({
5956 get => sub
5957 140 ▶ {
Subroutine __ANON__: called CC=8 SCAR=22.6
5958 140 my $self = shift( @_ );
5959 140 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 140 140
5960 140 ▶ if( CORE::length( $data->{ $field } ) && !ref( $data->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $data->{$field} and not ref $data->{$field}) 106 34 140
Condition100%3/3
length $data->{$field} and not ref $data->{$field}
!ll&&!rl&&r
1618106
MC/DC100%2/2
length $data->{$field} and not ref $data->{$field}
length $data->{$field} not ref $data->{$field}
Truth table100%3/3
A and not(B)
A= length $data->{$field}B= not ref $data->{$field}
ABresult
0X0
100
111
5961 {
5962 106 my $v = Module::Generic::Number->new( $data->{ $field } );
5963 106 ▶ $data->{ $field } = $v if( defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 106 0 106
5964 }
5965 140 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $opts->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 140 140
Condition33%2/6
$opts->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
14000
$opts->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
14000
MC/DC0%0/3
$opts->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$opts->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $opts->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
5966 140 return( $data->{ $field } );
5967 },
5968 set => sub
5969 247 ▶ {
Subroutine __ANON__: called CC=26 SCAR=53.6
5970 247 my $self = shift( @_ );
5971 247 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 247 247
5972 247 my $val = shift( @_ );
5973 247 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 247 247
5974 {
5975 # try-catch
5976 0 local $@;
5977 0 my $rv = eval{ $check->( $self, $val ) };
5978 0 ▶ 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
5979 {
5980 0 return( $self->pass_error );
5981 }
5982 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
5983 }
5984 247 ▶ if( !defined( $val ) )
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $val) { } 0 247 247
elsif (not length "$val") { } 0 247 247
elsif (ref $val and not $self->_can_overload($val, '""')) { } 0 247 247
elsif (defined $constraint and not +($val + 0) =~ /^$constraint$/) { } 0 247 247
5985 {
5986 0 ▶ if( CORE::exists( $opts->{undef_ok} ) && !$opts->{undef_ok} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'undef_ok'} and not $opts->{'undef_ok'}) { } 0 0 0
Condition0%0/3
exists $opts->{"undef_ok"} and not $opts->{"undef_ok"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"undef_ok"} and not $opts->{"undef_ok"}
exists $opts->{"undef_ok"} not $opts->{"undef_ok"}
Truth table0%0/3
A and not(B)
A= exists $opts->{"undef_ok"}B= not $opts->{"undef_ok"}
ABresult
0X0
100
111
5987 {
5988 0 return( $self->error( "Number provided is undef, which is not permitted for '${field}'" ) );
5989 }
5990 else
5991 {
5992 0 $data->{ $field } = shift( @_ );
5993 }
5994 }
5995 elsif( !length( "$val" ) )
5996 {
5997 0 return( $self->error( "Empty string is not a valid number for '$field'" ) );
5998 }
5999 ▶ elsif( ref( $val ) && !$self->_can_overload( $val => '""' ) )
Condition66%2/3
ref $val and not $self->_can_overload($val, "\"\"")
!ll&&!rl&&r
24610
MC/DC0%0/2
ref $val and not $self->_can_overload($val, "\"\"")
ref $val not $self->_can_overload($val, "\"\"")
Truth table66%2/3
A and not(B)
A= ref $valB= not $self->_can_overload($val, "\"\"")
ABresult
0X0
100
111
6000 {
6001 0 return( $self->error( "Value provided (", $self->_str_val( $val ), ") is a reference, but it does not stringify." ) );
6002 }
6003 # We force number context, which, if this is an overloaded object, should convert it to a number.
6004 ▶ elsif( defined( $constraint ) &&
Condition33%1/3
defined $constraint and not +($val + 0) =~ /^$constraint$/
!ll&&!rl&&r
24700
MC/DC0%0/2
defined $constraint and not +($val + 0) =~ /^$constraint$/
defined $constraint not +($val + 0) =~ /^$constraint$/
Truth table33%1/3
A and not(B)
A= defined $constraintB= not +($val + 0) =~ /^$constraint$/
ABresult
0X0
100
111
6005 ( $val + 0 ) !~ /^$constraint$/ )
6006 {
6007 0 ▶ $self->__message( 114, "Contraint $opts->{constraint} check failed for value '$val' and regexp: ", ( $constraint // 'undef' ) );
Condition0%0/2
$constraint // "undef"
l!l
00
MC/DC0%0/1
$constraint // "undef"
$constraint
Truth table0%0/2
A
A= $constraint
Aresult
11
00
6008 0 ▶ return( $self->error( "The value provided for this object numeric field '$field' is not a valid ", ( ref( $opts->{constraint} ) eq 'Regexp' ? 'value' : CORE::exists( $constraint_names->{ $opts->{constraint} } ) ? $constraint_names->{ $opts->{constraint} } : $opts->{constraint} ), "." ) );
Branch: 2 branches
BranchTrueFalseTotal
ref $opts->{'constraint'} eq 'Regexp' ? : 0 0 0
exists $$constraint_names{$opts->{'constraint'}} ? : 0 0 0
6009 }
6010 else
6011 {
6012 247 my $v = Module::Generic::Number->new( $val );
6013 247 ▶ return( $self->pass_error( Module::Generic::Number->error ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 247 247
6014 247 $data->{ $field } = $v;
6015 }
6016 247 ▶ if( !defined( $do_callback->() ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &$do_callback()) 0 247 247
6017 {
6018 0 return;
6019 }
6020  
6021 247 ▶ if( CORE::length( $data->{ $field } // '' ) && !ref( $data->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length($data->{$field} // "") and not ref $data->{$field}) 0 247 247
Condition40%2/5
length($data->{$field} // "") and not ref $data->{$field}
!ll&&!rl&&r
02470
$data->{$field} // ""
l!l
2470
MC/DC0%0/2
length($data->{$field} // "") and not ref $data->{$field}
$data->{$field} not ref $data->{$field}
Truth table33%1/3
A and not(B)
A= $data->{$field}B= not ref $data->{$field}
ABresult
0X0
100
111
6022 {
6023 0 my $v = Module::Generic::Number->new( $data->{ $field } );
6024 0 ▶ $data->{ $field } = $v if( defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 0 0 0
6025 }
6026 247 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $opts->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 247 247
Condition33%2/6
$opts->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
24700
$opts->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
24700
MC/DC0%0/3
$opts->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$opts->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $opts->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
6027 247 $self->clear_error;
6028 247 return( $data->{ $field } );
6029 },
6030 387 field => $field
6031 }, @_ ) );
6032 }
6033  
6034 0 ▶sub _set_get_number_as_object : lvalue { return( shift->_set_get_number( @_ ) ); }
Subroutine _set_get_number_as_object: not called CC=1 SCAR=6.9
6035  
6036 0 ▶sub _set_get_number_as_scalar : lvalue
Subroutine _set_get_number_as_scalar: not called CC=12 SCAR=49.9
6037 {
6038 0 my $self = shift( @_ );
6039 0 my $field = shift( @_ );
6040 0 my $this = $self->_obj2h;
6041 39 ▶ no overload;
Subroutine BEGIN: called CC=1 SCAR=0.0
6042 0 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 0 0
6043  
6044 0 my $callbacks = {};
6045 0 my $check;
6046 0 my $def = {};
6047 0 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 0 0
6048 {
6049 0 $def = $field;
6050 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
6051 defined( $def->{field} ) &&
6052 CORE::length( $def->{field} ) )
6053 {
6054 0 $field = $def->{field};
6055 }
6056 else
6057 {
6058 0 $field = undef;
6059 }
6060 # Should have been 'callbacks', but we catch it anyway.
6061 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
6062 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
6063 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
6064 }
6065  
6066 my $do_callback = sub
6067 0 ▶ {
Subroutine __ANON__: not called CC=13 SCAR=52.0
6068 0 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 0 0
Condition0%0/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
000
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table0%0/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
6069 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
6070 {
6071 0 my $coderef;
6072 0 foreach my $t ( qw( add set ) )
6073 {
6074 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
6075 {
6076 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
6077 ? $callbacks->{ $t }
6078 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
6079 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
6080 }
6081 }
6082 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
6083 {
6084 # try-catch
6085 0 local $@;
6086 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
6087 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
6088 {
6089 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
6090 }
6091 ▶ elsif( !defined( $rv ) && $self->error )
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
6092 {
6093 0 return( $self->pass_error );
6094 }
6095 0 $data->{ $field } = $rv;
6096 }
6097 }
6098 0 };
6099  
6100 return( $self->_set_get_callback({
6101 get => sub
6102 0 ▶ {
Subroutine __ANON__: not called CC=6 SCAR=37.4
6103 0 my $self = shift( @_ );
6104 0 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 0 0
6105 0 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && defined( $data->{ $field } ) && ref( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field}) 0 0 0
Condition0%0/9
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
000
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field}
!ll&&!rl&&r
000
$def->{"weaken"} and defined $data->{$field}
!ll&&!rl&&r
000
MC/DC0%0/4
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
$def->{"weaken"} defined $data->{$field} ref $data->{$field} not builtin::is_weak($data->{$field})
Truth table0%0/5
A and B and C and not(D)
A= $def->{"weaken"}B= defined $data->{$field}C= ref $data->{$field}D= not builtin::is_weak($data->{$field})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
6106 0 return( $data->{ $field } );
6107 },
6108 set => sub
6109 0 ▶ {
Subroutine __ANON__: not called CC=12 SCAR=50.5
6110 0 my $self = shift( @_ );
6111 0 my $arg = shift( @_ );
6112 0 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 0 0
6113 0 my $v = $arg;
6114 0 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 0 0
6115 {
6116 # try-catch
6117 0 local $@;
6118 0 my $rv = eval{ $check->( $self, $v ) };
6119 0 ▶ 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
6120 {
6121 0 return( $self->pass_error );
6122 }
6123 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
6124 }
6125 # If the user wants to remove it
6126 0 ▶ if( defined( $v ) && $v !~ /^$NUMBER_REAL_RE$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and not $v =~ /^$NUMBER_REAL_RE$/) 0 0 0
Condition0%0/3
defined $v and not $v =~ /^$NUMBER_REAL_RE$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $v and not $v =~ /^$NUMBER_REAL_RE$/
defined $v not $v =~ /^$NUMBER_REAL_RE$/
Truth table0%0/3
A and not(B)
A= defined $vB= not $v =~ /^$NUMBER_REAL_RE$/
ABresult
0X0
100
111
6127 {
6128 0 return( $self->error( "Method $field takes only a number, but value provided ($arg) is not a number" ) );
6129 }
6130 0 $data->{ $field } = $v;
6131 0 $do_callback->();
6132  
6133 0 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && defined( $data->{ $field } ) && ref( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field}) 0 0 0
Condition0%0/9
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
000
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field}
!ll&&!rl&&r
000
$def->{"weaken"} and defined $data->{$field}
!ll&&!rl&&r
000
MC/DC0%0/4
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
$def->{"weaken"} defined $data->{$field} ref $data->{$field} not builtin::is_weak($data->{$field})
Truth table0%0/5
A and B and C and not(D)
A= $def->{"weaken"}B= defined $data->{$field}C= ref $data->{$field}D= not builtin::is_weak($data->{$field})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
6134 0 $self->clear_error;
6135 0 return( $data->{ $field } );
6136 },
6137 0 field => $field,
6138 }, @_ ) );
6139 }
6140  
6141 sub _set_get_number_or_object
6142 0 ▶{
Subroutine _set_get_number_or_object: not called CC=17 SCAR=57.2
6143 0 my $self = shift( @_ );
6144 0 my $field = shift( @_ );
6145 0 my $class = shift( @_ );
6146 0 my $this = $self->_obj2h;
6147 0 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 0 0
6148  
6149 0 my $def;
6150 0 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 0 0
6151 {
6152 0 $def = $field;
6153 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
6154 defined( $def->{field} ) &&
6155 CORE::length( $def->{field} ) )
6156 {
6157 0 $field = $def->{field};
6158 }
6159 else
6160 {
6161 0 return( $self->error( "No field name was provided." ) )
6162 }
6163 }
6164  
6165 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
6166 {
6167 0 my $val = shift( @_ );
6168 0 ▶ if( ref( $val // '' ) eq 'HASH' || Scalar::Util::blessed( $val // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref($val // '') eq 'HASH' or builtin::blessed($val // '')) { } 0 0 0
Condition0%0/7
ref($val // "") eq "HASH" or builtin::blessed($val // "")
l!l&&r!l&&!r
000
$val // ""
l!l
00
$val // ""
l!l
00
MC/DC0%0/2
ref($val // "") eq "HASH" or builtin::blessed($val // "")
$val $val
Truth table0%0/3
A or B
A= $valB= $val
ABresult
1X1
011
000
6169 {
6170 0 ▶ return( $self->_set_get_object( ( $def // $field ), $class, $val ) );
Condition0%0/3
$def // $field
l!l&&r!l&&!r
000
MC/DC0%0/2
$def // $field
$def $field
Truth table0%0/3
A // B
A= $defB= $field
ABresult
1X1
011
000
6171 }
6172 else
6173 {
6174 0 ▶ return( $self->_set_get_number( ( $def // $field ), $val ) );
Condition0%0/3
$def // $field
l!l&&r!l&&!r
000
MC/DC0%0/2
$def // $field
$def $field
Truth table0%0/3
A // B
A= $defB= $field
ABresult
1X1
011
000
6175 }
6176 0 $self->clear_error;
6177 }
6178 0 ▶ if( !CORE::length( $data->{ $field } // '' ) && want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not length($data->{$field} // "") and want("OBJECT")) 0 0 0
Condition0%0/5
not length($data->{$field} // "") and want("OBJECT")
!ll&&!rl&&r
000
$data->{$field} // ""
l!l
00
MC/DC0%0/2
not length($data->{$field} // "") and want("OBJECT")
$data->{$field} want("OBJECT")
Truth table0%0/3
not(A) and B
A= $data->{$field}B= want("OBJECT")
ABresult
1X0
000
011
6179 {
6180 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or return $self->pass_error 0 0 0
6181 return( $self->pass_error );
6182 0 return( Module::Generic::Null->new( wants => 'OBJECT' ) );
6183 }
6184 0 $self->clear_error;
6185 0 return( $data->{ $field } );
6186 }
6187  
6188 sub _set_get_object
6189 242 ▶{
Subroutine _set_get_object: called CC=50 SCAR=68.7
6190 242 my $self = shift( @_ );
6191 242 my $field = shift( @_ );
6192 242 my $class = shift( @_ );
6193 242 my $this = $self->_obj2h;
6194 242 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 3 239 242
6195 126 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
6196  
6197 242 my $def = {};
6198 # no_init
6199 242 my $callback;
6200 my $check;
6201 242 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 242 242
6202 {
6203 0 $def = $field;
6204 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
6205 defined( $def->{field} ) &&
6206 CORE::length( $def->{field} ) )
6207 {
6208 0 $field = $def->{field};
6209 }
6210 else
6211 {
6212 0 $field = undef;
6213 }
6214 0 ▶ return( $self->error( "No property 'field' was provided in the parameters of _set_get_object" ) ) if( !length( $field // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($field // "") 0 0 0
Condition0%0/2
$field // ""
l!l
00
MC/DC0%0/1
$field // ""
$field
Truth table0%0/2
A
A= $field
Aresult
11
00
6215 0 ▶ if( CORE::exists( $def->{callback} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE") 0 0 0
Condition0%0/6
exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE"
!ll&&!rl&&r
000
exists $def->{"callback"} and defined $def->{"callback"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE"
exists $def->{"callback"} defined $def->{"callback"} ref $def->{"callback"} eq "CODE"
Truth table0%0/4
A and B and C
A= exists $def->{"callback"}B= defined $def->{"callback"}C= ref $def->{"callback"} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
6216 defined( $def->{callback} ) &&
6217 ref( $def->{callback} ) eq 'CODE' )
6218 {
6219 0 $callback = $def->{callback};
6220 }
6221 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
6222 }
6223  
6224 # Parameters are provided to instantiate the object
6225 242 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 105 137 242
6226 {
6227 105 ▶ if( scalar( @_ ) == 1 )
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1) { } 105 0 105
elsif ($def->{'no_init'} and not $data->{$field}) { } 0 0 0
6228 {
6229 105 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 105 105
6230 {
6231 0 my $val = $_[0];
6232 # try-catch
6233 0 local $@;
6234 0 my $rv = eval{ $check->( $self, $val ) };
6235 0 ▶ 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
6236 {
6237 0 return( $self->pass_error );
6238 }
6239 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
6240 }
6241  
6242 # User removed the value by passing it an undefined value
6243 105 ▶ if( !defined( $_[0] ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $_[0]) { } 0 105 105
elsif (builtin::blessed($_[0])) { } 105 0 105
6244 {
6245 0 $data->{ $field } = undef();
6246 }
6247 # User pass an object
6248 elsif( Scalar::Util::blessed( $_[0] ) )
6249 {
6250 105 my $o = shift( @_ );
6251 105 ▶ if( ref( $class ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class eq 'ARRAY') { } 0 105 105
6252 {
6253 0 my $ok = 0;
6254 0 foreach my $c ( @$class )
6255 {
6256 0 ▶ if( $o->isa( $c ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($o->isa($c)) 0 0 0
6257 {
6258 0 $ok++, last;
6259 }
6260 }
6261 0 ▶ return( $self->error( "Object provided (", ref( $o ), ") for $field does not match any of the possible classes: '", join( "', '", @$class ), "'." ) ) if( !$ok );
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
6262 }
6263 else
6264 {
6265 105 ▶ return( $self->error( "Object provided (", ref( $o ), ") for $field is not a valid $class object" ) ) if( !$o->isa( "$class" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $o->isa("$class") 0 105 105
6266 }
6267 105 $data->{ $field } = $o;
6268 }
6269 else
6270 {
6271 0 ▶ $class = $class->[0] if( ref( $class ) eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class eq "ARRAY" 0 0 0
6272 0 ▶ my $o = $self->_instantiate_object( { field => $field, ( defined( $callback ) ? ( callback => $callback ) : () ) }, $class, @_ );
Branch: 1 branch
BranchTrueFalseTotal
defined $callback ? : 0 0 0
6273 0 ▶ if( !defined( $o ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $o) 0 0 0
6274 {
6275 0 ▶ if( $class->can( 'error' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can('error')) { } 0 0 0
6276 {
6277 0 return( $self->pass_error( $class->error ) );
6278 }
6279 else
6280 {
6281 0 return( $self->error( "Unable to instantiate an object for class \"$class\" and values provided: '", join( "', '", @_ ), "'." ) );
6282 }
6283 }
6284 0 $data->{ $field } = $o;
6285 }
6286 }
6287 ▶ elsif( $def->{no_init} && !$data->{ $field } )
Condition0%0/3
$def->{"no_init"} and not $data->{$field}
!ll&&!rl&&r
000
MC/DC0%0/2
$def->{"no_init"} and not $data->{$field}
$def->{"no_init"} not $data->{$field}
Truth table0%0/3
A and not(B)
A= $def->{"no_init"}B= not $data->{$field}
ABresult
0X0
100
111
6288 {
6289 # We do nothing
6290 }
6291 else
6292 {
6293 0 ▶ $class = $class->[0] if( ref( $class ) eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class eq "ARRAY" 0 0 0
6294 # There is already an object, so we pass any argument to the existing object
6295 0 ▶ if( $data->{ $field } && $self->_is_a( $data->{ $field }, $class ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{$field} and $self->_is_a($data->{$field}, $class)) 0 0 0
Condition0%0/3
$data->{$field} and $self->_is_a($data->{$field}, $class)
!ll&&!rl&&r
000
MC/DC0%0/2
$data->{$field} and $self->_is_a($data->{$field}, $class)
$data->{$field} $self->_is_a($data->{$field}, $class)
Truth table0%0/3
A and B
A= $data->{$field}B= $self->_is_a($data->{$field}, $class)
ABresult
0X0
100
111
6296 {
6297 0 ▶ warn( "Re-setting existing object '", $self->_str_val( $data->{ $field } // 'undef' ), "' for field '$field' and class '$class'\n" );
Condition0%0/2
$data->{$field} // "undef"
l!l
00
MC/DC0%0/1
$data->{$field} // "undef"
$data->{$field}
Truth table0%0/2
A
A= $data->{$field}
Aresult
11
00
6298 }
6299  
6300 0 ▶ my $o = $self->_instantiate_object( { field => $field, ( defined( $callback ) ? ( callback => $callback ) : () ) }, $class, @_ );
Branch: 1 branch
BranchTrueFalseTotal
defined $callback ? : 0 0 0
6301 0 ▶ if( !defined( $o ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $o) 0 0 0
6302 {
6303 0 ▶ if( $class->can( 'error' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can('error')) { } 0 0 0
6304 {
6305 0 return( $self->pass_error( $class->error ) );
6306 }
6307 else
6308 {
6309 0 return( $self->error( "Unable to instantiate an object for class \"$class\" with no value provided." ) );
6310 }
6311 }
6312 0 $data->{ $field } = $o;
6313 }
6314 105 $self->clear_error;
6315 }
6316 # If nothing has been set for this field, ie no object, but we are called in chain
6317 # we set a dummy object that will just call itself to avoid perl complaining about undefined value calling a method
6318 242 ▶ if( !$data->{ $field } && want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $data->{$field} and want("OBJECT")) 37 205 242
Condition66%2/3
not $data->{$field} and want("OBJECT")
!ll&&!rl&&r
205037
MC/DC50%1/2
not $data->{$field} and want("OBJECT")
not $data->{$field} want("OBJECT")
Truth table66%2/3
not(A) and B
A= not $data->{$field}B= want("OBJECT")
ABresult
0X0
100
111
6319 {
6320 37 ▶ if( $def->{no_init} )
Branch: 1 branch
BranchTrueFalseTotal
if ($def->{'no_init'}) { } 0 37 37
6321 {
6322 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or return $self->pass_error 0 0 0
6323 return( $self->pass_error );
6324 0 my $null = Module::Generic::Null->new( '', { debug => $this->{debug} });
6325 0 return( $null );
6326 }
6327 else
6328 {
6329 37 ▶ $class = $class->[0] if( ref( $class ) eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class eq "ARRAY" 0 37 37
6330 37 ▶ my $o = $self->_instantiate_object( { field => $field, ( defined( $callback ) ? ( callback => $callback ) : () ) }, $class, @_ );
Branch: 1 branch
BranchTrueFalseTotal
defined $callback ? : 0 37 37
6331 37 ▶ if( !defined( $o ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $o) 0 37 37
6332 {
6333 0 ▶ if( $class->can( 'error' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can('error')) { } 0 0 0
6334 {
6335 0 return( $self->pass_error( $class->error ) );
6336 }
6337 else
6338 {
6339 0 return( $self->error( "Unable to instantiate an object for class \"$class\" with no value provided." ) );
6340 }
6341 }
6342 37 $data->{ $field } = $o;
6343 37 return( $o );
6344 }
6345 }
6346 205 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 205 205
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
20500
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
20500
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
6347 205 return( $data->{ $field } );
6348 }
6349  
6350 sub _set_get_object_array
6351 0 ▶{
Subroutine _set_get_object_array: not called CC=26 SCAR=65.5
6352 0 my $self = shift( @_ );
6353 0 my $field = shift( @_ );
6354 0 my $class = shift( @_ );
6355 0 my $this = $self->_obj2h;
6356 0 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 0 0
6357 0 ▶ @_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and not defined $_[0] 0 0 0
Condition0%0/3
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and not defined $_[0]
scalar @_ == 1 not defined $_[0]
Truth table0%0/3
A and not(B)
A= scalar @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
6358  
6359 0 my $def = {};
6360 0 my $callback;
6361 my $check;
6362 0 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 0 0
6363 {
6364 0 $def = $field;
6365 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
6366 defined( $def->{field} ) &&
6367 CORE::length( $def->{field} ) )
6368 {
6369 0 $field = $def->{field};
6370 }
6371 else
6372 {
6373 0 $field = undef;
6374 }
6375 0 ▶ return( $self->error( "No property 'field' was provided in the parameters of _set_get_object_array" ) ) if( !CORE::length( $field // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($field // "") 0 0 0
Condition0%0/2
$field // ""
l!l
00
MC/DC0%0/1
$field // ""
$field
Truth table0%0/2
A
A= $field
Aresult
11
00
6376 0 ▶ if( CORE::exists( $def->{callback} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE") 0 0 0
Condition0%0/6
exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE"
!ll&&!rl&&r
000
exists $def->{"callback"} and defined $def->{"callback"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE"
exists $def->{"callback"} defined $def->{"callback"} ref $def->{"callback"} eq "CODE"
Truth table0%0/4
A and B and C
A= exists $def->{"callback"}B= defined $def->{"callback"}C= ref $def->{"callback"} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
6377 defined( $def->{callback} ) &&
6378 ref( $def->{callback} ) eq 'CODE' )
6379 {
6380 0 $callback = $def->{callback};
6381 }
6382 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
6383 }
6384 0 ▶ $def->{empty_ok} //= 0;
Condition0%0/2
$def->{"empty_ok"} //= 0
l!l
00
MC/DC0%0/1
$def->{"empty_ok"} //= 0
$def->{"empty_ok"}
Truth table0%0/2
A
A= $def->{"empty_ok"}
Aresult
11
00
6385 0 ▶ $def->{skip_empty} //= 0;
Condition0%0/2
$def->{"skip_empty"} //= 0
l!l
00
MC/DC0%0/1
$def->{"skip_empty"} //= 0
$def->{"skip_empty"}
Truth table0%0/2
A
A= $def->{"skip_empty"}
Aresult
11
00
6386  
6387 my $process = sub
6388 0 ▶ {
Subroutine __ANON__: not called CC=16 SCAR=56.1
6389 0 my $ref = shift( @_ );
6390 0 ▶ return( $self->error( "I was expecting an array ref, but instead got '$ref'. _is_array returned: '", $self->_is_array( $ref ), "'" ) ) if( !$self->_is_array( $ref ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($ref) 0 0 0
6391 0 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 0 0
6392 {
6393 # try-catch
6394 0 local $@;
6395 0 my $rv = eval{ $check->( $self, $ref ) };
6396 0 ▶ 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
6397 {
6398 0 return( $self->pass_error );
6399 }
6400 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
6401 }
6402 0 my $arr = [];
6403 0 ▶ for( my $i = 0; $i < scalar( @$ref ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$ref) 0 0 0
6404 {
6405 0 ▶ if( defined( $ref->[$i] ) || $def->{empty_ok} )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $ref->[$i] or $def->{'empty_ok'}) { } 0 0 0
elsif ($def->{'skip_empty'}) { } 0 0 0
Condition0%0/3
defined $ref->[$i] or $def->{"empty_ok"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $ref->[$i] or $def->{"empty_ok"}
defined $ref->[$i] $def->{"empty_ok"}
Truth table0%0/3
A or B
A= defined $ref->[$i]B= $def->{"empty_ok"}
ABresult
1X1
011
000
6406 {
6407 # return( $self->error( "Array offset $i is not a reference. I was expecting an object of class $class or an hash reference to instantiate an object." ) ) if( !ref( $ref->[$i] ) );
6408 0 ▶ if( Scalar::Util::blessed( $ref->[$i] ) )
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($ref->[$i])) { } 0 0 0
elsif ($self->_is_empty($ref->[$i]) and $def->{'skip_empty'}) { } 0 0 0
6409 {
6410 0 ▶ return( $self->error( "Array offset $i contains an object from class ", $ref->[$i], ", but was expecting an object of class $class." ) ) if( !$self->_is_a( $ref->[$i] => $class ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($ref->[$i], $class) 0 0 0
6411 0 push( @$arr, $ref->[$i] );
6412 }
6413 ▶ elsif( $self->_is_empty( $ref->[$i] ) && $def->{skip_empty} )
Condition0%0/3
$self->_is_empty($ref->[$i]) and $def->{"skip_empty"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_empty($ref->[$i]) and $def->{"skip_empty"}
$self->_is_empty($ref->[$i]) $def->{"skip_empty"}
Truth table0%0/3
A and B
A= $self->_is_empty($ref->[$i])B= $def->{"skip_empty"}
ABresult
0X0
100
111
6414 {
6415 0 next;
6416 }
6417 else
6418 {
6419 0 ▶ my $o = $self->_instantiate_object( { field => $field, ( defined( $callback ) ? ( callback => $callback ) : () ) }, $class, $ref->[$i] ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
defined $callback ? : 0 0 0
Condition0%0/2
$self->_instantiate_object({'field', $field, defined $callback ? ('callback', $callback) : ()}, $class, $ref->[$i]) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_instantiate_object({'field', $field, defined $callback ? ('callback', $callback) : ()}, $class, $ref->[$i]) || (return $self->pass_error)
$self->_instantiate_object({'field', $field, defined $callback ? ('callback', $callback) : ()}, $class, $ref->[$i])
Truth table0%0/2
A
A= $self->_instantiate_object({'field', $field, defined $callback ? ('callback', $callback) : ()}, $class, $ref->[$i])
Aresult
11
00
6420 0 push( @$arr, $o );
6421 }
6422 }
6423 elsif( $def->{skip_empty} )
6424 {
6425 0 next;
6426 }
6427 else
6428 {
6429 0 return( $self->error( "Array offset $i contains an undefined value. I was expecting an object of class $class." ) );
6430 # my $o = $self->_instantiate_object( $field, $class ) || return( $self->pass_error );
6431 # push( @$arr, $o );
6432 }
6433 }
6434 0 return( $arr );
6435 0 };
6436  
6437 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
6438 {
6439 0 ▶ $data->{ $field } = $process->( @_ ) || return( $self->pass_error );
Condition0%0/2
&$process(@_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
&$process(@_) || (return $self->pass_error)
&$process(@_)
Truth table0%0/2
A
A= &$process(@_)
Aresult
11
00
6440 0 $self->clear_error;
6441 }
6442 # For example, if the object property is set at init, without using a method
6443 0 ▶ if( $data->{ $field } && ref( $data->{ $field } ) ne 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{$field} and ref $data->{$field} ne "ARRAY") 0 0 0
Condition0%0/3
$data->{$field} and ref $data->{$field} ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$data->{$field} and ref $data->{$field} ne "ARRAY"
$data->{$field} ref $data->{$field} ne "ARRAY"
Truth table0%0/3
A and B
A= $data->{$field}B= ref $data->{$field} ne "ARRAY"
ABresult
0X0
100
111
6444 {
6445 0 ▶ $data->{ $field } = $process->( $data->{ $field } ) || return( $self->pass_error );
Condition0%0/2
&$process($data->{$field}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
&$process($data->{$field}) || (return $self->pass_error)
&$process($data->{$field})
Truth table0%0/2
A
A= &$process($data->{$field})
Aresult
11
00
6446 }
6447 0 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && defined( $data->{ $field } ) && ref( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field}) 0 0 0
Condition0%0/9
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
000
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field}
!ll&&!rl&&r
000
$def->{"weaken"} and defined $data->{$field}
!ll&&!rl&&r
000
MC/DC0%0/4
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
$def->{"weaken"} defined $data->{$field} ref $data->{$field} not builtin::is_weak($data->{$field})
Truth table0%0/5
A and B and C and not(D)
A= $def->{"weaken"}B= defined $data->{$field}C= ref $data->{$field}D= not builtin::is_weak($data->{$field})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
6448 0 return( $data->{ $field } );
6449 }
6450  
6451 sub _set_get_object_array_object
6452 0 ▶{
Subroutine _set_get_object_array_object: not called CC=29 SCAR=67.7
6453 0 my $self = shift( @_ );
6454 0 ▶ my $field = shift( @_ ) || return( $self->error( "No field name was provided for this array of object." ) );
Condition0%0/2
shift @_ || (return $self->error('No field name was provided for this array of object.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No field name was provided for this array of object.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
6455 0 ▶ my $class = shift( @_ ) || return( $self->error( "No class was provided for this array of objects." ) );
Condition0%0/2
shift @_ || (return $self->error('No class was provided for this array of objects.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No class was provided for this array of objects.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
6456 0 my $this = $self->_obj2h;
6457 0 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 0 0
6458 0 ▶ @_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and not defined $_[0] 0 0 0
Condition0%0/3
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and not defined $_[0]
scalar @_ == 1 not defined $_[0]
Truth table0%0/3
A and not(B)
A= scalar @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
6459 0 ▶ $self->_load_class( 'Module::Generic::Array' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Array") or return $self->pass_error 0 0 0
6460  
6461 0 my $def = {};
6462 0 my $callback;
6463 # 'add' or 'remove' callbacks when data gets added or removed from the array object. See Module::Generic::Array documentation.
6464 my $callbacks;
6465 0 my $check;
6466 0 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq 'HASH') { } 0 0 0
6467 {
6468 0 $def = $field;
6469 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
6470 defined( $def->{field} ) &&
6471 CORE::length( $def->{field} ) )
6472 {
6473 0 $field = $def->{field};
6474 }
6475 else
6476 {
6477 0 $field = undef;
6478 }
6479 0 ▶ return( $self->error( "No property 'field' was provided in the parameters of _set_get_object_array" ) ) if( !CORE::length( $field // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($field // "") 0 0 0
Condition0%0/2
$field // ""
l!l
00
MC/DC0%0/1
$field // ""
$field
Truth table0%0/2
A
A= $field
Aresult
11
00
6480 0 ▶ if( CORE::exists( $def->{callback} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE") 0 0 0
Condition0%0/6
exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE"
!ll&&!rl&&r
000
exists $def->{"callback"} and defined $def->{"callback"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE"
exists $def->{"callback"} defined $def->{"callback"} ref $def->{"callback"} eq "CODE"
Truth table0%0/4
A and B and C
A= exists $def->{"callback"}B= defined $def->{"callback"}C= ref $def->{"callback"} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
6481 defined( $def->{callback} ) &&
6482 ref( $def->{callback} ) eq 'CODE' )
6483 {
6484 0 $callback = $def->{callback};
6485 }
6486 0 ▶ if( CORE::exists( $def->{callbacks} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{"callbacks"} and defined $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH") 0 0 0
Condition0%0/6
exists $def->{"callbacks"} and defined $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
exists $def->{"callbacks"} and defined $def->{"callbacks"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"callbacks"} and defined $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} defined $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/4
A and B and C
A= exists $def->{"callbacks"}B= defined $def->{"callbacks"}C= ref $def->{"callbacks"} eq "HASH"
ABCresult
0XX0
10X0
1100
1111
6487 defined( $def->{callbacks} ) &&
6488 ref( $def->{callbacks} ) eq 'HASH' )
6489 {
6490 0 $callbacks = $def->{callbacks};
6491 }
6492 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
6493 }
6494 else
6495 {
6496 0 $def = { field => $field };
6497 }
6498  
6499 my $process = sub
6500 0 ▶ {
Subroutine __ANON__: not called CC=14 SCAR=53.5
6501 0 ▶ my $that = ( scalar( @_ ) == 1 && UNIVERSAL::isa( $_[0], 'ARRAY' ) ) ? shift( @_ ) : [ @_ ];
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 && UNIVERSAL::isa($_[0], 'ARRAY') ? : 0 0 0
Condition0%0/3
scalar @_ == 1 and UNIVERSAL::isa($_[0], "ARRAY")
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and UNIVERSAL::isa($_[0], "ARRAY")
scalar @_ == 1 UNIVERSAL::isa($_[0], "ARRAY")
Truth table0%0/3
A and B
A= scalar @_ == 1B= UNIVERSAL::isa($_[0], "ARRAY")
ABresult
0X0
100
111
6502 0 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 0 0
6503 {
6504 # try-catch
6505 0 local $@;
6506 0 my $rv = eval{ $check->( $self, $that ) };
6507 0 ▶ 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
6508 {
6509 0 return( $self->pass_error );
6510 }
6511 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
6512 }
6513 0 ▶ my $ref = $self->_set_get_object_array( $def, $class, $that ) || return( $self->pass_error );
Condition0%0/2
$self->_set_get_object_array($def, $class, $that) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_set_get_object_array($def, $class, $that) || (return $self->pass_error)
$self->_set_get_object_array($def, $class, $that)
Truth table0%0/2
A
A= $self->_set_get_object_array($def, $class, $that)
Aresult
11
00
6514 0 my $obj = Module::Generic::Array->new( $ref );
6515 # Now, set the array callbacks if any
6516 0 ▶ if( defined( $callbacks ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $callbacks) 0 0 0
6517 {
6518 0 foreach my $t ( qw( add remove ) )
6519 {
6520 0 ▶ if( CORE::exists( $callbacks->{ "array_${t}" } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$callbacks{"array_$t"} and defined $$callbacks{"array_$t"}) 0 0 0
Condition0%0/3
exists $$callbacks{"array_$t"} and defined $$callbacks{"array_$t"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $$callbacks{"array_$t"} and defined $$callbacks{"array_$t"}
exists $$callbacks{"array_$t"} defined $$callbacks{"array_$t"}
Truth table0%0/3
A and B
A= exists $$callbacks{"array_$t"}B= defined $$callbacks{"array_$t"}
ABresult
0X0
100
111
6521 defined( $callbacks->{ "array_${t}" } ) )
6522 {
6523 my $coderef = ref( $callbacks->{ "array_${t}" } ) eq 'CODE'
6524 ? $callbacks->{ "array_${t}" }
6525 0 ▶ : $self->can( $callbacks->{ "array_${t}" } );
Branch: 1 branch
BranchTrueFalseTotal
ref $$callbacks{"array_$t"} eq 'CODE' ? : 0 0 0
6526 0 ▶ if( defined( $coderef ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef) 0 0 0
6527 {
6528 0 $obj->callback( $t => $coderef );
6529 }
6530 }
6531 }
6532 }
6533 0 return( $obj );
6534 0 };
6535  
6536 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
6537 {
6538 0 ▶ $data->{ $field } = $process->( @_ ) || return( $self->pass_error );
Condition0%0/2
&$process(@_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
&$process(@_) || (return $self->pass_error)
&$process(@_)
Truth table0%0/2
A
A= &$process(@_)
Aresult
11
00
6539 0 $self->clear_error;
6540 }
6541 ## Default value so that call to the caller's method like my_sub->length will not produce something like "Can't call method "length" on an undefined value"
6542 ## Also, this will make it possible to set default value in caller's object and we would turn it into array object.
6543 0 ▶ if( !$data->{ $field } || !$self->_is_a( $data->{ $field }, 'Module::Generic::Array' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($data->{$field} and $self->_is_a($data->{$field}, "Module::Generic::Array")) 0 0 0
Condition0%0/3
$data->{$field} and $self->_is_a($data->{$field}, "Module::Generic::Array")
!ll&&!rl&&r
000
MC/DC0%0/2
$data->{$field} and $self->_is_a($data->{$field}, "Module::Generic::Array")
$data->{$field} $self->_is_a($data->{$field}, "Module::Generic::Array")
Truth table0%0/3
A and B
A= $data->{$field}B= $self->_is_a($data->{$field}, "Module::Generic::Array")
ABresult
0X0
100
111
6544 {
6545 0 ▶ $data->{ $field } = $process->( CORE::defined( $data->{ $field } ) ? $data->{ $field } : () );
Branch: 1 branch
BranchTrueFalseTotal
defined $data->{$field} ? : 0 0 0
6546 }
6547 0 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 0 0
Condition0%0/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
000
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
000
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table0%0/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
6548 0 return( $data->{ $field } );
6549 }
6550  
6551 sub _set_get_object_array2
6552 0 ▶{
Subroutine _set_get_object_array2: not called CC=33 SCAR=70.2
6553 0 my $self = shift( @_ );
6554 0 my $field = shift( @_ );
6555 0 my $class = shift( @_ );
6556 0 my $this = $self->_obj2h;
6557 0 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 0 0
6558  
6559 0 my $def = {};
6560 0 my $callback;
6561 my $check;
6562 0 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 0 0
6563 {
6564 0 $def = $field;
6565 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
6566 defined( $def->{field} ) &&
6567 CORE::length( $def->{field} ) )
6568 {
6569 0 $field = $def->{field};
6570 }
6571 else
6572 {
6573 0 $field = undef;
6574 }
6575 0 ▶ return( $self->error( "No property 'field' was provided in the parameters of _set_get_object" ) ) if( !length( $field // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($field // "") 0 0 0
Condition0%0/2
$field // ""
l!l
00
MC/DC0%0/1
$field // ""
$field
Truth table0%0/2
A
A= $field
Aresult
11
00
6576 0 ▶ if( CORE::exists( $def->{callback} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE") 0 0 0
Condition0%0/6
exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE"
!ll&&!rl&&r
000
exists $def->{"callback"} and defined $def->{"callback"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE"
exists $def->{"callback"} defined $def->{"callback"} ref $def->{"callback"} eq "CODE"
Truth table0%0/4
A and B and C
A= exists $def->{"callback"}B= defined $def->{"callback"}C= ref $def->{"callback"} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
6577 defined( $def->{callback} ) &&
6578 ref( $def->{callback} ) eq 'CODE' )
6579 {
6580 0 $callback = $def->{callback};
6581 }
6582 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
6583 }
6584  
6585 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
6586 {
6587 0 my $data_to_process = shift( @_ );
6588 0 ▶ return( $self->error( "I was expecting an array ref, but instead got '$data_to_process'. _is_array returned: '", $self->_is_array( $data_to_process ), "'" ) ) if( !$self->_is_array( $data_to_process ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($data_to_process) 0 0 0
6589 0 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 0 0
6590 {
6591 # try-catch
6592 0 local $@;
6593 0 my $rv = eval{ $check->( $self, $data_to_process ) };
6594 0 ▶ 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
6595 {
6596 0 return( $self->pass_error );
6597 }
6598 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
6599 }
6600 0 my $arr1 = [];
6601 0 foreach my $ref ( @$data_to_process )
6602 {
6603 0 ▶ return( $self->error( "I was expecting an embeded array ref, but instead got '$ref'." ) ) if( ref( $ref ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref ne "ARRAY" 0 0 0
6604 0 my $arr = [];
6605 0 ▶ for( my $i = 0; $i < scalar( @$ref ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$ref) 0 0 0
6606 {
6607 0 my $o;
6608 0 ▶ if( defined( $ref->[$i] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->[$i]) { } 0 0 0
6609 {
6610 0 ▶ return( $self->error( "Parameter provided for adding object of class $class is not a reference." ) ) if( !ref( $ref->[$i] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ref->[$i] 0 0 0
6611 0 ▶ if( Scalar::Util::blessed( $ref->[$i] ) )
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($ref->[$i])) { } 0 0 0
elsif (ref $ref->[$i] eq 'HASH') { } 0 0 0
6612 {
6613 0 ▶ return( $self->error( "Array offset $i contains an object from class ", $ref->[$i], ", but was expecting an object of class $class." ) ) if( !$ref->[$i]->isa( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $ref->[$i]->isa($class) 0 0 0
6614 0 $o = $ref->[$i];
6615 }
6616 elsif( ref( $ref->[$i] ) eq 'HASH' )
6617 {
6618 #$o = $class->new( $h, $ref->[$i] );
6619 0 ▶ $o = $self->_instantiate_object( { field => $field, ( defined( $callback ) ? ( callback => $callback ) : () ) }, $class, $ref->[$i] );
Branch: 1 branch
BranchTrueFalseTotal
defined $callback ? : 0 0 0
6620 }
6621 else
6622 {
6623 0 $self->error( "Warning only: data provided to instaantiate object of class $class is not a hash reference" );
6624 }
6625 }
6626 else
6627 {
6628 #$o = $class->new( $h );
6629 0 ▶ $o = $self->_instantiate_object( { field => $field, ( defined( $callback ) ? ( callback => $callback ) : () ) }, $class );
Branch: 1 branch
BranchTrueFalseTotal
defined $callback ? : 0 0 0
6630 }
6631 0 ▶ return( $self->error( "Unable to instantiate an object of class $class: ", $class->error ) ) if( !defined( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 0 0
6632 0 ▶ Scalar::Util::weaken( $o ) if( $def->{weaken} && $self->_is_object( $o ) && !Scalar::Util::isweak( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($o) and not builtin::is_weak($o) 0 0 0
Condition0%0/6
$def->{"weaken"} and $self->_is_object($o) and not builtin::is_weak($o)
!ll&&!rl&&r
000
$def->{"weaken"} and $self->_is_object($o)
!ll&&!rl&&r
000
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($o) and not builtin::is_weak($o)
$def->{"weaken"} $self->_is_object($o) not builtin::is_weak($o)
Truth table0%0/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($o)C= not builtin::is_weak($o)
ABCresult
0XX0
10X0
1100
1111
6633 # $o->{_parent} = $self->{_parent};
6634 0 push( @$arr, $o );
6635 }
6636 0 push( @$arr1, $arr );
6637 }
6638 0 $data->{ $field } = $arr1;
6639 0 $self->clear_error;
6640 }
6641 0 return( $data->{ $field } );
6642 }
6643  
6644 0 ▶sub _set_get_object_lvalue : lvalue
Subroutine _set_get_object_lvalue: not called CC=12 SCAR=50.0
6645 {
6646 0 my $self = shift( @_ );
6647 0 my $field = shift( @_ );
6648 0 my $class = shift( @_ );
6649 38 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
6650 0 my $this = $self->_obj2h;
6651 0 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 0 0
6652  
6653 0 my $callbacks = {};
6654 0 my $check;
6655 0 my $def = {};
6656 0 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 0 0
6657 {
6658 0 $def = $field;
6659 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
6660 defined( $def->{field} ) &&
6661 CORE::length( $def->{field} ) )
6662 {
6663 0 $field = $def->{field};
6664 }
6665 else
6666 {
6667 0 $field = undef;
6668 }
6669 # Should have been 'callbacks', but we catch it anyway.
6670 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
6671 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
6672 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
6673 }
6674  
6675 return( $self->_set_get_callback({
6676 get => sub
6677 0 ▶ {
Subroutine __ANON__: not called CC=6 SCAR=37.4
6678 0 my $self = shift( @_ );
6679 0 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 0 0
6680 0 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && defined( $data->{ $field } ) && ref( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field}) 0 0 0
Condition0%0/9
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
000
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field}
!ll&&!rl&&r
000
$def->{"weaken"} and defined $data->{$field}
!ll&&!rl&&r
000
MC/DC0%0/4
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
$def->{"weaken"} defined $data->{$field} ref $data->{$field} not builtin::is_weak($data->{$field})
Truth table0%0/5
A and B and C and not(D)
A= $def->{"weaken"}B= defined $data->{$field}C= ref $data->{$field}D= not builtin::is_weak($data->{$field})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
6681 0 return( $data->{ $field } );
6682 },
6683 set => sub
6684 0 ▶ {
Subroutine __ANON__: not called CC=27 SCAR=66.3
6685 0 my $self = shift( @_ );
6686 0 my $arg = shift( @_ );
6687 0 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 0 0
6688 0 my $ctx = $_;
6689 0 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 0 0
6690 {
6691 # try-catch
6692 0 local $@;
6693 0 my $rv = eval{ $check->( $self, $arg ) };
6694 0 ▶ 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
6695 {
6696 0 return( $self->pass_error );
6697 }
6698 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
6699 }
6700  
6701 0 ▶ if( !defined( $arg ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $arg) { } 0 0 0
elsif (builtin::blessed($arg)) { } 0 0 0
6702 {
6703 0 $data->{ $field } = undef();
6704 }
6705 # User pass an object
6706 elsif( Scalar::Util::blessed( $arg ) )
6707 {
6708 0 ▶ if( ref( $class ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class eq 'ARRAY') { } 0 0 0
6709 {
6710 0 my $ok = 0;
6711 0 foreach my $c ( @$class )
6712 {
6713 0 ▶ if( $arg->isa( $c ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->isa($c)) 0 0 0
6714 {
6715 0 $ok++, last;
6716 }
6717 }
6718 0 return( $self->error( "Object provided (" . ref( $arg ) . ") for $field does not match any of the possible classes: '" . join( "', '", @$class ) . "'." ) );
6719 }
6720 else
6721 {
6722 0 ▶ if( !$arg->isa( "$class" ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg->isa("$class")) 0 0 0
6723 {
6724 0 return( $self->error( "Object provided (" . ref( $arg ) . ") for $field is not a valid $class object" ) );
6725 }
6726 }
6727 0 $data->{ $field } = $arg;
6728 # We reset the error before the callback
6729 0 $self->clear_error;
6730  
6731 0 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 0 0
Condition0%0/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
000
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table0%0/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
6732 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
6733 {
6734 0 my $coderef;
6735 0 foreach my $t ( qw( add set ) )
6736 {
6737 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
6738 {
6739 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
6740 ? $callbacks->{ $t }
6741 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
6742 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
6743 }
6744 }
6745 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
6746 {
6747 0 $coderef->( $self, $data->{ $field } );
6748 }
6749 }
6750 }
6751 else
6752 {
6753 0 ▶ return( $self->error( "Value provided (" . $self->_str_val( $arg // '' ) . " is not an object." ) );
Condition0%0/2
$arg // ""
l!l
00
MC/DC0%0/1
$arg // ""
$arg
Truth table0%0/2
A
A= $arg
Aresult
11
00
6754 }
6755 0 $self->clear_error;
6756 # We need to return something else than our object, or by virtue of perl's way of working
6757 # we would return our object as coded below, and that object will be assigned the
6758 # very value we will have passed in assignment !
6759 0 ▶ return( $data->{__dummy} = 'dummy' ) if( $ctx->{assign} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"assign"} 0 0 0
6760 0 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && defined( $data->{ $field } ) && ref( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field}) 0 0 0
Condition0%0/9
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
000
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field}
!ll&&!rl&&r
000
$def->{"weaken"} and defined $data->{$field}
!ll&&!rl&&r
000
MC/DC0%0/4
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
$def->{"weaken"} defined $data->{$field} ref $data->{$field} not builtin::is_weak($data->{$field})
Truth table0%0/5
A and B and C and not(D)
A= $def->{"weaken"}B= defined $data->{$field}C= ref $data->{$field}D= not builtin::is_weak($data->{$field})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
6761 0 return( $data->{ $field } );
6762 },
6763 0 field => $field,
6764 }, @_ ) );
6765 }
6766  
6767 sub _set_get_object_variant
6768 0 ▶{
Subroutine _set_get_object_variant: not called CC=19 SCAR=59.4
6769 0 my $self = shift( @_ );
6770 0 my $field = shift( @_ );
6771 # The class precisely depends on what we find looking ahead
6772 0 my $class = shift( @_ );
6773 0 my $this = $self->_obj2h;
6774 0 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 0 0
6775  
6776 0 my $def = {};
6777 0 my $callback;
6778 my $check;
6779 0 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 0 0
6780 {
6781 0 $def = $field;
6782 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
6783 defined( $def->{field} ) &&
6784 CORE::length( $def->{field} ) )
6785 {
6786 0 $field = $def->{field};
6787 }
6788 else
6789 {
6790 0 $field = undef;
6791 }
6792 0 ▶ return( $self->error( "No property 'field' was provided in the parameters of _set_get_object_array" ) ) if( !CORE::length( $field // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($field // "") 0 0 0
Condition0%0/2
$field // ""
l!l
00
MC/DC0%0/1
$field // ""
$field
Truth table0%0/2
A
A= $field
Aresult
11
00
6793 0 ▶ if( CORE::exists( $def->{callback} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE") 0 0 0
Condition0%0/6
exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE"
!ll&&!rl&&r
000
exists $def->{"callback"} and defined $def->{"callback"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"callback"} and defined $def->{"callback"} and ref $def->{"callback"} eq "CODE"
exists $def->{"callback"} defined $def->{"callback"} ref $def->{"callback"} eq "CODE"
Truth table0%0/4
A and B and C
A= exists $def->{"callback"}B= defined $def->{"callback"}C= ref $def->{"callback"} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
6794 defined( $def->{callback} ) &&
6795 ref( $def->{callback} ) eq 'CODE' )
6796 {
6797 0 $callback = $def->{callback};
6798 }
6799 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
6800 }
6801  
6802 my $process = sub
6803 0 ▶ {
Subroutine __ANON__: not called CC=10 SCAR=47.0
6804 0 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 0 0
6805 {
6806 0 my $val = $_[0];
6807 # try-catch
6808 0 local $@;
6809 0 my $rv = eval{ $check->( $self, $val ) };
6810 0 ▶ 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
6811 {
6812 0 return( $self->pass_error );
6813 }
6814 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
6815 }
6816  
6817 0 ▶ if( ref( $_[0] ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
elsif (ref $_[0] eq 'ARRAY') { } 0 0 0
6818 {
6819 0 my $o = $self->_instantiate_object( $field, $class, @_ );
6820 0 return( $o );
6821 }
6822 # An array of objects hash
6823 elsif( ref( $_[0] ) eq 'ARRAY' )
6824 {
6825 0 my $arr = shift( @_ );
6826 0 my $res = [];
6827 0 foreach my $data ( @$arr )
6828 {
6829 0 ▶ my $o = $self->_instantiate_object( { field => $field, ( defined( $callback ) ? ( callback => $callback ) : () ) }, $class, $data ) || return( $self->error( "Unable to create object: ", $self->error ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $callback ? : 0 0 0
Condition0%0/2
$self->_instantiate_object({'field', $field, defined $callback ? ('callback', $callback) : ()}, $class, $data) || (return $self->error('Unable to create object: ', $self->error))
l!l
00
MC/DC0%0/1
$self->_instantiate_object({'field', $field, defined $callback ? ('callback', $callback) : ()}, $class, $data) || (return $self->error('Unable to create object: ', $self->error))
$self->_instantiate_object({'field', $field, defined $callback ? ('callback', $callback) : ()}, $class, $data)
Truth table0%0/2
A
A= $self->_instantiate_object({'field', $field, defined $callback ? ('callback', $callback) : ()}, $class, $data)
Aresult
11
00
6830 0 push( @$res, $o );
6831 }
6832 0 return( $res );
6833 }
6834 0 };
6835  
6836 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
6837 {
6838 0 ▶ $data->{ $field } = $process->( @_ ) || return( $self->pass_error );
Condition0%0/2
&$process(@_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
&$process(@_) || (return $self->pass_error)
&$process(@_)
Truth table0%0/2
A
A= &$process(@_)
Aresult
11
00
6839 0 $self->clear_error;
6840 }
6841 0 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && defined( $data->{ $field } ) && ref( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field}) 0 0 0
Condition0%0/9
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
000
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field}
!ll&&!rl&&r
000
$def->{"weaken"} and defined $data->{$field}
!ll&&!rl&&r
000
MC/DC0%0/4
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
$def->{"weaken"} defined $data->{$field} ref $data->{$field} not builtin::is_weak($data->{$field})
Truth table0%0/5
A and B and C and not(D)
A= $def->{"weaken"}B= defined $data->{$field}C= ref $data->{$field}D= not builtin::is_weak($data->{$field})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
6842 0 return( $data->{ $field } );
6843 }
6844  
6845 sub _set_get_object_without_init
6846 0 ▶{
Subroutine _set_get_object_without_init: not called CC=73 SCAR=85.6
6847 0 my $self = shift( @_ );
6848 0 my $field = shift( @_ );
6849 0 my $class = shift( @_ );
6850 0 my $this = $self->_obj2h;
6851 0 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 0 0
6852 37 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
6853  
6854 0 my $def = {};
6855 0 my $callback;
6856 0 my $callbacks = {};
6857 0 my $check;
6858 0 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 0 0
6859 {
6860 0 $def = $field;
6861 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
6862 defined( $def->{field} ) &&
6863 CORE::length( $def->{field} ) )
6864 {
6865 0 $field = $def->{field};
6866 }
6867 else
6868 {
6869 0 $field = undef;
6870 }
6871 0 ▶ return( $self->error( "No property 'field' was provided in the parameters of _set_get_object" ) ) if( !length( $field // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($field // "") 0 0 0
Condition0%0/2
$field // ""
l!l
00
MC/DC0%0/1
$field // ""
$field
Truth table0%0/2
A
A= $field
Aresult
11
00
6872 # Callback used to instantiate the object
6873 0 ▶ if( CORE::exists( $def->{callback} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{"callback"} and defined $def->{"callback"}) 0 0 0
Condition0%0/3
exists $def->{"callback"} and defined $def->{"callback"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and defined $def->{"callback"}
exists $def->{"callback"} defined $def->{"callback"}
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= defined $def->{"callback"}
ABresult
0X0
100
111
6874 defined( $def->{callback} ) )
6875 {
6876 0 ▶ if( ref( $def->{callback} ) eq 'CODE' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $def->{'callback'} eq 'CODE') { } 0 0 0
elsif (ref $def->{'callback'} eq 'HASH') { } 0 0 0
6877 {
6878 0 $callback = $def->{callback};
6879 }
6880 # Should have been 'callbacks', but we catch it anyway.
6881 elsif( ref( $def->{callback} ) eq 'HASH' )
6882 {
6883 0 $callbacks = $def->{callback};
6884 }
6885 }
6886 # Should have been 'callbacks', but we catch it anyway.
6887 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
6888 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
6889 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
6890 }
6891  
6892 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
6893 {
6894 0 ▶ if( scalar( @_ ) == 1 )
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1) { } 0 0 0
elsif ((ref $class // '') eq 'ARRAY' and not defined $callback) { } 0 0 0
6895 {
6896 0 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 0 0
6897 {
6898 0 my $val = $_[0];
6899 0 ▶ $self->__message( 112, "Checking value provided (", $self->_str_val( $val // 'undef' ), ") for '$field'." );
Condition0%0/2
$val // "undef"
l!l
00
MC/DC0%0/1
$val // "undef"
$val
Truth table0%0/2
A
A= $val
Aresult
11
00
6900 # try-catch
6901 0 local $@;
6902 0 my $rv = eval{ $check->( $self, $val ) };
6903 0 ▶ 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
6904 {
6905 0 return( $self->pass_error );
6906 }
6907 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
6908 }
6909  
6910 # User removed the value by passing it an undefined value
6911 0 ▶ if( !defined( $_[0] ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $_[0]) { } 0 0 0
elsif (builtin::blessed($_[0])) { } 0 0 0
elsif ((ref $class // '') eq 'ARRAY' and not defined $callback) { } 0 0 0
6912 {
6913 0 $self->__message( 112, "Value provided is undef" );
6914 0 $data->{ $field } = undef();
6915 }
6916 # User pass an object
6917 elsif( Scalar::Util::blessed( $_[0] ) )
6918 {
6919 0 my $o = shift( @_ );
6920 0 ▶ $self->__message( 112, "Value provided for '$field' is blessed. Checking if it is among the supported classes: ", ( ref( $class ) eq 'ARRAY' ? join( ', ', @$class ) : $class ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $class eq 'ARRAY' ? : 0 0 0
6921 0 ▶ if( ref( $class ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class eq 'ARRAY') { } 0 0 0
6922 {
6923 0 my $ok = 0;
6924 0 foreach my $c ( @$class )
6925 {
6926 0 ▶ if( $o->isa( $c ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($o->isa($c)) 0 0 0
6927 {
6928 0 $ok++, last;
6929 }
6930 }
6931 0 ▶ return( $self->error( "Object provided (", ref( $o ), ") for $field does not match any of the possible classes: '", join( "', '", @$class ), "'." ) ) if( !$ok );
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
6932 }
6933 else
6934 {
6935 0 ▶ return( $self->error( "Object provided (", ref( $o ), ") for $field is not a valid $class object" ) ) if( !$o->isa( "$class" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $o->isa("$class") 0 0 0
6936 }
6937 0 ▶ $self->__message( 112, "Ok, object provided for '$field' is a valid class object of '", ( ref( $class ) eq 'ARRAY' ? join( ', ', @$class ) : $class ), "'." );
Branch: 1 branch
BranchTrueFalseTotal
ref $class eq 'ARRAY' ? : 0 0 0
6938 0 $data->{ $field } = $o;
6939 }
6940 ▶ elsif( ( ref( $class ) // '' ) eq 'ARRAY' && !defined( $callback ) )
Condition0%0/5
(ref $class // "") eq "ARRAY" and not defined $callback
!ll&&!rl&&r
000
ref $class // ""
l!l
00
MC/DC0%0/2
(ref $class // "") eq "ARRAY" and not defined $callback
ref $class not defined $callback
Truth table0%0/3
A and not(B)
A= ref $classB= not defined $callback
ABresult
0X0
100
111
6941 {
6942 # Cannot instantiate an object, when specified allowed classes is an array, because we would not know which class to use, unless there is a callback that would take of it of course.
6943 0 $self->__message( 112, "Parameters received to instantiate a class object for '$field', but multiple allowed classes were provided." );
6944 0 return( $self->error( "Cannot instantiate a class object for '$field' with multiple classes being set." ) );
6945 }
6946 else
6947 {
6948 0 $self->__message( 112, scalar( @_ ), " parameters provided. Instantiating a new class '$class'" );
6949 # return( $self->error( "Only undef or an ", ( ref( $class ) eq 'ARRAY' ? join( ', ', @$class ) : $class ), " object can be provided." ) );
6950 0 ▶ my $o = $self->_instantiate_object( { field => $field, ( defined( $callback ) ? ( callback => $callback ) : () ) }, $class, @_ );
Branch: 1 branch
BranchTrueFalseTotal
defined $callback ? : 0 0 0
6951 0 ▶ if( !defined( $o ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $o) 0 0 0
6952 {
6953 0 ▶ if( $class->can( 'error' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can('error')) { } 0 0 0
6954 {
6955 0 return( $self->pass_error( $class->error ) );
6956 }
6957 else
6958 {
6959 0 return( $self->error( "Unable to instantiate an object for class \"$class\" and values provided: '", join( "', '", @_ ), "'." ) );
6960 }
6961 }
6962 0 $data->{ $field } = $o;
6963 }
6964 }
6965 ▶ elsif( ( ref( $class ) // '' ) eq 'ARRAY' && !defined( $callback ) )
Condition0%0/5
(ref $class // "") eq "ARRAY" and not defined $callback
!ll&&!rl&&r
000
ref $class // ""
l!l
00
MC/DC0%0/2
(ref $class // "") eq "ARRAY" and not defined $callback
ref $class not defined $callback
Truth table0%0/3
A and not(B)
A= ref $classB= not defined $callback
ABresult
0X0
100
111
6966 {
6967 # Cannot instantiate an object, when specified allowed classes is an array, because we would not know which class to use.
6968 0 $self->__message( 112, "Parameters received to instaantiate a class object, but multiple allowed classes were provided." );
6969 0 return( $self->error( "Cannot instantiate a class object for '$field' with multiple classes being set." ) );
6970 }
6971 else
6972 {
6973 # return( $self->error( "Only undef or an ", ( ref( $class ) eq 'ARRAY' ? join( ', ', @$class ) : $class ), " object can be provided." ) );
6974 0 ▶ my $o = $self->_instantiate_object( { field => $field, ( defined( $callback ) ? ( callback => $callback ) : () ) }, $class, @_ );
Branch: 1 branch
BranchTrueFalseTotal
defined $callback ? : 0 0 0
6975 0 ▶ if( !defined( $o ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $o) 0 0 0
6976 {
6977 0 ▶ if( $class->can( 'error' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can('error')) { } 0 0 0
6978 {
6979 0 return( $self->pass_error( $class->error ) );
6980 }
6981 else
6982 {
6983 0 return( $self->error( "Unable to instantiate an object for class \"$class\" with no value provided." ) );
6984 }
6985 }
6986 0 $data->{ $field } = $o;
6987 }
6988  
6989 0 my $coderef;
6990 0 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 0 0
Condition0%0/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
000
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table0%0/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
6991 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
6992 {
6993 0 foreach my $t ( qw( add set ) )
6994 {
6995 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
6996 {
6997 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
6998 ? $callbacks->{ $t }
6999 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
7000 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
7001 }
7002 }
7003 }
7004 0 ▶ $self->__message( 112, "Did we find a callback for $field ? ", defined( $coderef ) ? 'yes' : 'no' );
Branch: 1 branch
BranchTrueFalseTotal
defined $coderef ? : 0 0 0
7005 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
7006 {
7007 0 ▶ $self->__message( 112, "Executing callback for $field passing new value '", $self->_str_val( $data->{ $field } // 'undef' ), "'" );
Condition0%0/2
$data->{$field} // "undef"
l!l
00
MC/DC0%0/1
$data->{$field} // "undef"
$data->{$field}
Truth table0%0/2
A
A= $data->{$field}
Aresult
11
00
7008 # try-catch
7009 0 local $@;
7010 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
7011 0 ▶ $self->__message( 112, "Callback done. Object field $field value is now '", $self->_str_val( $data->{ $field } // 'undef' ), "'" );
Condition0%0/2
$data->{$field} // "undef"
l!l
00
MC/DC0%0/1
$data->{$field} // "undef"
$data->{$field}
Truth table0%0/2
A
A= $data->{$field}
Aresult
11
00
7012 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
7013 {
7014 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
7015 }
7016 ▶ elsif( !defined( $rv ) && $self->error )
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
7017 {
7018 0 return( $self->pass_error );
7019 }
7020 # $data->{ $field } = $rv if( defined( $rv ) ); # Update with callback’s result if defined
7021 # Update with callback’s result if defined
7022 0 $data->{ $field } = $rv;
7023 }
7024 0 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 0 0
Condition0%0/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
000
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
000
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table0%0/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
7025 0 $self->clear_error;
7026 }
7027  
7028 # We only execute callbacks in accessor mode
7029 0 ▶ unless( @_ )
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 0 0
7030 {
7031 0 ▶ $self->__message( 112, "Property '$field' value is '", $self->_str_val( $data->{ $field } // 'undef' ), "'" );
Condition0%0/2
$data->{$field} // "undef"
l!l
00
MC/DC0%0/1
$data->{$field} // "undef"
$data->{$field}
Truth table0%0/2
A
A= $data->{$field}
Aresult
11
00
7032 0 my $v = $data->{ $field };
7033 0 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"get"} and ref $callbacks->{"get"} eq "CODE") 0 0 0
Condition0%0/6
scalar keys %$callbacks and exists $callbacks->{"get"} and ref $callbacks->{"get"} eq "CODE"
!ll&&!rl&&r
000
scalar keys %$callbacks and exists $callbacks->{"get"}
!ll&&!rl&&r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"get"} and ref $callbacks->{"get"} eq "CODE"
scalar keys %$callbacks exists $callbacks->{"get"} ref $callbacks->{"get"} eq "CODE"
Truth table0%0/4
A and B and C
A= scalar keys %$callbacksB= exists $callbacks->{"get"}C= ref $callbacks->{"get"} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
7034 CORE::exists( $callbacks->{get} ) &&
7035 ref( $callbacks->{get} ) eq 'CODE' )
7036 {
7037 0 $v = $callbacks->{get}->( $self, $v );
7038 }
7039 0 ▶ $self->__message( 112, "Returning property '$field' value -> '", $self->_str_val( $v // 'undef' ), "'" );
Condition0%0/2
$v // "undef"
l!l
00
MC/DC0%0/1
$v // "undef"
$v
Truth table0%0/2
A
A= $v
Aresult
11
00
7040 0 $data->{ $field } = $v;
7041 0 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 0 0
Condition0%0/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
000
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
000
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table0%0/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
7042 0 return( $data->{ $field } );
7043 }
7044 # If nothing has been set for this field, ie no object, but we are called in chain, this will fail on purpose.
7045 # To avoid this, use _set_get_object
7046 0 return( $data->{ $field } );
7047 }
7048  
7049 3453 ▶sub _set_get_scalar : lvalue
Subroutine _set_get_scalar: called CC=12 SCAR=28.1
7050 {
7051 3453 my $self = shift( @_ );
7052 3453 my $field = shift( @_ );
7053 3453 my $this = $self->_obj2h;
7054 3453 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 3453 3453
7055  
7056 3453 my $callbacks = {};
7057 3453 my $check;
7058 3453 my $def = {};
7059 3453 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 312 3141 3453
7060 {
7061 312 $def = $field;
7062 312 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 312 0 312
Condition33%2/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
00312
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
00312
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table25%1/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
7063 defined( $def->{field} ) &&
7064 CORE::length( $def->{field} ) )
7065 {
7066 312 $field = $def->{field};
7067 }
7068 else
7069 {
7070 0 $field = undef;
7071 }
7072 # Should have been 'callbacks', but we catch it anyway.
7073 312 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 312 312
Condition33%1/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
31200
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table33%1/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
7074 312 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 273 39 312
Condition66%2/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
390273
MC/DC50%1/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table66%2/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
7075 312 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 39 273 312
Condition66%2/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
273039
MC/DC50%1/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table66%2/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
7076 }
7077  
7078 return( $self->_set_get_callback({
7079 get => sub
7080 2598 ▶ {
Subroutine __ANON__: called CC=10 SCAR=27.3
7081 2598 my $self = shift( @_ );
7082 2598 ▶ $self->__message( 112, "Property '$field' value is '", $self->_str_val( $data->{ $field } // 'undef' ), "'" );
Condition100%2/2
$data->{$field} // "undef"
l!l
251583
MC/DC100%1/1
$data->{$field} // "undef"
$data->{$field}
Truth table100%2/2
A
A= $data->{$field}
Aresult
11
00
7083 2598 my $v = $data->{ $field };
7084 2598 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"get"} and ref $callbacks->{"get"} eq "CODE") 0 2598 2598
Condition50%3/6
scalar keys %$callbacks and exists $callbacks->{"get"} and ref $callbacks->{"get"} eq "CODE"
!ll&&!rl&&r
259800
scalar keys %$callbacks and exists $callbacks->{"get"}
!ll&&!rl&&r
24211770
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"get"} and ref $callbacks->{"get"} eq "CODE"
scalar keys %$callbacks exists $callbacks->{"get"} ref $callbacks->{"get"} eq "CODE"
Truth table50%2/4
A and B and C
A= scalar keys %$callbacksB= exists $callbacks->{"get"}C= ref $callbacks->{"get"} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
7085 CORE::exists( $callbacks->{get} ) &&
7086 ref( $callbacks->{get} ) eq 'CODE' )
7087 {
7088 0 $v = $callbacks->{get}->( $self, $v );
7089 }
7090 2598 ▶ $self->__message( 112, "Returning property '$field' value -> '", $self->_str_val( $v // 'undef' ), "'" );
Condition100%2/2
$v // "undef"
l!l
251583
MC/DC100%1/1
$v // "undef"
$v
Truth table100%2/2
A
A= $v
Aresult
11
00
7091 2598 $data->{ $field } = $v;
7092 2598 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && defined( $data->{ $field } ) && ref( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field}) 0 2598 2598
Condition33%3/9
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
259800
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field}
!ll&&!rl&&r
259800
$def->{"weaken"} and defined $data->{$field}
!ll&&!rl&&r
259800
MC/DC0%0/4
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
$def->{"weaken"} defined $data->{$field} ref $data->{$field} not builtin::is_weak($data->{$field})
Truth table20%1/5
A and B and C and not(D)
A= $def->{"weaken"}B= defined $data->{$field}C= ref $data->{$field}D= not builtin::is_weak($data->{$field})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
7093 2598 return( $v );
7094 },
7095 set => sub
7096 882 ▶ {
Subroutine __ANON__: called CC=28 SCAR=39.6
7097 882 my $self = shift( @_ );
7098 882 ▶ my $val = ( @_ == 1 ) ? shift( @_ ) : join( '', @_ );
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 882 0 882
7099 882 ▶ if( ref( $val ) eq 'HASH' || ref( $val ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq "HASH" or ref $val eq "ARRAY") 0 882 882
Condition33%1/3
ref $val eq "HASH" or ref $val eq "ARRAY"
l!l&&r!l&&!r
00882
MC/DC0%0/2
ref $val eq "HASH" or ref $val eq "ARRAY"
ref $val eq "HASH" ref $val eq "ARRAY"
Truth table33%1/3
A or B
A= ref $val eq "HASH"B= ref $val eq "ARRAY"
ABresult
1X1
011
000
7100 {
7101 0 return( $self->error( "Method $field takes only a scalar, but value provided ($val) is a reference" ) );
7102 }
7103 882 ▶ $self->__message( 112, "Setting value '", ( $val // 'undef' ), "' to object field '$field'." );
Condition100%2/2
$val // "undef"
l!l
738144
MC/DC100%1/1
$val // "undef"
$val
Truth table100%2/2
A
A= $val
Aresult
11
00
7104 882 my $original_val = $val;
7105 882 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 24 858 882
7106 {
7107 # try-catch
7108 24 local $@;
7109 24 my $rv = eval{ $check->( $self, $val ) };
7110 24 ▶ if( !defined( $rv ) && $self->error )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rv and $self->error) 0 24 24
Condition33%1/3
not defined $rv and $self->error
!ll&&!rl&&r
2400
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
7111 {
7112 0 return( $self->pass_error );
7113 }
7114 24 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 1 23 24
7115 }
7116 881 $data->{ $field } = $val; # Store immediately
7117 881 $self->clear_error;
7118  
7119 881 my $coderef;
7120 881 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 96 785 881
Condition50%3/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
785096
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
0960
MC/DC33%1/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table50%2/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
7121 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
7122 {
7123 96 foreach my $t ( qw( add set ) )
7124 {
7125 192 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 96 96 192
7126 {
7127 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
7128 ? $callbacks->{ $t }
7129 96 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 96 0 96
7130 96 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 96 0 96
7131 }
7132 }
7133 }
7134 881 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 96 785 881
Condition66%2/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
785096
MC/DC50%1/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table66%2/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
7135 {
7136 96 ▶ $self->__message( 112, "Executing callback passing new value '", ( $val // 'undef' ), "'" );
Condition50%1/2
$val // "undef"
l!l
960
MC/DC0%0/1
$val // "undef"
$val
Truth table50%1/2
A
A= $val
Aresult
11
00
7137 # try-catch
7138 96 local $@;
7139 96 my $rv = eval{ $coderef->( $self, $val ) };
7140 96 ▶ $self->__message( 112, "Callback done. Object field $field value is now '", ( $val // 'undef' ), "'" );
Condition50%1/2
$val // "undef"
l!l
960
MC/DC0%0/1
$val // "undef"
$val
Truth table50%1/2
A
A= $val
Aresult
11
00
7141 96 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 96 96
elsif (not defined $rv and $self->error) { } 0 192 192
7142 {
7143 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $val ), "': $@" ) );
7144 }
7145 ▶ elsif( !defined( $rv ) && $self->error )
Condition33%1/3
not defined $rv and $self->error
!ll&&!rl&&r
9600
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
7146 {
7147 0 return( $self->pass_error );
7148 }
7149 # $data->{ $field } = $rv if( defined( $rv ) ); # Update with callback’s result if defined
7150 # Update with callback’s result
7151 96 $data->{ $field } = $rv;
7152 }
7153 881 ▶ $self->__message( 106, "Returning field '$field' value '", ( $data->{ $field } // 'undef' ), "'." );
Condition100%2/2
$data->{$field} // "undef"
l!l
737144
MC/DC100%1/1
$data->{$field} // "undef"
$data->{$field}
Truth table100%2/2
A
A= $data->{$field}
Aresult
11
00
7154 881 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && defined( $data->{ $field } ) && ref( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field}) 0 881 881
Condition33%3/9
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
88100
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field}
!ll&&!rl&&r
88100
$def->{"weaken"} and defined $data->{$field}
!ll&&!rl&&r
88100
MC/DC0%0/4
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
$def->{"weaken"} defined $data->{$field} ref $data->{$field} not builtin::is_weak($data->{$field})
Truth table20%1/5
A and B and C and not(D)
A= $def->{"weaken"}B= defined $data->{$field}C= ref $data->{$field}D= not builtin::is_weak($data->{$field})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
7155 881 return( $data->{ $field } );
7156 },
7157 3453 field => $field,
7158 }, @_ ) );
7159 }
7160  
7161 712 ▶sub _set_get_scalar_as_object : lvalue
Subroutine _set_get_scalar_as_object: called CC=12 SCAR=34.7
7162 {
7163 712 my $self = shift( @_ );
7164 712 my $field = shift( @_ );
7165 712 my $this = $self->_obj2h;
7166 712 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 52 660 712
7167  
7168 712 my $callbacks = {};
7169 712 my $check;
7170 712 my $def = {};
7171 712 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 15 697 712
7172 {
7173 15 $def = $field;
7174 15 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 15 0 15
Condition33%2/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
0015
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
0015
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table25%1/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
7175 defined( $def->{field} ) &&
7176 CORE::length( $def->{field} ) )
7177 {
7178 15 $field = $def->{field};
7179 }
7180 else
7181 {
7182 0 $field = undef;
7183 }
7184 # Should have been 'callbacks', but we catch it anyway.
7185 15 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 15 15
Condition33%1/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
1500
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table33%1/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
7186 15 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 15 0 15
Condition33%1/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
0015
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table33%1/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
7187 15 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 15 15
Condition33%1/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
1500
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table33%1/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
7188 }
7189  
7190 my $get_value = sub
7191 122 ▶ {
Subroutine __ANON__: called CC=6 SCAR=22.4
7192 126 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7193 122 my $val = shift( @_ );
7194 122 my $rv;
7195 122 ▶ if( !defined( $val ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $val) { } 1 121 122
elsif ($self->_can($data->{$field}, '""')) { } 0 121 121
elsif (not ref $val) { } 121 0 121
7196 {
7197 1 return( undef );
7198 }
7199 elsif( $self->_can( $data->{ $field } => '""' ) )
7200 {
7201 0 ▶ if( $self->_can( $data->{ $field } => 'defined' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_can($data->{$field}, 'defined')) { } 0 0 0
7202 {
7203 0 ▶ $rv = $data->{ $field }->defined ? "$data->{ $field }" : $data->{ $field };
Branch: 1 branch
BranchTrueFalseTotal
$data->{$field}->defined ? : 0 0 0
7204 }
7205 else
7206 {
7207 0 $rv = "$data->{ $field }";
7208 }
7209 }
7210 elsif( !CORE::ref( $val ) )
7211 {
7212 121 $rv = $val;
7213 }
7214 # A reference of some sort that may not be acceptable actually.
7215 else
7216 {
7217 0 $rv = $val
7218 }
7219 712 };
7220  
7221 return( $self->_set_get_callback({
7222 get => sub
7223 495 ▶ {
Subroutine __ANON__: called CC=24 SCAR=43.3
7224 495 my $self = shift( @_ );
7225 495 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 495 495
7226 495 my $ctx = $_;
7227 495 ▶ if( !$self->_is_a( $data->{ $field } => 'Module::Generic::Scalar' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($data->{$field}, "Module::Generic::Scalar")) 122 373 495
7228 {
7229 122 my $val = $get_value->( $data->{ $field } );
7230 122 ▶ $self->_load_class( 'Module::Generic::Scalar' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or die "Unable to load Module::Generic::Scalar" 122 0 122
7231 die( "Unable to load Module::Generic::Scalar" );
7232 122 $data->{ $field } = Module::Generic::Scalar->new( $val );
7233 122 ▶ if( !defined( $data->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data->{$field}) 0 122 122
7234 {
7235 0 warn( Module::Generic::Scalar->error );
7236 0 return( $self->pass_error( Module::Generic::Scalar->error ) );
7237 }
7238 }
7239 495 ▶ my $is_weak = Scalar::Util::isweak( $data->{ $field } ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
builtin::is_weak($data->{$field}) ? : 0 495 495
7240 495 my $v = $data->{ $field };
7241 # If we have a callback, call it and get the resulting value
7242 495 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"get"} and ref $callbacks->{"get"} eq "CODE") 15 480 495
Condition66%4/6
scalar keys %$callbacks and exists $callbacks->{"get"} and ref $callbacks->{"get"} eq "CODE"
!ll&&!rl&&r
480015
scalar keys %$callbacks and exists $callbacks->{"get"}
!ll&&!rl&&r
480015
MC/DC33%1/3
scalar keys %$callbacks and exists $callbacks->{"get"} and ref $callbacks->{"get"} eq "CODE"
scalar keys %$callbacks exists $callbacks->{"get"} ref $callbacks->{"get"} eq "CODE"
Truth table50%2/4
A and B and C
A= scalar keys %$callbacksB= exists $callbacks->{"get"}C= ref $callbacks->{"get"} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
7243 CORE::exists( $callbacks->{get} ) &&
7244 ref( $callbacks->{get} ) eq 'CODE' )
7245 {
7246 15 $self->__message( 5, "There is a get callback for instance property '${field}'." );
7247 15 $v = $callbacks->{get}->( $self, $v );
7248 # Did the callback return a weak reference; if so, we respect it
7249 15 ▶ $is_weak = Scalar::Util::isweak( $v ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
builtin::is_weak($v) ? : 0 15 15
7250 }
7251  
7252 495 ▶ if( !$self->_is_a( $v => 'Module::Generic::Scalar' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_is_a($v, 'Module::Generic::Scalar')) { } 0 495 495
7253 {
7254 0 my $val = $get_value->( $v );
7255 0 ▶ $self->_load_class( 'Module::Generic::Scalar' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or return $self->pass_error 0 0 0
7256 return( $self->pass_error );
7257 0 $v = Module::Generic::Scalar->new( $val );
7258 0 ▶ if( !defined( $v ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 0 0 0
7259 {
7260 0 warn( Module::Generic::Scalar->error );
7261 0 return( $self->pass_error( Module::Generic::Scalar->error ) );
7262 }
7263 0 $data->{ $field } = $v;
7264 0 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 0 0
Condition0%0/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
000
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
000
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table0%0/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
7265 }
7266 else
7267 {
7268 495 $data->{ $field } = $v;
7269 # We weaken the reference if the original value was weak, or if we are instructed to make it weak.
7270 495 ▶ Scalar::Util::weaken( $data->{ $field } ) if( ( $def->{weaken} || $is_weak ) && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} || $is_weak and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 495 495
Condition33%3/9
$def->{"weaken"} || $is_weak and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
49500
$def->{"weaken"} || $is_weak and $self->_is_object($data->{$field})
!ll&&!rl&&r
49500
$def->{"weaken"} or $is_weak
l!l&&r!l&&!r
00495
MC/DC0%0/4
$def->{"weaken"} || $is_weak and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $is_weak $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table14%1/7
A or B and C and not(D)
A= $def->{"weaken"}B= $is_weakC= $self->_is_object($data->{$field})D= not builtin::is_weak($data->{$field})
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
7271 }
7272  
7273 # We avoid copying the reference, as it would make it a strong reference
7274 495 ▶ if( !CORE::defined( $data->{ $field } ) || !$data->{ $field }->defined )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $data->{$field} && $data->{$field}->defined) { } 4 491 495
Condition66%2/3
defined $data->{$field} && $data->{$field}->defined
!ll&&!rl&&r
04491
MC/DC50%1/2
defined $data->{$field} && $data->{$field}->defined
defined $data->{$field} $data->{$field}->defined
Truth table66%2/3
A && B
A= defined $data->{$field}B= $data->{$field}->defined
ABresult
0X0
100
111
7275 {
7276 # We might have need to specify, because I found a race condition where
7277 # even though the context is object, once in Null, the context became 'code'
7278 # return( Module::Generic::Null->new( wants => 'OBJECT' ) );
7279 4 ▶ if( $ctx->{object} && CORE::defined( $data->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'object'} and defined $data->{$field}) { } 2 2 4
Condition66%2/3
$ctx->{"object"} and defined $data->{$field}
!ll&&!rl&&r
202
MC/DC50%1/2
$ctx->{"object"} and defined $data->{$field}
$ctx->{"object"} defined $data->{$field}
Truth table66%2/3
A and B
A= $ctx->{"object"}B= defined $data->{$field}
ABresult
0X0
100
111
7280 {
7281 2 return( $data->{ $field } );
7282 }
7283 else
7284 {
7285 2 return;
7286 }
7287 }
7288 else
7289 {
7290 491 return( $data->{ $field } );
7291 }
7292 },
7293 set => sub
7294 218 ▶ {
Subroutine __ANON__: called CC=43 SCAR=61.7
7295 218 my $self = shift( @_ );
7296 218 my $arg = shift( @_ );
7297 218 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 218 218
7298 218 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 218 218
7299 {
7300 # try-catch
7301 0 local $@;
7302 0 my $rv = eval{ $check->( $self, $arg ) };
7303 0 ▶ 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
7304 {
7305 0 return( $self->pass_error );
7306 }
7307 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
7308 }
7309 218 my $ctx = $_;
7310 218 my $val;
7311 218 ▶ if( defined( $arg ) &&
Branch: 3 branches
BranchTrueFalseTotal
if (defined $arg and ref $arg eq 'SCALAR' || UNIVERSAL::isa($arg, 'SCALAR')) { } 0 218 218
elsif (defined $arg and ref $arg and $self->_is_object($arg) and overload::Overloaded($arg) and overload::Method($arg, '""')) { } 0 218 218
elsif (defined $arg and ref $arg) { } 0 218 218
Condition50%3/6
defined $arg and ref $arg eq "SCALAR" || UNIVERSAL::isa($arg, "SCALAR")
!ll&&!rl&&r
12170
ref $arg eq "SCALAR" or UNIVERSAL::isa($arg, "SCALAR")
l!l&&r!l&&!r
00217
MC/DC0%0/3
defined $arg and ref $arg eq "SCALAR" || UNIVERSAL::isa($arg, "SCALAR")
defined $arg ref $arg eq "SCALAR" UNIVERSAL::isa($arg, "SCALAR")
Truth table50%2/4
A and B or C
A= defined $argB= ref $arg eq "SCALAR"C= UNIVERSAL::isa($arg, "SCALAR")
ABCresult
0XX0
1000
11X1
1011
7312 (
7313 ref( $arg ) eq 'SCALAR' ||
7314 UNIVERSAL::isa( $arg, 'SCALAR' )
7315 ) )
7316 {
7317 0 $val = $$arg;
7318 }
7319 ▶ elsif( defined( $arg ) &&
Condition41%5/12
defined $arg and ref $arg and $self->_is_object($arg) and overload::Overloaded($arg) and overload::Method($arg, "\"\"")
!ll&&!rl&&r
21800
defined $arg and ref $arg and $self->_is_object($arg) and overload::Overloaded($arg)
!ll&&!rl&&r
21800
defined $arg and ref $arg and $self->_is_object($arg)
!ll&&!rl&&r
21800
defined $arg and ref $arg
!ll&&!rl&&r
12170
MC/DC0%0/5
defined $arg and ref $arg and $self->_is_object($arg) and overload::Overloaded($arg) and overload::Method($arg, "\"\"")
defined $arg ref $arg $self->_is_object($arg) overload::Overloaded($arg) overload::Method($arg, "\"\"")
Truth table33%2/6
A and B and C and D and E
A= defined $argB= ref $argC= $self->_is_object($arg)D= overload::Overloaded($arg)E= overload::Method($arg, "\"\"")
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
7320 ref( $arg ) &&
7321 $self->_is_object( $arg ) &&
7322 overload::Overloaded( $arg ) &&
7323 overload::Method( $arg, '""' ) )
7324 {
7325 38 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
7326 0 $val = "$arg";
7327 }
7328 ▶ elsif( defined( $arg ) && ref( $arg ) )
Condition66%2/3
defined $arg and ref $arg
!ll&&!rl&&r
12170
MC/DC0%0/2
defined $arg and ref $arg
defined $arg ref $arg
Truth table66%2/3
A and B
A= defined $argB= ref $arg
ABresult
0X0
100
111
7329 {
7330 0 return( $self->error( "I was expecting a string or a scalar reference, but instead got '$arg'" ) );
7331 }
7332 else
7333 {
7334 218 $val = $arg;
7335 }
7336  
7337 218 my $o = $data->{ $field };
7338 # $self->__message( 112, "Got here for value '", $self->_str_val( $val // 'undef' ), "' and current value '", $self->_str_val( $o // 'undef' ), "'" );
7339 218 ▶ if( ref( $data->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data->{$field}) { } 43 175 218
7340 {
7341 43 $data->{ $field }->set( $val );
7342 }
7343 else
7344 {
7345 175 ▶ $self->_load_class( 'Module::Generic::Scalar' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or return $self->pass_error 175 0 175
7346 return( $self->pass_error );
7347 175 $data->{ $field } = Module::Generic::Scalar->new( $val );
7348 175 ▶ if( !defined( $data->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data->{$field}) 0 175 175
7349 {
7350 0 warn( Module::Generic::Scalar->error );
7351 0 return( $self->pass_error( Module::Generic::Scalar->error ) );
7352 }
7353 }
7354 218 $self->clear_error;
7355  
7356 218 ▶ $self->__message( 112, "Do we have a callback set? ", ( scalar( keys( %$callbacks ) ) ? 'yes' : 'no' ) );
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %$callbacks ? : 0 218 218
7357 218 my $coderef;
7358 218 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 218 218
Condition16%1/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
21800
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table25%1/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
7359 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
7360 {
7361 0 foreach my $t ( qw( add set ) )
7362 {
7363 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
7364 {
7365 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
7366 ? $callbacks->{ $t }
7367 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
7368 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
7369 }
7370 }
7371 }
7372  
7373 218 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 218 218
Condition33%1/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
21800
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table33%1/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
7374 {
7375 # try-catch
7376 0 local $@;
7377 # $self->__message( 104, "Executing callback passing new value" );
7378 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
7379 # $self->__message( 104, "Callback done." );
7380 0 ▶ $self->__message( 112, "Callback done. Object field $field value is now '", ( $data->{ $field } // 'undef' ), "'" );
Condition0%0/2
$data->{$field} // "undef"
l!l
00
MC/DC0%0/1
$data->{$field} // "undef"
$data->{$field}
Truth table0%0/2
A
A= $data->{$field}
Aresult
11
00
7381  
7382 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
7383 {
7384 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
7385 }
7386 ▶ elsif( !defined( $rv ) && $self->error )
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
7387 {
7388 0 return( $self->pass_error );
7389 }
7390 # $data->{ $field } = $rv if( defined( $rv ) ); # Update with callback’s result if defined
7391 # Update with callback’s result
7392 0 $data->{ $field } = $rv;
7393 }
7394  
7395 218 ▶ if( !$self->_is_a( $data->{ $field } => 'Module::Generic::Scalar' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($data->{$field}, "Module::Generic::Scalar")) 0 218 218
7396 {
7397 0 ▶ $self->__message( 104, "Instantiating a new Module::Generic::Scalar object with the value '", $self->_str_val( $data->{ $field } ). "' (", ( $data->{ $field } // 'undef' ), ")." );
Condition0%0/2
$data->{$field} // "undef"
l!l
00
MC/DC0%0/1
$data->{$field} // "undef"
$data->{$field}
Truth table0%0/2
A
A= $data->{$field}
Aresult
11
00
7398 0 ▶ $self->_load_class( 'Module::Generic::Scalar' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or return $self->pass_error 0 0 0
7399 return( $self->pass_error );
7400 0 my $val = $get_value->( $data->{ $field } );
7401 0 $data->{ $field } = Module::Generic::Scalar->new( $val );
7402 0 ▶ if( !defined( $data->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data->{$field}) 0 0 0
7403 {
7404 0 warn( Module::Generic::Scalar->error );
7405 0 return( $self->pass_error( Module::Generic::Scalar->error ) );
7406 }
7407 0 ▶ $self->__message( 104, "After Module::Generic::Scalar object instantiation, \$data->{ $field } is now '", $self->_str_val( $data->{ $field } ). "' (", ( $data->{ $field } // 'undef' ), ")." );
Condition0%0/2
$data->{$field} // "undef"
l!l
00
MC/DC0%0/1
$data->{$field} // "undef"
$data->{$field}
Truth table0%0/2
A
A= $data->{$field}
Aresult
11
00
7408 }
7409  
7410 218 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 218 218
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
21800
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
21800
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
7411 218 $self->__message( 104, "\$data->{ $field } is now '", $self->_str_val( $data->{ $field } ), "'" );
7412 218 ▶ if( !$data->{ $field }->defined )
Branch: 1 branch
BranchTrueFalseTotal
if (not $data->{$field}->defined) { } 1 217 218
7413 {
7414 # We might have need to specify, because I found a race condition where
7415 # even though the context is object, once in Null, the context became 'code'
7416 # return( Module::Generic::Null->new( wants => 'OBJECT' ) );
7417 1 ▶ if( $ctx->{object} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'object'}) { } 0 1 1
7418 {
7419 0 return( $data->{ $field } );
7420 }
7421 else
7422 {
7423 1 return;
7424 }
7425 }
7426 else
7427 {
7428 217 return( $data->{ $field } );
7429 }
7430 },
7431 712 field => $field,
7432 }, @_ ) );
7433 }
7434  
7435 sub _set_get_scalar_or_object
7436 0 ▶{
Subroutine _set_get_scalar_or_object: not called CC=18 SCAR=58.3
7437 0 my $self = shift( @_ );
7438 0 my $field = shift( @_ );
7439 0 my $class = shift( @_ );
7440 0 my $this = $self->_obj2h;
7441 0 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 0 0
7442  
7443 0 my $def;
7444 0 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 0 0
7445 {
7446 0 $def = $field;
7447 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
7448 defined( $def->{field} ) &&
7449 CORE::length( $def->{field} ) )
7450 {
7451 0 $field = $def->{field};
7452 }
7453 else
7454 {
7455 0 return( $self->error( "No field name was provided." ) );
7456 }
7457 }
7458  
7459 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
7460 {
7461 0 ▶ if( ref( $_[0] ) eq 'HASH' || Scalar::Util::blessed( $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH' or builtin::blessed($_[0])) { } 0 0 0
Condition0%0/3
ref $_[0] eq "HASH" or builtin::blessed($_[0])
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] eq "HASH" or builtin::blessed($_[0])
ref $_[0] eq "HASH" builtin::blessed($_[0])
Truth table0%0/3
A or B
A= ref $_[0] eq "HASH"B= builtin::blessed($_[0])
ABresult
1X1
011
000
7462 {
7463 0 ▶ return( $self->_set_get_object( ( $def // $field ), $class, @_ ) );
Condition0%0/3
$def // $field
l!l&&r!l&&!r
000
MC/DC0%0/2
$def // $field
$def $field
Truth table0%0/3
A // B
A= $defB= $field
ABresult
1X1
011
000
7464 }
7465 else
7466 {
7467 0 ▶ return( $self->_set_get_scalar( ( $def // $field ), @_ ) );
Condition0%0/3
$def // $field
l!l&&r!l&&!r
000
MC/DC0%0/2
$def // $field
$def $field
Truth table0%0/3
A // B
A= $defB= $field
ABresult
1X1
011
000
7468 }
7469 0 $self->clear_error;
7470 }
7471 0 ▶ if( !$data->{ $field } && want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $data->{$field} and want("OBJECT")) 0 0 0
Condition0%0/3
not $data->{$field} and want("OBJECT")
!ll&&!rl&&r
000
MC/DC0%0/2
not $data->{$field} and want("OBJECT")
not $data->{$field} want("OBJECT")
Truth table0%0/3
not(A) and B
A= not $data->{$field}B= want("OBJECT")
ABresult
0X0
100
111
7472 {
7473 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or return $self->pass_error 0 0 0
7474 return( $self->pass_error );
7475 0 my $null = Module::Generic::Null->new({ debug => $this->{debug}, has_error => 1 });
7476 0 rreturn( $null );
7477 }
7478 0 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && defined( $data->{ $field } ) && ref( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field}) 0 0 0
Condition0%0/9
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
000
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field}
!ll&&!rl&&r
000
$def->{"weaken"} and defined $data->{$field}
!ll&&!rl&&r
000
MC/DC0%0/4
$def->{"weaken"} and defined $data->{$field} and ref $data->{$field} and not builtin::is_weak($data->{$field})
$def->{"weaken"} defined $data->{$field} ref $data->{$field} not builtin::is_weak($data->{$field})
Truth table0%0/5
A and B and C and not(D)
A= $def->{"weaken"}B= defined $data->{$field}C= ref $data->{$field}D= not builtin::is_weak($data->{$field})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
7479 0 return( $data->{ $field } );
7480 }
7481  
7482 11 ▶sub _set_get_uri : lvalue
Subroutine _set_get_uri: called CC=14 SCAR=43.4
7483 {
7484 11 my $self = shift( @_ );
7485 11 my $field = shift( @_ );
7486 11 my $this = $self->_obj2h;
7487 11 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 7 4 11
7488  
7489 11 my $uri_class = 'URI';
7490 11 my $callbacks = {};
7491 11 my $check;
7492 11 my $def = {};
7493 11 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 11 11
7494 {
7495 0 $def = $field;
7496 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
7497 defined( $def->{field} ) &&
7498 CORE::length( $def->{field} ) )
7499 {
7500 0 $field = $def->{field};
7501 }
7502 else
7503 {
7504 0 $field = undef;
7505 }
7506 0 ▶ $uri_class = $def->{class} if( CORE::exists( $def->{class} ) && ref( $def->{class} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"class"} and ref $def->{"class"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"class"} and ref $def->{"class"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"class"} and ref $def->{"class"} eq "HASH"
exists $def->{"class"} ref $def->{"class"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"class"}B= ref $def->{"class"} eq "HASH"
ABresult
0X0
100
111
7507 # Should have been 'callbacks', but we catch it anyway.
7508 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
7509 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
7510 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
7511 }
7512  
7513 return( $self->_set_get_callback({
7514 get => sub
7515 6 ▶ {
Subroutine __ANON__: called CC=8 SCAR=26.5
7516 6 my $self = shift( @_ );
7517 6 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 6 6
7518 6 ▶ $self->_load_class( $uri_class ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($uri_class) or return $self->pass_error 6 0 6
7519 # Data was pre-set or directly set but is not an URI object, so we convert it now
7520 6 ▶ if( $data->{ $field } && !$self->_is_a( $data->{ $field }, $uri_class ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{$field} and not $self->_is_a($data->{$field}, $uri_class)) 0 6 6
Condition33%1/3
$data->{$field} and not $self->_is_a($data->{$field}, $uri_class)
!ll&&!rl&&r
060
MC/DC0%0/2
$data->{$field} and not $self->_is_a($data->{$field}, $uri_class)
$data->{$field} not $self->_is_a($data->{$field}, $uri_class)
Truth table33%1/3
A and not(B)
A= $data->{$field}B= not $self->_is_a($data->{$field}, $uri_class)
ABresult
0X0
100
111
7521 {
7522 # Force stringification if this is an overloaded value
7523 0 $data->{ $field } = $uri_class->new( $data->{ $field } . '' );
7524 }
7525 6 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 6 6
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
600
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
600
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
7526 6 return( $data->{ $field } );
7527 },
7528 set => sub
7529 6 ▶ {
Subroutine __ANON__: called CC=36 SCAR=61.9
7530 6 my $self = shift( @_ );
7531 6 my $arg = shift( @_ );
7532 6 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 6 6
7533 6 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 6 6
7534 {
7535 # try-catch
7536 0 local $@;
7537 0 my $rv = eval{ $check->( $self, $arg ) };
7538 0 ▶ 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
7539 {
7540 0 return( $self->pass_error );
7541 }
7542 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
7543 }
7544 6 ▶ $self->_load_class( $uri_class ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($uri_class) or return $self->pass_error 6 0 6
7545 6 my $str = $arg;
7546 6 ▶ if( Scalar::Util::blessed( $str ) && $str->isa( $uri_class ) )
Branch: 4 branches
BranchTrueFalseTotal
if (builtin::blessed($str) and $str->isa($uri_class)) { } 0 6 6
elsif (defined $str and $str =~ m[^[a-zA-Z]+:/{2}] || $str =~ /^urn\:[a-z]+\:/ || $str =~ /^[a-z]+\:/) { } 4 2 6
elsif (substr($str, 0, 1) eq '/') { } 2 0 2
elsif (defined $str) { } 0 0 0
Condition33%1/3
builtin::blessed($str) and $str->isa($uri_class)
!ll&&!rl&&r
600
MC/DC0%0/2
builtin::blessed($str) and $str->isa($uri_class)
builtin::blessed($str) $str->isa($uri_class)
Truth table33%1/3
A and B
A= builtin::blessed($str)B= $str->isa($uri_class)
ABresult
0X0
100
111
7547 {
7548 0 $data->{ $field } = $str;
7549 }
7550 ▶ elsif( defined( $str ) && ( $str =~ /^[a-zA-Z]+:\/{2}/ || $str =~ /^urn\:[a-z]+\:/ || $str =~ /^[a-z]+\:/ ) )
Condition66%6/9
defined $str and $str =~ m[^[a-zA-Z]+:/{2}] || $str =~ /^urn\:[a-z]+\:/ || $str =~ /^[a-z]+\:/
!ll&&!rl&&r
024
$str =~ m[^[a-zA-Z]+:/{2}] or $str =~ /^urn\:[a-z]+\:/ or $str =~ /^[a-z]+\:/
l!l&&r!l&&!r
402
$str =~ m[^[a-zA-Z]+:/{2}] or $str =~ /^urn\:[a-z]+\:/
l!l&&r!l&&!r
402
MC/DC25%1/4
defined $str and $str =~ m[^[a-zA-Z]+:/{2}] || $str =~ /^urn\:[a-z]+\:/ || $str =~ /^[a-z]+\:/
defined $str $str =~ m[^[a-zA-Z]+:/{2}] $str =~ /^urn\:[a-z]+\:/ $str =~ /^[a-z]+\:/
Truth table40%2/5
A and B or C or D
A= defined $strB= $str =~ m[^[a-zA-Z]+:/{2}]C= $str =~ /^urn\:[a-z]+\:/D= $str =~ /^[a-z]+\:/
ABCDresult
0XXX0
10000
11XX1
101X1
10011
7551 {
7552 4 $data->{ $field } = $uri_class->new( $str );
7553 4 ▶ warn( "$uri_class subclass is missing to handle this specific URI '$str'\n" ) if( !$data->{ $field }->has_recognized_scheme );
Branch: 1 branch
BranchTrueFalseTotal
unless $data->{$field}->has_recognized_scheme 0 4 4
7554 }
7555 # Is it an absolute path?
7556 elsif( substr( $str, 0, 1 ) eq '/' )
7557 {
7558 2 $data->{ $field } = $uri_class->new( $str );
7559 }
7560 elsif( defined( $str ) )
7561 {
7562 # try-catch
7563 0 local $@;
7564 eval
7565 0 {
7566 0 ▶ die( "Cannot use a reference as an URI. Received '$str'" ) if( ref( $str ) && !$self->_is_object( $str ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $str and not $self->_is_object($str) 0 0 0
Condition0%0/3
ref $str and not $self->_is_object($str)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $str and not $self->_is_object($str)
ref $str not $self->_is_object($str)
Truth table0%0/3
A and not(B)
A= ref $strB= not $self->_is_object($str)
ABresult
0X0
100
111
7567 0 my $u = $uri_class->new( $str );
7568 0 $data->{ $field } = $u;
7569 };
7570 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
7571 {
7572 0 return( $self->error( "URI value provided '$str' does not look like an URI, so I do not know what to do with it: $@" ) );
7573 }
7574 }
7575 else
7576 {
7577 0 $data->{ $field } = undef();
7578 }
7579  
7580 # Data was pre-set or directly set but is not an URI object, so we convert it now
7581 6 ▶ if( $data->{ $field } && !$self->_is_a( $data->{ $field }, $uri_class ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{$field} and not $self->_is_a($data->{$field}, $uri_class)) 0 6 6
Condition33%1/3
$data->{$field} and not $self->_is_a($data->{$field}, $uri_class)
!ll&&!rl&&r
060
MC/DC0%0/2
$data->{$field} and not $self->_is_a($data->{$field}, $uri_class)
$data->{$field} not $self->_is_a($data->{$field}, $uri_class)
Truth table33%1/3
A and not(B)
A= $data->{$field}B= not $self->_is_a($data->{$field}, $uri_class)
ABresult
0X0
100
111
7582 {
7583 # Force stringification if this is an overloaded value
7584 0 $data->{ $field } = $uri_class->new( $data->{ $field } . '' );
7585 }
7586 6 $self->clear_error;
7587  
7588 6 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 6 6
Condition16%1/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
600
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table25%1/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
7589 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
7590 {
7591 0 my $coderef;
7592 0 foreach my $t ( qw( add set ) )
7593 {
7594 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
7595 {
7596 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
7597 ? $callbacks->{ $t }
7598 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
7599 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
7600 }
7601 }
7602 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
7603 {
7604 # try-catch
7605 0 local $@;
7606 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
7607 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
7608 {
7609 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
7610 }
7611 ▶ elsif( !defined( $rv ) && $self->error )
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
7612 {
7613 0 return( $self->pass_error );
7614 }
7615 0 $data->{ $field } = $rv;
7616 }
7617 }
7618  
7619 6 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 6 6
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
600
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
600
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
7620 6 return( $data->{ $field } );
7621 },
7622 11 field => $field,
7623 }, @_ ) );
7624 }
7625  
7626 # Universally Unique Identifier
7627 4 ▶sub _set_get_uuid : lvalue
Subroutine _set_get_uuid: called CC=10 SCAR=36.6
7628 {
7629 4 my $self = shift( @_ );
7630 4 my $field = shift( @_ );
7631 4 my $this = $self->_obj2h;
7632 4 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 3 1 4
7633  
7634 4 my $callbacks = {};
7635 4 my $def = {};
7636 4 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 4 4
7637 {
7638 0 $def = $field;
7639 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
7640 defined( $def->{field} ) &&
7641 CORE::length( $def->{field} ) )
7642 {
7643 0 $field = $def->{field};
7644 }
7645 else
7646 {
7647 0 $field = undef;
7648 }
7649 # Should have been 'callbacks', but we catch it anyway.
7650 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
7651 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
7652 }
7653  
7654 return( $self->_set_get_callback({
7655 get => sub
7656 2 ▶ {
Subroutine __ANON__: called CC=7 SCAR=24.5
7657 2 my $self = shift( @_ );
7658 2 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 2 2
7659 2 ▶ unless( $self->_is_a( $data->{ $field }, 'Module::Generic::Scalar' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($data->{$field}, "Module::Generic::Scalar")) 0 2 2
7660 {
7661 0 $data->{ $field } = $self->new_scalar( $data->{ $field } );
7662 }
7663 2 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 2 2
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
200
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
200
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
7664 2 ▶ if( !$data->{ $field }->defined )
Branch: 1 branch
BranchTrueFalseTotal
if (not $data->{$field}->defined) { } 0 2 2
7665 {
7666 0 return;
7667 }
7668 else
7669 {
7670 2 return( $data->{ $field } );
7671 }
7672 },
7673 set => sub
7674 2 ▶ {
Subroutine __ANON__: called CC=21 SCAR=51.8
7675 2 my $self = shift( @_ );
7676 2 my $arg = shift( @_ );
7677 2 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 2 2
7678 2 my $v = $arg;
7679 # If the user wants to remove it
7680 2 ▶ if( !defined( $v ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $v) { } 0 2 2
elsif (length $v and not $self->_is_uuid($v)) { } 0 2 2
7681 {
7682 0 $data->{ $field } = $v;
7683 }
7684 # If the user provided a string, let's check it
7685 ▶ elsif( length( $v ) && !$self->_is_uuid( $v ) )
Condition33%1/3
length $v and not $self->_is_uuid($v)
!ll&&!rl&&r
020
MC/DC0%0/2
length $v and not $self->_is_uuid($v)
length $v not $self->_is_uuid($v)
Truth table33%1/3
A and not(B)
A= length $vB= not $self->_is_uuid($v)
ABresult
0X0
100
111
7686 {
7687 0 return( $self->error( "Value provided is not a valid uuid." ) );
7688 }
7689 2 $data->{ $field } = $self->new_scalar( $v );
7690 2 $self->clear_error;
7691  
7692 2 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 2 2
Condition16%1/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
200
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table25%1/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
7693 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
7694 {
7695 0 my $coderef;
7696 0 foreach my $t ( qw( add set ) )
7697 {
7698 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
7699 {
7700 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
7701 ? $callbacks->{ $t }
7702 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
7703 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
7704 }
7705 }
7706 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
7707 {
7708 # try-catch
7709 0 local $@;
7710 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
7711 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
7712 {
7713 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
7714 }
7715 ▶ elsif( !defined( $rv ) && $self->error )
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
7716 {
7717 0 return( $self->pass_error );
7718 }
7719 0 $data->{ $field } = $rv;
7720 }
7721 }
7722  
7723 2 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 2 2
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
200
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
200
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
7724 2 ▶ if( !$data->{ $field }->defined )
Branch: 1 branch
BranchTrueFalseTotal
if (not $data->{$field}->defined) { } 0 2 2
7725 {
7726 0 return;
7727 }
7728 else
7729 {
7730 2 return( $data->{ $field } );
7731 }
7732 },
7733 4 field => $field,
7734 }, @_ ) );
7735 }
7736  
7737 7 ▶sub _set_get_version : lvalue
Subroutine _set_get_version: called CC=13 SCAR=41.2
7738 {
7739 7 my $self = shift( @_ );
7740 7 my $field = shift( @_ );
7741 7 my $this = $self->_obj2h;
7742 7 ▶ my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 6 1 7
7743  
7744 7 my $version_class = 'version';
7745 7 my $callbacks = {};
7746 7 my $check;
7747 7 my $def = {};
7748 7 ▶ if( ref( $field ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 0 7 7
7749 {
7750 0 $def = $field;
7751 0 ▶ if( CORE::exists( $def->{field} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{'field'} and defined $def->{'field'} and length $def->{'field'}) { } 0 0 0
Condition0%0/6
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
!ll&&!rl&&r
000
exists $def->{"field"} and defined $def->{"field"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $def->{"field"} and defined $def->{"field"} and length $def->{"field"}
exists $def->{"field"} defined $def->{"field"} length $def->{"field"}
Truth table0%0/4
A and B and C
A= exists $def->{"field"}B= defined $def->{"field"}C= length $def->{"field"}
ABCresult
0XX0
10X0
1100
1111
7752 defined( $def->{field} ) &&
7753 CORE::length( $def->{field} ) )
7754 {
7755 0 $field = $def->{field};
7756 }
7757 else
7758 {
7759 0 $field = undef;
7760 }
7761 0 ▶ $version_class = $def->{class} if( CORE::exists( $def->{class} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"class"} 0 0 0
7762 # Should have been 'callbacks', but we catch it anyway.
7763 0 ▶ $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callback"} and ref $def->{"callback"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callback"} and ref $def->{"callback"} eq "HASH"
exists $def->{"callback"} ref $def->{"callback"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callback"}B= ref $def->{"callback"} eq "HASH"
ABresult
0X0
100
111
7764 0 ▶ $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH" 0 0 0
Condition0%0/3
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"callbacks"} and ref $def->{"callbacks"} eq "HASH"
exists $def->{"callbacks"} ref $def->{"callbacks"} eq "HASH"
Truth table0%0/3
A and B
A= exists $def->{"callbacks"}B= ref $def->{"callbacks"} eq "HASH"
ABresult
0X0
100
111
7765 0 ▶ $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"check"} and ref $def->{"check"} eq "CODE" 0 0 0
Condition0%0/3
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{"check"} and ref $def->{"check"} eq "CODE"
exists $def->{"check"} ref $def->{"check"} eq "CODE"
Truth table0%0/3
A and B
A= exists $def->{"check"}B= ref $def->{"check"} eq "CODE"
ABresult
0X0
100
111
7766 }
7767  
7768 return( $self->_set_get_callback({
7769 get => sub
7770 4 ▶ {
Subroutine __ANON__: called CC=11 SCAR=35.4
7771 4 my $self = shift( @_ );
7772 4 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 4 4
7773 4 $self->__message( 112, "Loading class '$version_class'" );
7774 4 ▶ $self->_load_class( $version_class ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($version_class) or return $self->pass_error 4 0 4
7775 4 ▶ if( !CORE::defined( $data->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $data->{$field}) { } 0 4 4
7776 {
7777 0 return;
7778 }
7779 else
7780 {
7781 4 ▶ if( CORE::length( "$data->{ $field }" ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (length "$data->{$field}" and not $self->_is_a($data->{$field}, $version_class)) 0 4 4
Condition33%1/3
length "$data->{$field}" and not $self->_is_a($data->{$field}, $version_class)
!ll&&!rl&&r
040
MC/DC0%0/2
length "$data->{$field}" and not $self->_is_a($data->{$field}, $version_class)
length "$data->{$field}" not $self->_is_a($data->{$field}, $version_class)
Truth table33%1/3
A and not(B)
A= length "$data->{$field}"B= not $self->_is_a($data->{$field}, $version_class)
ABresult
0X0
100
111
7782 !$self->_is_a( $data->{ $field } => $version_class ) )
7783 {
7784 # try-catch
7785 0 local $@;
7786 my $v = eval
7787 0 {
7788 0 ▶ $version_class->can( 'parse' ) ? $version_class->parse( "$data->{ $field }" ) : $version_class->new( "$data->{ $field }" );
Branch: 1 branch
BranchTrueFalseTotal
$version_class->can('parse') ? : 0 0 0
7789 };
7790 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
7791 {
7792 0 warn( "Value set for property '${field}' is not a valid version: $@\n" );
7793 }
7794 0 $data->{ $field } = $v;
7795 }
7796 4 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 4 4
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
400
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
400
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
7797 4 return( $data->{ $field } );
7798 }
7799 },
7800 set => sub
7801 3 ▶ {
Subroutine __ANON__: called CC=36 SCAR=60.1
7802 3 my $self = shift( @_ );
7803 3 my $arg = shift( @_ );
7804 3 ▶ return( $self->error( "No field name was provided." ) ) if( !defined( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 3 3
7805 3 ▶ if( defined( $check ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check) 0 3 3
7806 {
7807 # try-catch
7808 0 local $@;
7809 0 my $rv = eval{ $check->( $self, $arg ) };
7810 0 ▶ 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
7811 {
7812 0 return( $self->pass_error );
7813 }
7814 0 ▶ return( $self->error( "Invalid value provided." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
7815 }
7816 3 $self->__message( 112, "Loading class '$version_class'" );
7817 3 ▶ $self->_load_class( $version_class ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($version_class) or return $self->pass_error 3 0 3
7818 3 my $v = $arg;
7819 3 ▶ $self->__message( 112, "Checking version argument provided '", ( defined( $v ) ? $v : 'undef' ), "'" );
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 3 0 3
7820 3 my $version;
7821 # If the user wants to remove it
7822 3 ▶ if( !defined( $v ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $v) { } 0 3 3
elsif ($self->_is_a($v, $version_class)) { } 0 3 3
elsif (length $v) { } 3 0 3
7823 {
7824 0 $self->__message( 112, "Version value provided is undef, ok." );
7825 0 $data->{ $field } = $v;
7826 }
7827 elsif( $self->_is_a( $v => $version_class ) )
7828 {
7829 0 $self->__message( 112, "Version value provided is an object of class $version_class, ok." );
7830 0 $version = $v;
7831 }
7832 # If the user provided a string, let's check it
7833 elsif( length( $v ) )
7834 {
7835 3 $self->__message( 112, "Version value provided is a regular string, parsing it." );
7836 3 my $error;
7837 3 ▶ if( $v !~ /^$VERSION_LAX_REGEX$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (not $v =~ /^$VERSION_LAX_REGEX$/) { } 0 3 3
7838 {
7839 0 $self->__message( 112, "Version '$v' does not look like a proper version." );
7840 0 $error = "Value provided is not a valid version.";
7841 }
7842 else
7843 {
7844 # try-catch
7845 3 local $@;
7846 eval
7847 3 {
7848 3 ▶ $version = $version_class->can( 'parse' ) ? $version_class->parse( "$v" ) : $version_class->new( "$v" );
Branch: 1 branch
BranchTrueFalseTotal
$version_class->can('parse') ? : 3 0 3
7849 3 ▶ $self->__message( 112, "Parsing version '$v' yielded the object '", $self->_str_val( $version // 'undef' ), "', ok." );
Condition50%1/2
$version // "undef"
l!l
30
MC/DC0%0/1
$version // "undef"
$version
Truth table50%1/2
A
A= $version
Aresult
11
00
7850 };
7851 3 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 3 3
7852 {
7853 0 $error = "Value provided is not a valid version: $@";
7854 }
7855 }
7856 3 ▶ return( $self->error( $error ) ) if( defined( $error ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 3 3
7857 }
7858 3 $data->{ $field } = $version;
7859 3 $self->clear_error;
7860  
7861 3 ▶ if( scalar( keys( %$callbacks ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}) 0 3 3
Condition16%1/6
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
!ll&&!rl&&r
300
exists $callbacks->{"add"} or exists $callbacks->{"set"}
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar keys %$callbacks and exists $callbacks->{"add"} || exists $callbacks->{"set"}
scalar keys %$callbacks exists $callbacks->{"add"} exists $callbacks->{"set"}
Truth table25%1/4
A and B or C
A= scalar keys %$callbacksB= exists $callbacks->{"add"}C= exists $callbacks->{"set"}
ABCresult
0XX0
1000
11X1
1011
7862 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
7863 {
7864 0 my $coderef;
7865 0 foreach my $t ( qw( add set ) )
7866 {
7867 0 ▶ if( CORE::exists( $callbacks->{ $t } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks->{$t}) 0 0 0
7868 {
7869 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
7870 ? $callbacks->{ $t }
7871 0 ▶ : $self->can( $callbacks->{ $t } );
Branch: 1 branch
BranchTrueFalseTotal
ref $callbacks->{$t} eq 'CODE' ? : 0 0 0
7872 0 ▶ last if( defined( $coderef ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $coderef 0 0 0
7873 }
7874 }
7875 0 ▶ if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/3
defined $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $coderef and ref $coderef eq "CODE"
defined $coderef ref $coderef eq "CODE"
Truth table0%0/3
A and B
A= defined $coderefB= ref $coderef eq "CODE"
ABresult
0X0
100
111
7876 {
7877 # try-catch
7878 0 local $@;
7879 0 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
7880 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv and $self->error) { } 0 0 0
7881 {
7882 0 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
7883 }
7884 ▶ elsif( !defined( $rv ) && $self->error )
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
7885 {
7886 0 return( $self->pass_error );
7887 }
7888 0 $data->{ $field } = $rv;
7889 }
7890 }
7891  
7892 3 ▶ if( !CORE::defined( $data->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $data->{$field}) { } 0 3 3
7893 {
7894 0 return;
7895 }
7896 else
7897 {
7898 3 ▶ if( CORE::length( "$data->{ $field }" ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (length "$data->{$field}" and not $self->_is_a($data->{$field}, $version_class)) 0 3 3
Condition33%1/3
length "$data->{$field}" and not $self->_is_a($data->{$field}, $version_class)
!ll&&!rl&&r
030
MC/DC0%0/2
length "$data->{$field}" and not $self->_is_a($data->{$field}, $version_class)
length "$data->{$field}" not $self->_is_a($data->{$field}, $version_class)
Truth table33%1/3
A and not(B)
A= length "$data->{$field}"B= not $self->_is_a($data->{$field}, $version_class)
ABresult
0X0
100
111
7899 !$self->_is_a( $data->{ $field } => $version_class ) )
7900 {
7901 # try-catch
7902 0 local $@;
7903 my $v = eval
7904 0 {
7905 0 ▶ $version_class->can( 'parse' ) ? $version_class->parse( "$data->{ $field }" ) : $version_class->new( "$data->{ $field }" );
Branch: 1 branch
BranchTrueFalseTotal
$version_class->can('parse') ? : 0 0 0
7906 };
7907 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
7908 {
7909 0 warn( "Value set for property '${field}' is not a valid version: $@\n" );
7910 }
7911 0 $data->{ $field } = $v;
7912 }
7913 3 ▶ Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field}) 0 3 3
Condition33%2/6
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
!ll&&!rl&&r
300
$def->{"weaken"} and $self->_is_object($data->{$field})
!ll&&!rl&&r
300
MC/DC0%0/3
$def->{"weaken"} and $self->_is_object($data->{$field}) and not builtin::is_weak($data->{$field})
$def->{"weaken"} $self->_is_object($data->{$field}) not builtin::is_weak($data->{$field})
Truth table25%1/4
A and B and not(C)
A= $def->{"weaken"}B= $self->_is_object($data->{$field})C= not builtin::is_weak($data->{$field})
ABCresult
0XX0
10X0
1100
1111
7914 3 return( $v );
7915 }
7916 },
7917 7 field => $field,
7918 }, @_ ) );
7919 }
7920  
7921 # $obj->_str_val( $some_object );
7922 # $obj->_str_val( undef );
7923 sub _str_val
7924 14822 ▶{
Subroutine _str_val: called CC=3 SCAR=11.8
7925 38 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
7926 14822 ▶ return( '' ) unless( scalar( @_ ) > 1 && defined( $_[1] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ > 1 and defined $_[1] 0 14822 14822
Condition33%1/3
scalar @_ > 1 and defined $_[1]
!ll&&!rl&&r
0014822
MC/DC0%0/2
scalar @_ > 1 and defined $_[1]
scalar @_ > 1 defined $_[1]
Truth table33%1/3
A and B
A= scalar @_ > 1B= defined $_[1]
ABresult
0X0
100
111
7927 14822 return( "$_[1]" );
7928 }
7929  
7930 sub _to_array_object
7931 0 ▶{
Subroutine _to_array_object: not called CC=6 SCAR=37.4
7932 0 my $self = shift( @_ );
7933 0 ▶ my $data = scalar( @_ ) == 1 && $self->_is_array( $_[0] )
Branch: 2 branches
BranchTrueFalseTotal
scalar @_ == 1 && $self->_is_array($_[0]) ? : 0 0 0
scalar @_ == 0 || scalar @_ == 1 && !defined($_[0]) ? : 0 0 0
Condition0%0/9
scalar @_ == 1 and $self->_is_array($_[0])
!ll&&!rl&&r
000
scalar @_ == 0 or scalar @_ == 1 and not defined $_[0]
l!l&&r!l&&!r
000
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and $self->_is_array($_[0])
scalar @_ == 1 $self->_is_array($_[0])
MC/DC0%0/3
scalar @_ == 0 or scalar @_ == 1 and not defined $_[0]
scalar @_ == 0 scalar @_ == 1 not defined $_[0]
Truth table0%0/3
A and B
A= scalar @_ == 1B= $self->_is_array($_[0])
ABresult
0X0
100
111
Truth table0%0/4
A or B and not(C)
A= scalar @_ == 0B= scalar @_ == 1C= not defined $_[0]
ABCresult
1XX1
0111
00X0
0100
7934 ? shift( @_ )
7935 : ( scalar( @_ ) == 0 || ( scalar( @_ ) == 1 && !defined( $_[0] ) ) )
7936 ? []
7937 : [ @_ ];
7938 0 return( $self->new_array( $data ) );
7939 }
7940  
7941 # $self->_warnings_is_enabled()
7942 # $self->_warnings_is_enabled( $other_object );
7943 sub _warnings_is_enabled
7944 91 ▶{
Subroutine _warnings_is_enabled: called CC=6 SCAR=18.2
7945 91 my $self = shift( @_ );
7946 # I hate dying, but here this is a show-stopper
7947 91 ▶ die( "Object provided is undef!\n" ) if( @_ && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if @_ and not defined $_[0] 0 91 91
Condition66%2/3
@_ and not defined $_[0]
!ll&&!rl&&r
8830
MC/DC0%0/2
@_ and not defined $_[0]
@_ not defined $_[0]
Truth table66%2/3
A and not(B)
A= @_B= not defined $_[0]
ABresult
0X0
100
111
7948 91 ▶ my $obj = @_ ? shift( @_ ) : $self;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 3 88 91
7949 # $self->__message( 105, "Are warnings registered for '", ( ref( $obj ) || $obj ), "' ? ", ( $self->_warnings_is_registered( $obj ) ? 'yes' : 'no' ) );
7950 91 ▶ return(0) if( !$self->_warnings_is_registered( $obj ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_warnings_is_registered($obj) 72 19 91
7951 19 ▶ return( warnings::enabled( ref( $obj ) || $obj ) );
Condition66%2/3
ref $obj || $obj
l!l&&r!l&&!r
1630
MC/DC0%0/2
ref $obj || $obj
ref $obj $obj
Truth table66%2/3
A || B
A= ref $objB= $obj
ABresult
1X1
011
000
7952 }
7953  
7954 sub _warnings_is_registered
7955 91 ▶{
Subroutine _warnings_is_registered: called CC=6 SCAR=19.3
7956 91 my $self = shift( @_ );
7957 # I hate dying, but here this is a show-stopper
7958 91 ▶ die( "Object provided is undef!\n" ) if( @_ && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if @_ and not defined $_[0] 0 91 91
Condition33%1/3
@_ and not defined $_[0]
!ll&&!rl&&r
0910
MC/DC0%0/2
@_ and not defined $_[0]
@_ not defined $_[0]
Truth table33%1/3
A and not(B)
A= @_B= not defined $_[0]
ABresult
0X0
100
111
7959 91 ▶ my $obj = @_ ? shift( @_ ) : $self;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 91 0 91
7960 91 ▶ return(1) if( defined( $warnings::Bits{ ref( $obj ) || $obj } ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $warnings::Bits{ref $obj or $obj} 19 72 91
Condition66%2/3
ref $obj || $obj
l!l&&r!l&&!r
8740
MC/DC0%0/2
ref $obj || $obj
ref $obj $obj
Truth table66%2/3
A || B
A= ref $objB= $obj
ABresult
1X1
011
000
7961 72 return(0);
7962 }
7963  
7964 sub _autoload_subs
7965 23 ▶{
Subroutine _autoload_subs: called CC=7 SCAR=30.7
7966 23 my $subs =
7967 {
7968 # NOTE: __colour_data()
7969 __colour_data => <<'PERL',
7970 # Initially those data were stored after the __END__, but it seems some module is interfering with <DATA>
7971 # and so those data could not be loaded reliably
7972 # This is called once by colour_to_rgb to generate the hash reference COLOUR_NAME_TO_RGB
7973 sub __colour_data
7974 {
7975 my $colour_data = <<EOT;
7976 {'alice blue' => ['240','248','255'],'aliceblue' => ['240','248','255'],'antique white' => ['250','235','215'],'antiquewhite' => ['250','235','215'],'antiquewhite1' => ['255','239','219'],'antiquewhite2' => ['238','223','204'],'antiquewhite3' => ['205','192','176'],'antiquewhite4' => ['139','131','120'],'aquamarine' => ['127','255','212'],'aquamarine1' => ['127','255','212'],'aquamarine2' => ['118','238','198'],'aquamarine3' => ['102','205','170'],'aquamarine4' => ['69','139','116'],'azure' => ['240','255','255'],'azure1' => ['240','255','255'],'azure2' => ['224','238','238'],'azure3' => ['193','205','205'],'azure4' => ['131','139','139'],'beige' => ['245','245','220'],'bisque' => ['255','228','196'],'bisque1' => ['255','228','196'],'bisque2' => ['238','213','183'],'bisque3' => ['205','183','158'],'bisque4' => ['139','125','107'],'black' => ['0','0','0'],'blanched almond' => ['255','235','205'],'blanchedalmond' => ['255','235','205'],'blue' => ['0','0','255'],'blue violet' => ['138','43','226'],'blue1' => ['0','0','255'],'blue2' => ['0','0','238'],'blue3' => ['0','0','205'],'blue4' => ['0','0','139'],'blueviolet' => ['138','43','226'],'brown' => ['165','42','42'],'brown1' => ['255','64','64'],'brown2' => ['238','59','59'],'brown3' => ['205','51','51'],'brown4' => ['139','35','35'],'burlywood' => ['222','184','135'],'burlywood1' => ['255','211','155'],'burlywood2' => ['238','197','145'],'burlywood3' => ['205','170','125'],'burlywood4' => ['139','115','85'],'cadet blue' => ['95','158','160'],'cadetblue' => ['95','158','160'],'cadetblue1' => ['152','245','255'],'cadetblue2' => ['142','229','238'],'cadetblue3' => ['122','197','205'],'cadetblue4' => ['83','134','139'],'chartreuse' => ['127','255','0'],'chartreuse1' => ['127','255','0'],'chartreuse2' => ['118','238','0'],'chartreuse3' => ['102','205','0'],'chartreuse4' => ['69','139','0'],'chocolate' => ['210','105','30'],'chocolate1' => ['255','127','36'],'chocolate2' => ['238','118','33'],'chocolate3' => ['205','102','29'],'chocolate4' => ['139','69','19'],'coral' => ['255','127','80'],'coral1' => ['255','114','86'],'coral2' => ['238','106','80'],'coral3' => ['205','91','69'],'coral4' => ['139','62','47'],'cornflower blue' => ['100','149','237'],'cornflowerblue' => ['100','149','237'],'cornsilk' => ['255','248','220'],'cornsilk1' => ['255','248','220'],'cornsilk2' => ['238','232','205'],'cornsilk3' => ['205','200','177'],'cornsilk4' => ['139','136','120'],'cyan' => ['0','255','255'],'cyan1' => ['0','255','255'],'cyan2' => ['0','238','238'],'cyan3' => ['0','205','205'],'cyan4' => ['0','139','139'],'dark blue' => ['0','0','139'],'dark cyan' => ['0','139','139'],'dark goldenrod' => ['184','134','11'],'dark gray' => ['169','169','169'],'dark green' => ['0','100','0'],'dark grey' => ['169','169','169'],'dark khaki' => ['189','183','107'],'dark magenta' => ['139','0','139'],'dark olive green' => ['85','107','47'],'dark orange' => ['255','140','0'],'dark orchid' => ['153','50','204'],'dark red' => ['139','0','0'],'dark salmon' => ['233','150','122'],'dark sea green' => ['143','188','143'],'dark slate blue' => ['72','61','139'],'dark slate gray' => ['47','79','79'],'dark slate grey' => ['47','79','79'],'dark turquoise' => ['0','206','209'],'dark violet' => ['148','0','211'],'darkblue' => ['0','0','139'],'darkcyan' => ['0','139','139'],'darkgoldenrod' => ['184','134','11'],'darkgoldenrod1' => ['255','185','15'],'darkgoldenrod2' => ['238','173','14'],'darkgoldenrod3' => ['205','149','12'],'darkgoldenrod4' => ['139','101','8'],'darkgray' => ['169','169','169'],'darkgreen' => ['0','100','0'],'darkgrey' => ['169','169','169'],'darkkhaki' => ['189','183','107'],'darkmagenta' => ['139','0','139'],'darkolivegreen' => ['85','107','47'],'darkolivegreen1' => ['202','255','112'],'darkolivegreen2' => ['188','238','104'],'darkolivegreen3' => ['162','205','90'],'darkolivegreen4' => ['110','139','61'],'darkorange' => ['255','140','0'],'darkorange1' => ['255','127','0'],'darkorange2' => ['238','118','0'],'darkorange3' => ['205','102','0'],'darkorange4' => ['139','69','0'],'darkorchid' => ['153','50','204'],'darkorchid1' => ['191','62','255'],'darkorchid2' => ['178','58','238'],'darkorchid3' => ['154','50','205'],'darkorchid4' => ['104','34','139'],'darkred' => ['139','0','0'],'darksalmon' => ['233','150','122'],'darkseagreen' => ['143','188','143'],'darkseagreen1' => ['193','255','193'],'darkseagreen2' => ['180','238','180'],'darkseagreen3' => ['155','205','155'],'darkseagreen4' => ['105','139','105'],'darkslateblue' => ['72','61','139'],'darkslategray' => ['47','79','79'],'darkslategray1' => ['151','255','255'],'darkslategray2' => ['141','238','238'],'darkslategray3' => ['121','205','205'],'darkslategray4' => ['82','139','139'],'darkslategrey' => ['47','79','79'],'darkturquoise' => ['0','206','209'],'darkviolet' => ['148','0','211'],'deep pink' => ['255','20','147'],'deep sky blue' => ['0','191','255'],'deeppink' => ['255','20','147'],'deeppink1' => ['255','20','147'],'deeppink2' => ['238','18','137'],'deeppink3' => ['205','16','118'],'deeppink4' => ['139','10','80'],'deepskyblue' => ['0','191','255'],'deepskyblue1' => ['0','191','255'],'deepskyblue2' => ['0','178','238'],'deepskyblue3' => ['0','154','205'],'deepskyblue4' => ['0','104','139'],'dim gray' => ['105','105','105'],'dim grey' => ['105','105','105'],'dimgray' => ['105','105','105'],'dimgrey' => ['105','105','105'],'dodger blue' => ['30','144','255'],'dodgerblue' => ['30','144','255'],'dodgerblue1' => ['30','144','255'],'dodgerblue2' => ['28','134','238'],'dodgerblue3' => ['24','116','205'],'dodgerblue4' => ['16','78','139'],'firebrick' => ['178','34','34'],'firebrick1' => ['255','48','48'],'firebrick2' => ['238','44','44'],'firebrick3' => ['205','38','38'],'firebrick4' => ['139','26','26'],'floral white' => ['255','250','240'],'floralwhite' => ['255','250','240'],'forest green' => ['34','139','34'],'forestgreen' => ['34','139','34'],'gainsboro' => ['220','220','220'],'ghost white' => ['248','248','255'],'ghostwhite' => ['248','248','255'],'gold' => ['255','215','0'],'gold1' => ['255','215','0'],'gold2' => ['238','201','0'],'gold3' => ['205','173','0'],'gold4' => ['139','117','0'],'goldenrod' => ['218','165','32'],'goldenrod1' => ['255','193','37'],'goldenrod2' => ['238','180','34'],'goldenrod3' => ['205','155','29'],'goldenrod4' => ['139','105','20'],'gray' => ['190','190','190'],'gray0' => ['0','0','0'],'gray1' => ['3','3','3'],'gray10' => ['26','26','26'],'gray100' => ['255','255','255'],'gray11' => ['28','28','28'],'gray12' => ['31','31','31'],'gray13' => ['33','33','33'],'gray14' => ['36','36','36'],'gray15' => ['38','38','38'],'gray16' => ['41','41','41'],'gray17' => ['43','43','43'],'gray18' => ['46','46','46'],'gray19' => ['48','48','48'],'gray2' => ['5','5','5'],'gray20' => ['51','51','51'],'gray21' => ['54','54','54'],'gray22' => ['56','56','56'],'gray23' => ['59','59','59'],'gray24' => ['61','61','61'],'gray25' => ['64','64','64'],'gray26' => ['66','66','66'],'gray27' => ['69','69','69'],'gray28' => ['71','71','71'],'gray29' => ['74','74','74'],'gray3' => ['8','8','8'],'gray30' => ['77','77','77'],'gray31' => ['79','79','79'],'gray32' => ['82','82','82'],'gray33' => ['84','84','84'],'gray34' => ['87','87','87'],'gray35' => ['89','89','89'],'gray36' => ['92','92','92'],'gray37' => ['94','94','94'],'gray38' => ['97','97','97'],'gray39' => ['99','99','99'],'gray4' => ['10','10','10'],'gray40' => ['102','102','102'],'gray41' => ['105','105','105'],'gray42' => ['107','107','107'],'gray43' => ['110','110','110'],'gray44' => ['112','112','112'],'gray45' => ['115','115','115'],'gray46' => ['117','117','117'],'gray47' => ['120','120','120'],'gray48' => ['122','122','122'],'gray49' => ['125','125','125'],'gray5' => ['13','13','13'],'gray50' => ['127','127','127'],'gray51' => ['130','130','130'],'gray52' => ['133','133','133'],'gray53' => ['135','135','135'],'gray54' => ['138','138','138'],'gray55' => ['140','140','140'],'gray56' => ['143','143','143'],'gray57' => ['145','145','145'],'gray58' => ['148','148','148'],'gray59' => ['150','150','150'],'gray6' => ['15','15','15'],'gray60' => ['153','153','153'],'gray61' => ['156','156','156'],'gray62' => ['158','158','158'],'gray63' => ['161','161','161'],'gray64' => ['163','163','163'],'gray65' => ['166','166','166'],'gray66' => ['168','168','168'],'gray67' => ['171','171','171'],'gray68' => ['173','173','173'],'gray69' => ['176','176','176'],'gray7' => ['18','18','18'],'gray70' => ['179','179','179'],'gray71' => ['181','181','181'],'gray72' => ['184','184','184'],'gray73' => ['186','186','186'],'gray74' => ['189','189','189'],'gray75' => ['191','191','191'],'gray76' => ['194','194','194'],'gray77' => ['196','196','196'],'gray78' => ['199','199','199'],'gray79' => ['201','201','201'],'gray8' => ['20','20','20'],'gray80' => ['204','204','204'],'gray81' => ['207','207','207'],'gray82' => ['209','209','209'],'gray83' => ['212','212','212'],'gray84' => ['214','214','214'],'gray85' => ['217','217','217'],'gray86' => ['219','219','219'],'gray87' => ['222','222','222'],'gray88' => ['224','224','224'],'gray89' => ['227','227','227'],'gray9' => ['23','23','23'],'gray90' => ['229','229','229'],'gray91' => ['232','232','232'],'gray92' => ['235','235','235'],'gray93' => ['237','237','237'],'gray94' => ['240','240','240'],'gray95' => ['242','242','242'],'gray96' => ['245','245','245'],'gray97' => ['247','247','247'],'gray98' => ['250','250','250'],'gray99' => ['252','252','252'],'green' => ['0','255','0'],'green yellow' => ['173','255','47'],'green1' => ['0','255','0'],'green2' => ['0','238','0'],'green3' => ['0','205','0'],'green4' => ['0','139','0'],'greenyellow' => ['173','255','47'],'grey' => ['190','190','190'],'grey0' => ['0','0','0'],'grey1' => ['3','3','3'],'grey10' => ['26','26','26'],'grey100' => ['255','255','255'],'grey11' => ['28','28','28'],'grey12' => ['31','31','31'],'grey13' => ['33','33','33'],'grey14' => ['36','36','36'],'grey15' => ['38','38','38'],'grey16' => ['41','41','41'],'grey17' => ['43','43','43'],'grey18' => ['46','46','46'],'grey19' => ['48','48','48'],'grey2' => ['5','5','5'],'grey20' => ['51','51','51'],'grey21' => ['54','54','54'],'grey22' => ['56','56','56'],'grey23' => ['59','59','59'],'grey24' => ['61','61','61'],'grey25' => ['64','64','64'],'grey26' => ['66','66','66'],'grey27' => ['69','69','69'],'grey28' => ['71','71','71'],'grey29' => ['74','74','74'],'grey3' => ['8','8','8'],'grey30' => ['77','77','77'],'grey31' => ['79','79','79'],'grey32' => ['82','82','82'],'grey33' => ['84','84','84'],'grey34' => ['87','87','87'],'grey35' => ['89','89','89'],'grey36' => ['92','92','92'],'grey37' => ['94','94','94'],'grey38' => ['97','97','97'],'grey39' => ['99','99','99'],'grey4' => ['10','10','10'],'grey40' => ['102','102','102'],'grey41' => ['105','105','105'],'grey42' => ['107','107','107'],'grey43' => ['110','110','110'],'grey44' => ['112','112','112'],'grey45' => ['115','115','115'],'grey46' => ['117','117','117'],'grey47' => ['120','120','120'],'grey48' => ['122','122','122'],'grey49' => ['125','125','125'],'grey5' => ['13','13','13'],'grey50' => ['127','127','127'],'grey51' => ['130','130','130'],'grey52' => ['133','133','133'],'grey53' => ['135','135','135'],'grey54' => ['138','138','138'],'grey55' => ['140','140','140'],'grey56' => ['143','143','143'],'grey57' => ['145','145','145'],'grey58' => ['148','148','148'],'grey59' => ['150','150','150'],'grey6' => ['15','15','15'],'grey60' => ['153','153','153'],'grey61' => ['156','156','156'],'grey62' => ['158','158','158'],'grey63' => ['161','161','161'],'grey64' => ['163','163','163'],'grey65' => ['166','166','166'],'grey66' => ['168','168','168'],'grey67' => ['171','171','171'],'grey68' => ['173','173','173'],'grey69' => ['176','176','176'],'grey7' => ['18','18','18'],'grey70' => ['179','179','179'],'grey71' => ['181','181','181'],'grey72' => ['184','184','184'],'grey73' => ['186','186','186'],'grey74' => ['189','189','189'],'grey75' => ['191','191','191'],'grey76' => ['194','194','194'],'grey77' => ['196','196','196'],'grey78' => ['199','199','199'],'grey79' => ['201','201','201'],'grey8' => ['20','20','20'],'grey80' => ['204','204','204'],'grey81' => ['207','207','207'],'grey82' => ['209','209','209'],'grey83' => ['212','212','212'],'grey84' => ['214','214','214'],'grey85' => ['217','217','217'],'grey86' => ['219','219','219'],'grey87' => ['222','222','222'],'grey88' => ['224','224','224'],'grey89' => ['227','227','227'],'grey9' => ['23','23','23'],'grey90' => ['229','229','229'],'grey91' => ['232','232','232'],'grey92' => ['235','235','235'],'grey93' => ['237','237','237'],'grey94' => ['240','240','240'],'grey95' => ['242','242','242'],'grey96' => ['245','245','245'],'grey97' => ['247','247','247'],'grey98' => ['250','250','250'],'grey99' => ['252','252','252'],'honeydew' => ['240','255','240'],'honeydew1' => ['240','255','240'],'honeydew2' => ['224','238','224'],'honeydew3' => ['193','205','193'],'honeydew4' => ['131','139','131'],'hot pink' => ['255','105','180'],'hotpink' => ['255','105','180'],'hotpink1' => ['255','110','180'],'hotpink2' => ['238','106','167'],'hotpink3' => ['205','96','144'],'hotpink4' => ['139','58','98'],'indian red' => ['205','92','92'],'indianred' => ['205','92','92'],'indianred1' => ['255','106','106'],'indianred2' => ['238','99','99'],'indianred3' => ['205','85','85'],'indianred4' => ['139','58','58'],'ivory' => ['255','255','240'],'ivory1' => ['255','255','240'],'ivory2' => ['238','238','224'],'ivory3' => ['205','205','193'],'ivory4' => ['139','139','131'],'khaki' => ['240','230','140'],'khaki1' => ['255','246','143'],'khaki2' => ['238','230','133'],'khaki3' => ['205','198','115'],'khaki4' => ['139','134','78'],'lavender' => ['230','230','250'],'lavender blush' => ['255','240','245'],'lavenderblush' => ['255','240','245'],'lavenderblush1' => ['255','240','245'],'lavenderblush2' => ['238','224','229'],'lavenderblush3' => ['205','193','197'],'lavenderblush4' => ['139','131','134'],'lawn green' => ['124','252','0'],'lawngreen' => ['124','252','0'],'lemon chiffon' => ['255','250','205'],'lemonchiffon' => ['255','250','205'],'lemonchiffon1' => ['255','250','205'],'lemonchiffon2' => ['238','233','191'],'lemonchiffon3' => ['205','201','165'],'lemonchiffon4' => ['139','137','112'],'light blue' => ['173','216','230'],'light coral' => ['240','128','128'],'light cyan' => ['224','255','255'],'light goldenrod' => ['238','221','130'],'light goldenrod yellow' => ['250','250','210'],'light gray' => ['211','211','211'],'light green' => ['144','238','144'],'light grey' => ['211','211','211'],'light pink' => ['255','182','193'],'light salmon' => ['255','160','122'],'light sea green' => ['32','178','170'],'light sky blue' => ['135','206','250'],'light slate blue' => ['132','112','255'],'light slate gray' => ['119','136','153'],'light slate grey' => ['119','136','153'],'light steel blue' => ['176','196','222'],'light yellow' => ['255','255','224'],'lightblue' => ['173','216','230'],'lightblue1' => ['191','239','255'],'lightblue2' => ['178','223','238'],'lightblue3' => ['154','192','205'],'lightblue4' => ['104','131','139'],'lightcoral' => ['240','128','128'],'lightcyan' => ['224','255','255'],'lightcyan1' => ['224','255','255'],'lightcyan2' => ['209','238','238'],'lightcyan3' => ['180','205','205'],'lightcyan4' => ['122','139','139'],'lightgoldenrod' => ['238','221','130'],'lightgoldenrod1' => ['255','236','139'],'lightgoldenrod2' => ['238','220','130'],'lightgoldenrod3' => ['205','190','112'],'lightgoldenrod4' => ['139','129','76'],'lightgoldenrodyellow' => ['250','250','210'],'lightgray' => ['211','211','211'],'lightgreen' => ['144','238','144'],'lightgrey' => ['211','211','211'],'lightpink' => ['255','182','193'],'lightpink1' => ['255','174','185'],'lightpink2' => ['238','162','173'],'lightpink3' => ['205','140','149'],'lightpink4' => ['139','95','101'],'lightsalmon' => ['255','160','122'],'lightsalmon1' => ['255','160','122'],'lightsalmon2' => ['238','149','114'],'lightsalmon3' => ['205','129','98'],'lightsalmon4' => ['139','87','66'],'lightseagreen' => ['32','178','170'],'lightskyblue' => ['135','206','250'],'lightskyblue1' => ['176','226','255'],'lightskyblue2' => ['164','211','238'],'lightskyblue3' => ['141','182','205'],'lightskyblue4' => ['96','123','139'],'lightslateblue' => ['132','112','255'],'lightslategray' => ['119','136','153'],'lightslategrey' => ['119','136','153'],'lightsteelblue' => ['176','196','222'],'lightsteelblue1' => ['202','225','255'],'lightsteelblue2' => ['188','210','238'],'lightsteelblue3' => ['162','181','205'],'lightsteelblue4' => ['110','123','139'],'lightyellow' => ['255','255','224'],'lightyellow1' => ['255','255','224'],'lightyellow2' => ['238','238','209'],'lightyellow3' => ['205','205','180'],'lightyellow4' => ['139','139','122'],'lime green' => ['50','205','50'],'limegreen' => ['50','205','50'],'linen' => ['250','240','230'],'magenta' => ['255','0','255'],'magenta1' => ['255','0','255'],'magenta2' => ['238','0','238'],'magenta3' => ['205','0','205'],'magenta4' => ['139','0','139'],'maroon' => ['176','48','96'],'maroon1' => ['255','52','179'],'maroon2' => ['238','48','167'],'maroon3' => ['205','41','144'],'maroon4' => ['139','28','98'],'medium aquamarine' => ['102','205','170'],'medium blue' => ['0','0','205'],'medium orchid' => ['186','85','211'],'medium purple' => ['147','112','219'],'medium sea green' => ['60','179','113'],'medium slate blue' => ['123','104','238'],'medium spring green' => ['0','250','154'],'medium turquoise' => ['72','209','204'],'medium violet red' => ['199','21','133'],'mediumaquamarine' => ['102','205','170'],'mediumblue' => ['0','0','205'],'mediumorchid' => ['186','85','211'],'mediumorchid1' => ['224','102','255'],'mediumorchid2' => ['209','95','238'],'mediumorchid3' => ['180','82','205'],'mediumorchid4' => ['122','55','139'],'mediumpurple' => ['147','112','219'],'mediumpurple1' => ['171','130','255'],'mediumpurple2' => ['159','121','238'],'mediumpurple3' => ['137','104','205'],'mediumpurple4' => ['93','71','139'],'mediumseagreen' => ['60','179','113'],'mediumslateblue' => ['123','104','238'],'mediumspringgreen' => ['0','250','154'],'mediumturquoise' => ['72','209','204'],'mediumvioletred' => ['199','21','133'],'midnight blue' => ['25','25','112'],'midnightblue' => ['25','25','112'],'mint cream' => ['245','255','250'],'mintcream' => ['245','255','250'],'misty rose' => ['255','228','225'],'mistyrose' => ['255','228','225'],'mistyrose1' => ['255','228','225'],'mistyrose2' => ['238','213','210'],'mistyrose3' => ['205','183','181'],'mistyrose4' => ['139','125','123'],'moccasin' => ['255','228','181'],'navajo white' => ['255','222','173'],'navajowhite' => ['255','222','173'],'navajowhite1' => ['255','222','173'],'navajowhite2' => ['238','207','161'],'navajowhite3' => ['205','179','139'],'navajowhite4' => ['139','121','94'],'navy' => ['0','0','128'],'navy blue' => ['0','0','128'],'navyblue' => ['0','0','128'],'old lace' => ['253','245','230'],'oldlace' => ['253','245','230'],'olive drab' => ['107','142','35'],'olivedrab' => ['107','142','35'],'olivedrab1' => ['192','255','62'],'olivedrab2' => ['179','238','58'],'olivedrab3' => ['154','205','50'],'olivedrab4' => ['105','139','34'],'orange' => ['255','165','0'],'orange red' => ['255','69','0'],'orange1' => ['255','165','0'],'orange2' => ['238','154','0'],'orange3' => ['205','133','0'],'orange4' => ['139','90','0'],'orangered' => ['255','69','0'],'orangered1' => ['255','69','0'],'orangered2' => ['238','64','0'],'orangered3' => ['205','55','0'],'orangered4' => ['139','37','0'],'orchid' => ['218','112','214'],'orchid1' => ['255','131','250'],'orchid2' => ['238','122','233'],'orchid3' => ['205','105','201'],'orchid4' => ['139','71','137'],'pale goldenrod' => ['238','232','170'],'pale green' => ['152','251','152'],'pale turquoise' => ['175','238','238'],'pale violet red' => ['219','112','147'],'palegoldenrod' => ['238','232','170'],'palegreen' => ['152','251','152'],'palegreen1' => ['154','255','154'],'palegreen2' => ['144','238','144'],'palegreen3' => ['124','205','124'],'palegreen4' => ['84','139','84'],'paleturquoise' => ['175','238','238'],'paleturquoise1' => ['187','255','255'],'paleturquoise2' => ['174','238','238'],'paleturquoise3' => ['150','205','205'],'paleturquoise4' => ['102','139','139'],'palevioletred' => ['219','112','147'],'palevioletred1' => ['255','130','171'],'palevioletred2' => ['238','121','159'],'palevioletred3' => ['205','104','137'],'palevioletred4' => ['139','71','93'],'papaya whip' => ['255','239','213'],'papayawhip' => ['255','239','213'],'peach puff' => ['255','218','185'],'peachpuff' => ['255','218','185'],'peachpuff1' => ['255','218','185'],'peachpuff2' => ['238','203','173'],'peachpuff3' => ['205','175','149'],'peachpuff4' => ['139','119','101'],'peru' => ['205','133','63'],'pink' => ['255','192','203'],'pink1' => ['255','181','197'],'pink2' => ['238','169','184'],'pink3' => ['205','145','158'],'pink4' => ['139','99','108'],'plum' => ['221','160','221'],'plum1' => ['255','187','255'],'plum2' => ['238','174','238'],'plum3' => ['205','150','205'],'plum4' => ['139','102','139'],'powder blue' => ['176','224','230'],'powderblue' => ['176','224','230'],'purple' => ['160','32','240'],'purple1' => ['155','48','255'],'purple2' => ['145','44','238'],'purple3' => ['125','38','205'],'purple4' => ['85','26','139'],'red' => ['255','0','0'],'red1' => ['255','0','0'],'red2' => ['238','0','0'],'red3' => ['205','0','0'],'red4' => ['139','0','0'],'rosy brown' => ['188','143','143'],'rosybrown' => ['188','143','143'],'rosybrown1' => ['255','193','193'],'rosybrown2' => ['238','180','180'],'rosybrown3' => ['205','155','155'],'rosybrown4' => ['139','105','105'],'royal blue' => ['65','105','225'],'royalblue' => ['65','105','225'],'royalblue1' => ['72','118','255'],'royalblue2' => ['67','110','238'],'royalblue3' => ['58','95','205'],'royalblue4' => ['39','64','139'],'saddle brown' => ['139','69','19'],'saddlebrown' => ['139','69','19'],'salmon' => ['250','128','114'],'salmon1' => ['255','140','105'],'salmon2' => ['238','130','98'],'salmon3' => ['205','112','84'],'salmon4' => ['139','76','57'],'sandy brown' => ['244','164','96'],'sandybrown' => ['244','164','96'],'sea green' => ['46','139','87'],'seagreen' => ['46','139','87'],'seagreen1' => ['84','255','159'],'seagreen2' => ['78','238','148'],'seagreen3' => ['67','205','128'],'seagreen4' => ['46','139','87'],'seashell' => ['255','245','238'],'seashell1' => ['255','245','238'],'seashell2' => ['238','229','222'],'seashell3' => ['205','197','191'],'seashell4' => ['139','134','130'],'sienna' => ['160','82','45'],'sienna1' => ['255','130','71'],'sienna2' => ['238','121','66'],'sienna3' => ['205','104','57'],'sienna4' => ['139','71','38'],'sky blue' => ['135','206','235'],'skyblue' => ['135','206','235'],'skyblue1' => ['135','206','255'],'skyblue2' => ['126','192','238'],'skyblue3' => ['108','166','205'],'skyblue4' => ['74','112','139'],'slate blue' => ['106','90','205'],'slate gray' => ['112','128','144'],'slate grey' => ['112','128','144'],'slateblue' => ['106','90','205'],'slateblue1' => ['131','111','255'],'slateblue2' => ['122','103','238'],'slateblue3' => ['105','89','205'],'slateblue4' => ['71','60','139'],'slategray' => ['112','128','144'],'slategray1' => ['198','226','255'],'slategray2' => ['185','211','238'],'slategray3' => ['159','182','205'],'slategray4' => ['108','123','139'],'slategrey' => ['112','128','144'],'snow' => ['255','250','250'],'snow1' => ['255','250','250'],'snow2' => ['238','233','233'],'snow3' => ['205','201','201'],'snow4' => ['139','137','137'],'spring green' => ['0','255','127'],'springgreen' => ['0','255','127'],'springgreen1' => ['0','255','127'],'springgreen2' => ['0','238','118'],'springgreen3' => ['0','205','102'],'springgreen4' => ['0','139','69'],'steel blue' => ['70','130','180'],'steelblue' => ['70','130','180'],'steelblue1' => ['99','184','255'],'steelblue2' => ['92','172','238'],'steelblue3' => ['79','148','205'],'steelblue4' => ['54','100','139'],'tan' => ['210','180','140'],'tan1' => ['255','165','79'],'tan2' => ['238','154','73'],'tan3' => ['205','133','63'],'tan4' => ['139','90','43'],'thistle' => ['216','191','216'],'thistle1' => ['255','225','255'],'thistle2' => ['238','210','238'],'thistle3' => ['205','181','205'],'thistle4' => ['139','123','139'],'tomato' => ['255','99','71'],'tomato1' => ['255','99','71'],'tomato2' => ['238','92','66'],'tomato3' => ['205','79','57'],'tomato4' => ['139','54','38'],'turquoise' => ['64','224','208'],'turquoise1' => ['0','245','255'],'turquoise2' => ['0','229','238'],'turquoise3' => ['0','197','205'],'turquoise4' => ['0','134','139'],'violet' => ['238','130','238'],'violet red' => ['208','32','144'],'violetred' => ['208','32','144'],'violetred1' => ['255','62','150'],'violetred2' => ['238','58','140'],'violetred3' => ['205','50','120'],'violetred4' => ['139','34','82'],'wheat' => ['245','222','179'],'wheat1' => ['255','231','186'],'wheat2' => ['238','216','174'],'wheat3' => ['205','186','150'],'wheat4' => ['139','126','102'],'white' => ['255','255','255'],'white smoke' => ['245','245','245'],'whitesmoke' => ['245','245','245'],'yellow' => ['255','255','0'],'yellow green' => ['154','205','50'],'yellow1' => ['255','255','0'],'yellow2' => ['238','238','0'],'yellow3' => ['205','205','0'],'yellow4' => ['139','139','0'],'yellowgreen' => ['154','205','50']}
7977 EOT
7978 }
7979 PERL
7980 # NOTE: __create_class()
7981 __create_class => <<'PERL',
7982 sub __create_class
7983 {
7984 my $self = shift( @_ );
7985 my $field = shift( @_ ) || return( $self->error( "No field was provided to create a dynamic class." ) );
7986 my $def = shift( @_ );
7987 my $class;
7988 if( $def->{_class} )
7989 {
7990 $class = $def->{_class};
7991 }
7992 else
7993 {
7994 my $new_class = $field;
7995 $new_class =~ tr/-/_/;
7996 $new_class =~ s/\_{2,}/_/g;
7997 $new_class = join( '', map( ucfirst( lc( $_ ) ), split( /\_/, $new_class ) ) );
7998 $class = ( ref( $self ) || $self ) . "\::${new_class}";
7999 }
8000 $self->__message( 112, "Class to be used is '$class' (", ( $self->_is_class_loaded( $class ) ? "already loaded" : "not yet loaded" ), ") and dictionary is: ", sub{ $self->Module::Generic::dump( $def ) } );
8001 if( $self->_is_class_loaded( $class ) )
8002 {
8003 my $ref = eval( "\\%${class}::" );
8004 # $self->__message( 112, "Class $class seems to be already loaded. Symbols are -> ", sub{ $self->Module::Generic::dump( $ref ) } );
8005 }
8006  
8007 unless( $self->_is_class_loaded( $class ) )
8008 {
8009 my $type2func =
8010 {
8011 array => '_set_get_array',
8012 # Alias for 'array_as_object'
8013 array_object => '_set_get_array_as_object',
8014 array_as_object => '_set_get_array_as_object',
8015 boolean => '_set_get_boolean',
8016 class => '_set_get_class',
8017 class_array => '_set_get_class_array',
8018 class_array_object => '_set_get_class_array_object',
8019 code => '_set_get_code',
8020 datetime => '_set_get_datetime',
8021 decimal => '_set_get_number',
8022 file => '_set_get_file',
8023 float => '_set_get_number',
8024 glob => '_set_get_glob',
8025 hash => '_set_get_hash',
8026 hash_as_object => '_set_get_hash_as_mix_object',
8027 integer => '_set_get_number',
8028 ip => '_set_get_ip',
8029 long => '_set_get_number',
8030 number => '_set_get_number',
8031 object => '_set_get_object',
8032 object_no_init => '_set_get_object_without_init',
8033 object_array => '_set_get_object_array',
8034 object_array_object => '_set_get_object_array_object',
8035 scalar => '_set_get_scalar',
8036 scalar_as_object => '_set_get_scalar_as_object',
8037 scalar_or_object => '_set_get_scalar_or_object',
8038 uri => '_set_get_uri',
8039 uuid => '_set_get_uuid',
8040 version => '_set_get_version',
8041 };
8042 # Alias
8043 $type2func->{string} = $type2func->{scalar};
8044  
8045 my $perl = <<EOT;
8046 package $class;
8047 BEGIN
8048 {
8049 use strict;
8050 use Module::Generic;
8051 use parent -norequire, qw( Module::Generic );
8052 };
8053  
8054 sub init
8055 {
8056 my \$self = shift( \@_ );
8057 \$self->{_fields} = [qw(
8058 EOT
8059 $perl .= join( ' ', sort( keys( %$def ) ) ) . "\n";
8060 $perl .= <<EOT;
8061 )];
8062 return( \$self->SUPER::init( \@_ ) );
8063 }
8064 EOT
8065 my $call_sub = ( split( /::/, ( caller(1) )[3] ) )[-1];
8066 my $call_frame = $call_sub eq '_set_get_class' ? 1 : 0;
8067 my( $pack, $file, $line ) = caller( $call_frame );
8068 my $code_lines = [];
8069 foreach my $f ( sort( keys( %$def ) ) )
8070 {
8071 my $info;
8072 # Allow for lazy field => $type_value definition instead of field => { type => $type_value }
8073 # Also helps trap if the definition is not an hash as we expect and avoid a perl error
8074 if( !ref( $def->{ $f } // '' ) )
8075 {
8076 if( !defined( $def->{ $f } ) )
8077 {
8078 warn( "Warning only: _set_get_class was called from package ${pack} at line ${line} in file ${file}, but the type provided has value 'undef', so we are skipping this field \"${f}\" in the creation of our virtual class.\n" );
8079 next;
8080 }
8081 $info = { type => $def->{ $f } };
8082 }
8083 elsif( ref( $def->{ $f } ) eq 'HASH' )
8084 {
8085 $info = $def->{ $f };
8086 if( !CORE::exists( $info->{type} ) ||
8087 !CORE::length( $info->{type} // '' ) )
8088 {
8089 warn( "Warning only: _set_get_class was called from package ${pack} at line ${line} in file ${file}, but the hash reference provided for this field \"${f}\" does not contain the property \"type\".\n" );
8090 next;
8091 }
8092 }
8093 else
8094 {
8095 warn( "Warning only: _set_get_class was called from package ${pack} at line ${line} in file ${file}, but the type provided for this field \"${f}\" is unsupported: '", $self->_str_val( $def->{ $f } // 'undef' ), "'" );
8096 next;
8097 }
8098 my $type = lc( $info->{type} );
8099 $self->__message( 112, "Processing method $f as type $type in class $class" );
8100 # Convenience
8101 $info->{class} = $info->{package} if( $info->{package} && !length( $info->{class} ) );
8102 if( !defined( $type ) )
8103 {
8104 warn( "_set_get_class was called from package ${pack} at line ${line} in file ${file}, but the type provided is undefined for this field \"${f}\".\n" );
8105 next;
8106 }
8107 elsif( !CORE::exists( $type2func->{ $type } ) )
8108 {
8109 warn( "Warning only: _set_get_class was called from package ${pack} at line ${line} in file ${file}, but the type provided \"${type}\" is unknown to us, so we are skipping this field \"${f}\" in the creation of our virtual class.\n" . ( $type eq 'url' ? qq{Maybe you meant to use "uri" instead of "url" ?\n} : '' ) );
8110 next;
8111 }
8112 my $func = $type2func->{ $type };
8113 if( $type eq 'object' ||
8114 $type eq 'object_no_init' ||
8115 $type eq 'scalar_or_object' ||
8116 $type eq 'object_array_object' ||
8117 $type eq 'object_array' )
8118 {
8119 if( !$info->{class} && !$info->{package} )
8120 {
8121 warn( "Warning only: _set_get_class was called from package ${pack} at line ${line} in file ${file}, and class \"${class}\" field \"${f}\" is to require an object, but no object class name was provided. Use the \"class\" or \"package\" property parameter. So we are skipping this field \"${f}\" in the creation of our virtual class.\n" );
8122 next;
8123 }
8124 my $this_class = $info->{class} || $info->{package};
8125 CORE::push( @$code_lines, "sub $f { return( shift->${func}( '${f}', '${this_class}', \@_ ) ); }" );
8126 }
8127 elsif( $type eq 'class' || $type eq 'class_array' || $type eq 'class_array_object' )
8128 {
8129 my $this_def = $info->{definition} // $info->{def};
8130 if( !CORE::exists( $info->{definition} ) && !CORE::exists( $info->{def} ) )
8131 {
8132 warn( "Warning only: No dynamic class fields definition was provided for this field \"${f}\". Skipping this field.\n" );
8133 next;
8134 }
8135 elsif( ref( $this_def ) ne 'HASH' )
8136 {
8137 warn( "Warning only: I was expecting a fields definition hash reference for dynamic class field \"${f}\", but instead got '${this_def}'. Skipping this field.\n" );
8138 next;
8139 }
8140 # my $d = Data::Dumper->new( [ $this_def ] );
8141 # $d->Indent( 0 );
8142 # $d->Purity( 1 );
8143 # $d->Pad( '' );
8144 # $d->Terse( 1 );
8145 # $d->Sortkeys( 1 );
8146 # my $hash_str = $d->Dump;
8147 require Data::Dump;
8148 my $hash_str = Data::Dump::dump( $this_def );
8149 $self->__message( 112, "For field $f, using dictionary definition string -> $hash_str" );
8150 CORE::push( @$code_lines, "sub ${f} { return( shift->${func}( '${f}', ${hash_str}, \@_ ) ); }" );
8151 }
8152 elsif( $type eq 'version' && ( exists( $info->{def} ) || exists( $info->{definition} ) ) )
8153 {
8154 my $this_def = $info->{definition} // $info->{def};
8155 require Data::Dump;
8156 my $hash_str = Data::Dump::dump( $this_def );
8157 CORE::push( @$code_lines, "sub ${f} { return( shift->${func}( '${f}', ${hash_str}, \@_ ) ); }" );
8158 }
8159 else
8160 {
8161 CORE::push( @$code_lines, "sub ${f} { return( shift->${func}( '${f}', \@_ ) ); }" );
8162 }
8163 }
8164 CORE::push( @$code_lines, "sub _fields { return( shift->_set_get_array_as_object( '_fields', \@_ ) ); }" );
8165 $perl .= join( "\n\n", @$code_lines );
8166  
8167 $perl .= <<'EOT';
8168 # NOTE: For CBOR and Sereal
8169 sub FREEZE
8170 {
8171 my $self = CORE::shift( @_ );
8172 my $serialiser = CORE::shift( @_ ) // '';
8173 my $class = CORE::ref( $self );
8174  
8175 my @props = grep( /^\w+/, keys( %$self ) );
8176  
8177 my $hash = {};
8178 foreach my $prop ( @props )
8179 {
8180 if( CORE::exists( $self->{ $prop } ) &&
8181 defined( $self->{ $prop } ) &&
8182 CORE::ref( $self->{ $prop } ) ne 'CODE' )
8183 {
8184 $hash->{ $prop } = $self->{ $prop };
8185 }
8186 }
8187  
8188 # Return an array reference rather than a list so this works with Sereal and CBOR.
8189 # On or before Sereal version 4.023, Sereal did not support multiple values returned.
8190 if( $serialiser eq 'Sereal' )
8191 {
8192 require Sereal::Encoder;
8193 require version;
8194  
8195 if( version->parse( Sereal::Encoder->VERSION ) <= version->parse( '4.023' ) )
8196 {
8197 CORE::return( [$class, $hash] );
8198 }
8199 }
8200  
8201 # But Storable wants a list with the first element being the serialised element
8202 CORE::return( $class, $hash );
8203 }
8204  
8205 sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
8206  
8207 sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
8208  
8209 sub STORABLE_thaw_post_processing
8210 {
8211 my $obj = shift( @_ );
8212 my @keys = %$obj;
8213 my $class = ref( $obj );
8214 my $hash = {};
8215 @$hash{ @keys } = @$obj{ @keys };
8216 my $self = bless( $hash => $class );
8217 return( $self );
8218 }
8219  
8220 sub THAW
8221 {
8222 # STORABLE_thaw would issue $cloning as the 2nd argument, while CBOR would issue
8223 # 'CBOR' as the second value.
8224 my( $self, undef, @args ) = @_;
8225 my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
8226 my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
8227 my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
8228 my $new;
8229 # Storable pattern requires to modify the object it created rather than returning a new one
8230 if( CORE::ref( $self ) )
8231 {
8232 foreach( CORE::keys( %$hash ) )
8233 {
8234 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
8235 }
8236 $new = $self;
8237 }
8238 else
8239 {
8240 $new = CORE::bless( $hash => $class );
8241 }
8242 CORE::return( $new );
8243 }
8244  
8245 EOT
8246  
8247 $perl .= <<EOT;
8248  
8249  
8250 sub TO_JSON { return( shift->as_hash ); }
8251  
8252 1;
8253  
8254 EOT
8255 $self->__message( 112, "Evaluating code -> $perl" );
8256 local $@;
8257 my $rc = eval( $perl );
8258 die( "Unable to dynamically create module $class: $@" ) if( $@ );
8259 }
8260 return( $class );
8261 }
8262 PERL
8263 # NOTE: __dbh()
8264 __dbh => <<'PERL',
8265 sub __dbh
8266 {
8267 my $self = shift( @_ );
8268 my $class = ref( $self ) || $self;
8269 my $this = $self->_obj2h;
8270 no strict 'refs';
8271 if( !$this->{__dbh} )
8272 {
8273 return( '' ) if( !${ "$class\::DB_DSN" } );
8274 $self->_load_class( 'DBI' ) ||
8275 return( $self->pass_error );
8276 # Connecting to database
8277 my $db_opt = {};
8278 $db_opt->{RaiseError} = ${ "$class\::DB_RAISE_ERROR" } if( length( ${ "$class\::DB_RAISE_ERROR" } ) );
8279 $db_opt->{AutoCommit} = ${ "$class\::DB_AUTO_COMMIT" } if( length( ${ "$class\::DB_AUTO_COMMIT" } ) );
8280 $db_opt->{PrintError} = ${ "$class\::DB_PRINT_ERROR" } if( length( ${ "$class\::DB_PRINT_ERROR" } ) );
8281 $db_opt->{ShowErrorStatement} = ${ "$class\::DB_SHOW_ERROR_STATEMENT" } if( length( ${ "$class\::DB_SHOW_ERROR_STATEMENT" } ) );
8282 $db_opt->{client_encoding} = ${ "$class\::DB_CLIENT_ENCODING" } if( length( ${ "$class\::DB_CLIENT_ENCODING" } ) );
8283 my $dbh = DBI->connect_cached( ${ "$class\::DB_DSN" } ) ||
8284 die( "Unable to connect to sql database with dsn '", ${ "$class\::DB_DSN" }, "'\n" );
8285 $dbh->{pg_server_prepare} = 1 if( ${ "$class\::DB_SERVER_PREPARE" } );
8286 $this->{__dbh} = $dbh;
8287 }
8288 return( $this->{__dbh} );
8289 }
8290 PERL
8291 # NOTE: _can_overload()
8292 _can_overload => <<'PERL',
8293 sub _can_overload
8294 {
8295 my $self = shift( @_ );
8296 no overloading;
8297 # Nothing provided
8298 return if( !scalar( @_ ) );
8299 return if( !defined( $_[0] ) );
8300 return if( !Scalar::Util::blessed( $_[0] ) );
8301 if( $self->_is_array( $_[1] ) )
8302 {
8303 foreach my $op ( @{$_[1]} )
8304 {
8305 return(0) unless( overload::Method( $_[0] => $op ) );
8306 }
8307 return(1);
8308 }
8309 else
8310 {
8311 return( overload::Method( $_[0] => $_[1] ) );
8312 }
8313 }
8314 PERL
8315 # NOTE: _dump_options()
8316 _dump_options => <<'PERL',
8317 sub _dump_options
8318 {
8319 my $self = shift( @_ );
8320 my $opts = shift( @_ ) || return( '' );
8321 my $args = [];
8322 foreach my $opt ( sort( keys( %$opts ) ) )
8323 {
8324 push( @$args, $opt, $self->_str_val( $opts->{ $opt } ) );
8325 }
8326 return( $self->Module::Generic::dump( $args ) );
8327 }
8328 PERL
8329 # NOTE: _error_callbacks()
8330 _error_callbacks => <<'PERL',
8331 # To get a specific callback by name:
8332 # my $code = $self->_error_callbacks( $some_name );
8333 # To register a bunch of error callbacks, using an hash reference:
8334 # $self->_error_callbacks({ $some_name => sub{ $some_callback });
8335 # Or, using an array of callbacks
8336 # $self->_error_callbacks( $some_name => sub{ $some_callback );
8337 # To retrieve all registered error callbacks:
8338 # my $array_ref = $self-_error_callbacks;
8339 sub _error_callbacks
8340 {
8341 my $self = shift( @_ );
8342 my $this = $self->_obj2h;
8343 my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
8344 if( @_ )
8345 {
8346 if( scalar( @_ ) == 1 &&
8347 ref( $_[0] ) eq 'HASH' )
8348 {
8349 my $def = shift( @_ );
8350 foreach my $k ( keys( %$def ) )
8351 {
8352 $self->_register_error_callback( $k => $def->{ $k } );
8353 }
8354 }
8355 elsif( scalar( @_ ) == 1 )
8356 {
8357 my $name = shift( @_ );
8358 return( '' ) if( !exists( $data->{_error_callbacks} ) );
8359 return( '' ) if( ref( $data->{_error_callbacks} ) ne 'ARRAY' );
8360 for( my $i = 0; $i < scalar( @{$data->{_error_callbacks}} ); $i++ )
8361 {
8362 my $ref = $data->{_error_callbacks}->[$i];
8363 next unless( defined( $ref ) && ref( $ref ) eq 'HASH' );
8364 if( exists( $ref->{name} ) &&
8365 defined( $ref->{name} ) &&
8366 $ref->{name} eq $name )
8367 {
8368 return( $ref->{cb} // '' );
8369 }
8370 }
8371 return( '' );
8372 }
8373 else
8374 {
8375 for( my $i = 0; $i < scalar( @_ ); $i += 2 )
8376 {
8377 my $name = $_[$i];
8378 my $code = $_[$i + 1];
8379 $self->_register_error_callback( $name => $code );
8380 }
8381 }
8382 }
8383 return( [] ) unless( exists( $data->{_error_callbacks} ) && defined( $data->{_error_callbacks} ) && ref( $data->{_error_callbacks} ) eq 'ARRAY' );
8384 return( $data->{_error_callbacks} );
8385 }
8386 PERL
8387 # NOTE: _get_args_as_array()
8388 _get_args_as_array => <<'PERL',
8389 # NOTE: sub _get_args_as_array() is now a XS method
8390 sub _get_args_as_array
8391 {
8392 my $self = shift( @_ );
8393 return( [] ) if( !scalar( @_ ) );
8394 my $ref = [];
8395 if( scalar( @_ ) == 1 && $self->_is_array( $_[0] ) )
8396 {
8397 $ref = shift( @_ );
8398 }
8399 else
8400 {
8401 $ref = [ @_ ];
8402 }
8403 return( $ref );
8404 }
8405 PERL
8406 # NOTE: _get_datetime_regexp()
8407 _get_datetime_regexp => <<'PERL',
8408 sub _get_datetime_regexp
8409 {
8410 my $self = shift( @_ );
8411 my $elem = shift( @_ );
8412 use utf8;
8413 unless( defined( $PARSE_DATE_FRACTIONAL1_RE ) )
8414 {
8415 my $aliases = [qw( JST )];
8416 if( $self->_load_class( 'DateTime::Lite::TimeZone', { version => 'v0.5.7' } ) )
8417 {
8418 $aliases = DateTime::Lite::TimeZone->extended_aliases;
8419 }
8420 my $tz_aliases = join( '|', sort( keys( %$aliases ) ) );
8421 $PARSE_DATE_FRACTIONAL1_RE = qr/
8422 (?<year>\d{4})
8423 (?<d_sep>[^\d\+])
8424 (?<month>\d{1,2})
8425 [^\d\+]
8426 (?<day>\d{1,2})
8427 (?<sep>[[:blank:]\h]+)
8428 (?<hour>\d{1,2})
8429 (?<t_sep>[^\d\+])
8430 (?<minute>\d{1,2})
8431 (?:[^\d\+](?<second>\d{1,2}))?
8432 (?<tz>
8433 (?:
8434 (?<blank2>[[:blank:]]*)
8435 (?<tz1>[-+]?\d{2,4})
8436 )
8437 |
8438 (?:
8439 (?<blank2>(?:[[:blank:]]+|[-+]))
8440 (?<tz2>$tz_aliases)
8441 )
8442 )?
8443 /x;
8444 }
8445  
8446 # 2019-06-19 23:23:57.000000000+0900
8447 # From PostgreSQL: 2019-06-20 11:02:36.306917+09
8448 # From SQLite: 2019-06-20 02:03:14
8449 # From MySQL: 2019-06-20 11:04:01
8450 # ISO 8601: 2019-06-20T11:08:27
8451 # ISO 8601: 2019-06-20T11:08:27Z
8452 # 2022-11-17T08:12:31+0900
8453 unless( defined( $PARSE_DATE_WITH_MILI_SECONDS_RE ) )
8454 {
8455 $PARSE_DATE_WITH_MILI_SECONDS_RE = qr/
8456 (?<year>\d{4})
8457 (?<d_sep>[-|\/])
8458 (?<month>\d{1,2})
8459 [-|\/]
8460 (?<day>\d{1,2})
8461 (?<sep>[[:blank:]]+|T)
8462 (?:
8463 (?<time>\d{1,2}:\d{1,2}:\d{1,2})
8464 |
8465 (?<time_short>\d{1,2}:\d{1,2})
8466 )
8467 (?:\.(?<milli>\d+))?
8468 (?:
8469 (?<tz>(?:\+|\-)(?:\d{2,4}|\d{2}:\d{2}))
8470 |
8471 (?<tz_utc>Z)
8472 )?
8473 /x;
8474 }
8475  
8476 # e.g. Sun, 06 Oct 2019 06:41:11 GMT
8477 unless( defined( $PARSE_DATE_HTTP_RE ) )
8478 {
8479 $PARSE_DATE_HTTP_RE = qr/
8480 (?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)
8481 ,[[:blank:]]+
8482 (?<day>\d{2})
8483 [[:blank:]]+
8484 (?<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)
8485 [[:blank:]]+
8486 (?<year>\d{4})
8487 [[:blank:]]+
8488 (?<hour>\d{2})
8489 :
8490 (?<minute>\d{2})
8491 :
8492 (?<second>\d{2})
8493 [[:blank:]]+
8494 GMT
8495 /x;
8496 }
8497  
8498 # 12 March 2001 17:07:30 JST
8499 # 12-March-2001 17:07:30 JST
8500 # 12/March/2001 17:07:30 JST
8501 # 12 March 2001 17:07
8502 # 12 March 2001 17:07 JST
8503 # 12 March 2001 17:07:30+0900
8504 # 12 March 2001 17:07:30 +0900
8505 # Monday, 12 March 2001 17:07:30 JST
8506 # Monday, 12 Mar 2001 17:07:30 JST
8507 # 03/Feb/1994:00:00:00 0000
8508 unless( defined( $PARSE_DATE_NON_STDANDARD_RE ) )
8509 {
8510 my $aliases = [qw( JST )];
8511 if( $self->_load_class( 'DateTime::Lite::TimeZone', { version => 'v0.5.7' } ) )
8512 {
8513 $aliases = DateTime::Lite::TimeZone->extended_aliases;
8514 }
8515 my $tz_aliases = join( '|', sort( keys( %$aliases ) ) );
8516  
8517 $PARSE_DATE_NON_STDANDARD_RE = qr/
8518 (?:
8519 (?:
8520 (?<wd>Mon|Tue|Wed|Thu|Fri|Sat|Sun)
8521 |
8522 (?<wd_long>Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)
8523 )
8524 (?<wd_comma>\,)?(?<blank0>[[:blank:]]+)
8525 )?
8526 (?<day>\d{1,2})
8527 (?<sep1>[[:blank:]]+|[-\/])
8528 (?:
8529 (?<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)
8530 |
8531 (?<month_long>January|February|March|April|May|June|July|August|September|Octocber|November|December)
8532 )
8533 (?<sep2>[[:blank:]]+|[-\/])
8534 (?<year>\d{2}|\d{4})
8535 (?<blank1>[[:blank:]]+|\:)
8536 (?<hour>\d{1,2})
8537 :
8538 (?<minute>\d{1,2})
8539 (?:\:(?<second>\d{1,2}))?
8540 (?<tz>
8541 (?:
8542 (?<blank2>[[:blank:]]*)
8543 (?<tz1>[-+]?\d{2,4})
8544 )
8545 |
8546 (?:
8547 (?<blank2>[[:blank:]]+)
8548 (?<tz2>$tz_aliases)
8549 )
8550 )?
8551 /x;
8552 }
8553  
8554 # Fri Mar 25 12:18:36 2011
8555 # Fri Mar 25 12:16:25 ADT 2011
8556 # Fri Mar 25 2011
8557 unless( defined( $PARSE_DATE_NON_STDANDARD2_RE ) )
8558 {
8559 my $aliases = [qw( JST )];
8560 if( $self->_load_class( 'DateTime::Lite::TimeZone', { version => 'v0.5.7' } ) )
8561 {
8562 $aliases = DateTime::Lite::TimeZone->extended_aliases;
8563 }
8564 my $tz_aliases = join( '|', sort( keys( %$aliases ) ) );
8565  
8566 $PARSE_DATE_NON_STDANDARD2_RE = qr/
8567 (?:
8568 (?<wd>Mon|Tue|Wed|Thu|Fri|Sat|Sun)
8569 |
8570 (?<wd_long>Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)
8571 )
8572 (?<blank1>[[:blank:]\h]+)
8573 (?:
8574 (?<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)
8575 |
8576 (?<month_long>January|February|March|April|May|June|July|August|September|Octocber|November|December)
8577 )
8578 (?<blank2>[[:blank:]\h]+)
8579 (?<day>\d{1,2})
8580 (?<blank3>[[:blank:]\h]+)
8581 (?:
8582 (?<time>\d{1,2}:\d{1,2}:\d{1,2})
8583 (?<blank4>[[:blank:]\h]+)
8584 (?:
8585 (?<tz>$tz_aliases)
8586 (?<blank5>[[:blank:]\h]+)
8587 )?
8588 )?
8589 (?<year>\d{4})
8590 /x;
8591 }
8592  
8593 # 2019-06-20
8594 # 2019/06/20
8595 # 2016.04.22
8596 unless( defined( $PARSE_DATE_ONLY_RE ) )
8597 {
8598 $PARSE_DATE_ONLY_RE = qr/
8599 (?<year>\d{4})
8600 (?<d_sep>\D)
8601 (?<month>\d{1,2})
8602 \D
8603 (?<day>\d{1,2})
8604 /x;
8605 }
8606  
8607 # 2014, Feb 17
8608 unless( defined( $PARSE_DATE_ONLY_US_SHORT_RE ) )
8609 {
8610 $PARSE_DATE_ONLY_US_SHORT_RE = qr/
8611 (?<year>\d{4})
8612 ,(?<sep1>[[:blank:]\h]+)
8613 (?<month>[a-zA-Z]{3,4})
8614 (?<sep2>[[:blank:]\h]+)
8615 (?<day>\d{1,2})
8616 /x;
8617 }
8618  
8619 # 17 Feb, 2014
8620 unless( defined( $PARSE_DATE_ONLY_EU_SHORT_RE ) )
8621 {
8622 $PARSE_DATE_ONLY_EU_SHORT_RE = qr/
8623 (?<day>\d{1,2})
8624 (?<sep1>[[:blank:]\h]+)
8625 (?<month>[a-zA-Z]{3,4})
8626 ,(?<sep2>[[:blank:]\h]+)
8627 (?<year>\d{4})
8628 /x;
8629 }
8630  
8631 # February 17, 2009
8632 unless( defined( $PARSE_DATE_ONLY_US_LONG_RE ) )
8633 {
8634 $PARSE_DATE_ONLY_US_LONG_RE = qr/
8635 (?<month>[a-zA-Z]{3,9})
8636 (?<sep1>[[:blank:]\h]+)
8637 (?<day>\d{1,2})
8638 ,(?<sep2>[[:blank:]\h]+)
8639 (?<year>\d{4})
8640 /x;
8641 }
8642  
8643 # 15 July 2021
8644 unless( defined( $PARSE_DATE_ONLY_EU_LONG_RE ) )
8645 {
8646 $PARSE_DATE_ONLY_EU_LONG_RE = qr/
8647 (?<day>\d{1,2})
8648 (?<sep1>[[:blank:]\h]+)
8649 (?<month>[a-zA-Z]{3,9})
8650 (?<sep2>[[:blank:]\h]+)
8651 (?<year>\d{4})
8652 /x;
8653 }
8654  
8655 # 22.04.2016
8656 # 22-04-2016
8657 # 17. 3. 2018.
8658 unless( defined( $PARSE_DATE_DOTTED_ONLY_EU_RE ) )
8659 {
8660 $PARSE_DATE_DOTTED_ONLY_EU_RE = qr/
8661 (?<day>\d{1,2})
8662 (?<sep>\D)
8663 (?<blank1>[[:blank:]\h]+)?
8664 (?<month>\d{1,2})
8665 \D
8666 (?<blank2>[[:blank:]\h]+)?
8667 (?<year>\d{4})
8668 (?<trailing_dot>\.)?
8669 /x;
8670 }
8671  
8672 # 17.III.2020
8673 # 17. III. 2018.
8674 unless( defined( $PARSE_DATE_ROMAN_RE ) )
8675 {
8676 $PARSE_DATE_ROMAN_RE = qr/
8677 (?<day>\d{1,2})
8678 \.
8679 (?<blank1>[[:blank:]\h]+)?
8680 (?<month>XI{0,2}|I{0,3}|IV|VI{0,3}|IX)
8681 \.
8682 (?<blank2>[[:blank:]\h]+)?
8683 (?<year>\d{4})
8684 (?<trailing_dot>\.)?
8685 /x;
8686 }
8687  
8688 # 20030613
8689 unless( defined( $PARSE_DATE_DIGITS_ONLY_RE ) )
8690 {
8691 $PARSE_DATE_DIGITS_ONLY_RE = qr/
8692 (?<year>\d{4})
8693 (?<month>\d{2})
8694 (?<day>\d{2})
8695 /x;
8696 }
8697  
8698 # 2021年7月14日
8699 # 令和3年7月14日
8700 # 2021年7月14日18時7分10秒
8701 # 2021年7月14日18時7分
8702 # 令和3年7月14日18時7分10秒
8703 # 令和3年7月14日18時7分
8704 unless( defined( $PARSE_DATETIME_JP_RE ) )
8705 {
8706 $PARSE_DATETIME_JP_RE = qr/
8707 (?<era>[\p{Han}]+)?
8708 (?<year>\d{1,4})å¹´
8709 (?<month>\d{1,2})月
8710 (?<day>\d{1,2})æ—¥
8711 (?<time>
8712 (?<hour>[\d]{1,2})(?<hour_suffix>時)?
8713 (?:
8714 (?<hour_sep>|:|:)?(?<minute>[\d]{1,2})(?<minute_suffix>分)
8715 (?:
8716 (?<minute_sep>|:|:)?(?<second>[\d]{1,2})(?<second_suffix>秒)
8717 )?
8718 )?
8719 )?
8720 /x;
8721 }
8722  
8723 unless( defined( $PARSE_DATE_TIMESTAMP_RE ) )
8724 {
8725 $PARSE_DATE_TIMESTAMP_RE = qr/
8726 (?<timestamp>\d{1,10})
8727 (?:\.(?<milli>\d+))?
8728 /x;
8729 }
8730  
8731 unless( defined( $PARSE_DATETIME_RELATIVE_RE ) )
8732 {
8733 $PARSE_DATETIME_RELATIVE_RE = qr/
8734 ([\+\-]?\d+)
8735 ([YyMDdhms])?
8736 /x;
8737 }
8738  
8739 unless( defined( $PARSE_DATES_ALL_RE ) )
8740 {
8741 $PARSE_DATES_ALL_RE = qr/
8742 (?<parse_datetime>
8743 $PARSE_DATE_FRACTIONAL1_RE
8744 |
8745 $PARSE_DATE_WITH_MILI_SECONDS_RE
8746 |
8747 $PARSE_DATE_HTTP_RE
8748 |
8749 $PARSE_DATE_NON_STDANDARD_RE
8750 |
8751 $PARSE_DATE_NON_STDANDARD2_RE
8752 |
8753 $PARSE_DATE_ONLY_RE
8754 |
8755 $PARSE_DATE_ONLY_US_SHORT_RE
8756 |
8757 $PARSE_DATE_ONLY_EU_SHORT_RE
8758 |
8759 $PARSE_DATE_ONLY_US_LONG_RE
8760 |
8761 $PARSE_DATE_ONLY_EU_LONG_RE
8762 |
8763 $PARSE_DATE_DOTTED_ONLY_EU_RE
8764 |
8765 $PARSE_DATE_ROMAN_RE
8766 |
8767 $PARSE_DATE_DIGITS_ONLY_RE
8768 |
8769 $PARSE_DATETIME_JP_RE
8770 |
8771 $PARSE_DATE_TIMESTAMP_RE
8772 |
8773 $PARSE_DATETIME_RELATIVE_RE
8774 )
8775 /x;
8776 }
8777 my $def =
8778 {
8779 incomplete => $PARSE_DATE_FRACTIONAL1_RE,
8780 iso8601 => $PARSE_DATE_WITH_MILI_SECONDS_RE,
8781 http => $PARSE_DATE_HTTP_RE,
8782 non_standard => $PARSE_DATE_NON_STDANDARD_RE,
8783 non_standard2 => $PARSE_DATE_NON_STDANDARD2_RE,
8784 date_only => $PARSE_DATE_ONLY_RE,
8785 us_short => $PARSE_DATE_ONLY_US_SHORT_RE,
8786 eu_short => $PARSE_DATE_ONLY_EU_SHORT_RE,
8787 us_long => $PARSE_DATE_ONLY_US_LONG_RE,
8788 eu_long => $PARSE_DATE_ONLY_EU_LONG_RE,
8789 date_only_eu => $PARSE_DATE_DOTTED_ONLY_EU_RE,
8790 date_roman => $PARSE_DATE_ROMAN_RE,
8791 date_digits => $PARSE_DATE_DIGITS_ONLY_RE,
8792 japan => $PARSE_DATETIME_JP_RE,
8793 unix => $PARSE_DATE_TIMESTAMP_RE,
8794 relative => $PARSE_DATETIME_RELATIVE_RE,
8795 all => $PARSE_DATES_ALL_RE,
8796 };
8797 return( ( CORE::defined( $elem ) && CORE::exists( $def->{ $elem } ) ) ? $def->{ $elem } : $def );
8798 }
8799 PERL
8800 # NOTE: _get_symbol()
8801 _get_symbol => <<'PERL',
8802 sub _get_symbol
8803 {
8804 my $self = shift( @_ );
8805 my( $class, $var ) = ( @_ >= 2 ) ? splice( @_, 0, 2 ) : ( ( ref( $self ) || $self ), shift( @_ ) );
8806 if( $class !~ /^[a-zA-Z_][a-zA-Z0-9_]+(?:\:{2}[a-zA-Z0-9_]+)*$/ )
8807 {
8808 return( $self->error( "Invalid class name '$class'" ) );
8809 }
8810 elsif( !defined( $var ) || !length( $var ) )
8811 {
8812 return( $self->error( "No variable was aprovided." ) );
8813 }
8814  
8815 no strict 'refs';
8816 my $ns = \%{$class . '::'};
8817 my $map =
8818 {
8819 '$' => 'SCALAR',
8820 '@' => 'ARRAY',
8821 '%' => 'HASH',
8822 '&' => 'CODE',
8823 '*' => 'GLOB',
8824 };
8825 my( $sigil, $type );
8826 if( exists( $map->{ substr( $var, 0, 1 ) } ) )
8827 {
8828 $sigil = substr( $var, 0, 1, '' );
8829 $type = $map->{ $sigil };
8830 }
8831 else
8832 {
8833 # $type = $map->{ '' };
8834 return( $self->error( "Unsupported variable ${var}. You can only set array, hash, scalar, code or glob" ) );
8835 }
8836  
8837 if( !exists( $ns->{ $var } ) )
8838 {
8839 return( wantarray ? () : undef );
8840 }
8841 my $glob = \$ns->{ $var };
8842 if( ( Scalar::Util::reftype( $glob ) // '' ) eq 'GLOB' )
8843 {
8844 return( *{$glob}{$type} );
8845 }
8846 elsif( $type eq 'CODE' )
8847 {
8848 if( $] < 5.013004 )
8849 {
8850 return( \&{ $class . '::' . $var } );
8851 }
8852 else
8853 {
8854 return( *{ $ns->{ $var } }{CODE} );
8855 }
8856 }
8857 else
8858 {
8859 return( wantarray ? () : undef );
8860 }
8861 }
8862 PERL
8863 # NOTE: _has_base64()
8864 _has_base64 => <<'PERL',
8865 sub _has_base64
8866 {
8867 my $self = shift( @_ );
8868 my $val = shift( @_ );
8869 return( '' ) if( !defined( $val ) || !length( $val ) );
8870 if( ref( $val ) eq 'ARRAY' &&
8871 scalar( @$val ) >= 2 &&
8872 defined( $val->[0] ) &&
8873 defined( $val->[1] ) &&
8874 ref( $val->[0] ) eq 'CODE' &&
8875 ref( $val->[1] ) eq 'CODE' )
8876 {
8877 return( $val );
8878 }
8879
8880 my $class = ref( $self ) || $self;
8881
8882 unless( defined( ${"${class}\::HAS_B64"} ) && ref( ${"${class}\::HAS_B64"} ) eq 'HASH' )
8883 {
8884 my $ref = ${"${class}\::HAS_B64"} = {};
8885 if( $self->_is_class_loadable( 'MIME::Base64' ) )
8886 {
8887 $ref->{ 'MIME::Base64' } =
8888 [
8889 sub{ return( &{"MIME::Base64\::encode_base64"}( shift( @_ ), '' ) ); },
8890 \&{"MIME::Base64\::decode_base64"},
8891 ];
8892 }
8893 if( $self->_is_class_loadable( 'Crypt::Misc' ) )
8894 {
8895 $ref->{ 'Crypt::Misc' } =
8896 [
8897 \&{"Crypt::Misc\::encode_b64"},
8898 \&{"Crypt::Misc\::decode_b64"},
8899 ];
8900 }
8901 }
8902 my $ref = ${"${class}\::HAS_B64"};
8903 return( '' ) if( !scalar( keys( %$ref ) ) );
8904
8905 my $prefs = [];
8906 if( $val eq 'Crypt::Misc' || $val eq 'CryptX' )
8907 {
8908 push( @$prefs, qw( Crypt::Misc MIME::Base64 ) );
8909 }
8910 # for any other value, including 'MIME::Base64'
8911 else
8912 {
8913 push( @$prefs, qw( MIME::Base64 Crypt::Misc ) );
8914 }
8915
8916 foreach my $mod ( @$prefs )
8917 {
8918 if( exists( $ref->{ $mod } ) && $self->_load_class( $mod ) )
8919 {
8920 return( $ref->{ $mod } );
8921 }
8922 }
8923 return( '' );
8924 }
8925 PERL
8926 # NOTE: _has_symbol()
8927 _has_symbol => <<'PERL',
8928 sub _has_symbol
8929 {
8930 my $self = shift( @_ );
8931 my( $class, $var ) = ( @_ >= 2 ) ? splice( @_, 0, 2 ) : ( ( ref( $self ) || $self ), shift( @_ ) );
8932 if( $class !~ /^[a-zA-Z_][a-zA-Z0-9_]+(?:\:{2}[a-zA-Z0-9_]+)*$/ )
8933 {
8934 return( $self->error( "Invalid class name '$class'" ) );
8935 }
8936 elsif( !defined( $var ) || !length( $var ) )
8937 {
8938 return( $self->error( "No variable was aprovided." ) );
8939 }
8940  
8941 no strict 'refs';
8942 my $ns = \%{$class . '::'};
8943 my $map =
8944 {
8945 '$' => 'SCALAR',
8946 '@' => 'ARRAY',
8947 '%' => 'HASH',
8948 '&' => 'CODE',
8949 '' => 'IO',
8950 };
8951 my( $sigil, $type );
8952 if( exists( $map->{ substr( $var, 0, 1 ) } ) )
8953 {
8954 $sigil = substr( $var, 0, 1, '' );
8955 $type = $map->{ $sigil };
8956 }
8957 else
8958 {
8959 $type = $map->{ '' };
8960 }
8961 return(0) if( !exists( $ns->{ $var } ) );
8962 my $glob = \$ns->{ $var };
8963 if( ( Scalar::Util::reftype( $glob ) // '' ) eq 'GLOB' )
8964 {
8965 if( $type eq 'SCALAR' )
8966 {
8967 return( defined( ${ *{$glob}{$type} } ) ? 1 : 0 );
8968 }
8969 else
8970 {
8971 return( defined( *{$glob}{$type} ) ? 1 : 0 );
8972 }
8973 }
8974 else
8975 {
8976 return( $type eq 'CODE' ? 1 : 0 );
8977 }
8978 }
8979 PERL
8980 # NOTE: _implement_freeze_thaw()
8981 _implement_freeze_thaw => <<'PERL',
8982 sub _implement_freeze_thaw
8983 {
8984 my $self = shift( @_ );
8985 my @classes = @_;
8986 foreach my $class ( @classes )
8987 {
8988 unless( defined( &{"${class}\::STORABLE_freeze"} ) )
8989 {
8990 no warnings 'once';
8991 *{"${class}\::STORABLE_freeze"} = sub
8992 {
8993 my $self = CORE::shift( @_ );
8994 my $serialiser = CORE::shift( @_ ) // '';
8995 my $class = CORE::ref( $self );
8996 my %hash = %$self;
8997 # Return an array reference rather than a list so this works with Sereal and CBOR
8998 CORE::return( [$class, \%hash] ) if( $serialiser eq 'Sereal' || $serialiser eq 'CBOR' );
8999 # But Storable/Storable::Improved want a list with the first element being the serialised element
9000 CORE::return( $class, \%hash );
9001 };
9002 }
9003
9004 unless( defined( &{"${class}\::STORABLE_thaw"} ) )
9005 {
9006 no warnings 'once';
9007 *{"${class}\::STORABLE_thaw"} = sub
9008 {
9009 # STORABLE_thaw would issue $cloning as the 2nd argument, while CBOR would issue
9010 # 'CBOR' as the second value.
9011 my( $self, undef, @args ) = @_;
9012 my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
9013 my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
9014 my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
9015 my $new;
9016 # Storable pattern requires to modify the object it created rather than returning a new one
9017 if( CORE::ref( $self ) )
9018 {
9019 foreach( CORE::keys( %$hash ) )
9020 {
9021 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
9022 }
9023 $new = $self;
9024 }
9025 else
9026 {
9027 $new = CORE::bless( $hash => $class );
9028 }
9029 CORE::return( $new );
9030 };
9031 }
9032
9033 unless( defined( &{"${class}\::FREEZE"} ) )
9034 {
9035 no warnings 'once';
9036 *{"${class}::FREEZE"} = sub
9037 {
9038 my $self = CORE::shift( @_ );
9039 my $serialiser = CORE::shift( @_ ) // '';
9040 my @args = &{"${class}::STORABLE_freeze"}( $self );
9041 CORE::return( \@args ) if( $serialiser eq 'Sereal' || $serialiser eq 'CBOR' );
9042 CORE::return( @args );
9043 };
9044 }
9045  
9046 unless( defined( &{"${class}::THAW"} ) )
9047 {
9048 no warnings 'once';
9049 *{"${class}::THAW"} = sub
9050 {
9051 my( $self, undef, @args ) = @_;
9052 my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
9053 $self = bless( {} => $self ) unless( ref( $self ) );
9054 CORE::return( &{"${class}::STORABLE_thaw"}( $self, undef, @$ref ) );
9055 };
9056 }
9057 }
9058 }
9059 PERL
9060 # NOTE: _is_array()
9061 _is_array => <<'PERL',
9062 # NOTE: sub _is_array() is now a XS method
9063 sub _is_array
9064 {
9065 return(0) if( scalar( @_ ) < 2 );
9066 return(0) if( !defined( $_[1] ) );
9067 my $type = Scalar::Util::reftype( $_[1] );
9068 return(0) if( !defined( $type ) );
9069 return( $type eq 'ARRAY' );
9070 }
9071 PERL
9072 # NOTE: _is_code()
9073 _is_code => <<'PERL',
9074 # NOTE: sub _is_code() is now a XS method
9075 sub _is_code
9076 {
9077 return(0) if( scalar( @_ ) < 2 );
9078 return(0) if( !defined( $_[1] ) );
9079 my $type = Scalar::Util::reftype( $_[1] );
9080 return(0) if( !defined( $type ) );
9081 return( $type eq 'CODE' );
9082 }
9083 PERL
9084 # NOTE: _is_empty()
9085 _is_empty => <<'PERL',
9086 sub _is_empty
9087 {
9088 my $self = shift( @_ );
9089 # $self->__message( 104, "Got here with '", join( "', '", @_ ), "'" );
9090 return(1) if( !@_ );
9091 return(1) if( !defined( $_[0] ) );
9092 # Check scalar reference or simply strings.
9093 if( (
9094 ( Scalar::Util::reftype( $_[0] ) // '' ) eq 'SCALAR' &&
9095 !CORE::length( ${$_[0]} // '' )
9096 ) ||
9097 (
9098 !ref( $_[0] ) &&
9099 !CORE::length( $_[0] // '' )
9100 ) )
9101 {
9102 return(1);
9103 }
9104 # Checking array reference
9105 elsif( ( Scalar::Util::reftype( $_[0] ) // '' ) eq 'ARRAY' &&
9106 !scalar( @{$_[0]} ) )
9107 {
9108 # $self->__message( 104, "Found that array $_[0] (is blessed ? ", ( Scalar::Util::blessed( $_[0] ) ? 'yes' : 'no' ), ") is empty with ", scalar( @{$_[0]} ), " element. is_empty on array returns -> ", $_[0]->is_empty );
9109 return(1);
9110 }
9111 # Checking blessed hash reference
9112 elsif( ( Scalar::Util::reftype( $_[0] ) // '' ) eq 'HASH' &&
9113 Scalar::Util::blessed( $_[0] ) &&
9114 $_[0]->can( 'is_empty' ) &&
9115 ( $_[0]->is_empty ? 1 : 0 ) )
9116 {
9117 return(1);
9118 }
9119 # Checking hash reference
9120 elsif( ref( $_[0] ) eq 'HASH' &&
9121 !scalar( keys( %{$_[0]} ) ) )
9122 {
9123 return(1);
9124 }
9125 return(0);
9126 }
9127 PERL
9128 # NOTE: _is_glob()
9129 _is_glob => <<'PERL',
9130 # NOTE: sub _is_glob() is now a XS method
9131 sub _is_glob
9132 {
9133 return(0) if( scalar( @_ ) < 2 );
9134 return(0) if( !defined( $_[1] ) );
9135 my $type = Scalar::Util::reftype( $_[1] );
9136 return(0) if( !defined( $type ) );
9137 return( $type eq 'GLOB' );
9138 }
9139 PERL
9140 # NOTE: _is_hash()
9141 _is_hash => <<'PERL',
9142 # NOTE: sub _is_hash() is now a XS method
9143 sub _is_hash
9144 {
9145 return(0) if( scalar( @_ ) < 2 );
9146 return(0) if( !defined( $_[1] ) );
9147 my $type;
9148 if( @_ > 2 && defined( $_[2] ) && ( $_[2] eq 'strict' || $_[2] eq 'native' ) )
9149 {
9150 $type = ref( $_[1] );
9151 }
9152 else
9153 {
9154 $type = Scalar::Util::reftype( $_[1] );
9155 }
9156 return(0) if( !defined( $type ) );
9157 return( $type eq 'HASH' ? 1 : 0 );
9158 }
9159 PERL
9160 # NOTE: _is_integer()
9161 _is_integer => <<'PERL',
9162 # NOTE: sub _is_integer() is now a XS method
9163 sub _is_integer
9164 {
9165 return(0) if( scalar( @_ ) < 2 );
9166 return(0) if( !defined( $_[1] ) || !length( $_[1] ) );
9167 return( $_[1] =~ /^[\+\-]?\d+$/ ? 1 : 0 );
9168 }
9169 PERL
9170 # NOTE: _is_number()
9171 _is_number => <<'PERL',
9172 # NOTE: sub _is_number() is now a XS method
9173 sub _is_number
9174 {
9175 return(0) if( scalar( @_ ) < 2 );
9176 my( $self, $v ) = @_;
9177  
9178 return(0) unless( defined( $v ) );
9179 return(0) if( ref( $v ) );
9180  
9181 # Accept only scalars that actually carry numeric flags.
9182 # JSON marks numbers with IOK/NOK; plain strings (even "12") will not have them.
9183 my $sv = B::svref_2object( \$v );
9184 my $flags = $sv->FLAGS;
9185  
9186 local $@;
9187 # SVf_IOK = 0x02000000, SVf_NOK = 0x04000000 on most builds;
9188 # we do not hardcode constants-B::SV’s FLAGS is stable to test with these bitmasks.
9189 # Use string eval to avoid importing platform-specific constants.
9190 my $SVf_IOK = eval{ B::SVf_IOK() } || 0x02000000;
9191 my $SVf_NOK = eval{ B::SVf_NOK() } || 0x04000000;
9192  
9193 return( ( $flags & ( $SVf_IOK | $SVf_NOK ) ) ? 1 : 0 );
9194 }
9195 PERL
9196 # NOTE: _is_object()
9197 _is_object => <<'PERL',
9198 # NOTE: sub _is_object() is now a XS method
9199 sub _is_object
9200 {
9201 return(0) if( scalar( @_ ) < 2 );
9202 return(0) if( !defined( $_[1] ) );
9203 return( Scalar::Util::blessed( $_[1] ) ? 1 : 0 );
9204 }
9205 PERL
9206 # NOTE: _is_overloaded()
9207 _is_overloaded => <<'PERL',
9208 # NOTE: sub _is_overloaded() is now a XS method
9209 sub _is_overloaded
9210 {
9211 my $self = shift( @_ );
9212 no overloading;
9213 # Nothing provided
9214 return(0) if( !scalar( @_ ) );
9215 return(0) if( !defined( $_[0] ) );
9216 return(0) if( !Scalar::Util::blessed( $_[0] ) );
9217 return( overload::Overloaded( $_[0] ) ? 1 : 0 );
9218 }
9219 PERL
9220 # NOTE: _is_scalar()
9221 _is_scalar => <<'PERL',
9222 # NOTE: sub _is_scalar() is now a XS method
9223 sub _is_scalar
9224 {
9225 return(0) if( scalar( @_ ) < 2 );
9226 return(0) if( !defined( $_[1] ) );
9227 return( ( Scalar::Util::reftype( $_[1] ) // '' ) eq 'SCALAR' ? 1 : 0 );
9228 }
9229 PERL
9230 # NOTE: _is_tty()
9231 _is_tty => <<'PERL',
9232 sub _is_tty
9233 {
9234 return( -t( STDIN ) && ( -t( STDOUT ) || !( -f STDOUT || -c STDOUT ) ) );
9235 }
9236 PERL
9237 # NOTE: _is_version()
9238 _is_version => <<'PERL',
9239 my $version_lax_regex = qr/
9240 (?<ver_str>
9241 # Lax dotted-decimal version number. Distinguished by having either leading "v"
9242 # or at least three non-alpha parts. Alpha part is only permitted if there are
9243 # at least two non-alpha parts. Strangely enough, without the leading "v", Perl
9244 # takes .1.2 to mean v0.1.2, so when there is no "v", the leading part is optional
9245 (?<dotted>
9246 (?<has_v>v)
9247 (?<ver>
9248 (?<major>[0-9]+)
9249 (?:
9250 (?<minor_patch>(?:\.[0-9]+)+)
9251 (?:_(?<alpha>[0-9]+))?
9252 )?
9253 )
9254 |
9255 (?<ver>
9256 (?<major>[0-9]+)?
9257 (?<minor_patch>(?:\.[0-9]+){2,})
9258 (?:_(?<alpha>[0-9]+))?
9259 )
9260 )
9261 |
9262 (?<dotted>
9263 (?<dotted_numified>
9264 (?<dotted_numified_under>
9265 (?<ver>
9266 (?<release>
9267 (?<major>[0-9]+)
9268 (?<minor_patch>
9269 \.
9270 (?<minor>[0-9]{3})
9271 (?:_(?<patch>[0-9]{3}))
9272 )
9273 )
9274 )
9275 )
9276 |
9277 (?<ver>
9278 (?<release>
9279 (?<major>[0-9]+)
9280 (?<minor_patch>
9281 \.
9282 (?<minor>0[0-9]{2})
9283 (?<patch>0[0-9]{2})
9284 )
9285 )
9286 (?:_(?<alpha>[0-9]+))?
9287 )
9288 )
9289 )
9290 |
9291 # Lax decimal version number. Just like the strict one except for allowing an
9292 # alpha suffix or allowing a leading or trailing decimal-point
9293 (?<decimal>
9294 (?<ver>(?<release>(?<major>[0-9]+) (?: (?:\.(?<minor>[0-9]+)) | \. )?) (?:_(?<alpha>[0-9]+))?)
9295 |
9296 (?<ver>(?:\.(?<release>(?<major>[0-9]+))) (?:_(?<alpha>[0-9]+))?)
9297 )
9298 )/x;
9299 sub _is_version
9300 {
9301 my $self = shift( @_ );
9302 return(0) if( !@_ );
9303 return(0) if( !defined( $_[0] ) );
9304 # Taken from Changes::Version
9305 return( $_[0] =~ /^$version_lax_regex$/ ? 1 : 0 );
9306 }
9307 PERL
9308 # NOTE: _list_symbols()
9309 _list_symbols => <<'PERL',
9310 sub _list_symbols
9311 {
9312 # $type can be SCALAR, ARRAY, HASH or CODE (case insensitive)
9313 my $self = shift( @_ );
9314 my( $class, $type );
9315 if( !scalar( @_ ) )
9316 {
9317 $class = ( ref( $self ) || $self );
9318 }
9319 elsif( scalar( @_ ) >= 2 )
9320 {
9321 ( $class, $type ) = splice( @_, 0, 2 );
9322 }
9323 else
9324 {
9325 $class = shift( @_ );
9326 }
9327 if( $class !~ /^[a-zA-Z_][a-zA-Z0-9_]+(?:\:{2}[a-zA-Z0-9_]+)*$/ )
9328 {
9329 return( $self->error( "Invalid class name '$class'" ) );
9330 }
9331 no strict 'refs';
9332 my $ns = \%{$class . '::'};
9333 unless( defined( $type ) )
9334 {
9335 return( keys( %$ns ) );
9336 }
9337 $type = uc( $type );
9338  
9339 if( $type eq 'CODE' )
9340 {
9341 return( grep
9342 {
9343 ( Scalar::Util::reftype( \$ns->{ $_ } ) // '' ) ne 'GLOB' ||
9344 defined( *{ $ns->{ $_ } }{CODE} )
9345 } keys( %$ns ) );
9346 }
9347 elsif( $type eq 'SCALAR' )
9348 {
9349 return( grep
9350 {
9351 ( Scalar::Util::reftype( \$ns->{ $_ } ) // '' ) eq 'GLOB' &&
9352 defined( ${*{ $ns->{ $_ } }{SCALAR}} )
9353 } keys( %$ns ) );
9354 }
9355 else
9356 {
9357 return( grep
9358 {
9359 ( Scalar::Util::reftype( \$ns->{ $_ } ) // '' ) eq 'GLOB' &&
9360 defined( *{$ns->{ $_ }}{ $type} )
9361 } keys( %$ns ) );
9362 }
9363 }
9364 PERL
9365 # NOTE: _looks_like_path()
9366 _looks_like_path => <<'PERL',
9367 my $control_chars_re = qr{[\x00-\x1F\x7F]};
9368 my $url_scheme_re = qr{^[a-z][a-z0-9+.\-]*://}i;
9369 my $non_windows_scheme_re = qr{^[a-z][a-z0-9+.\-]*:}i;
9370 my $email_re = qr{^[^\s@]+@[^\s@]+\.[A-Za-z]{2,}$};
9371 my $windows_drive_re = qr{^[A-Za-z]:[\\\/][^\s/\\]+(?:[\\\/][^\s/\\]+)*\.[A-Za-z0-9]{1,4}$};
9372 my $unc_share_re = qr{^\\\\(?:\[[0-9A-Fa-f:]+\]|[^\\\/]+)[\\\/][^\\\/]+};
9373 my $home_expansion_re = qr{^~(?:[A-Za-z0-9._\-]+)?[\\\/]};
9374 my $relative_path_re = qr{^\.(?:\.|)[\\\/]};
9375 my $separator_re = qr{[\\\/]};
9376 my $windows_invalid_char_re = qr{[<>\"|?*]};
9377 my $no_trailing_space = qr{(?:^|[\\\/])\s*$};
9378 my $lone_filename_re = qr{^[^\s.][^\s]*\.[A-Za-z0-9]{1,4}$};
9379 sub _looks_like_path
9380 {
9381 my $self = shift( @_ );
9382 return(0) if( !@_ );
9383 return(0) if( !defined( $_[0] ) );
9384 return(0) if( ref( $_[0] ) );
9385  
9386 # Avoid control chars (include DEL \x7F)
9387 return(0) if( $_[0] =~ /$control_chars_re/ );
9388  
9389 # Reject obvious non-paths
9390 # URL schemes: scheme://...
9391 return(0) if( $_[0] =~ m{$url_scheme_re} );
9392  
9393 # Other schemes like mailto:, data:, etc., but allow Windows "C:\"
9394 return(0) if( $_[0] =~ m{$non_windows_scheme_re} && $_[0] !~ /^[a-z]:[\\\/]/i );
9395  
9396 # "Email-ish" strings (no slashes, single @, plausible TLD at end)
9397 # We keep this heuristic *narrow* to avoid false rejections.
9398 return(0) if( $_[0] !~ m{[\\/]} && $_[0] =~ /$email_re/ );
9399  
9400 # High confidence:
9401 # Windows drive path: C:\ or C:/ ...
9402 # NOTE: Actually, even this is too broad and likely to catch false positive
9403 # return(1) if( $_[0] =~ /^[A-Za-z]:[\\\/]/ );
9404  
9405 # Windows drive path: C:\dir\file.txt, C:/dir
9406 return(1) if( $_[0] =~ /$windows_drive_re/ );
9407  
9408 # UNC share: \\Server\Share\... (also allow IPv6 host literal \\[fe80::1]\Share)
9409 return(1) if( $_[0] =~ /$unc_share_re/ );
9410  
9411 # Unix absolute: /usr/... (including root "/")
9412 # NOTE: Hmmm, not sure about that one. This could lead easily to false positive.
9413 # return(1) if( $_[0] =~ m{^/} );
9414  
9415 # Home expansion: ~/something or ~user/something
9416 return(1) if( $_[0] =~ m{$home_expansion_re} );
9417  
9418 # Relative: ./foo, ../bar, .\foo, ..\bar
9419 return(1) if( $_[0] =~ m{$relative_path_re} );
9420  
9421 # Env-based: $HOME/foo, %USERPROFILE%\foo
9422 # NOTE: This is actually too hazardous
9423 # return(1) if( $_[0] =~ m{^\$[A-Za-z_]\w*[\\\/]} || $_[0] =~ m{^%[A-Za-z_]\w*%[\\\/]} );
9424  
9425 # Lower confidence (needs a separator):
9426 if( $_[0] =~ m{$separator_re} )
9427 {
9428 # Disallow Windows-invalid chars
9429 return(0) if( $_[0] =~ m{$windows_invalid_char_re} );
9430 # No empty trailing segment of spaces
9431 return(0) if( $_[0] =~ m{$no_trailing_space} );
9432 return(1);
9433 }
9434  
9435 # Lone filename heuristics (last resort):
9436 # Useful when the *field name* hints it's a file/path and value is just "config.json".
9437 # We keep it conservative: require an extension of up to 4 characters; avoid leading/trailing spaces.
9438 return(1) if( $_[0] =~ /$lone_filename_re/ );
9439  
9440 return(0);
9441 }
9442 PERL
9443 # NOTE: _obj2h()
9444 _obj2h => <<'PERL',
9445 # NOTE: sub _obj2h() is now a XS method
9446 sub _obj2h
9447 {
9448 my $self = shift( @_ );
9449 # The method that called message was itself called using the package name like My::Package->some_method
9450 # We are going to check if global $DEBUG or $VERBOSE variables are set and create the related debug and verbose entry into the hash we return
9451 no strict 'refs';
9452 if( !ref( $self ) )
9453 {
9454 my $class = $self;
9455 my $hash =
9456 {
9457 debug => ${ "${class}\::DEBUG" },
9458 verbose => ${ "${class}\::VERBOSE" },
9459 error => ${ "${class}\::ERROR" },
9460 };
9461 return( bless( $hash => $class ) );
9462 }
9463 elsif( ( Scalar::Util::reftype( $self ) // '' ) eq 'HASH' )
9464 {
9465 return( $self );
9466 }
9467 elsif( ( Scalar::Util::reftype( $self ) // '' ) eq 'GLOB' )
9468 {
9469 if( ref( *$self ) eq 'HASH' )
9470 {
9471 return( *$self );
9472 }
9473 else
9474 {
9475 return( \%{*$self} );
9476 }
9477 }
9478 # Because object may be accessed as My::Package->method or My::Package::method
9479 # there is not always an object available, so we need to fake it to avoid error
9480 # This is primarly itended for generic methods error(), errstr() to work under any conditions.
9481 else
9482 {
9483 return( {} );
9484 }
9485 }
9486 PERL
9487 # NOTE: _on_error()
9488 _on_error => <<'PERL',
9489 sub _on_error { return( shift->_set_get_code( '_on_error', @_ ) ); }
9490 PERL
9491 # NOTE: _parse_timestamp()
9492 _parse_timestamp => <<'PERL',
9493 # Ref:
9494 # <https://en.wikipedia.org/wiki/Date_format_by_country>
9495 sub _parse_timestamp
9496 {
9497 my $self = shift( @_ );
9498 my $str = shift( @_ );
9499 # No value was actually provided
9500 return if( !length( $str ) );
9501 my $params = $self->_get_args_as_hash( @_ );
9502 $str = "$str";
9503 my $this = $self->_obj2h;
9504 my $class = ref( $self ) || $self;
9505 # Load the regular expressions
9506 $self->_get_datetime_regexp;
9507 $self->_load_class( 'DateTime::Format::Lite' ) || return( $self->pass_error );
9508 # We set this has a distinctive key across all process and threads since this value is ubiquitous
9509 my $repo = Module::Generic::Global->new( 'globals' => $class, key => 'has_local_tz' );
9510 my $HAS_LOCAL_TZ = $repo->get;
9511 my $tz;
9512 # "Cannot determine local time zone"
9513 if( !defined( $HAS_LOCAL_TZ ) )
9514 {
9515 $self->_load_class( 'DateTime::Lite::TimeZone' ) || return( $self->pass_error );
9516 $repo->lock;
9517 # try-catch
9518 local $@;
9519 eval
9520 {
9521 $tz = DateTime::Lite::TimeZone->new( name => 'local' );
9522 $HAS_LOCAL_TZ = 1;
9523 };
9524 if( $@ || !defined( $tz ) )
9525 {
9526 $tz = DateTime::Lite::TimeZone->new( name => 'UTC' );
9527 $HAS_LOCAL_TZ = 0;
9528 warn( "Your system is missing key timezone components. ${class}::_parse_timestamp is reverting to UTC instead of local time zone.\n" ) if( $self->_warnings_is_enabled );
9529 }
9530 $repo->set( $HAS_LOCAL_TZ );
9531  
9532 if( CORE::exists( $params->{tz} ) &&
9533 CORE::defined( $params->{tz} ) &&
9534 $params->{tz} )
9535 {
9536 # try-catch
9537 local $@;
9538 eval
9539 {
9540 $tz = DateTime::Lite::TimeZone->new( name => "$params->{tz}" );
9541 };
9542 my $err;
9543 if( $@ )
9544 {
9545 $err = $@;
9546 }
9547 elsif( !defined( $tz ) && DateTime::Lite::TimeZone->error )
9548 {
9549 $err = DateTime::Lite::TimeZone->error;
9550 }
9551  
9552 if( defined( $err ) )
9553 {
9554 warn( "Failed setting the specified time zone $params->{tz}: $err" ) if( $self->_warnings_is_enabled );
9555 }
9556 }
9557 }
9558 else
9559 {
9560 # try-catch
9561 local $@;
9562 eval
9563 {
9564 $tz = ( CORE::exists( $params->{tz} ) && CORE::defined( $params->{tz} ) && $params->{tz} )
9565 ? DateTime::Lite::TimeZone->new( name => "$params->{tz}" )
9566 : DateTime::Lite::TimeZone->new( name => ( $HAS_LOCAL_TZ ? 'local' : 'UTC' ) );
9567 };
9568 if( $@ || !$tz )
9569 {
9570 warn( "Error trying to set a DateTime object using ", ( $HAS_LOCAL_TZ ? 'local' : 'UTC' ), " time zone: $@" );
9571 $tz = DateTime::Lite::TimeZone->new( name => 'UTC' );
9572 }
9573 }
9574  
9575 $self->__message( 104, "Using time zone '", ( defined( $tz ) ? $tz->name : 'undef' ), "'" );
9576 # my $tz = DateTime::Lite::TimeZone->new( name => 'Europe/Berlin' );
9577 my $error = 0;
9578 # For some Japanese here
9579 use utf8;
9580 my $opt =
9581 {
9582 pattern => '%Y-%m-%d %T',
9583 time_zone => $tz->name,
9584 on_error => 'croak',
9585 };
9586  
9587 my $fmt =
9588 {
9589 pattern => '%Y-%m-%d %T',
9590 locale => 'en_GB',
9591 time_zone => $tz->name,
9592 };
9593  
9594 my $formatter = 'DateTime::Format::Lite';
9595  
9596 my $roman2regular =
9597 {
9598 I => 1,
9599 II => 2,
9600 III => 3,
9601 IV => 4,
9602 V => 5,
9603 VI => 6,
9604 VII => 7,
9605 VIII=> 8,
9606 IX => 9,
9607 X => 10,
9608 XI => 11,
9609 XII => 12,
9610 i => 1,
9611 ii => 2,
9612 iii => 3,
9613 iv => 4,
9614 v => 5,
9615 vi => 6,
9616 vii => 7,
9617 viii=> 8,
9618 ix => 9,
9619 x => 10,
9620 xi => 11,
9621 xii => 12,
9622 };
9623 # (^(?=[MDCLXVI])M*(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$)
9624 # <https://stackoverflow.com/a/36576402/4814971>
9625 #
9626 # ^(I[VX]|VI{0,3}|I{1,3})|((X[LC]|LX{0,3}|X{1,3})(I[VX]|V?I{0,3}))|((C[DM]|DC{0,3}|C{1,3})(X[LC]|L?X{0,3})(I[VX]|V?I{0,3}))|(M+(C[DM]|D?C{0,3})(X[LC]|L?X{0,3})(I[VX]|V?I{0,3}))$
9627 # <https://stackoverflow.com/a/60469651/4814971>
9628  
9629 # Of course, when an era starts and another era ends, it is during the same Gregorian year, so we use the new era for the year start although it is perfectly correct to use the nth year for the year end as well, but that would mean two eras for the same year, and although for humans it is ok, for computing it does not work.
9630 # For example end of Meiji is in 1912 (45th year) which is also the first of the Taisho era
9631 # Ref: <http://www.ajnet.ne.jp/benri/conversion.hpml>
9632  
9633 # GNU PO file
9634 # 2019-10-03 19-44+0000
9635 # 2019-10-03 19:44:01+0000
9636 # 2001-03-12 17:07+JST
9637 # NOTE: PARSE_DATE_FRACTIONAL1_RE
9638 if( $str =~ /^$PARSE_DATE_FRACTIONAL1_RE$/x )
9639 {
9640 my $re = { %+ };
9641 $self->__message( 105, "Pattern of type 'PARSE_DATE_FRACTIONAL1_RE' matched -> ", sub{ $self->Module::Generic::dump( $re ) } );
9642 my @buff = ();
9643 my @buff_fmt = ();
9644 push( @buff, '%F %T' );
9645 # $fmt->{pattern} = join( $re->{d_sep}, qw( %Y %m %d ) ) . $re->{sep} . join( $re->{t_sep}, qw( %H %M ) );
9646 push( @buff_fmt, join( $re->{d_sep}, qw( %Y %m %d ) ) . $re->{sep} . join( $re->{t_sep}, qw( %H %M ) ) );
9647 if( length( $re->{second} ) )
9648 {
9649 # $fmt->{pattern} .= $re->{t_sep} . '%S';
9650 push( @buff_fmt, $re->{t_sep} . '%S' );
9651 }
9652 # $fmt->{pattern} .= '%z';
9653 # push( @buff_fmt, '%z' );
9654 $str = join( '-', @$re{qw( year month day )} ) . ' ' . join( ':', @$re{qw( hour minute )}, ( length( $re->{second} ) ? $re->{second} : '00' ) ) . ( $re->{tz} // '' );
9655  
9656 if( CORE::defined( $re->{tz1} ) || CORE::defined( $re->{tz2} ) )
9657 {
9658 if( CORE::defined( $re->{tz1} ) && length( $re->{tz1} ) )
9659 {
9660 $self->__message( 105, "\tFound timezone as digits '", ( $re->{tz1} // 'undef' ), "'" );
9661 $fmt->{time_zone} = $opt->{time_zone} = $re->{tz};
9662 my $tz_sign = substr( $re->{tz1}, 0, 1 );
9663 if( $tz_sign eq '+' || $tz_sign eq '-' )
9664 {
9665 push( @buff, ( $re->{blank2} // '' ) . '%z' );
9666 push( @buff_fmt, ( $re->{blank2} // '' ) . '%z' );
9667 CORE::delete( $fmt->{time_zone} );
9668 CORE::delete( $opt->{time_zone} );
9669 }
9670 else
9671 {
9672 push( @buff_fmt, $re->{blank2} . $re->{tz1} );
9673 }
9674 }
9675 elsif( CORE::defined( $re->{tz2} ) && length( $re->{tz2} ) )
9676 {
9677 $self->__message( 105, "\tFound timezone as alias '", ( $re->{tz2} // 'undef' ), "'" );
9678 # try-catch
9679 local $@;
9680 eval
9681 {
9682 $tz = DateTime::Lite::TimeZone->new( name => $re->{tz2} , extended => 1);
9683 };
9684 if( $@ || !defined( $tz ) )
9685 {
9686 warn( "Warning only: error trying to set the time zone object using '$re->{tz2}': ", ( $@ || DateTime::Lite::TimeZone->error ), "\n" ) if( $self->_warnings_is_enabled );
9687 }
9688 push( @buff, ( $re->{blank2} // '' ) . '%O' );
9689 push( @buff_fmt, ( $re->{blank2} // '' ) . $re->{tz2} );
9690 $opt->{time_zone} = $fmt->{time_zone} = $tz->name;
9691 }
9692 }
9693 # $opt->{pattern} = '%F %T%z';
9694 $opt->{pattern} = join( '', @buff );
9695 $fmt->{pattern} = join( '', @buff_fmt );
9696 $self->__message( 104, "String is '$str', parsing pattern is '$opt->{pattern}' and formatting pattern is '$fmt->{pattern}'" );
9697 }
9698 # 2019-06-19 23:23:57.000000000+0900
9699 # From PostgreSQL: 2019-06-20 11:02:36.306917+09
9700 # ISO 8601: 2019-06-20T11:08:27
9701 # NOTE: PARSE_DATE_WITH_MILI_SECONDS_RE
9702 elsif( $str =~ /^$PARSE_DATE_WITH_MILI_SECONDS_RE$/x )
9703 {
9704 my $re = { %+ };
9705 $self->__message( 105, "Pattern of type 'PARSE_DATE_WITH_MILI_SECONDS_RE' matched -> ", sub{ $self->Module::Generic::dump( $re ) } );
9706 $opt->{pattern} = join( $re->{d_sep}, qw( %Y %m %d ) ) . $re->{sep} . ( defined( $re->{time_short} ) ? '%H:%M' : '%T' );
9707 $str = join( $re->{d_sep}, @$re{qw( year month day )} ) . $re->{sep} . ( defined( $re->{time_short} ) ? $re->{time_short} : $re->{time} );
9708 if( length( $re->{milli} ) )
9709 {
9710 $opt->{pattern} .= '.%' . length( $re->{milli} ) . 'N';
9711 $str .= '.' . $re->{milli};
9712 }
9713 $fmt->{pattern} = $opt->{pattern};
9714  
9715 if( length( $re->{tz} ) )
9716 {
9717 $opt->{pattern} .= '%z';
9718 $re->{tz} .= '00' if( length( $re->{tz} ) == 3 );
9719 $str .= $re->{tz};
9720 $fmt->{pattern} .= '%z';
9721 $fmt->{time_zone} = $opt->{time_zone} = $re->{tz};
9722 }
9723 elsif( length( $re->{tz_utc} // '' ) )
9724 {
9725 $str .= $re->{tz_utc};
9726 $opt->{pattern} .= 'Z';
9727 $fmt->{pattern} .= 'Z';
9728 $fmt->{time_zone} = $opt->{time_zone} = 'UTC';
9729 }
9730 $self->__message( 105, "Using pattern '$opt->{pattern}' for datetime string '$str' and formatter '$fmt->{pattern}'" );
9731 }
9732 # From SQLite: 2019-06-20 02:03:14
9733 # From MySQL: 2019-06-20 11:04:01
9734 # NOTE: SQLite / MySQL
9735 elsif( $str =~ /^(?<year>\d{4})(?<d_sep>[-|\/])(?<month>\d{1,2})[-|\/](?<day>\d{1,2})(?<sep>[[:blank:]]+|T)(?<time>\d{1,2}:\d{1,2}:\d{1,2})$/ )
9736 {
9737 my $re = { %+ };
9738 $self->__message( 105, "Pattern of type 'SQL' matched -> ", sub{ $self->Module::Generic::dump( $re ) } );
9739 # $opt->{pattern} = $fmt->{pattern} = join( $re->{d_sep}, qw( %Y %m %d ) ) . $re->{sep} . $re->{time};
9740 $opt->{pattern} = $fmt->{pattern} = join( $re->{d_sep}, qw( %Y %m %d ) ) . $re->{sep} . '%T';
9741 $str = join( $re->{d_sep}, @$re{qw( year month day )} ) . $re->{sep} . $re->{time};
9742 my $dt = DateTime::Lite->now( time_zone => $tz );
9743 my $offset = $dt->offset;
9744 # e.g. 9 or possibly 9.5
9745 my $offset_hour = ( $offset / 3600 );
9746 # e.g. 9.5 => 0.5 * 60 = 30
9747 my $offset_min = ( $offset_hour - CORE::int( $offset_hour ) ) * 60;
9748 $str .= sprintf( '%+03d%02d', $offset_hour, $offset_min );
9749 $opt->{pattern} .= '%z';
9750 }
9751 # e.g. Sun, 06 Oct 2019 06:41:11 GMT
9752 # NOTE: PARSE_DATE_HTTP_RE
9753 elsif( $str =~ /^$PARSE_DATE_HTTP_RE$/x )
9754 {
9755 my $re = { %+ };
9756 $self->__message( 105, "Pattern of type 'PARSE_DATE_HTTP_RE' matched -> ", sub{ $self->Module::Generic::dump( $re ) } );
9757 $opt->{pattern} = $fmt->{pattern} = q{%a, %d %b %Y %T GMT};
9758 $fmt->{time_zone} = $opt->{time_zone} = 'UTC';
9759 }
9760 # 12 March 2001 17:07:30 JST
9761 # 12-March-2001 17:07:30 JST
9762 # 12/March/2001 17:07:30 JST
9763 # 12 March 2001 17:07
9764 # 12 March 2001 17:07 JST
9765 # 12 March 2001 17:07:30+0900
9766 # 12 March 2001 17:07:30 +0900
9767 # Monday, 12 March 2001 17:07:30 JST
9768 # Monday, 12 Mar 2001 17:07:30 JST
9769 # 03/Feb/1994:00:00:00 0000
9770 # NOTE: PARSE_DATE_NON_STDANDARD_RE
9771 elsif( $str =~ /^$PARSE_DATE_NON_STDANDARD_RE$/x )
9772 {
9773 my $re = { %+ };
9774 $self->__message( 105, "Pattern of type 'PARSE_DATE_NON_STDANDARD_RE' matched -> ", sub{ $self->Module::Generic::dump( $re ) } );
9775 $self->__message( 104, "Non-standard date found with regexp captured -> ", sub{ $self->dump( $re ) } );
9776 my @buff = ();
9777 my @buff_fmt = ();
9778 if( $re->{wd} || $re->{wd_long} )
9779 {
9780 # push( @buff, ( $re->{wd} || $re->{wd_long} ) );
9781 push( @buff, ( defined( $re->{wd} ) ? '%a' : '%A' ) );
9782 push( @buff, ',' ) if( $re->{wd_comma} );
9783 push( @buff, $re->{blank0} ) if( defined( $re->{blank0} ) );
9784 }
9785 push( @buff, length( $re->{day} ) > 1 ? '%d' : '%e' );
9786 push( @buff, $re->{sep1} );
9787 push( @buff, ( $re->{month} ? '%b' : '%B' ) );
9788 push( @buff, $re->{sep2} );
9789 push( @buff, length( $re->{year} ) == 2 ? '%y' : '%Y' );
9790 push( @buff, $re->{blank1} );
9791 if( $re->{hour} && $re->{minute} && $re->{second} )
9792 {
9793 push( @buff, '%T' );
9794 }
9795 elsif( $re->{hour} && $re->{minute} )
9796 {
9797 push( @buff, '%H:%M' );
9798 }
9799  
9800 push( @buff_fmt, @buff );
9801 if( CORE::defined( $re->{tz} ) || CORE::defined( $re->{tz2} ) )
9802 {
9803 if( CORE::defined( $re->{tz1} ) && length( $re->{tz1} ) )
9804 {
9805 my $tz_sign = substr( $re->{tz1}, 0, 1 );
9806 if( $tz_sign eq '+' || $tz_sign eq '-' )
9807 {
9808 push( @buff, ( $re->{blank2} // '' ) . '%z' );
9809 push( @buff_fmt, ( $re->{blank2} // '' ) . '%z' );
9810 CORE::delete( $fmt->{time_zone} );
9811 CORE::delete( $opt->{time_zone} );
9812 }
9813 else
9814 {
9815 push( @buff_fmt, $re->{blank2} . $re->{tz1} );
9816 }
9817 }
9818 elsif( CORE::defined( $re->{tz2} ) && length( $re->{tz2} ) )
9819 {
9820 # try-catch
9821 local $@;
9822 eval
9823 {
9824 $tz = DateTime::Lite::TimeZone->new( name => $re->{tz2}, extended => 1 );
9825 };
9826 if( $@ || !defined( $tz ) )
9827 {
9828 warn( "Warning only: error trying to set the time zone object using '$re->{tz2}': ", ( $@ || DateTime::Lite::TimeZone->error->message ), "\n" ) if( $self->_warnings_is_enabled );
9829 }
9830 push( @buff, ( $re->{blank2} // '' ) . '%O' );
9831 push( @buff_fmt, ( $re->{blank2} // '' ) . $re->{tz2} );
9832 $opt->{time_zone} = $fmt->{time_zone} = $tz->name;
9833 }
9834 }
9835 $opt->{pattern} = join( '', @buff );
9836 $fmt->{pattern} = join( '', @buff_fmt );
9837 $self->__message( 104, "String is '$str', parsing pattern is '$opt->{pattern}' and formatting pattern is '$fmt->{pattern}'" );
9838 }
9839 # Fri Mar 25 12:18:36 2011
9840 # Fri Mar 25 12:16:25 ADT 2011
9841 # Fri Mar 25 2011
9842 # NOTE: PARSE_DATE_NON_STDANDARD2_RE
9843 elsif( $str =~ /^$PARSE_DATE_NON_STDANDARD2_RE$/x )
9844 {
9845 my $re = { %+ };
9846 $self->__message( 105, "Pattern of type 'PARSE_DATE_NON_STDANDARD2_RE' matched -> ", sub{ $self->Module::Generic::dump( $re ) } );
9847 $self->__message( 104, "Non-standard date found with regexp captured -> ", sub{ $self->dump( $re ) } );
9848 my @buff = ();
9849 my @buff_fmt = ();
9850 if( $re->{wd} || $re->{wd_long} )
9851 {
9852 push( @buff, ( defined( $re->{wd} ) ? '%a' : '%A' ) );
9853 push( @buff, ',' ) if( $re->{wd_comma} );
9854 push( @buff, $re->{blank1} );
9855 }
9856 push( @buff, ( $re->{month} ? '%b' : '%B' ) );
9857 push( @buff, $re->{blank2} );
9858 push( @buff, length( $re->{day} ) > 1 ? '%d' : '%e' );
9859 push( @buff, $re->{blank3} );
9860 if( defined( $re->{time} ) )
9861 {
9862 push( @buff, '%T' );
9863 push( @buff, $re->{blank4} );
9864 }
9865 push( @buff_fmt, @buff );
9866 if( length( $re->{tz} // '' ) )
9867 {
9868 # try-catch
9869 local $@;
9870 eval
9871 {
9872 $tz = DateTime::Lite::TimeZone->new( name => $re->{tz}, extended => 1 );
9873 };
9874 if( $@ || !defined( $tz ) )
9875 {
9876 warn( "Warning only: error trying to set the time zone object using '$re->{tz}': ", ( $@ || DateTime::Lite::TimeZone->error ), "\n" ) if( $self->_warnings_is_enabled );
9877 }
9878 push( @buff, '%O' . ( $re->{blank5} // '' ) );
9879 push( @buff_fmt, $re->{tz} . ( $re->{blank5} // '' ) );
9880 $opt->{time_zone} = $fmt->{time_zone} = $tz->name;
9881 }
9882 push( @buff, length( $re->{year} ) == 2 ? '%y' : '%Y' );
9883 push( @buff_fmt, length( $re->{year} ) == 2 ? '%y' : '%Y' );
9884 $opt->{pattern} = join( '', @buff );
9885 $fmt->{pattern} = join( '', @buff_fmt );
9886 $self->__message( 104, "String is '$str', parsing pattern is '$opt->{pattern}' and formatting pattern is '$fmt->{pattern}'" );
9887 }
9888 # 2019-06-20
9889 # 2019/06/20
9890 # 2016.04.22
9891 # NOTE: PARSE_DATE_ONLY_RE
9892 elsif( $str =~ /^$PARSE_DATE_ONLY_RE$/x )
9893 {
9894 my $re = { %+ };
9895 $self->__message( 105, "Pattern of type 'PARSE_DATE_ONLY_RE' matched -> ", sub{ $self->Module::Generic::dump( $re ) } );
9896 $str = join( $re->{d_sep}, @$re{qw( year month day )} );
9897 $opt->{pattern} = $fmt->{pattern} = join( $re->{d_sep}, qw( %Y %m %d ) );
9898 }
9899 # 2014, Feb 17
9900 # NOTE: PARSE_DATE_ONLY_US_SHORT_RE
9901 elsif( $str =~ /^$PARSE_DATE_ONLY_US_SHORT_RE$/x )
9902 {
9903 my $re = { %+ };
9904 $self->__message( 105, "Pattern of type 'PARSE_DATE_ONLY_US_SHORT_RE' matched -> ", sub{ $self->Module::Generic::dump( $re ) } );
9905 $opt->{pattern} = $fmt->{pattern} = '%Y,' . $re->{sep1} . '%b' . $re->{sep2} . '%d';
9906 }
9907 # 17 Feb, 2014
9908 # NOTE: PARSE_DATE_ONLY_EU_SHORT_RE
9909 elsif( $str =~ /^$PARSE_DATE_ONLY_EU_SHORT_RE$/x )
9910 {
9911 my $re = { %+ };
9912 $self->__message( 105, "Pattern of type 'PARSE_DATE_ONLY_EU_SHORT_RE' matched -> ", sub{ $self->Module::Generic::dump( $re ) } );
9913 $opt->{pattern} = $fmt->{pattern} = '%d' . $re->{sep1} . '%b,' . $re->{sep2} . '%Y';
9914 }
9915 # February 17, 2009
9916 # NOTE: PARSE_DATE_ONLY_US_LONG_RE
9917 elsif( $str =~ /^$PARSE_DATE_ONLY_US_LONG_RE$/x )
9918 {
9919 my $re = { %+ };
9920 $self->__message( 105, "Pattern of type 'PARSE_DATE_ONLY_US_LONG_RE' matched -> ", sub{ $self->Module::Generic::dump( $re ) } );
9921 $opt->{pattern} = $fmt->{pattern} = '%B' . $re->{sep1} . '%d,' . $re->{sep2} . '%Y';
9922 }
9923 # 15 July 2021
9924 # NOTE: PARSE_DATE_ONLY_EU_LONG_RE
9925 elsif( $str =~ /^$PARSE_DATE_ONLY_EU_LONG_RE$/x )
9926 {
9927 my $re = { %+ };
9928 $self->__message( 105, "Pattern of type 'PARSE_DATE_ONLY_EU_LONG_RE' matched -> ", sub{ $self->Module::Generic::dump( $re ) } );
9929 $opt->{pattern} = $fmt->{pattern} = '%d' . $re->{sep1} . '%B' . $re->{sep2} . '%Y';
9930 }
9931 # 22.04.2016
9932 # 22-04-2016
9933 # 17. 3. 2018.
9934 # NOTE: PARSE_DATE_DOTTED_ONLY_EU_RE
9935 elsif( $str =~ /^$PARSE_DATE_DOTTED_ONLY_EU_RE$/x )
9936 {
9937 my $re = { %+ };
9938 $self->__message( 105, "Pattern of type 'PARSE_DATE_DOTTED_ONLY_EU_RE' matched -> ", sub{ $self->Module::Generic::dump( $re ) } );
9939 # $opt->{pattern} = $fmt->{pattern} = join( $re->{sep}, qw( %d %m %Y ) );
9940 $opt->{pattern} = $fmt->{pattern} = "%d$re->{sep}" . ( $re->{blank1} // '' ) . "%m$re->{sep}" . ( $re->{blank2} // '' ) . "%Y" . ( $re->{trailing_dot} // '' );
9941 $fmt->{leading_zero} = 1 if( substr( $re->{day}, 0, 1 ) == 0 || substr( $re->{month}, 0, 1 ) == 0 );
9942 {
9943 package
9944 DateTime::Format::DMY;
9945 sub new
9946 {
9947 my $this = shift( @_ );
9948 my $hash = { @_ };
9949 return( bless( $hash => ( ref( $this ) || $this ) ) );
9950 }
9951 sub format_datetime
9952 {
9953 my( $self, $dt ) = @_;
9954 my $d = $dt->day;
9955 my $m = $dt->month;
9956 my $y = $dt->year;
9957 my $pat = $self->{pattern};
9958 $pat =~ s/\%d/$d/;
9959 $pat =~ s/\%m/$m/;
9960 $pat =~ s/\%Y/$y/;
9961 return( $pat );
9962 }
9963 }
9964 if( $fmt->{leading_zero} )
9965 {
9966 # We do not want it to interfere with the module supported parameters
9967 delete( $fmt->{leading_zero} );
9968 }
9969 else
9970 {
9971 $formatter = 'DateTime::Format::DMY';
9972 }
9973 }
9974 # 17.III.2020
9975 # 17. III. 2018.
9976 # NOTE: PARSE_DATE_ROMAN_RE
9977 elsif( $str =~ /^$PARSE_DATE_ROMAN_RE$/xi )
9978 {
9979 my $re = { %+ };
9980 $self->__message( 105, "Pattern of type 'PARSE_DATE_ROMAN_RE' matched -> ", sub{ $self->Module::Generic::dump( $re ) } );
9981 $re->{month} = $roman2regular->{ $re->{month} };
9982 $str = join( '-', @$re{qw( year month day )} );
9983 $opt->{pattern} = '%F';
9984 $fmt->{pattern} = "%d." . ( $re->{blank1} // '' ) . "%m." . ( $re->{blank2} // '' ) . "%Y" . ( $re->{trailing_dot} // '' );
9985 {
9986 package
9987 DateTime::Format::RomanDDXXXYYYY;
9988 our $ROMAN2REGULAR = $roman2regular;
9989 sub new
9990 {
9991 my $this = shift( @_ );
9992 my $hash = { @_ };
9993 return( bless( $hash => ( ref( $this ) || $this ) ) );
9994 }
9995  
9996 sub parse_datetime {}
9997  
9998 sub parse_duration {}
9999  
10000 sub format_duration {}
10001  
10002 sub format_datetime
10003 {
10004 my( $self, $dt ) = @_;
10005 my $d = $dt->day;
10006 my $m = $dt->month;
10007 my $y = $dt->year;
10008 foreach my $k ( keys( %$ROMAN2REGULAR ) )
10009 {
10010 # Skip lowercase ones
10011 next if( $k =~ /^[a-z]+$/ );
10012 if( $ROMAN2REGULAR->{ $k } == $m )
10013 {
10014 $m = $k;
10015 last;
10016 }
10017 }
10018 my $pat = $self->{pattern};
10019 $pat =~ s/\%d/$d/;
10020 $pat =~ s/\%m/$m/;
10021 $pat =~ s/\%Y/$y/;
10022 return( $pat );
10023 }
10024 }
10025 $formatter = 'DateTime::Format::RomanDDXXXYYYY';
10026 }
10027 # 20030613
10028 # NOTE: PARSE_DATE_DIGITS_ONLY_RE
10029 elsif( $str =~ /^$PARSE_DATE_DIGITS_ONLY_RE$/x )
10030 {
10031 my $re = { %+ };
10032 $self->__message( 105, "Pattern of type 'PARSE_DATE_DIGITS_ONLY_RE' matched -> ", sub{ $self->Module::Generic::dump( $re ) } );
10033 $opt->{pattern} = '%F';
10034 $str = join( '-', @$re{qw( year month day )} );
10035 $fmt->{pattern} = join( '', qw( %Y %m %d ) );
10036 # $opt->{pattern} = $fmt->{pattern} = join( '', qw( %d %m %Y ) );
10037 }
10038 # 2021年7月14日
10039 # 令和3年7月14日
10040 # NOTE: PARSE_DATETIME_JP_RE
10041 elsif( $str =~ /^$PARSE_DATETIME_JP_RE$/x )
10042 {
10043 my $re = { %+ };
10044 $self->__message( 104, "Japanese date found with regexp captured -> ", sub{ $self->dump( $re ) } );
10045 use utf8;
10046 $self->_load_class( 'DateTime::Format::JP' ) || return( $self->pass_error );
10047 my $pattern;
10048 if( defined( $re->{era} ) && $re->{era} )
10049 {
10050 $pattern = '%E%y年%m月%d日';
10051 }
10052 else
10053 {
10054 $pattern = '%Y年%m月%d日';
10055 }
10056  
10057 if( $re->{time} )
10058 {
10059 $pattern .= '%H' . ( $re->{hour_suffix} // '' );
10060 if( $re->{minute} )
10061 {
10062 $pattern .= ( $re->{hour_sep} // '' ) . '%M' . ( $re->{minute_suffix} // '' );
10063 }
10064 if( $re->{second} )
10065 {
10066 $pattern .= ( $re->{minute_sep} // '' ) . '%S' . ( $re->{second_suffix} // '' );
10067 }
10068 }
10069  
10070 my $use_full_width = 0;
10071 if( $re->{year} =~ /^[\x{FF10}-\x{FF19}]+$/ )
10072 {
10073 $use_full_width++;
10074 }
10075  
10076 my $parser;
10077 $self->__message( 104, "Calling DateTime::Format::JP with pattern '$pattern'" );
10078 # try-catch
10079 local $@;
10080 eval
10081 {
10082 $parser = DateTime::Format::JP->new(
10083 pattern => $pattern,
10084 time_zone => $tz,
10085 ( $use_full_width ? ( zenkaku => 1 ) : () ),
10086 );
10087 };
10088 if( $@ )
10089 {
10090 warn( "Your system is missing key timezone components. ${class}::_parse_timestamp is reverting to UTC instead of local time zone.\n" ) if( $self->_warnings_is_enabled );
10091 $parser = DateTime::Format::JP->new(
10092 pattern => $pattern,
10093 time_zone => 'UTC',
10094 ( $use_full_width ? ( zenkaku => 1 ) : () ),
10095 );
10096 }
10097  
10098 # try-catch
10099 my $dt;
10100 eval
10101 {
10102 $dt = $parser->parse_datetime( $str );
10103 $dt->set_formatter( $parser );
10104 };
10105 if( $@ )
10106 {
10107 return( $self->error( "An error occurred while trying to use DateTime::Format::JP: $@" ) );
10108 }
10109 if( $dt && Scalar::Util::blessed( $dt ) && !$dt->isa( 'DateTime::Lite' ) )
10110 {
10111 # NOTE: This branch is defensive. Since DateTime::Format::JP v0.1.7 we expect
10112 # parse_datetime() to return a DateTime::Lite directly. If we land here, it
10113 # means an older DateTime::Format::JP is installed (returning a DateTime
10114 # object), or some other unexpected blessed object was returned. We convert
10115 # to DateTime::Lite via from_object() so the caller always gets a consistent
10116 # return type, and emit a diagnostic on CPAN Testers smokers so we can investigate.
10117 if( $ENV{AUTOMATED_TESTING} || $ENV{AUTHOR_TESTING} )
10118 {
10119 my $jp_version = DateTime::Format::JP->VERSION // 'undef';
10120 warn( "DateTime::Format::JP ${jp_version} returned a ", ref( $dt ), " instead of a DateTime::Lite for input '${str}'.\n" );
10121 }
10122 $self->_load_class( 'DateTime::Lite', { version => 'v0.7.3', no_warning => 1 } ) ||
10123 return( $self->pass_error );
10124 $dt = DateTime::Lite->from_object( object => $dt ) ||
10125 return( $self->pass_error( DateTime::Lite->error ) );
10126 }
10127 return( $dt );
10128 }
10129 # <https://en.wikipedia.org/wiki/Date_format_by_country>
10130 # Possibly followed by a dot and some integer for milliseconds as provided by Time::HiRes
10131 # NOTE: PARSE_DATE_TIMESTAMP_RE
10132 elsif( $str =~ /^$PARSE_DATE_TIMESTAMP_RE$/x )
10133 {
10134 my $re = { %+ };
10135 $self->__message( 104, "Unix timestamp found with regexp captured -> ", sub{ $self->Module::Generic::dump( $re ) } );
10136 # try-catch
10137 local $@;
10138 my $dt = DateTime::Lite->from_epoch( epoch => $str, time_zone => $tz ) ||
10139 return( $self->pass_error( DateTime::Lite->error ) );
10140  
10141 my $strp = eval
10142 {
10143 $opt->{pattern} = ( CORE::index( $str, '.' ) != -1 ? '%s.%' . CORE::length( $re->{milli} ) . 'N' : '%s' );
10144 $self->__message( 104, "Calling formatter with pattern '$opt->{pattern}'" );
10145 DateTime::Format::Lite->new( %$opt );
10146 };
10147 if( $@ || !defined( $strp ) )
10148 {
10149 return( $self->error( "An error occurred while parsing the time stamp based on the unix timestamp '$str': ", ( $@ || DateTime::Format::Lite->error ) ) );
10150 }
10151 $dt->set_formatter( $strp );
10152 return( $dt );
10153 }
10154 # NOTE: PARSE_DATETIME_RELATIVE_RE
10155 elsif( $str =~ /^$PARSE_DATETIME_RELATIVE_RE$/x )
10156 {
10157 my( $num, $unit ) = ( $1, $2 );
10158 $self->__message( 105, "Pattern of type 'PARSE_DATETIME_RELATIVE_RE' matched with number '$num' and unit '$unit'" );
10159 $unit = 's' if( !length( $unit ) );
10160 my $interval =
10161 {
10162 's' => 1,
10163 'm' => 60,
10164 'h' => 3600,
10165 'D' => 86400,
10166 'd' => 86400,
10167 'M' => 86400 * 30,
10168 'Y' => 86400 * 365,
10169 'y' => 86400 * 365,
10170 };
10171 my $offset = ( $interval->{ $unit } || 1 ) * int( $num );
10172 my $ts = time() + $offset;
10173 my $dt;
10174 # try-catch
10175 local $@;
10176 eval
10177 {
10178 $dt = DateTime::Lite->from_epoch( epoch => $ts, time_zone => $tz );
10179 };
10180 if( $@ || !defined( $tz ) )
10181 {
10182 # Exception raised by DateTime::Lite::TimeZone
10183 my $err = ( $@ || DateTime::Lite::TimeZone->error );
10184 if( $err =~ /Cannot[[:blank:]\h]+determine[[:blank:]\h]+local[[:blank:]\h]+time[[:blank:]\h]+zone/i )
10185 {
10186 warn( "Your system is missing key timezone components. ${class}::_parse_timestamp is reverting to UTC instead of local time zone.\n" ) if( $self->_warnings_is_enabled );
10187 $dt = DateTime::Lite->from_epoch( epoch => $ts, time_zone => 'UTC' );
10188 return( $dt );
10189 }
10190 else
10191 {
10192 return( $self->error( "An error occurred while trying to create a DateTime::Lite object with the relative timestamp '$str' that translated into the unix time stamp '$ts': $err" ) );
10193 }
10194 }
10195 return( $dt );
10196 }
10197 # NOTE: now
10198 elsif( lc( $str ) eq 'now' )
10199 {
10200 $dt = DateTime::Lite->now( time_zone => $tz );
10201 return( $dt );
10202 }
10203 else
10204 {
10205 return( '' );
10206 }
10207  
10208 $self->__message( 105, "Instantiating datetime parser with options -> ", sub{ $self->dump( $opt ) } );
10209 my $strp = DateTime::Format::Lite->new( %$opt ) ||
10210 return( $self->pass_error( DateTime::Format::Lite->error ) );
10211 my $dt;
10212 # try-catch
10213 local $@;
10214 eval
10215 {
10216 $dt = $strp->parse_datetime( $str );
10217 $self->__message( 105, "Parser returned datetime object '", $self->_str_val( $dt // 'undef' ), "'" );
10218 $self->__message( 105, "Instantiating datetime formatter with options -> ", sub{ $self->dump( $fmt ) } );
10219 my $strp2 = $formatter->new( %$fmt );
10220 # To enable the date string to be stringified to its original format
10221 $dt->set_formatter( $strp2 ) if( $dt );
10222 $self->__message( 105, "Returning datetime object '", ( defined( $dt ) ? $self->_str_val( $dt // 'undef' ) : 'undef' ), "'" );
10223 };
10224 if( $@ || !defined( $dt ) )
10225 {
10226 my $err = ( $@ || $strp->error );
10227 $self->__message( 105, "Error creating a DateTime::Lite object with the timestamp '$str': $err" );
10228 return( $self->error( "Error creating a DateTime::Lite object with the timestamp '$str': $err" ) );
10229 }
10230 return( $dt );
10231 }
10232 PERL
10233 # NOTE: _refaddr()
10234 _refaddr => <<'PERL',
10235 # NOTE: sub _refaddr() is now a XS method
10236 sub _refaddr
10237 {
10238 return if( scalar( @_ ) < 2 );
10239 return if( !defined( $_[1] ) );
10240 return( Scalar::Util::refaddr( $_[1] ) );
10241 }
10242 PERL
10243 # NOTE: _register_error_callback()
10244 _register_error_callback => <<'PERL',
10245 sub _register_error_callback
10246 {
10247 my $self = shift( @_ );
10248 my $this = $self->_obj2h;
10249 my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
10250 # No choice, but to die
10251 my $name = shift( @_ ) || die( "No name for this error callback was provided." );
10252 my $cb = shift( @_ ) || die( "No error callback was provided." );
10253 unless( ref( $cb ) eq 'CODE' )
10254 {
10255 die( "Error callback provided is not a code reference." );
10256 }
10257 $data->{_error_callbacks} //= [];
10258 foreach my $ref ( @{$data->{_error_callbacks}} )
10259 {
10260 next unless( ref( $ref ) eq 'HASH' );
10261 next unless( $ref->{name} && $ref->{cb} );
10262 if( $ref->{namae} eq $name )
10263 {
10264 $ref->{cb} = $cb;
10265 return( $self );
10266 }
10267 }
10268 push( @{$data->{_error_callbacks}}, { name => $name, cb => $cb } );
10269 return( $self );
10270 }
10271 PERL
10272 # NOTE: _remove_error_callback()
10273 _remove_error_callback => <<'PERL',
10274 sub _remove_error_callback
10275 {
10276 my $self = shift( @_ );
10277 my $this = $self->_obj2h;
10278 my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
10279 # No choice, but to die
10280 my $name = shift( @_ ) || die( "No name for this error callback was provided." );
10281 # return undef is only for errors, so instead we return false, but not undef.
10282 return( '' ) if( !CORE::exists( $data->{_error_callbacks} ) );
10283 if( !ref( $data->{_error_callbacks} ) &&
10284 !CORE::length( $data->{_error_callbacks} ) )
10285 {
10286 CORE::delete( $data->{_error_callbacks} );
10287 return( '' );
10288 }
10289 elsif( ref( $data->{_error_callbacks} ) ne 'ARRAY' )
10290 {
10291 warn( "Error callback repository was expected to be an array reference, but instead found a value of type '", $self->_str_val( $data->{_error_callbacks} ), "'" ) if( $self->_is_warnings_enabled() );
10292 return;
10293 }
10294 for( my $i = 0; $i < scalar( @{$data->{_error_callbacks}} ); $i++ )
10295 {
10296 my $ref = $data->{_error_callbacks}->[$i];
10297 next unless( defined( $ref ) );
10298 next unless( ref( $ref ) eq 'HASH' );
10299 next unless( $ref->{name} );
10300 if( $ref->{namae} eq $name )
10301 {
10302 my $cb = $ref->{cb};
10303 # Remove our entry
10304 splice( @{$data->{_error_callbacks}}, $i, 1 );
10305 # Remove the instance property '_error_callbacks' if there are no entries left.
10306 CORE::delete( $data->{_error_callbacks} ) unless( scalar( @{$data->{_error_callbacks}} ) );
10307 # Return the old code reference value, and make sure we do not return undef, because it would mean an error.
10308 return( $cb // '' );
10309 }
10310 }
10311 return( '' );
10312 }
10313 PERL
10314 # NOTE: _set_get_class_array_object()
10315 _set_get_class_array_object => <<'PERL',
10316 sub _set_get_class_array_object
10317 {
10318 my $self = shift( @_ );
10319 my $field = shift( @_ );
10320 my $def = shift( @_ );
10321 my $this = $self->_obj2h;
10322 my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
10323 my $ref = $self->_set_get_class_array( $field, $def, @_ ) ||
10324 return( $self->pass_error );
10325  
10326 if( ref( $def ) ne 'HASH' )
10327 {
10328 CORE::warn( "Warning only: dynamic class field definition hash ($def) for field \"$field\" is not a hash reference." );
10329 return;
10330 }
10331 $def->{wantlist} //= 0;
10332  
10333 if( !$data->{ $field } || !$self->_is_object( $data->{ $field } ) )
10334 {
10335 $self->_load_class( 'Module::Generic::Array' ) ||
10336 return( $self->pass_error );
10337 my $o = Module::Generic::Array->new( ( defined( $data->{ $field } ) && CORE::length( $data->{ $field } ) ) ? $data->{ $field } : [] );
10338 $data->{ $field } = $o;
10339 }
10340  
10341 if( $def->{wantlist} && want( 'LIST' ) )
10342 {
10343 return( $data->{ $field } ? $data->{ $field }->list : () );
10344 }
10345 else
10346 {
10347 Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
10348 return( $data->{ $field } );
10349 }
10350 }
10351 PERL
10352 # NOTE: _set_get_datetime()
10353 _set_get_datetime => <<'PERL',
10354 sub _set_get_datetime : lvalue
10355 {
10356 my $self = shift( @_ );
10357 my $field = shift( @_ );
10358 my $this = $self->_obj2h;
10359 my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
10360 my $class = ref( $self ) || $self;
10361  
10362 my( $opts, $check, $fmt, $tz );
10363 my $callbacks = {};
10364 my $def = {};
10365 if( ref( $field ) eq 'HASH' )
10366 {
10367 $def = { %$field };
10368 if( CORE::exists( $def->{field} ) && defined( $def->{field} ) && CORE::length( $def->{field} ) )
10369 {
10370 $field = CORE::delete( $def->{field} );
10371 }
10372 else
10373 {
10374 warn( "No 'field' parameter provided in calling _set_get_datetime\n" ) if( $self->_warnings_is_enabled );
10375 }
10376 # Should have been 'callbacks', but we catch it anyway.
10377 $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
10378 $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
10379 $check = CORE::delete( $def->{check} ) if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
10380 # The optional format for DateTime::Format::Lite
10381 $fmt = CORE::delete( $def->{format} ) if( CORE::exists( $def->{format} ) && CORE::length( $def->{format} // '' ) );
10382 if( CORE::exists( $def->{tz} ) && CORE::length( $def->{tz} // '' ) )
10383 {
10384 # We do not 'delete' it from $def, because we will pass it to '_parse_timestamp' below as part of the $opts options
10385 $tz = $def->{tz};
10386 }
10387 elsif( CORE::exists( $def->{time_zone} ) && CORE::length( $def->{time_zone} // '' ) )
10388 {
10389 $tz = $def->{tz} = CORE::delete( $def->{time_zone} );
10390 }
10391 # The rest of the options are passed to _parse_timestamp() as parameters
10392 $opts = $def;
10393 }
10394  
10395 my $process = sub
10396 {
10397 my $time = shift( @_ );
10398 my $now;
10399 if( Scalar::Util::blessed( $time ) )
10400 {
10401 return( $self->error( "Object provided as value for $field, but this is not a DateTime::Lite, a DateTime or a Module::Generic::DateTime object" ) ) if( !$time->isa( 'DateTime::Lite' ) && !$time->isa( 'DateTime' ) && !$time->isa( 'Module::Generic::DateTime' ) );
10402 $data->{ $field } = $time;
10403 if( defined( $fmt ) )
10404 {
10405 $self->_load_class( 'DateTime::Format::Lite' ) || return( $self->pass_error );
10406 # try-catch
10407 local $@;
10408 my $strp = eval
10409 {
10410 DateTime::Format::Lite->new( pattern => $fmt );
10411 };
10412 if( $@ )
10413 {
10414 return( $self->error( "Error getting the DateTime::Format::Lite object for format '$fmt': $@" ) );
10415 }
10416
10417 eval
10418 {
10419 $time->set_formatter( $strp );
10420 };
10421 if( $@ )
10422 {
10423 return( $self->error( "Error setting the formatter DateTime::Format::Lite on the DateTime::Lite object: $@" ) );
10424 }
10425 }
10426 return( $data->{ $field } );
10427 }
10428 elsif( $time =~ /^\d+$/ && $time !~ /^\d{1,10}$/ )
10429 {
10430 return( $self->error( "DateTime::Lite value ($time) provided for field $field does not look like a unix timestamp" ) );
10431 }
10432 # Parsed successfully and transformed into a DateTime::Lite object
10433 elsif( $now = $self->_parse_timestamp( $time, ( CORE::defined( $opts ) ? ( %$opts ) : () ) ) )
10434 {
10435 # Found a parsed datetime value
10436 # $data->{ $field } = $now;
10437 # return( $now );
10438 }
10439  
10440 unless( Scalar::Util::blessed( $now ) && ( $now->isa( 'DateTime::Lite' ) || $now->isa( 'DateTime' ) || $now->isa( 'Module::Generic::DateTime' ) ) )
10441 {
10442 # We set this has a distinctive key across all process and threads since this value is ubiquitous
10443 my $repo = Module::Generic::Global->new( 'globals' => $class, key => 'has_local_tz' );
10444 my $HAS_LOCAL_TZ = $repo->get;
10445 $self->_load_class( 'DateTime::Lite' ) || return( $self->pass_error );
10446 if( !defined( $HAS_LOCAL_TZ ) )
10447 {
10448 $self->_load_class( 'DateTime::Lite::TimeZone' ) || return( $self->pass_error );
10449 $repo->lock;
10450 $tz = DateTime::Lite::TimeZone->new( name => 'local' );
10451 if( !defined( $tz ) )
10452 {
10453 $tz = DateTime::Lite::TimeZone->new( name => 'UTC' );
10454 $HAS_LOCAL_TZ = 0;
10455 warn( "Your system is missing key timezone components. ${class}::_parse_timestamp is reverting to UTC instead of local time zone.\n" ) if( $self->_warnings_is_enabled );
10456 }
10457 else
10458 {
10459 $HAS_LOCAL_TZ = 1;
10460 }
10461 $repo->set( $HAS_LOCAL_TZ );
10462  
10463 if( CORE::defined( $opts ) &&
10464 CORE::exists( $opts->{tz} ) &&
10465 CORE::defined( $opts->{tz} ) &&
10466 CORE::length( $opts->{tz} ) )
10467 {
10468 $tz = DateTime::Lite::TimeZone->new( name => "$opts->{tz}" );
10469 if( !defined( $tz ) )
10470 {
10471 warn( "Failed setting the specified time zone $opts->{tz}: ", DateTime::Lite::TimeZone->error, "\n" ) if( $self->_warnings_is_enabled );
10472 }
10473 }
10474 }
10475 else
10476 {
10477 $now = ( CORE::defined( $opts ) && CORE::exists( $opts->{tz} ) && CORE::defined( $opts->{tz} ) && CORE::length( $opts->{tz} ) )
10478 ? DateTime::Lite->from_epoch( epoch => $time, time_zone => "$opts->{tz}" )
10479 : DateTime::Lite->from_epoch( epoch => $time, time_zone => ( $HAS_LOCAL_TZ ? 'local' : 'UTC' ) );
10480
10481 if( !defined( $now ) )
10482 {
10483 warn( "Error trying to set a DateTime::Lite object using ", ( ( CORE::defined( $opts ) && CORE::exists( $opts->{tz} ) && CORE::defined( $opts->{tz} ) && CORE::length( $opts->{tz} ) ) ? $opts->{tz} : ( $HAS_LOCAL_TZ ? 'local' : 'UTC' ) ), " time zone -> ", DateTime::Lite->error ) if( $self->_warnings_is_enabled );
10484 $now = DateTime::Lite->from_epoch( epoch => $time, time_zone => 'UTC' );
10485 }
10486 }
10487 }
10488  
10489 if( $def->{prefer_dt_lite} && !$self->_is_a( $now => 'DateTime::Lite' ) )
10490 {
10491 $self->_load_class( 'DateTime::Lite' ) || return( $self->pass_error );
10492 $now = DateTime::Lite->from_object( object => $now ) ||
10493 return( $self->pass_error( DateTime::Lite->error ) );
10494 }
10495  
10496 # We only set a default formatter if one was not set already
10497 if( defined( $fmt ) )
10498 {
10499 $self->_load_class( 'DateTime::Format::Lite' ) || return( $self->pass_error );
10500 my $strp = DateTime::Format::Lite->new( pattern => $fmt );
10501 if( !defined( $strp ) )
10502 {
10503 return( $self->error( "Error getting the DateTime::Format::Lite object for format '$fmt': ", DateTime::Format::Lite->error ) );
10504 }
10505  
10506 $now->set_formatter( $strp ) ||
10507 return( $self->error( "Error setting the formatter DateTime::Format::Lite on the DateTime::Lite object: $@" ) );
10508 }
10509 elsif( !$now->formatter )
10510 {
10511 $self->_load_class( 'DateTime::Format::Lite' ) || return( $self->pass_error );
10512 my $strp = DateTime::Format::Lite->new(
10513 pattern => '%s',
10514 locale => 'en_GB',
10515 );
10516 $now->set_formatter( $strp );
10517 if( !defined( $strp ) )
10518 {
10519 warn( "Error creating DateTime::Lite object: ", DateTime::Format::Lite->error, "\n" ) if( $self->_warnings_is_enabled );
10520 }
10521 }
10522 return( $now );
10523 };
10524  
10525 return( $self->_set_get_callback({
10526 get => sub
10527 {
10528 my $self = shift( @_ );
10529 # So that a call to this field will not trigger an error: "Can't call method "xxx" on an undefined value"
10530 if( !$data->{ $field } )
10531 {
10532 return;
10533 }
10534 elsif( defined( $data->{ $field } ) &&
10535 length( $data->{ $field } ) &&
10536 !$self->_is_a( $data->{ $field }, 'DateTime::Lite' ) )
10537 {
10538 my $now = $process->( $data->{ $field } ) || return( $self->pass_error );
10539 $data->{ $field } = $now;
10540 }
10541 Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
10542 return( $data->{ $field } );
10543 },
10544 set => sub
10545 {
10546 my $self = shift( @_ );
10547 my $arg = shift( @_ );
10548 if( defined( $check ) )
10549 {
10550 # try-catch
10551 local $@;
10552 my $rv = eval{ $check->( $self, $arg ) };
10553 if( !defined( $rv ) && $self->error )
10554 {
10555 return( $self->pass_error );
10556 }
10557 return( $self->error( "Invalid value provided." ) ) if( !$rv );
10558 }
10559 my $time = $arg;
10560 if( !defined( $time ) )
10561 {
10562 return( $data->{ $field } = $time );
10563 }
10564 my $now = $process->( $time ) || do
10565 {
10566 $self->__message( 105, "Error processing datetime '", ( defined( $time ) ? $self->_str_val( $time // 'undef' ) : 'undef' ), "'" );
10567 return( $self->pass_error );
10568 };
10569 $self->__message( 105, "Setting datetime object '", ( defined( $now ) ? $self->_str_val( $now // 'undef' ) : 'undef' ), "'" );
10570 $data->{ $field } = $now;
10571 $self->clear_error;
10572  
10573 if( scalar( keys( %$callbacks ) ) &&
10574 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
10575 {
10576 my $coderef;
10577 foreach my $t ( qw( add set ) )
10578 {
10579 if( CORE::exists( $callbacks->{ $t } ) )
10580 {
10581 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
10582 ? $callbacks->{ $t }
10583 : $self->can( $callbacks->{ $t } );
10584 last if( defined( $coderef ) );
10585 }
10586 }
10587 if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
10588 {
10589 # try-catch
10590 local $@;
10591 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
10592 if( $@ )
10593 {
10594 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
10595 }
10596 elsif( !defined( $rv ) && $self->error )
10597 {
10598 return( $self->pass_error );
10599 }
10600 $data->{ $field } = $rv;
10601 }
10602 }
10603  
10604 # So that a call to this field will not trigger an error: "Can't call method "xxx" on an undefined value"
10605 if( !$data->{ $field } )
10606 {
10607 return;
10608 }
10609 elsif( defined( $data->{ $field } ) &&
10610 length( $data->{ $field } ) &&
10611 !$self->_is_a( $data->{ $field }, 'DateTime::Lite' ) )
10612 {
10613 my $now = $process->( $data->{ $field } ) || return( $self->pass_error );
10614 $data->{ $field } = $now;
10615 }
10616 Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
10617 return( $data->{ $field } );
10618 },
10619 field => $field,
10620 }, @_ ) );
10621 }
10622 PERL
10623 # NOTE: _set_get_enum()
10624 _set_get_enum => <<'PERL',
10625 sub _set_get_enum : lvalue
10626 {
10627 my $self = shift( @_ );
10628 my $this = $self->_obj2h;
10629 my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
10630 my $class = ref( $self ) || $self;
10631 my( $field, $allowed );
10632 my $case_sensitive = 1;
10633 my $callbacks = {};
10634 my $check;
10635 my $def = {};
10636 if( scalar( @_ ) &&
10637 ref( $_[0] // '' ) eq 'HASH' )
10638 {
10639 $def = shift( @_ );
10640 if( CORE::exists( $def->{field} ) && defined( $def->{field} ) && CORE::length( $def->{field} ) )
10641 {
10642 $field = CORE::delete( $def->{field} );
10643 }
10644 else
10645 {
10646 warn( "No 'field' parameter provided in calling _set_get_datetime\n" ) if( $self->_warnings_is_enabled );
10647 }
10648 if( CORE::exists( $def->{allowed} ) && defined( $def->{allowed} ) && CORE::length( $def->{allowed} ) )
10649 {
10650 $allowed = CORE::delete( $def->{allowed} );
10651 }
10652 else
10653 {
10654 die( "No 'allowed' parameter provided in calling _set_get_enum" );
10655 }
10656 # It could be defined, but empty (''), or set to a positive (1) or false value (0)
10657 if( CORE::exists( $def->{case} ) && defined( $def->{case} ) )
10658 {
10659 $case_sensitive = CORE::delete( $def->{case} ) ? 1 : 0;
10660 }
10661 # Should have been 'callbacks', but we catch it anyway.
10662 $callbacks = $def->{callback} if( CORE::exists( $def->{callback} ) && ref( $def->{callback} ) eq 'HASH' );
10663 $callbacks = $def->{callbacks} if( CORE::exists( $def->{callbacks} ) && ref( $def->{callbacks} ) eq 'HASH' );
10664 $check = $def->{check} if( CORE::exists( $def->{check} ) && ref( $def->{check} ) eq 'CODE' );
10665 }
10666 elsif( scalar( @_ ) >= 2 )
10667 {
10668 ( $field, $allowed ) = splice( @_, 0, 2 );
10669 }
10670 else
10671 {
10672 die( "Error calling _set_get_enum. Either call _set_get_enum with an hash reference, such as \$self->_set_get_enum({ field => \$my_field, allowed => [qw( value1 value2 )] }), or by passing it as 2 arguments, such as \$self->_set_get_enum( \$my_field, \$allowed_array_reference )" );
10673 }
10674  
10675 if( !$self->_is_array( $allowed ) )
10676 {
10677 die( "Property value 'allowed' provided (", $self->_str_val( $allowed // 'undef' ), ") is not an array reference." );
10678 }
10679  
10680 return( $self->_set_get_callback({
10681 field => $field,
10682 get => sub
10683 {
10684 my $self = shift( @_ );
10685 # So that a call to this field will not trigger an error: "Can't call method "xxx" on an undefined value"
10686 if( !defined( $data->{ $field } ) || !CORE::length( $data->{ $field } ) )
10687 {
10688 return;
10689 }
10690 Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
10691 return( $data->{ $field } );
10692 },
10693 set => sub
10694 {
10695 my $self = shift( @_ );
10696 my $arg = shift( @_ );
10697 $self->__message( 112, "Value received for enum field '$field' is '", ( $arg // 'undef' ), "'" );
10698 if( defined( $check ) )
10699 {
10700 $self->__message( 112, "Check code is defined, calling now." );
10701 # try-catch
10702 local $@;
10703 my $rv = eval{ $check->( $self, $arg ) };
10704 if( !defined( $rv ) && $self->error )
10705 {
10706 return( $self->pass_error );
10707 }
10708 return( $self->error( "Invalid value provided." ) ) if( !$rv );
10709 }
10710  
10711 if( defined( $arg ) )
10712 {
10713 $self->__message( 112, "Checking if value '$arg' for enum field '$field' is among allowed ones: '", join( "', '", @$allowed ), "'" );
10714 my $is_ok = $case_sensitive
10715 ? scalar( grep( $_ eq ( $arg // '' ), @$allowed ) )
10716 : scalar( grep( /^\Q$arg\E/i, @$allowed ) );
10717 $self->__message( 112, "Is field '$field' enum value provided ($arg) ok ? ", ( $is_ok ? 'yes' : 'no' ) );
10718 return( $self->error( "Invalid value '", $self->_str_val( $arg // 'undef' ), "'" ) ) if( !$is_ok );
10719 $data->{ $field } = $arg;
10720 }
10721 else
10722 {
10723 $self->__message( 112, "No value was provided. Setting enum field '$field' to undef" );
10724 $data->{ $field } = undef;
10725 }
10726 $self->clear_error;
10727  
10728 if( scalar( keys( %$callbacks ) ) &&
10729 ( CORE::exists( $callbacks->{add} ) || CORE::exists( $callbacks->{set} ) ) )
10730 {
10731 my $coderef;
10732 foreach my $t ( qw( add set ) )
10733 {
10734 if( CORE::exists( $callbacks->{ $t } ) )
10735 {
10736 $coderef = ref( $callbacks->{ $t } ) eq 'CODE'
10737 ? $callbacks->{ $t }
10738 : $self->can( $callbacks->{ $t } );
10739 last if( defined( $coderef ) );
10740 }
10741 }
10742 if( defined( $coderef ) && ref( $coderef ) eq 'CODE' )
10743 {
10744 # try-catch
10745 local $@;
10746 my $rv = eval{ $coderef->( $self, $data->{ $field } ) };
10747 $self->__message( 112, "Callback done. Object field $field value is now '", ( $data->{ $field } // 'undef' ), "'" );
10748 if( $@ )
10749 {
10750 return( $self->error( "Error while executing callback for field '$field', and value '", $self->_str_val( $data->{ $field } ), "': $@" ) );
10751 }
10752 elsif( !defined( $rv ) && $self->error )
10753 {
10754 return( $self->pass_error );
10755 }
10756 # Update with callback’s result
10757 $data->{ $field } = $rv;
10758 }
10759 }
10760  
10761 # So that a call to this field will not trigger an error: "Can't call method "xxx" on an undefined value"
10762 if( !defined( $data->{ $field } ) )
10763 {
10764 return;
10765 }
10766 Scalar::Util::weaken( $data->{ $field } ) if( $def->{weaken} && $self->_is_object( $data->{ $field } ) && !Scalar::Util::isweak( $data->{ $field } ) );
10767 return( $data->{ $field } );
10768 }
10769 }, @_ ) );
10770 }
10771 PERL
10772 # NOTE: _set_get_hash_as_object()
10773 _set_get_hash_as_object => <<'PERL',
10774 # There is no lvalue here on purpose
10775 sub _set_get_hash_as_object
10776 {
10777 my $self = shift( @_ );
10778 my $this = $self->_obj2h;
10779 my $field = shift( @_ ) || return( $self->error( "No field provided for _set_get_hash_as_object" ) );
10780 my $class;
10781 @_ = () if( @_ == 1 && !defined( $_[0] ) );
10782 no strict 'refs';
10783 if( @_ )
10784 {
10785 # No class was provided
10786 if( ( Scalar::Util::reftype( $_[0] ) // '' ) eq 'HASH' )
10787 {
10788 my $new_class = $field;
10789 $new_class =~ tr/-/_/;
10790 $new_class =~ s/\_{2,}/_/g;
10791 $new_class = join( '', map( ucfirst( lc( $_ ) ), split( /\_/, $new_class ) ) );
10792 $class = ( ref( $self ) || $self ) . "\::${new_class}";
10793 }
10794 elsif( ref( $_[0] ) )
10795 {
10796 return( $self->error( "Class name in _set_get_hash_as_object helper method cannot be a reference. Received: \"", $self->_str_val( $_[0] // 'undef' ), "\"." ) );
10797 }
10798 else
10799 {
10800 $class = shift( @_ );
10801 }
10802 }
10803 else
10804 {
10805 my $new_class = $field;
10806 $new_class =~ tr/-/_/;
10807 $new_class =~ s/\_{2,}/_/g;
10808 $new_class = join( '', map( ucfirst( lc( $_ ) ), split( /\_/, $new_class ) ) );
10809 $class = ( ref( $self ) || $self ) . "\::${new_class}";
10810 }
10811 # my $class = shift( @_ );
10812 my $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
10813 unless( $self->_is_class_loaded( $class ) )
10814 {
10815 my $perl .= <<EOT;
10816 package $class;
10817 BEGIN
10818 {
10819 use strict;
10820 use warnings::register;
10821 use Module::Generic;
10822 use parent qw( Module::Generic::Dynamic );
10823 };
10824  
10825 1;
10826  
10827 EOT
10828 local $@;
10829 my $rc = eval( $perl );
10830 die( "Unable to dynamically create module \"$class\" for field \"$field\" based on our own class \"", ( ref( $self ) || $self ), "\": $@" ) if( $@ );
10831 }
10832  
10833 if( @_ )
10834 {
10835 my $hash = shift( @_ );
10836 my $o = $self->__instantiate_object( $field, $class, $hash );
10837 $data->{ $field } = $o;
10838 }
10839  
10840 if( !$data->{ $field } || !$self->_is_object( $data->{ $field } ) )
10841 {
10842 my $o = $data->{ $field } = $self->__instantiate_object( $field, $class, $data->{ $field } );
10843 }
10844 return( $data->{ $field } );
10845 }
10846 PERL
10847 # NOTE: _set_symbol()
10848 _set_symbol => <<'PERL',
10849 # $o->_set_symbol(
10850 # class => 'Foo::Bar',
10851 # variable => '$some_var',
10852 # value => 'some value',
10853 # filename => '/some/where/file.pl',
10854 # start_line => 10,
10855 # end_line => 15,
10856 # );
10857 sub _set_symbol
10858 {
10859 my $self = shift( @_ );
10860 my $opts = $self->_get_args_as_hash( @_ );
10861 if( !CORE::exists( $opts->{class} ) )
10862 {
10863 $opts->{class} = ( ref( $self ) || $self );
10864 }
10865  
10866 if( !defined( $opts->{class} ) ||
10867 !CORE::length( $opts->{class} // '' ) )
10868 {
10869 return( $self->error( "No class name was provided to add symbol." ) );
10870 }
10871 elsif( $opts->{class} !~ /^[a-zA-Z_][a-zA-Z0-9_]+(?:\:{2}[a-zA-Z0-9_]+)*$/ )
10872 {
10873 return( $self->error( "Invalid class name '$opts->{class}'" ) );
10874 }
10875 elsif( !CORE::exists( $opts->{variable} ) ||
10876 !defined( $opts->{variable} ) ||
10877 !CORE::length( $opts->{variable} // '' ) )
10878 {
10879 return( $self->error( "No variable was aprovided." ) );
10880 }
10881 my $class = $opts->{class};
10882 my $var = $opts->{variable};
10883 no strict 'refs';
10884 my $ns = \%{$class . '::'};
10885 require Symbol;
10886 my $map =
10887 {
10888 '$' => 'SCALAR',
10889 '@' => 'ARRAY',
10890 '%' => 'HASH',
10891 '&' => 'CODE',
10892 '*' => 'GLOB',
10893 };
10894 my $defaults =
10895 {
10896 ARRAY => [],
10897 CODE => sub{},
10898 HASH => {},
10899 GLOB => Symbol::geniosym,
10900 SCALAR => \undef,
10901 };
10902 my( $name, $sigil, $type );
10903 if( CORE::exists( $opts->{type} ) &&
10904 defined( $opts->{type} ) &&
10905 CORE::exists( $defaults->{uc( $opts->{type} )} ) )
10906 {
10907 $sigil = substr( $name = $var, 0, 1, '' );
10908 $type = $opts->{type};
10909 }
10910 elsif( exists( $map->{ substr( $var, 0, 1 ) } ) )
10911 {
10912 $sigil = substr( $name = $var, 0, 1, '' );
10913 $type = $map->{ $sigil };
10914 }
10915 else
10916 {
10917 # $type = $map->{ '' };
10918 return( $self->error( "Unsupported variable ${var}. You can only set array, hash, scalar, code or glob" ) );
10919 }
10920  
10921 my $value;
10922 if( CORE::exists( $opts->{value} ) &&
10923 defined( $opts->{value} ) )
10924 {
10925 my $refval = ( Scalar::Util::reftype( $opts->{value} ) // '' );
10926 if( $type eq 'SCALAR' &&
10927 ( $refval eq 'HASH' || $refval eq 'ARRAY' || $refval eq 'CODE' ) )
10928 {
10929 $type = $refval;
10930 $value = \$opts->{value};
10931 }
10932 else
10933 {
10934 $value = $opts->{value};
10935 }
10936  
10937 if( $type eq 'ARRAY' ||
10938 $type eq 'CODE' ||
10939 $type eq 'HASH' ||
10940 $type eq 'GLOB' )
10941 {
10942 return( $self->error( "Value of type ${refval} provided for ${var} is incompatible." ) ) if( $refval ne $type );
10943 }
10944 elsif( $refval ne 'SCALAR' &&
10945 $refval ne 'REF' &&
10946 $refval ne 'LVALUE' &&
10947 $refval ne 'REGEXP' &&
10948 $refval ne 'VSTRING' )
10949 {
10950 return( $self->error( "Value of type ${refval} provided for ${var} cannot be used." ) );
10951 }
10952  
10953 # cheap fail-fast check for PERLDBf_SUBLINE and '&'
10954 if( $^P &&
10955 ( $^P & 0x10 ) &&
10956 $sigil eq '&' )
10957 {
10958 no warnings 'once';
10959 my $filename = $opts->{filename};
10960 my $start_line = $opts->{start_line};
10961 ( $filename, $start_line ) = (caller)[1,2] if( !defined( $filename ) );
10962 my $end_line = $opts->{end_line} || ( $start_line ||= 0 );
10963 # <http://perldoc.perl.org/perldebguts.html#Debugger-Internals>
10964 $DB::sub{ $class . '::' . $name } = "${filename}:${start_line}-${end_line}";
10965 }
10966 }
10967  
10968 if( defined( $value ) )
10969 {
10970 no strict 'refs';
10971 no warnings 'redefine';
10972 *{ $class . '::' . $name } = ref( $value )
10973 ? $value
10974 : \$value;
10975 }
10976 else
10977 {
10978 no strict 'refs';
10979 # Broken ISA assignment
10980 if( $] < 5.012 &&
10981 $name eq 'ISA' )
10982 {
10983 *{ $class . '::' . $name };
10984 }
10985 else
10986 {
10987 *{ $class . '::' . $name } = $defaults->{ $type };
10988 }
10989 }
10990 }
10991 PERL
10992 # NOTE: _subinfo()
10993 _subinfo => <<'PERL',
10994 # Credits: Inspired from Sub::Identify
10995 # Usage:
10996 # my $name = $self->_subinfo(); # auto-detect (best for named subs)
10997 # my $name = $self->_subinfo(__SUB__); # explicit (works with closures/anon)
10998 # my @info = $self->_subinfo(__SUB__); # list context = full info
10999 sub _subinfo
11000 {
11001 my $self = shift( @_ );
11002 my $coderef;
11003 if( @_ )
11004 {
11005 # Something was provided to us, but not suitable.
11006 $coderef = shift( @_ ) ||
11007 return( $self->error( 'No subroutine code reference was provided. Call it like this: \$self->_subinfo(__SUB__)' ) );
11008 }
11009 # Auto-detect via caller if no argument was passed
11010 else
11011 {
11012 my( $pkg, $file, $line, $subname ) = caller(1);
11013 if( $subname )
11014 {
11015 # works well for named subs
11016 $coderef = \&{ $subname };
11017 }
11018 else
11019 {
11020 return( $self->error( "Could not auto-detect current subroutine" ) );
11021 }
11022 }
11023  
11024  
11025  
11026 # We make sure we are dealing with a code reference.
11027 unless( ref( $coderef ) eq 'CODE' )
11028 {
11029 return( $self->error( 'Value provided to _subinfo is not a code reference. Call it like this: $self->_subinfo(__SUB__)' ) );
11030 }
11031 require B;
11032 my $cv = B::svref_2object( $coderef );
11033 # We make sure it is a valid CV
11034 $cv->isa( 'B::CV' ) ||
11035 return( $self->error( "Not a subroutine CV (got ", ref( $cv ), ")." ) );
11036  
11037 my $gv = $cv->GV;
11038  
11039 # If GV is undefined (possible in some edge cases with anonymous subs), bail out
11040 unless( $gv && !$gv->isa( 'B::SPECIAL' ) )
11041 {
11042 return( $self->error( 'Could not get GV for subroutine' ) );
11043 }
11044  
11045 my $stash = $gv->STASH;
11046 my $name = $gv->NAME;
11047 my $class = $stash ? $stash->NAME : '';
11048 my $file = $gv->FILE;
11049 my $line = $gv->LINE;
11050 my $is_anon = ( $name eq '__ANON__' ) ? 1 : 0;
11051 my $is_closure = 0;
11052  
11053 # This works well under perl v5.16.0 through v5.40.0
11054 # See unit tests t/39.subinfo.t
11055 my $padlist = eval{ $cv->PADLIST };
11056 if( $padlist )
11057 {
11058 my $names = eval{ $padlist->can( 'NAMES' ) ? $padlist->NAMES : $padlist->ARRAYelt( 0 ) };
11059  
11060 if( $names )
11061 {
11062 for( my $i = 0; $i <= $names->MAX; $i++ )
11063 {
11064 my $padname = eval{ $names->ARRAYelt( $i ) };
11065 next if( !$padname || $padname->isa( 'B::SPECIAL' ) );
11066  
11067 my $flags = eval{ $padname->FLAGS } || 0;
11068  
11069 if( $padname->can( 'PVX' ) )
11070 {
11071 my $pv = eval{ $padname->PVX } // '';
11072 next if( $pv !~ /^[\$\@\%\&]/ );
11073  
11074 if( defined( &B::SVf_FAKE ) && ( $flags & B::SVf_FAKE ) )
11075 {
11076 $is_closure = 1;
11077 last;
11078 }
11079 }
11080 elsif( $padname->can( 'FLAGS' ) )
11081 {
11082 if( defined( &B::PADNAMEf_OUTER ) && ( $flags & B::PADNAMEf_OUTER ) )
11083 {
11084 $is_closure = 1;
11085 last;
11086 }
11087 }
11088 }
11089 }
11090 }
11091 # my $is_xsub = ( $cv->FLAGS & B::CVf_XSUB ) ? 1 : 0;
11092 my $is_xsub = ( defined( &B::CVf_XSUB ) && ( $cv->FLAGS & B::CVf_XSUB ) ) ? 1 : 0;
11093 # e.g. '$$@' or empty string
11094 my $prototype = $cv->PV // '';
11095  
11096 # Construct fully qualified name
11097 my $full_name = ( $class ? $class . '::' : '' ) . $name;
11098 return( $name ) if( !wantarray );
11099 return( $name, $full_name, $class, $file, $line, $is_anon, $is_closure, $is_xsub, $prototype,
11100 {
11101 name => $name,
11102 fullname => $full_name,
11103 class => $class,
11104 package => $class,
11105 file => $file,
11106 line => $line,
11107 is_anon => $is_anon,
11108 is_closure => $is_closure,
11109 is_xsub => $is_xsub,
11110 prototype => $prototype,
11111 });
11112 }
11113 PERL
11114 # NOTE: _subname()
11115 _subname => <<'PERL',
11116 # Credits: Inspired from Sub::Identify
11117 # Usage:
11118 # my $name = $self->_subname(); # auto-detect (best for named subs)
11119 # my $name = $self->_subname(__SUB__); # explicit (works with closures/anon)
11120 sub _subname { return( scalar( shift->_subinfo( @_ ) ) ); }
11121 PERL
11122 # NOTE: as_hash()
11123 as_hash => <<'PERL',
11124 sub as_hash
11125 {
11126 my $self = shift( @_ );
11127 my $p = $self->_get_args_as_hash( @_ );
11128 # $p = shift( @_ ) if( scalar( @_ ) == 1 && ref( $_[0] ) eq 'HASH' );
11129 $p->{convert_array} //= 1;
11130 my $me = $self->_obj2h;
11131 my $seen = $p->{seen} || {};
11132 my $levels = $p->{levels} || [];
11133 my $keys = $p->{fields} || [];
11134  
11135 my $added_subs = CORE::exists( $me->{_added_method} ) && ref( $me->{_added_method} ) eq 'HASH'
11136 ? $me->{_added_method}
11137 : {};
11138
11139 my $crawl;
11140 $crawl = sub
11141 {
11142 my $this = shift( @_ );
11143 my $rval = ref( $this ) ? $this : \$this;
11144 my( $dataref, $class, $type, $id );
11145 my $strval = $dataref = $self->_str_val( $rval // 'undef' );
11146 # Parse $strval without using regexps, in order not to clobber $1, $2,...
11147 if( ( my $i = rindex( $dataref, '=' ) ) >= 0 )
11148 {
11149 $class = substr( $dataref, 0, $i );
11150 $dataref = substr( $dataref, $i + 1 );
11151 }
11152 if( ( my $i = index( $dataref, "(0x" ) ) >= 0 )
11153 {
11154 $type = substr( $dataref, 0, $i );
11155 $id = substr( $dataref, $i + 2, -1 );
11156 }
11157
11158 my $levels = shift( @_ );
11159 my $prefix = join( '->', @$levels ) . ':';
11160 $self->__message( 112, "$prefix Processing $strval of type $type and class ", ( $class // 'undef' ) );
11161
11162 if( defined( $class ) )
11163 {
11164 if( $class eq 'JSON::PP::Boolean' ||
11165 $class eq 'Module::Generic::Boolean' )
11166 {
11167 $self->__message( 113, "$prefix Converting known boolean object." );
11168 return( $$this ? 1 : 0 );
11169 }
11170 # NOTE: Not sure why I did this, because as_hash is about converting into hash, not stringifying everything
11171 # elsif( $this->can( 'as_hash' ) &&
11172 # overload::Overloaded( $this ) &&
11173 # overload::Method( $this, '""' ) )
11174 # {
11175 # $self->__message( 105, "$prefix object supports 'as_hash' and can stringify." );
11176 # return( $this . '' );
11177 # }
11178 elsif( $this->can( 'as_hash' ) )
11179 {
11180 if( $self->_is_array( $this ) && !$p->{convert_array} )
11181 {
11182 return( $this );
11183 }
11184 elsif( ++$seen->{ Scalar::Util::refaddr( $this ) } < 2 )
11185 {
11186 $self->__message( 112, "$prefix object supports 'as_hash', but cannot stringify." );
11187 my $old_debug;
11188 $old_debug = $this->debug if( $this->can( 'debug' ) );
11189 my $rv = $this->as_hash( { %$p, seen => $seen, levels => $levels } );
11190 $this->debug( $old_debug ) if( defined( $old_debug ) );
11191
11192 if( Scalar::Util::blessed( $rv ) )
11193 {
11194 $self->__message( 112, "$prefix $strval->as_hash() returned a blessed value (", $self->_str_val( $rv // 'undef' ), ")." );
11195 return( $crawl->( $rv, [@$levels, $strval] ) );
11196 }
11197 else
11198 {
11199 $self->__message( 112, "$prefix $strval->as_hash() returned a ", ( ref( $rv ) ? lc( ref( $rv ) ) . ' reference' : "string ($rv)" ) );
11200 return( $rv );
11201 }
11202 }
11203 else
11204 {
11205 $self->__message( 112, "$prefix $strval has already been procesed, avoid looping, returning it as-is." );
11206 return( $this );
11207 }
11208 }
11209 # If the object can be overloaded, and has no TO_JSON method we get its string representation here.
11210 # If it has a TO_JSON and we are asked to return data for json, we let the JSON module call the TO_JSON method
11211 # NOTE: Not sure why I did this, because as_hash is about converting into hash, not stringifying everything
11212 # elsif( overload::Overloaded( $this ) &&
11213 # overload::Method( $this, '""' ) )
11214 # {
11215 # $self->__message( 105, "$prefix $strval can stringify, and can it do $strval->TO_JSON ? ", ( $this->can( 'TO_JSON' ) ? 'yes' : 'no' ), " and is option 'json' enabled ? ", ( $p->{json} ? 'yes' : 'no' ), ". Stringifying it ? ", ( ( $p->{json} && $this->can( 'TO_JSON' ) ) ? 'no' : 'yes' ) );
11216 # if( $p->{json} && $this->can( 'TO_JSON' ) )
11217 # {
11218 # return( $this );
11219 # }
11220 # else
11221 # {
11222 # return( "$this" );
11223 # }
11224 # }
11225 else
11226 {
11227 $self->__message( 112, "$prefix $strval cannot do as_hash, returning it (", $self->_str_val( $this // 'undef' ), ") as-is." );
11228 return( $this );
11229 }
11230 }
11231 elsif( $type eq 'HASH' )
11232 {
11233 $self->__message( 112, "$prefix $strval is an hash reference." );
11234 my $hash = {};
11235 foreach my $k ( keys( %$this ) )
11236 {
11237 if( ref( $this->{ $k } ) )
11238 {
11239 if( ++$seen->{ Scalar::Util::refaddr( $this->{ $k } ) } > 1 )
11240 {
11241 next;
11242 }
11243 }
11244 my $rv = $crawl->( $this->{ $k }, [@$levels, $k] );
11245 $hash->{ $k } = $rv;
11246 }
11247 return( $hash );
11248 }
11249 elsif( $type eq 'ARRAY' )
11250 {
11251 $self->__message( 112, "$prefix $strval is an array reference." );
11252 my $array = [];
11253 for( my $i = 0; $i < scalar( @$this ); $i++ )
11254 {
11255 if( ref( $this->[$i] ) )
11256 {
11257 if( ++$seen->{ Scalar::Util::refaddr( $this->[$i] ) } > 1 )
11258 {
11259 next;
11260 }
11261 }
11262 my $rv = $crawl->( $this->[$i], [@$levels, "[$i]"] );
11263 push( @$array, $rv );
11264 }
11265 return( $array );
11266 }
11267 elsif( !ref( $this ) )
11268 {
11269 $self->__message( 113, "$prefix $strval is a ", ( defined( $this ) ? 'defined' : 'undefined' ), ' string.' );
11270 defined( $this )
11271 ? return( $this )
11272 : return;
11273 }
11274 elsif( $type eq 'SCALAR' )
11275 {
11276 $self->__message( 113, "$prefix $strval is a scalar reference." );
11277 my $str = $$this;
11278 return( \$str );
11279 }
11280 elsif( $type eq 'CODE' )
11281 {
11282 $self->__message( 113, "$prefix $strval is a code reference." );
11283 return( $this );
11284 }
11285 elsif( $type eq 'GLOB' )
11286 {
11287 $self->__message( 113, "$prefix $strval is a glob reference." );
11288 return( $this );
11289 }
11290 elsif( $type eq 'VSTRING' )
11291 {
11292 $self->__message( 113, "$prefix $strval is a version string." );
11293 return( $this );
11294 }
11295 else
11296 {
11297 die( "$prefix: Unknown reference ", $self->_str_val( $this // 'undef' ), " with value $this" );
11298 }
11299 };
11300
11301 $self->__message( 112, "Converting object ", $self->_str_val( $self // 'undef' ), " into an hash reference." );
11302 my $ref = {};
11303 my @keys = ();
11304 if( $self->_is_array( $keys ) && scalar( @$keys ) )
11305 {
11306 @keys = @$keys;
11307 }
11308 else
11309 {
11310 @keys = grep( !/^(debug|verbose)$/, keys( %$me ) );
11311 push( @keys, 'debug' ) if( $self->_has_symbol( 'debug' ) );
11312 push( @keys, 'verbose' ) if( $self->_has_symbol( 'verbose' ) );
11313 }
11314 foreach my $k ( @keys )
11315 {
11316 next if( substr( $k, 0, 1 ) eq '_' );
11317 next if( CORE::exists( $added_subs->{ $k } ) );
11318 my $rv = $crawl->( $me->{ $k }, [@$levels, $k] );
11319 next if( !defined( $rv ) );
11320 $ref->{ $k } = $rv;
11321 }
11322 return( $ref );
11323 }
11324 PERL
11325 # NOTE: clear()
11326 clear => <<'PERL',
11327 sub clear
11328 {
11329 return( shift->clear_error );
11330 }
11331 PERL
11332 # NOTE: clear_error()
11333 clear_error => <<'PERL',
11334 sub clear_error
11335 {
11336 my $self = shift( @_ );
11337 my $class = ref( $self ) || $self;
11338 my $this = $self->_obj2h;
11339 no strict 'refs';
11340 if( HAS_THREADS )
11341 {
11342 lock( ${ $class . '::ERROR' } );
11343 $this->{error} = ${ $class . '::ERROR' } = '';
11344 }
11345 else
11346 {
11347 $this->{error} = ${ $class . '::ERROR' } = '';
11348 }
11349 return( $self );
11350 }
11351 PERL
11352 # NOTE: clone()
11353 clone => <<'PERL',
11354 sub clone
11355 {
11356 my $self = shift( @_ );
11357 require Clone;
11358 my $new;
11359 # try-catch
11360 local $@;
11361 if( @_ )
11362 {
11363 if( scalar( @_ ) > 1 )
11364 {
11365 return( $self->error( "clone() requires zero or 1 argument, at most, and it must be a reference." ) );
11366 }
11367 elsif( !defined( $_[0] ) )
11368 {
11369 $self->__message( 5, "The value provided to clone is undefined." );
11370 # So, we return undef too.
11371 return;
11372 }
11373 elsif( !ref( $_[0] ) )
11374 {
11375 return( $self->error( "The value provided is not a reference." ) );
11376 }
11377 my $this = shift( @_ );
11378 $new = eval{ Clone::clone( $this ) };
11379 if( $@ )
11380 {
11381 return( $self->error( "Error cloning reference provided \"", $self->_str_val( $this ), "\": $@" ) );
11382 }
11383 }
11384 else
11385 {
11386 $new = eval
11387 {
11388 if( $self->_is_object( $self ) )
11389 {
11390 Clone::clone( $self );
11391 }
11392 else
11393 {
11394 $self->new;
11395 }
11396 };
11397 if( $@ )
11398 {
11399 return( $self->error( "Error cloning object \"", $self->_str_val( $self // 'undef' ), "\": $@" ) );
11400 }
11401 }
11402 return( $new );
11403 }
11404 PERL
11405 # NOTE: colour_close()
11406 colour_close => <<'PERL',
11407 sub colour_close { return( shift->_set_get( 'colour_close', @_ ) ); }
11408 PERL
11409 # NOTE: colour_closest()
11410 colour_closest => <<'PERL',
11411 sub colour_closest
11412 {
11413 my $self = shift( @_ );
11414 my $colour = uc( shift( @_ ) );
11415 my $this = $self->_obj2h;
11416 my $colours =
11417 {
11418 '000000000' => 'black',
11419 '000000255' => 'blue',
11420 '000255000' => 'green',
11421 '000255255' => 'cyan',
11422 '255000000' => 'red',
11423 '255000255' => 'magenta',
11424 '255255000' => 'yellow',
11425 '255255255' => 'white',
11426 };
11427 my( $red, $green, $blue ) = ( '', '', '' );
11428 our $COLOUR_NAME_TO_RGB;
11429 if( $colour =~ /^[A-Z]+([A-Z\s]+)*$/ )
11430 {
11431 if( !scalar( keys( %$COLOUR_NAME_TO_RGB ) ) )
11432 {
11433 my $colour_data = $self->__colour_data;
11434 local $@;
11435 $COLOUR_NAME_TO_RGB = eval( $colour_data );
11436 if( $@ )
11437 {
11438 return( $self->error( "An error occurred loading data from __colour_data: $@" ) );
11439 }
11440 }
11441 if( CORE::exists( $COLOUR_NAME_TO_RGB->{ lc( $colour ) } ) )
11442 {
11443 ( $red, $green, $blue ) = @{$COLOUR_NAME_TO_RGB->{ lc( $colour ) }};
11444 }
11445 }
11446 # Colour all in decimal??
11447 elsif( $colour =~ /^\d{9}$/ )
11448 {
11449 $red = substr( $colour, 0, 3 );
11450 $green = substr( $colour, 3, 3 );
11451 $blue = substr( $colour, 6, 3 );
11452 }
11453 # Colour in hexadecimal, convert it
11454 elsif( $colour =~ /^[A-F0-9]+$/ )
11455 {
11456 $red = hex( substr( $colour, 0, 2 ) );
11457 $green = hex( substr( $colour, 2, 2 ) );
11458 $blue = hex( substr( $colour, 4, 2 ) );
11459 }
11460 # Clueless
11461 else
11462 {
11463 # Not undef, but rather empty string. Undef is associated with an error
11464 return( '' );
11465 }
11466 my $dec_colour = CORE::sprintf( '%3d%3d%3d', $red, $green, $blue );
11467 my $last = '';
11468 my @colours = reverse( sort( keys( %$colours ) ) );
11469 $red = CORE::sprintf( '%03d', $red );
11470 $green = CORE::sprintf( '%03d', $green );
11471 $blue = CORE::sprintf( '%03d', $blue );
11472 my $cur = CORE::sprintf( '%03d%03d%03d', $red, $green, $blue );
11473 my( $red_ok, $green_ok, $blue_ok ) = ( 0, 0, 0 );
11474 for( my $i = 0; $i < scalar( @colours ); $i++ )
11475 {
11476 my $r = CORE::sprintf( '%03d', substr( $colours[ $i ], 0, 3 ) );
11477 my $g = CORE::sprintf( '%03d', substr( $colours[ $i ], 3, 3 ) );
11478 my $b = CORE::sprintf( '%03d', substr( $colours[ $i ], 6, 3 ) );
11479
11480 my $r_p = CORE::sprintf( '%03d', substr( $colours[ $i - 1 ], 0, 3 ) );
11481 my $g_p = CORE::sprintf( '%03d', substr( $colours[ $i - 1 ], 3, 3 ) );
11482 my $b_p = CORE::sprintf( '%03d', substr( $colours[ $i - 1 ], 6, 3 ) );
11483
11484 if( $red == $r ||
11485 ( $red < $r && $red > int( $r / 2 ) ) ||
11486 ( $red > $r && $red < int( $r_p / 2 ) && $r_p ) ||
11487 $red > $r )
11488 {
11489 $red_ok++;
11490 }
11491
11492 if( $red_ok )
11493 {
11494 if( $green == $g ||
11495 ( $green < $g && $green > int( $g / 2 ) ) ||
11496 ( $green > $g && $green < int( $g_p / 2 ) && $g_p ) ||
11497 $green > $g )
11498 {
11499 $blue_ok++;
11500 }
11501 }
11502
11503 if( $blue_ok )
11504 {
11505 if( $blue == $b ||
11506 ( $blue < $b && $blue > int( $b / 2 ) ) ||
11507 ( $blue > $b && $blue < int( $b_p / 2 ) && $b_p ) ||
11508 $blue > $b )
11509 {
11510 $last = $colours[ $i ];
11511 last;
11512 }
11513 }
11514 }
11515 return( $colours->{ $last } );
11516 }
11517 PERL
11518 # NOTE: colour_format()
11519 colour_format => <<'PERL',
11520 sub colour_format
11521 {
11522 my $self = shift( @_ );
11523 # style, colour or color and text
11524 my $opts = shift( @_ );
11525 return( $self->error( "Parameter hash provided is not an hash reference." ) ) if( !$self->_is_hash( $opts ) );
11526 my $this = $self->_obj2h;
11527 # To make it possible to use either text or message property
11528 $opts->{text} = CORE::delete( $opts->{message} ) if( CORE::length( $opts->{message} ) && !CORE::length( $opts->{text} ) );
11529 return( $self->error( "No text was provided to format." ) ) if( !CORE::length( $opts->{text} ) );
11530  
11531 $opts->{colour} //= CORE::delete( $opts->{color} ) || CORE::delete( $opts->{fg_colour} ) || CORE::delete( $opts->{fg_color} ) || CORE::delete( $opts->{fgcolour} ) || CORE::delete( $opts->{fgcolor} );
11532 $opts->{bgcolour} //= CORE::delete( $opts->{bgcolor} ) || CORE::delete( $opts->{bg_colour} ) || CORE::delete( $opts->{bg_color} );
11533  
11534 my $bold = "\e[1m";
11535 my $underline = "\e[4m";
11536 my $reverse = "\e[7m";
11537 my $normal = "\e[m";
11538 my $cls = "\e[H\e[2J";
11539 my $styles =
11540 {
11541 # Bold
11542 b => 1,
11543 bold => 1,
11544 strong => 1,
11545 # Italic
11546 i => 3,
11547 italic => 3,
11548 # Underline
11549 u => 4,
11550 underline => 4,
11551 underlined => 4,
11552 blink => 5,
11553 # Reverse
11554 r => 7,
11555 reverse => 7,
11556 reversed => 7,
11557 # Concealed
11558 c => 8,
11559 conceal => 8,
11560 concealed => 8,
11561 strike => 9,
11562 striked => 9,
11563 striken => 9,
11564 };
11565  
11566 my $round = sub
11567 {
11568 my( $num ) = @_;
11569 my $res;
11570 if( $num >= 0 )
11571 {
11572 $res = CORE::int( $num + 0.5 );
11573 }
11574 else
11575 {
11576 $res = -CORE::int( -$num + 0.5 );
11577 }
11578 return( $res );
11579 };
11580  
11581 my $convert_24_To_8bits = sub
11582 {
11583 my( $r, $g, $b ) = @_;
11584 return( ( POSIX::floor( $r * 7 / 255 ) << 5 ) +
11585 ( POSIX::floor( $g * 7 / 255 ) << 2 ) +
11586 ( POSIX::floor( $b * 3 / 255 ) )
11587 );
11588 };
11589  
11590 # opacity * original + (1-opacity)*background = resulting pixel
11591 # https://stackoverflow.com/a/746934/4814971
11592 my $colour_with_alpha = sub
11593 {
11594 my( $r, $g, $b, $a, $bg ) = @_;
11595 ## Assuming a white background (255)
11596 my( $bg_r, $bg_g, $bg_b ) = ( 255, 255, 255 );
11597 if( ref( $bg ) eq 'HASH' )
11598 {
11599 ( $bg_r, $bg_g, $bg_b ) = @$bg{qw( red green blue )};
11600 }
11601 $r = $round->( ( $a * $r ) + ( ( 1 - $a ) * $bg_r ) );
11602 $g = $round->( ( $a * $g ) + ( ( 1 - $a ) * $bg_g ) );
11603 $b = $round->( ( $a * $b ) + ( ( 1 - $a ) * $bg_b ) );
11604 return( [$r, $g, $b] );
11605 };
11606  
11607 my $check_colour = sub
11608 {
11609 my $col = shift( @_ );
11610 # $colours or $bg_colours
11611 my $map = shift( @_ );
11612 my $code;
11613 my $light;
11614 # Example: 'light red' or 'light_red'
11615 if( $col =~ /^(?:(?<light>bright|light)[[:blank:]\_]+)?
11616 (?<colour>
11617 (?:[a-zA-Z]+)(?:[[:blank:]]+\w+)?
11618 |
11619 (?<rgb_type>rgb[a]?)\([[:blank:]]*(?<red>\d{1,3})[[:blank:]]*\,[[:blank:]]*(?<green>\d{1,3})[[:blank:]]*\,[[:blank:]]*(?<blue>\d{1,3})
11620 (?:[[:blank:]]*\,[[:blank:]]*(?<opacity>\d(?:\.\d+)?))?[[:blank:]]*
11621 \)
11622 )$/xi )
11623 {
11624 my %regexp = %+;
11625 ( $light, $col ) = ( $+{light}, $+{colour} );
11626 if( CORE::length( $+{rgb_type} ) &&
11627 CORE::length( $+{red} ) &&
11628 CORE::length( $+{green} ) &&
11629 CORE::length( $+{blue} ) )
11630 {
11631 if( $+{opacity} || $light )
11632 {
11633 my $opacity = CORE::length( $+{opacity} )
11634 ? $+{opacity}
11635 : $light
11636 ? 0.5
11637 : 1;
11638 $col = CORE::sprintf( 'rgba(%03d%03d%03d,%.1f)', $+{red}, $+{green}, $+{blue}, $opacity );
11639 }
11640 else
11641 {
11642 $col = CORE::sprintf( 'rgb(%03d%03d%03d)', $+{red}, $+{green}, $+{blue} );
11643 }
11644 }
11645 else
11646 {
11647 }
11648 }
11649 elsif( $col =~ /^(?<rgb_type>rgb[a]?)\([[:blank:]]*(?<red>\d{1,3})[[:blank:]]*\,[[:blank:]]*(?<green>\d{1,3})[[:blank:]]*\,[[:blank:]]*(?<blue>\d{1,3})[[:blank:]]*(?:\,[[:blank:]]*(?<opacity>\d(?:\.\d+)?))?[[:blank:]]*\)$/i )
11650 {
11651 if( $+{opacity} )
11652 {
11653 $col = CORE::sprintf( 'rgba(%03d%03d%03d,%.1f)', $+{red}, $+{green}, $+{blue}, $+{opacity} );
11654 }
11655 else
11656 {
11657 $col = CORE::sprintf( '%03d%03d%03d', $+{red}, $+{green}, $+{blue} );
11658 }
11659 }
11660 else
11661 {
11662 }
11663  
11664 my $col_ref;
11665 if( $col =~ /^rgb[a]?\((?<red>\d{3})(?<green>\d{3})(?<blue>\d{3})\)$/i )
11666 {
11667 $col_ref = {};
11668 %$col_ref = %+;
11669 return({
11670 _24bits => [@$col_ref{qw( red green blue )}],
11671 _8bits => $convert_24_To_8bits->( @$col_ref{qw( red green blue )} )
11672 });
11673 }
11674 # Treating opacity to make things lighter; not ideal, but standard scheme
11675 elsif( $col =~ /^rgba\((?<red>\d{3})(?<green>\d{3})(?<blue>\d{3})[[:blank:]]*\,[[:blank:]]*(?<opacity>\d(?:\.\d)?)\)$/i )
11676 {
11677 $col_ref = {};
11678 %$col_ref = %+;
11679 if( $+{opacity} )
11680 {
11681 my $opacity = $+{opacity};
11682 my $bg;
11683 if( $opts->{bgcolour} )
11684 {
11685 $bg = $self->colour_to_rgb( $opts->{bgcolour} );
11686 }
11687 my $new_col = $colour_with_alpha->( @$col_ref{qw( red green blue )}, $opacity, $bg );
11688 @$col_ref{qw( red green blue )} = @$new_col;
11689 }
11690 return({
11691 _24bits => [@$col_ref{qw( red green blue )}],
11692 _8bits => $convert_24_To_8bits->( @$col_ref{qw( red green blue )} )
11693 });
11694 }
11695 elsif( $self->__message( 109, "Checking if rgb value exists for colour '$col'" ) &&
11696 ( $col_ref = $self->colour_to_rgb( $col ) ) )
11697 {
11698 # $code = $map->{ $col };
11699 return({
11700 _24bits => [@$col_ref{qw( red green blue )}],
11701 _8bits => $convert_24_To_8bits->( @$col_ref{qw( red green blue )} )
11702 });
11703 }
11704 else
11705 {
11706 return( {} );
11707 }
11708 # my $is_bg = ( CORE::substr( $code, 0, 1 ) == 4 );
11709 # if( CORE::length( $code ) && $light )
11710 # {
11711 # ## If the colour is a background colour, replace 4 by 10 (e.g.: 42 becomes 103)
11712 # ## and if foreground colour, replace 3 by 9
11713 # CORE::substr( $code, 0, 1 ) = ( $is_bg ? 10 : 9 );
11714 # }
11715 # return( $code );
11716 };
11717 my $data = [];
11718 my $data8 = [];
11719 my $params = [];
11720 # 8 bits parameters compatible
11721 my $params8 = [];
11722 if( $opts->{colour} || $opts->{color} || $opts->{fgcolour} || $opts->{fgcolor} || $opts->{fg_colour} || $opts->{fg_color} )
11723 {
11724 $opts->{colour} ||= CORE::delete( $opts->{color} ) || CORE::delete( $opts->{fg_colour} ) || CORE::delete( $opts->{fg_color} ) || CORE::delete( $opts->{fgcolour} ) || CORE::delete( $opts->{fgcolor} );
11725 # my $col_ref = $check_colour->( $opts->{colour}, $colours );
11726 my $col_ref = $check_colour->( $opts->{colour} );
11727 # CORE::push( @$params, $col ) if( CORE::length( $col ) );
11728 if( scalar( keys( %$col_ref ) ) )
11729 {
11730 CORE::push( @$params8, sprintf( '38;5;%d', $col_ref->{_8bits} ) );
11731 CORE::push( @$params, sprintf( '38;2;%d;%d;%d', @{$col_ref->{_24bits}} ) );
11732 }
11733 else
11734 {
11735 }
11736 }
11737 if( $opts->{bgcolour} || $opts->{bgcolor} || $opts->{bg_colour} || $opts->{bg_color} )
11738 {
11739 $opts->{bgcolour} ||= CORE::delete( $opts->{bgcolor} ) || CORE::delete( $opts->{bg_colour} ) || CORE::delete( $opts->{bg_color} );
11740 # my $col_ref = $check_colour->( $opts->{bgcolour}, $bg_colours );
11741 my $col_ref = $check_colour->( $opts->{bgcolour} );
11742 ## CORE::push( @$params, $col ) if( CORE::length( $col ) );
11743 if( scalar( keys( %$col_ref ) ) )
11744 {
11745 CORE::push( @$params8, sprintf( '48;5;%d', $col_ref->{_8bits} ) );
11746 CORE::push( @$params, sprintf( '48;2;%d;%d;%d', @{$col_ref->{_24bits}} ) );
11747 }
11748 else
11749 {
11750 }
11751 }
11752 if( $opts->{style} )
11753 {
11754 my $those_styles = [CORE::split( /\|/, $opts->{style} )];
11755 foreach my $s ( @$those_styles )
11756 {
11757 if( CORE::exists( $styles->{lc($s)} ) )
11758 {
11759 CORE::push( @$params, $styles->{lc($s)} );
11760 # We add the 8 bits compliant version only if any colour was provided, i.e.
11761 # This is not just a style definition
11762 CORE::push( @$params8, $styles->{lc($s)} ) if( scalar( @$params8 ) );
11763 }
11764 }
11765 }
11766 CORE::push( @$data, "\e[" . CORE::join( ';', @$params8 ) . "m" ) if( scalar( @$params8 ) );
11767 CORE::push( @$data, "\e[" . CORE::join( ';', @$params ) . "m" ) if( scalar( @$params ) );
11768 # If the text contains libe breaks, we must stop the formatting before, or else there would be an ugly formatting on the entire screen following the line break
11769 if( scalar( @$params ) && $opts->{text} =~ /\n+/ )
11770 {
11771 my $text_parts = [CORE::split( /\n/, $opts->{text} )];
11772 my $fmt = CORE::join( '', @$data );
11773 my $fmt8 = CORE::join( '', @$data8 );
11774 for( my $i = 0; $i < scalar( @$text_parts ); $i++ )
11775 {
11776 # Empty due to \n repeated
11777 next if( !CORE::length( $text_parts->[$i] ) );
11778 $text_parts->[$i] = $fmt . $text_parts->[$i] . $normal;
11779 }
11780 $opts->{text} = CORE::join( "\n", @$text_parts );
11781 CORE::push( @$data, $opts->{text} );
11782 }
11783 else
11784 {
11785 CORE::push( @$data, $opts->{text} );
11786 CORE::push( @$data, $normal ) if( scalar( @$params ) );
11787 }
11788 return( CORE::join( '', @$data ) );
11789 }
11790 PERL
11791 # NOTE: colour_max_depth()
11792 colour_max_depth => <<'PERL',
11793 sub colour_max_depth { return( shift->_set_get( 'colour_max_depth', @_ ) ); }
11794 PERL
11795 # NOTE: colour_open()
11796 colour_open => <<'PERL',
11797 sub colour_open { return( shift->_set_get( 'colour_open', @_ ) ); }
11798 PERL
11799 # NOTE: colour_parse()
11800 colour_parse => <<'PERL',
11801 # Term definition:
11802 # - delimiter is one or more characters used to delimit the start and end of a formatting tag
11803 # - tag: is a container of colour formatting parameters whose perimeter is marked by 'delimiter'. It is also a closing tag, such as </>, or {/} or custom ones specified.
11804 sub colour_parse
11805 {
11806 my $self = shift( @_ );
11807 my $txt = join( '', @_ );
11808 my $this = $self->_obj2h;
11809 my @opens = ( '{', '<' );
11810 my @closes = ( '}', '>' );
11811 my $cust_open = $self->colour_open;
11812 my $cust_close = $self->colour_close;
11813 # If we have custom open / close delimiters, we must make sure we have even pairs
11814 # Custom or explicit open and close delimiters replace our prospective set of delimiters, i.e. instead of guessing, we are given explicit delimiters to use.
11815 if( defined( $cust_open ) &&
11816 length( $cust_open ) &&
11817 defined( $cust_close ) &&
11818 length( $cust_close ) &&
11819 !ref( $cust_open ) &&
11820 !ref( $cust_close ) )
11821 {
11822 if( $cust_open eq $cust_close )
11823 {
11824 warn( "Warning only: you are using the same delimiter ($cust_open) for open and close!" );
11825 }
11826 else
11827 {
11828 @opens = ( $cust_open );
11829 @closes = ( $cust_close );
11830 }
11831 }
11832 # This will prevent an opening delimiter such as '{' to be inadvertently caught as a perl string declaration if a dollar sign '$' is prepended, such as '${blue}Hello world{/}'
11833 my $open = join( '|', map( quotemeta( $_ ), @opens ) );
11834 my $close = join( '|', map( quotemeta( $_ ), @closes ) );
11835 # Create a quick map of open delimiter to its corresponding closing one
11836 my $map = {}; @$map{ @opens } = @closes;
11837 my $force_tty = $self->force_tty;
11838 my $is_tty = defined( $force_tty ) ? $force_tty : $self->_is_tty;
11839 $self->__message( 120, "Is tty enabled ? ", ( $is_tty ? 'yes' : 'no' ) );
11840 my $max_depth = $self->colour_max_depth // 10;
11841 my $normal = "\e[m";
11842  
11843 my $colour_re = qr{
11844 (?:
11845 (?:bright|light)
11846 [[:blank:]]+
11847 )?
11848 (?:
11849 (?:
11850 [a-zA-Z]+
11851 (?:[[:blank:]]+[\w\-]+)?
11852 )
11853 |
11854 (?:
11855 rgb[a]?\(
11856 [[:blank:]]*\d{1,3}[[:blank:]]*\,
11857 [[:blank:]]*\d{1,3}[[:blank:]]*\,
11858 [[:blank:]]*\d{1,3}[[:blank:]]*
11859 (?:\,[[:blank:]]*\d(?:\.\d)?)?
11860 [[:blank:]]*
11861 \)
11862 )
11863 |
11864 (?:
11865 rgb[a]?\(
11866 (?<red>\d{3})
11867 (?<green>\d{3})
11868 (?<blue>\d{3})
11869 (?:
11870 [[:blank:]]*\,[[:blank:]]*
11871 (?<opacity>
11872 \d(?:\.\d)?
11873 )
11874 )?
11875 \)
11876 )
11877 )
11878 }x;
11879 my $style_re = qr/(?:bold|faint|italic|underline|blink|reverse|conceal|strike)/;
11880  
11881 # NOTE: colour_format()
11882 my $colour_format = sub
11883 {
11884 # style, colour or color and text
11885 my $opts = shift( @_ );
11886 # To make it possible to use either text or message property
11887 # $opts->{text} = CORE::delete( $opts->{message} ) if( CORE::length( $opts->{message} ) && !CORE::length( $opts->{text} ) );
11888  
11889 $opts->{colour} //= CORE::delete( $opts->{color} ) || CORE::delete( $opts->{fg_colour} ) || CORE::delete( $opts->{fg_color} ) || CORE::delete( $opts->{fgcolour} ) || CORE::delete( $opts->{fgcolor} );
11890 $opts->{bgcolour} //= CORE::delete( $opts->{bgcolor} ) || CORE::delete( $opts->{bg_colour} ) || CORE::delete( $opts->{bg_color} );
11891  
11892 my $bold = "\e[1m";
11893 my $underline = "\e[4m";
11894 my $reverse = "\e[7m";
11895 my $normal = "\e[m";
11896 my $cls = "\e[H\e[2J";
11897 my $styles =
11898 {
11899 # Bold
11900 b => 1,
11901 bold => 1,
11902 strong => 1,
11903 # Italic
11904 i => 3,
11905 italic => 3,
11906 # Underline
11907 u => 4,
11908 underline => 4,
11909 underlined => 4,
11910 blink => 5,
11911 # Reverse
11912 r => 7,
11913 reverse => 7,
11914 reversed => 7,
11915 # Concealed
11916 c => 8,
11917 conceal => 8,
11918 concealed => 8,
11919 strike => 9,
11920 striked => 9,
11921 striken => 9,
11922 };
11923  
11924 my $round = sub
11925 {
11926 my( $num ) = @_;
11927 my $res;
11928 if( $num >= 0 )
11929 {
11930 $res = CORE::int( $num + 0.5 );
11931 }
11932 else
11933 {
11934 $res = -CORE::int( -$num + 0.5 );
11935 }
11936 return( $res );
11937 };
11938  
11939 # NOTE: convert_24_To_8bits()
11940 my $convert_24_To_8bits = sub
11941 {
11942 my( $r, $g, $b ) = @_;
11943 return( ( POSIX::floor( $r * 7 / 255 ) << 5 ) +
11944 ( POSIX::floor( $g * 7 / 255 ) << 2 ) +
11945 ( POSIX::floor( $b * 3 / 255 ) )
11946 );
11947 };
11948  
11949 # NOTE: colour_with_alpha()
11950 # opacity * original + (1-opacity)*background = resulting pixel
11951 # https://stackoverflow.com/a/746934/4814971
11952 my $colour_with_alpha = sub
11953 {
11954 my( $r, $g, $b, $a, $bg ) = @_;
11955 ## Assuming a white background (255)
11956 my( $bg_r, $bg_g, $bg_b ) = ( 255, 255, 255 );
11957 if( ref( $bg ) eq 'HASH' )
11958 {
11959 ( $bg_r, $bg_g, $bg_b ) = @$bg{qw( red green blue )};
11960 }
11961 $r = $round->( ( $a * $r ) + ( ( 1 - $a ) * $bg_r ) );
11962 $g = $round->( ( $a * $g ) + ( ( 1 - $a ) * $bg_g ) );
11963 $b = $round->( ( $a * $b ) + ( ( 1 - $a ) * $bg_b ) );
11964 return( [$r, $g, $b] );
11965 };
11966  
11967 # NOTE: check_colour()
11968 my $check_colour = sub
11969 {
11970 my $col = shift( @_ );
11971 # $colours or $bg_colours
11972 my $map = shift( @_ );
11973 my $code;
11974 my $light;
11975 # Example: 'light red' or 'light_red'
11976 if( $col =~ m{
11977 ^(?:
11978 (?<light>bright|light)
11979 [[:blank:]\_\-]+
11980 )?
11981 (?<colour>
11982 (?:
11983 (?:[a-zA-Z]+)(?:[[:blank:]]+\w+)?
11984 )
11985 |
11986 (?:
11987 (?<rgb_type>
11988 rgb[a]?
11989 )
11990 \(
11991 [[:blank:]]*(?<red>\d{1,3})[[:blank:]]*\,
11992 [[:blank:]]*(?<green>\d{1,3})[[:blank:]]*\,
11993 [[:blank:]]*(?<blue>\d{1,3})[[:blank:]]*
11994 (?:
11995 \,[[:blank:]]*
11996 (?<opacity>\d(?:\.\d+)?)
11997 )?
11998 [[:blank:]]*
11999 \)
12000 )
12001 )$
12002 }xi )
12003 {
12004 my %regexp = %+;
12005 ( $light, $col ) = ( $+{light}, $+{colour} );
12006 if( CORE::length( $+{rgb_type} ) &&
12007 CORE::length( $+{red} ) &&
12008 CORE::length( $+{green} ) &&
12009 CORE::length( $+{blue} ) )
12010 {
12011 if( $+{opacity} || $light )
12012 {
12013 my $opacity = CORE::length( $+{opacity} )
12014 ? $+{opacity}
12015 : $light
12016 ? 0.5
12017 : 1;
12018 $col = CORE::sprintf( 'rgba(%03d%03d%03d,%.1f)', $+{red}, $+{green}, $+{blue}, $opacity );
12019 }
12020 else
12021 {
12022 $col = CORE::sprintf( 'rgb(%03d%03d%03d)', $+{red}, $+{green}, $+{blue} );
12023 }
12024 }
12025 }
12026 elsif( $col =~ m{
12027 ^
12028 (?<rgb_type>rgb[a]?)
12029 \(
12030 [[:blank:]]*(?<red>\d{1,3})[[:blank:]]*\,
12031 [[:blank:]]*(?<green>\d{1,3})[[:blank:]]*\,
12032 [[:blank:]]*(?<blue>\d{1,3})[[:blank:]]*
12033 (?:
12034 \,[[:blank:]]*
12035 (?<opacity>
12036 \d(?:\.\d+)?
12037 )
12038 )?
12039 [[:blank:]]*
12040 \)$
12041 }xi )
12042 {
12043 if( $+{opacity} )
12044 {
12045 $col = CORE::sprintf( 'rgba(%03d%03d%03d,%.1f)', $+{red}, $+{green}, $+{blue}, $+{opacity} );
12046 }
12047 else
12048 {
12049 $col = CORE::sprintf( '%03d%03d%03d', $+{red}, $+{green}, $+{blue} );
12050 }
12051 }
12052  
12053 my $col_ref;
12054 if( $col =~ /^rgb[a]?\((?<red>\d{3})(?<green>\d{3})(?<blue>\d{3})\)$/i )
12055 {
12056 $col_ref = {};
12057 %$col_ref = %+;
12058 return({
12059 _24bits => [@$col_ref{qw( red green blue )}],
12060 _8bits => $convert_24_To_8bits->( @$col_ref{qw( red green blue )} )
12061 });
12062 }
12063 # Treating opacity to make things lighter; not ideal, but standard scheme
12064 elsif( $col =~ m{
12065 ^rgba
12066 \(
12067 (?<red>\d{3})
12068 (?<green>\d{3})
12069 (?<blue>\d{3})
12070 (?:
12071 [[:blank:]]*\,[[:blank:]]*
12072 (?<opacity>
12073 \d(?:\.\d)?
12074 )
12075 )?
12076 \)$
12077 }xi )
12078 {
12079 $col_ref = {};
12080 %$col_ref = %+;
12081 if( $+{opacity} )
12082 {
12083 my $opacity = $+{opacity};
12084 my $bg;
12085 if( $opts->{bgcolour} )
12086 {
12087 $bg = $self->colour_to_rgb( $opts->{bgcolour} );
12088 }
12089 my $new_col = $colour_with_alpha->( @$col_ref{qw( red green blue )}, $opacity, $bg );
12090 @$col_ref{qw( red green blue )} = @$new_col;
12091 }
12092 return({
12093 _24bits => [@$col_ref{qw( red green blue )}],
12094 _8bits => $convert_24_To_8bits->( @$col_ref{qw( red green blue )} )
12095 });
12096 }
12097 elsif( $self->__message( 109, "Checking if rgb value exists for colour '$col'" ) &&
12098 ( $col_ref = $self->colour_to_rgb( $col ) ) )
12099 {
12100 # $code = $map->{ $col };
12101 return({
12102 _24bits => [@$col_ref{qw( red green blue )}],
12103 _8bits => $convert_24_To_8bits->( @$col_ref{qw( red green blue )} )
12104 });
12105 }
12106 else
12107 {
12108 return({});
12109 }
12110 };
12111  
12112 my $data = [];
12113 my $data8 = [];
12114 my $params = [];
12115 # 8 bits parameters compatible
12116 my $params8 = [];
12117 if( $opts->{colour} ||
12118 $opts->{color} ||
12119 $opts->{fgcolour} ||
12120 $opts->{fgcolor} ||
12121 $opts->{fg_colour} ||
12122 $opts->{fg_color} )
12123 {
12124 $opts->{colour} ||= CORE::delete( $opts->{color} ) || CORE::delete( $opts->{fg_colour} ) || CORE::delete( $opts->{fg_color} ) || CORE::delete( $opts->{fgcolour} ) || CORE::delete( $opts->{fgcolor} );
12125 # my $col_ref = $check_colour->( $opts->{colour}, $colours );
12126 my $col_ref = $check_colour->( $opts->{colour} );
12127 # CORE::push( @$params, $col ) if( CORE::length( $col ) );
12128 if( scalar( keys( %$col_ref ) ) )
12129 {
12130 CORE::push( @$params8, sprintf( '38;5;%d', $col_ref->{_8bits} ) );
12131 CORE::push( @$params, sprintf( '38;2;%d;%d;%d', @{$col_ref->{_24bits}} ) );
12132 }
12133 }
12134 if( $opts->{bgcolour} ||
12135 $opts->{bgcolor} ||
12136 $opts->{bg_colour} ||
12137 $opts->{bg_color} )
12138 {
12139 $opts->{bgcolour} ||= CORE::delete( $opts->{bgcolor} ) || CORE::delete( $opts->{bg_colour} ) || CORE::delete( $opts->{bg_color} );
12140 # my $col_ref = $check_colour->( $opts->{bgcolour}, $bg_colours );
12141 my $col_ref = $check_colour->( $opts->{bgcolour} );
12142 ## CORE::push( @$params, $col ) if( CORE::length( $col ) );
12143 if( scalar( keys( %$col_ref ) ) )
12144 {
12145 CORE::push( @$params8, sprintf( '48;5;%d', $col_ref->{_8bits} ) );
12146 CORE::push( @$params, sprintf( '48;2;%d;%d;%d', @{$col_ref->{_24bits}} ) );
12147 }
12148 }
12149 if( $opts->{style} )
12150 {
12151 my $those_styles = [CORE::split( /\|/, $opts->{style} )];
12152 foreach my $s ( @$those_styles )
12153 {
12154 if( CORE::exists( $styles->{lc($s)} ) )
12155 {
12156 CORE::push( @$params, $styles->{lc($s)} );
12157 # We add the 8 bits compliant version only if any colour was provided, i.e.
12158 # This is not just a style definition
12159 CORE::push( @$params8, $styles->{lc($s)} ) if( scalar( @$params8 ) );
12160 }
12161 }
12162 }
12163 CORE::push( @$data, "\e[" . CORE::join( ';', @$params8 ) . "m" ) if( scalar( @$params8 ) );
12164 CORE::push( @$data, "\e[" . CORE::join( ';', @$params ) . "m" ) if( scalar( @$params ) );
12165 return( $data );
12166 };
12167  
12168 # NOTE: process_params()
12169 my $process_params = sub
12170 {
12171 my( $params ) = @_;
12172 return if( !defined( $params ) || !length( $params // '' ) );
12173 my $def = {};
12174 # Example: bold green underline on black
12175 if( $params =~ m{
12176 ^[[:blank:]]*
12177 (?:
12178 (?<style1>$style_re)
12179 [[:blank:]]+
12180 )?
12181 (?<fg_colour>$colour_re)
12182 (?:
12183 [[:blank:]]+
12184 (?<style2>$style_re)
12185 )?
12186 (?:
12187 [[:blank:]]+on[[:blank:]]+
12188 (?<bg_colour>$colour_re)
12189 )?
12190 [[:blank:]]*$
12191 }xi )
12192 {
12193 my $style = $+{style1} || $+{style2};
12194 my $fg = $+{fg_colour};
12195 my $bg = $+{bg_colour};
12196 $def =
12197 {
12198 style => $style,
12199 colour => $fg,
12200 bg_colour => $bg,
12201 };
12202 $self->__message( 120, "\$process_params->(): Params regular expression matched -> ", sub{ $self->Module::Generic::dump( $def ) } );
12203 }
12204 else
12205 {
12206 $self->__message( 120, "\$process_params->(): Params regular expression failed to match. Trying to eval '$params' instead." );
12207 # Only allow characters that make sense for hash-like parameters.
12208 # This forbids variables, code blocks, Perl ops, backticks, etc.
12209 if( $params =~ /[^a-zA-Z0-9_,\=>\s\h[:blank:]'"\|\(\)\.\-]/ )
12210 {
12211 $self->__message( 120, "\$process_params->(): Illegal characters found inside eval." );
12212 return;
12213 }
12214 # illegal functions that have no business being here, and could pass through the previous check
12215 elsif( $params =~ /\b(?:
12216 qx|system|open|exec|fork|require|use|eval|do|
12217 package|sub|BEGIN|UNITCHECK|CHECK|INIT|END|
12218 readpipe|sysopen|unlink|rename|chmod|chown|utime|truncate|mkdir|rmdir|opendir|readdir|closedir|glob
12219 )\b/i )
12220 {
12221 $self->__message( 120, "\$process_params->(): Illegal functions used inside eval." );
12222 return;
12223 }
12224  
12225 local $SIG{__WARN__} = sub{};
12226 local $SIG{__DIE__} = sub{};
12227 local $@;
12228 my @res = eval( $params );
12229 $self->__message( 120, "\$process_params->(): evaluating '$params' produced -> ", sub{ $self->Module::Generic::dump( \@res ) } );
12230 $def = { @res } if( scalar( @res ) && !( scalar( @res ) % 2 ) );
12231 if( $@ || ref( $def ) ne 'HASH' )
12232 {
12233 my $err = $@ || "Invalid styling \"${params}\"";
12234 $self->__message( 120, "\$process_params->(): Error evaluating '$params' -> $@" );
12235 $def = {};
12236 }
12237 }
12238  
12239 if( scalar( keys( %$def ) ) )
12240 {
12241 $self->__message( 120, "\$process_params->(): colour definition is: ", sub{ $self->Module::Generic::dump( $def ) } );
12242 my $ref = $colour_format->( $def );
12243 $self->__message( 120, "\$process_params->(): Returning -> ", sub{ $self->Module::Generic::dump( $ref ) } );
12244 return if( !$ref || !scalar( @$ref ) );
12245 return( $ref );
12246 }
12247 $self->__message( 120, "\$process_params->(): Returning nothing." );
12248 return;
12249 };
12250  
12251 # NOTE: parse()
12252 my $parse;
12253 $parse = sub
12254 {
12255 # $chunk is the text from position $pos until the end of the string, as provided by parent
12256 my $chunk = shift( @_ );
12257 my $args = shift( @_ ) || {};
12258 my $copy = $chunk;
12259 my $out = '';
12260 my $level = $args->{level} // 1;
12261 my $counter = $args->{counter} // 0;
12262 return( $chunk ) if( $level > $max_depth );
12263 my( $open_d, $close_d );
12264 # If we are given specific open and close delimiter use them, otherwise, use our list of candidates.
12265 # This only happens the first time we hist the text to parse and search for those delimiters.
12266 # Afterward, as a rule, we always stick to the same delimiters used. The user cannot mix delimiters in the same string.
12267 # We create Regexp object on purpose, so we can differentiate from plain string later in our code.
12268 # The initial '$open' and '$close' are simple strings, not Regexp object, so we can differentiate them:
12269 # Regexp -> confirmed open and close delimiters
12270 # Non-Regexp -> prospective open and close delimiters
12271 # Once the open and close delimiters are confirmed they never change.
12272 # $open_d = $args->{open} ? ( ref( $args->{open} ) ? $args->{open} : qr{(?<open_d>\Q$args->{open}\E)} ) : $open;
12273 # $close_d = $args->{close} ? ( ref( $args->{close} ) ? $args->{close} : qr{?<close_d>\Q$args->{close})} ) : $close;
12274 $open_d = $args->{open} ? $args->{open} : $open;
12275 $close_d = $args->{close} ? $args->{close} : $close;
12276 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Using \$open_d '$open_d', and \$close_d '$close_d' with closing counter '$counter'" );
12277 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Processing string '", ( $chunk // 'undef' ), "'" );
12278 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Have we inherited some formatting ? ", ( $args->{format} ? sub{ ' yes -> ' . $self->Module::Generic::dump( $args->{format} ) } : 'no' ) );
12279 # We found our closing mark
12280 if( defined( $args->{open} ) &&
12281 defined( $args->{close} ) &&
12282 $chunk =~ s/^(?<content>.*?)(${open_d}\/${close_d})// )
12283 {
12284 my $content = $+{content};
12285 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Text '", ( $copy // 'undef' ), "' is now '", ( $chunk // 'undef' ), "' and \$content is '", ( $content // 'undef' ), "' after removing a closing tag '$2'" );
12286 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Found some text content followed by a close tag '$2'. Checking if captured content contains an open one within data -> '", ( $content // 'undef' ), "'." );
12287 # Whether the parameters are in the form of 'bold underline red' or "style => 'bold', colour => 'red'", either way, the parameters must start with an alphabetic character. No space is allowed.
12288 # Also, since the opening delimiter may have more than 1 character, we check if the first character is '{' or '['.
12289 my $open_re = ( substr( $open_d, 0, 2 ) eq quotemeta('{') || substr( $open_d, 0, 2 ) eq quotemeta('[') )
12290 ? "(?<!\\\$)${open_d}"
12291 : $open_d;
12292 if( $content =~ /${open_re}(?=[a-zA-Z]+)/ )
12293 {
12294 # Found an opening delimiter before our closing tag, returning the text untouched.
12295 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Found an opening delimiter before our closing tag in text content captured (", ( $content // 'undef' ), "), most likely embedded formatting, continuing." );
12296 $chunk = $copy;
12297 }
12298 elsif( !$is_tty )
12299 {
12300 $out = $content;
12301 }
12302 else
12303 {
12304 $self->__message( 120, "\$parse->() [LEVEL ${level}]: No undesired open delimiter found. Do we have formatting ? ", ( $args->{format} ? 'yes' : 'no' ) );
12305 if( my $fmt_ref = $args->{format} )
12306 {
12307 # We cannot make the assumption that there are any formatting parameters found, and returned by $process_params
12308 # If there is nothing, then there is nothing to format, and we return the text as is.
12309 if( !scalar( @$fmt_ref ) )
12310 {
12311 # We do not format the $content
12312 }
12313 else
12314 {
12315 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Formatting was passed down to us, using it -> ", sub{ $self->Module::Generic::dump( $fmt_ref ) } );
12316 my $fmt = CORE::join( '', @$fmt_ref );
12317 # We differentiate text with and without new lines, because if there are multiple lines, we skip the empty ones.
12318 # However, if there are no multiple line, we surround that (possibly empty) line with the formatting and the normaliser.
12319 if( index( $content, "\n" ) != -1 )
12320 {
12321 my $text_parts = [CORE::split( /\n/, $content )];
12322 for( my $i = 0; $i < scalar( @$text_parts ); $i++ )
12323 {
12324 # Empty due to \n repeated
12325 next if( !CORE::length( $text_parts->[$i] ) );
12326 $text_parts->[$i] = $fmt . $text_parts->[$i] . $normal;
12327 }
12328 $content = CORE::join( "\n", @$text_parts );
12329 }
12330 else
12331 {
12332 $content = $fmt . $content . $normal;
12333 }
12334 }
12335 }
12336 else
12337 {
12338 # Only add a normaliser matching the closing tag we found IF there were valid colouring parameters, otherwise we would be adding normaliser where it is not needed.
12339 $content = $content . ( $counter ? $normal : '' );
12340 }
12341 # We reduce the closing tag counter since we found one.
12342 $counter-- if( $counter > 0 );
12343 $self->__message( 120, "\$parse->() [LEVEL ${level}]: \$content is now '", quotemeta( $content // 'undef' ), "'." );
12344 $out = $content;
12345 # We can only use this once, and if we do not remove it now, it would be used again later in our code...
12346 delete( $args->{format} );
12347 # Continue, since we got a closing tag
12348 }
12349 }
12350 $copy = $chunk;
12351 # Capture the opening delimiter, and everything after, then check that what came after contains a closing delimiter.
12352 # We have to do this in two steps, because we cannot use an hash reference in the first part of the regular expression, such as:
12353 # s{^(?<before>.*?)(?<open>$open)(?<params>[a-zA-Z]+)(?:<more_params>.*?)(?<close>$map->{ \1 })}
12354 # So, we need to do this in two steps
12355 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Checking for some text followed by an opening delimiter, and possibly the begining of some parameters from the string '", ( $chunk // 'undef' ), "'" );
12356 # Special case for '{' or '['
12357 # Since the opening delimiter may have more than 1 character, we check if the first character is '{' or '['.
12358 my $open_re = ( substr( $open_d, 0, 2 ) eq quotemeta('{') || substr( $open_d, 0, 2 ) eq quotemeta('[') )
12359 ? "(?<!\\\$)${open_d}"
12360 : $open_d;
12361 $chunk =~ s{^(?<before>.*?)(?<open>$open_re)(?<params>[a-zA-Z]+)(?<remaining>.*?)$}
12362 {
12363 my $re = { %+ };
12364 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Found -> ", sub{ $self->Module::Generic::dump( $re ) } );
12365 # Unless the open and close delimiters have already been set and confirmed, i.e. they have been passed as arguments, we set them as Regexp now.
12366 unless( $args->{open_d} )
12367 {
12368 $open_d = quotemeta( $re->{open} );
12369 $close_d = quotemeta( $map->{ $re->{open} } );
12370 }
12371 my $before = $re->{before};
12372 my $params = $re->{params};
12373 my $remaining = $re->{remaining};
12374 # We have been provided with an open and close delimiter, which means we are in a $level > 1, and we have some colour formatting, and we found a closing tag in the leading text chunk, so we need to wrap that leading text in the given colour formatting.
12375 if( exists( $args->{open} ) &&
12376 exists( $args->{close} ) &&
12377 defined( $args->{open} ) &&
12378 defined( $args->{close} ) &&
12379 $before =~ /${open_d}\/${close_d}/ )
12380 {
12381 $self->__message( 120, "The leading text has a closing tag, so we append the normaliser \$normal" );
12382 my( $before_close, $after_close ) = split( /${open_d}\/${close_d}/, $before, 2 );
12383 if( !$is_tty )
12384 {
12385 $out .= $before_close . $after_close;
12386 }
12387 elsif( $args->{format} )
12388 {
12389 my $fmt = CORE::join( '', @{$args->{format}} );
12390 my $text_parts = [CORE::split( /\n/, $before_close )];
12391 for( my $i = 0; $i < scalar( @$text_parts ); $i++ )
12392 {
12393 # Empty due to \n repeated
12394 next if( !CORE::length( $text_parts->[$i] ) );
12395 $text_parts->[$i] = $fmt . $text_parts->[$i] . $normal;
12396 }
12397 $before_close = CORE::join( "\n", @$text_parts );
12398 $out .= $before_close . ( $after_close // '' );
12399 }
12400 else
12401 {
12402 $out .= ( $before_close // '' ) . $normal . ( $after_close // '' );
12403 }
12404 # We reduce the closing tag counter, since we just found one.
12405 $counter-- if( $counter > 0 );
12406 }
12407 else
12408 {
12409 $out .= $before;
12410 }
12411  
12412 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Checking remaining text '", ( $remaining // 'undef' ), "'" );
12413 # Closing delimiter for the open tag
12414 if( $remaining =~ s/^(?<more_params>.*?)${close_d}// )
12415 {
12416 my $params2 = $+{more_params};
12417 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Found more formatting parameters '", ( $params2 // 'undef' ), "' followed by a closing delimiter." );
12418 # We search for another opening delimiter, which would be an error, since we are not closed yet, but could happen.
12419 if( $params2 =~ /(?:$open_d)(?=[a-zA-Z]+)/ )
12420 {
12421 $self->__message( 120, "\$parse->() [LEVEL ${level}]: The 'remaining' part contains some opening delimiter, so it seems there is a user-error. Returning the backed up string '", ( $copy // 'undef' ), "'" );
12422 $copy;
12423 }
12424 else
12425 {
12426 # Ok, found parameters + close delimiter
12427 $params .= $params2;
12428 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Ok, we found some more parameters in the 'remaining' capture. \$params is now '", ( $params // 'undef' ), "'. Calling \$process_params->()" );
12429 # Get back an array reference of formatting.
12430 my $fmt = $process_params->( $params );
12431 $self->__message( 120, "\$parse->() [LEVEL ${level}]: \$process_params->() returned -> ", sub{ $self->Module::Generic::dump( $fmt ) } );
12432 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Calling ourself recursively to parse the rest of the string caught in 'remaining' -> '", ( $remaining // 'undef' ), "'" );
12433 my $rv = $parse->( $remaining => {
12434 open => $open_d,
12435 close => $close_d,
12436 # We pass the colour formatting that will be applied on the text our next round of parsing will extract
12437 format => $fmt,
12438 level => ( $level + 1 ),
12439 # We keep track of the number of valid open tags we got, so we can decide to remove any usless one (if its corresponding open tag was improper), or to replace them with a normaliser
12440 counter => ( $fmt ? ( $counter + 1 ) : $counter ),
12441 });
12442 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Our recursive run returned '", quotemeta( $rv // 'undef' ), "'" );
12443 $rv;
12444 }
12445 }
12446 # We could not find a close delimiter; we call the whole thing off
12447 else
12448 {
12449 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Failed to find a closing delimier in the 'remaining' capture. This is a user-error. Stopping here, and returning the text unaltered -> '", ( $copy // 'undef' ), "'" );
12450 $copy;
12451 }
12452 # Or, we search for a closing delimiter
12453 # Once we have the closing delimiter, we get the colour formatting the the parmeters in between.
12454 }gexs;
12455 $out .= $chunk;
12456 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Resulting output is so far '", quotemeta( $out // 'undef' ), "'" );
12457  
12458 if( $is_tty && exists( $args->{format} ) && defined( $args->{format} ) )
12459 {
12460 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Some colour formatting was passed down to us. Applying it now." );
12461 $out = CORE::join( '', @{$args->{format}} ) . $out;
12462 }
12463 # Also ensure that any closing tag leftovers are replaced by the special formatter $normal. $normal closes formatting, so using it is safe.
12464 # We do this only if we inherited a previously identified opening and closing delimiter; OR
12465 # if we have not inherited any, but identified it earlier
12466 if( ( $args->{open} && $args->{close} ) ||
12467 ( $open_d && $close_d && $open_d ne $open ) )
12468 {
12469 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Removing possible closing tags from string '", quotemeta( $out // 'undef' ), "'" );
12470 $out =~ s/(?:${open_d}\/${close_d})/$normal/;
12471 }
12472  
12473 $self->__message( 120, "\$parse->() [LEVEL ${level}]: Done. Returning the final resulting formatted string '", quotemeta( $out // 'undef' ), "'" );
12474 return( $out );
12475 };
12476 return( $parse->( $txt ) );
12477 }
12478 PERL
12479 # NOTE: colour_to_rgb()
12480 colour_to_rgb => <<'PERL',
12481 sub colour_to_rgb
12482 {
12483 my $self = shift( @_ );
12484 my $colour = lc( shift( @_ ) );
12485 my $this = $self->_obj2h;
12486 my( $red, $green, $blue ) = ( '', '', '' );
12487 our $COLOUR_NAME_TO_RGB;
12488 if( $colour =~ /^[A-Za-z]+([\w\-]+)*([[:blank:]]+\w+)?$/ )
12489 {
12490 if( !scalar( keys( %$COLOUR_NAME_TO_RGB ) ) )
12491 {
12492 my $colour_data = $self->__colour_data;
12493 local $@;
12494 $COLOUR_NAME_TO_RGB = eval( $colour_data );
12495 if( $@ )
12496 {
12497 return( $self->error( "An error occurred loading data from __colour_data: $@" ) );
12498 }
12499 }
12500 if( CORE::exists( $COLOUR_NAME_TO_RGB->{ $colour } ) )
12501 {
12502 ( $red, $green, $blue ) = @{$COLOUR_NAME_TO_RGB->{ $colour }};
12503 }
12504 else
12505 {
12506 return( '' );
12507 }
12508 }
12509 ## Colour all in decimal??
12510 elsif( $colour =~ /^\d{9}$/ )
12511 {
12512 $red = substr( $colour, 0, 3 );
12513 $green = substr( $colour, 3, 3 );
12514 $blue = substr( $colour, 6, 3 );
12515 }
12516 ## Colour in hexadecimal, convert it
12517 elsif( $colour =~ /^[A-F0-9]+$/ )
12518 {
12519 $red = hex( substr( $colour, 0, 2 ) );
12520 $green = hex( substr( $colour, 2, 2 ) );
12521 $blue = hex( substr( $colour, 4, 2 ) );
12522 }
12523 ## Clueless
12524 else
12525 {
12526 ## Not undef, but rather empty string. Undef is associated with an error
12527 return( '' );
12528 }
12529 return({ red => $red, green => $green, blue => $blue });
12530 }
12531 PERL
12532 # NOTE: coloured()
12533 coloured => <<'PERL',
12534 sub coloured
12535 {
12536 my $self = shift( @_ );
12537 my $pref = shift( @_ );
12538 my $text = CORE::join( '', @_ );
12539 my $this = $self->_obj2h;
12540 my( $style, $fg, $bg );
12541 ## my $colour_re = qr/(?:(?:bright|light)[[:blank:]])?[a-zA-Z]+/;
12542 my $colour_re = qr/(?:(?:bright|light)[[:blank:]])?(?:[a-zA-Z]+(?:[[:blank:]]+[\w\-]+)?|rgb[a]?\([[:blank:]]*\d{1,3}[[:blank:]]*\,[[:blank:]]*\d{1,3}[[:blank:]]*\,[[:blank:]]*\d{1,3}[[:blank:]]*(?:\,[[:blank:]]*\d(?:\.\d)?)?[[:blank:]]*\))/;
12543 my $style_re = qr/(?:bold|faint|italic|underline|blink|reverse|conceal|strike)/;
12544 if( $pref =~ /^(?:(?<style1>$style_re)[[:blank:]]+)?(?<fg_colour>$colour_re)(?:[[:blank:]]+(?<style2>$style_re))?(?:[[:blank:]]+on[[:blank:]]+(?<bg_colour>$colour_re))?$/i )
12545 {
12546 $style = $+{style1} || $+{style2};
12547 $fg = $+{fg_colour};
12548 $bg = $+{bg_colour};
12549 return( $self->colour_format({ text => $text, style => $style, colour => $fg, bg_colour => $bg }) );
12550 }
12551 else
12552 {
12553 return( '' );
12554 }
12555 }
12556 PERL
12557 # NOTE: dump_hex()
12558 dump_hex => <<'PERL',
12559 sub dump_hex
12560 {
12561 my $self = shift( @_ );
12562 $self->_load_class( 'Devel::Hexdump' ) ||
12563 return( $self->pass_error );
12564 # try-catch
12565 local $@;
12566 my $rv = eval
12567 {
12568 Devel::Hexdump::xd( shift( @_ ) );
12569 };
12570 if( $@ )
12571 {
12572 return( $self->error( "Error dumping with Devel::Hexdump: $@" ) );
12573 }
12574 return( $rv );
12575 }
12576 PERL
12577 # NOTE: dump_print()
12578 dump_print => <<'PERL',
12579 # For backward compatibility and traceability
12580 sub dump_print { return( shift->dumpto_printer( @_ ) ); }
12581 PERL
12582 # NOTE: dumper()
12583 dumper => <<'PERL',
12584 sub dumper
12585 {
12586 my $self = shift( @_ );
12587 my $opts = {};
12588 $opts = pop( @_ ) if( scalar( @_ ) > 1 && ref( $_[-1] ) eq 'HASH' );
12589 $self->_load_class( 'Data::Dumper' ) ||
12590 return( $self->pass_error );
12591 # try-catch
12592 local $@;
12593 my $rv = eval
12594 {
12595 no warnings 'once';
12596 # local $Data::Dumper::Sortkeys = 1;
12597 local $Data::Dumper::Terse = 1;
12598 local $Data::Dumper::Indent = 1;
12599 local $Data::Dumper::Useqq = 1;
12600 local $Data::Dumper::Maxdepth = $opts->{depth} if( CORE::length( $opts->{depth} ) );
12601 local $Data::Dumper::Sortkeys = sub
12602 {
12603 my $h = shift( @_ );
12604 return( [ sort( grep{ ref( $h->{ $_ } ) !~ /^(DateTime\:\:Lite|DateTime\:\:Lite\:\:|DateTime|DateTime\:\:)/ } keys( %$h ) ) ] );
12605 };
12606 Data::Dumper::Dumper( @_ );
12607 };
12608 if( $@ )
12609 {
12610 return( $self->error( "Error dumping with Data::Dumper: $@" ) );
12611 }
12612 return( $rv );
12613 }
12614 PERL
12615 # NOTE: dumpto_dumper()
12616 dumpto_dumper => <<'PERL',
12617 sub dumpto_dumper
12618 {
12619 my $self = shift( @_ );
12620 my( $data, $file ) = @_;
12621 $self->_load_class( 'Data::Dumper' ) ||
12622 return( $self->pass_error );
12623 $self->_load_class( 'Module::Generic::File' ) ||
12624 return( $self->pass_error );
12625 # try-catch
12626 local $@;
12627 my $rv = eval
12628 {
12629 no warnings 'once';
12630 local $Data::Dumper::Sortkeys = 1;
12631 local $Data::Dumper::Terse = 1;
12632 local $Data::Dumper::Indent = 1;
12633 local $Data::Dumper::Useqq = 1;
12634 $file = Module::Generic::File::file( $file );
12635 my $fh = $file->open( '>', { autoflush => 1 }) ||
12636 die( "Unable to create file '$file': $!\n" );
12637 if( ref( $data ) )
12638 {
12639 $fh->print( Data::Dumper::Dumper( $data ), "\n" );
12640 }
12641 else
12642 {
12643 $fh->binmode( ':utf8' );
12644 $fh->print( $data );
12645 }
12646 $fh->close;
12647 # 666 so it can work under command line and web alike
12648 chmod( 0666, $file );
12649 return(1);
12650 };
12651 if( $@ )
12652 {
12653 return( $self->error( "Unable to dump data to \"$file\" using Data::Dumper: $@" ) );
12654 }
12655 return( $rv );
12656 }
12657 PERL
12658 # NOTE: dumpto_printer()
12659 dumpto_printer => <<'PERL',
12660 sub dumpto_printer
12661 {
12662 my $self = shift( @_ );
12663 my( $data, $file ) = @_;
12664 $self->_load_class( 'Module::Generic::File' ) ||
12665 return( $self->pass_error );
12666 $self->_load_class( 'Data::Dump' ) ||
12667 return( $self->pass_error );
12668 $file = Module::Generic::File::file( $file );
12669 my $fh = $file->open( '>', { binmode => 'utf-8', autoflush => 1 }) ||
12670 die( "Unable to create file '$file': $!\n" );
12671 $fh->print( Data::Dump::dump( $data ), "\n" );
12672 $fh->close;
12673 # 666 so it can work under command line and web alike
12674 chmod( 0666, $file );
12675 return(1);
12676 }
12677 PERL
12678 # NOTE: errno()
12679 errno => <<'PERL',
12680 sub errno
12681 {
12682 my $self = shift( @_ );
12683 my $this = $self->_obj2h;
12684 if( @_ )
12685 {
12686 $this->{errno} = shift( @_ ) if( $_[ 0 ] =~ /^\-?\d+$/ );
12687 return( $self->error( @_ ) ) if( @_ );
12688 }
12689 return( $this->{errno} );
12690 }
12691 PERL
12692 # NOTE: force_tty()
12693 force_tty => <<'PERL',
12694 sub force_tty { return( shift->_set_get( 'force_tty', @_ ) ); }
12695 PERL
12696 # NOTE: message_colour()
12697 message_colour => <<'PERL',
12698 sub message_colour
12699 {
12700 my $self = shift( @_ );
12701 my $this = $self->_obj2h;
12702 my $opts = {};
12703 my $args = [@_];
12704 if( scalar( @$args ) > 1 &&
12705 ref( $args->[-1] ) eq 'HASH' &&
12706 (
12707 CORE::exists( $args->[-1]->{level} ) ||
12708 CORE::exists( $args->[-1]->{type} ) ||
12709 CORE::exists( $args->[-1]->{message} )
12710 ) )
12711 {
12712 $opts = pop( @$args );
12713 }
12714 $opts->{colour} = 1;
12715 return( $self->__message( @$args, $opts ) );
12716 }
12717 PERL
12718 # NOTE: messagef_colour()
12719 messagef_colour => <<'PERL',
12720 sub messagef_colour
12721 {
12722 my $self = shift( @_ );
12723 my $this = $self->_obj2h;
12724 my $opts = {};
12725 my $args = [@_];
12726 no strict 'refs';
12727 if( scalar( @$args ) > 1 &&
12728 ref( $args->[-1] ) eq 'HASH' &&
12729 (
12730 CORE::exists( $args->[-1]->{level} ) ||
12731 CORE::exists( $args->[-1]->{type} ) ||
12732 CORE::exists( $args->[-1]->{message} )
12733 ) )
12734 {
12735 $opts = pop( @$args );
12736 }
12737 $opts->{colour} = 1;
12738 return( $self->__messagef( @$args, $opts ) );
12739 }
12740 PERL
12741 # NOTE: printer()
12742 printer => <<'PERL',
12743 sub printer
12744 {
12745 my $self = shift( @_ );
12746 my $opts = {};
12747 $opts = pop( @_ ) if( scalar( @_ ) > 1 && ref( $_[-1] ) eq 'HASH' );
12748 $self->_load_class( 'Data::Printer' ) ||
12749 return( $self->pass_error );
12750 # try-catch
12751 local $@;
12752 my $rv = eval
12753 {
12754 local $SIG{__WARN__} = sub{ };
12755 if( scalar( keys( %$opts ) ) )
12756 {
12757 return( Data::Printer::np( @_, %$opts ) );
12758 }
12759 else
12760 {
12761 return( Data::Printer::np( @_ ) );
12762 }
12763 };
12764 if( $@ )
12765 {
12766 return( $self->error( "Error dumping data using Data::Printer: $@" ) );
12767 }
12768 return( $rv );
12769 }
12770 PERL
12771 # NOTE: save()
12772 save => <<'PERL',
12773 sub save
12774 {
12775 my $self = shift( @_ );
12776 my $this = $self->_obj2h;
12777 my $opts = {};
12778 $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
12779 my( $file, $data );
12780 if( @_ == 2 )
12781 {
12782 $opts->{data} = shift( @_ );
12783 $opts->{file} = shift( @_ );
12784 }
12785 return( $self->error( "No file was provided to save data to." ) ) if( !$opts->{file} );
12786 $self->_load_class( 'Module::Generic::File' ) ||
12787 return( $self->pass_error );
12788 $file = Module::Generic::File::file( $opts->{file} );
12789 my $fh = $file->open( '>', {
12790 ( $opts->{encoding} ? ( binmode => $opts->{encoding} ) : () ),
12791 autoflush => 1,
12792 }) ||
12793 return( $self->error( "Unable to open file \"$file\" in write mode: $!" ) );
12794 if( !defined( $fh->print( ref( $opts->{data} ) eq 'SCALAR' ? ${$opts->{data}} : $opts->{data} ) ) )
12795 {
12796 return( $self->error( "Unable to write data to file \"$file\": $!" ) )
12797 }
12798 $fh->close;
12799 my $bytes = -s( $opts->{file} );
12800 return( $bytes );
12801 }
12802 PERL
12803 # NOTE: subclasses()
12804 subclasses => <<'PERL',
12805 sub subclasses
12806 {
12807 my $self = shift( @_ );
12808 my $that = '';
12809 $that = @_ ? shift( @_ ) : $self;
12810 my $base = ref( $that ) || $that;
12811 $base =~ s,::,/,g;
12812 $base .= '.pm';
12813  
12814 $self->_load_class( 'IO::Dir' ) ||
12815 return( $self->pass_error );
12816 # remove '.pm'
12817 my $dir = substr( $INC{ $base }, 0, ( length( $INC{ $base } ) ) - 3 );
12818
12819 my @packages = ();
12820 my $io = IO::Dir->open( $dir );
12821 if( defined( $io ) )
12822 {
12823 @packages = map{ substr( $_, 0, length( $_ ) - 3 ) } grep{ substr( $_, -3 ) eq '.pm' && -f( "$dir/$_" ) } $io->read();
12824 $io->close ||
12825 warn( "Unable to close directory \"$dir\": $!\n" );
12826 }
12827 else
12828 {
12829 warn( "Unable to open directory \"$dir\": $!\n" );
12830 }
12831 return( wantarray() ? @packages : \@packages );
12832 }
12833 PERL
12834 };
12835  
12836 23 ▶ unless( $AUTOLOAD_SUBS && CORE::scalar( CORE::keys( %$AUTOLOAD_SUBS ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($AUTOLOAD_SUBS and scalar keys %$AUTOLOAD_SUBS) 23 0 23
Condition50%1/2
$AUTOLOAD_SUBS and scalar keys %$AUTOLOAD_SUBS
!ll
230
MC/DC0%0/1
$AUTOLOAD_SUBS and scalar keys %$AUTOLOAD_SUBS
$AUTOLOAD_SUBS
Truth table50%1/2
A
A= $AUTOLOAD_SUBS
Aresult
00
11
12837 {
12838 # Avoid dependency on HAS_THREADS, and make it explicit
12839 # Maybe threads were loaded at runtime ?
12840 23 ▶ if( $Config{useithreads} && $INC{'threads.pm'} )
Branch: 1 branch
BranchTrueFalseTotal
if ($Config{'useithreads'} and $INC{'threads.pm'}) { } 0 23 23
Condition33%1/3
$Config{"useithreads"} and $INC{"threads.pm"}
!ll&&!rl&&r
2300
MC/DC0%0/2
$Config{"useithreads"} and $INC{"threads.pm"}
$Config{"useithreads"} $INC{"threads.pm"}
Truth table33%1/3
A and B
A= $Config{"useithreads"}B= $INC{"threads.pm"}
ABresult
0X0
100
111
12841 {
12842 0 my %tmp :shared;
12843 # Make sure the value is not undefined, before locking it.
12844 0 $AUTOLOAD_SUBS = \%tmp;
12845  
12846 # We need to catch any possible error, or they may ripple in other parts of the code and wreak havoc
12847 # try-catch
12848 0 local $@;
12849 # Get the scoped returned value from lock so it works within our block
12850 eval
12851 0 {
12852 0 CORE::lock( $AUTOLOAD_SUBS );
12853 0 ▶ unless( CORE::scalar( CORE::keys( %$AUTOLOAD_SUBS ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar keys %$AUTOLOAD_SUBS) 0 0 0
12854 {
12855 0 %$AUTOLOAD_SUBS = %$subs;
12856 }
12857 };
12858 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
12859 {
12860 0 warn( "Error: unable to get a lock on the shared \$AUTOLOAD_SUBS: $@" );
12861 }
12862 }
12863 else
12864 {
12865 23 $AUTOLOAD_SUBS = $subs;
12866 }
12867 }
12868 23 return(1);
12869 }
12870  
12871 # NOTE: class function
12872 # Used internally also in Module::Generic::Exception
12873 sub UNIVERSAL::create_class
12874 2 ▶{
Subroutine create_class: called CC=60 SCAR=73.3
Pod undocumented
12875 2 my $class = shift( @_ );
12876 2 my $self = __PACKAGE__;
12877 # $self->__message( 104, "Arguments received for class '$class' are: '", join( "', '", map( overload::StrVal( $_ // 'undef' ), @_ ) ), "'" );
12878 2 ▶ return( $self->error( "No class name was provided." ) ) if( $self->_is_empty( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_empty($class) 0 2 2
12879 2 my $opts = $self->_get_args_as_hash( @_ );
12880 2 ▶ my $parent = $opts->{extends} || $self;
Condition33%1/3
$opts->{'extends'} || $self
l!l&&r!l&&!r
200
MC/DC0%0/2
$opts->{'extends'} || $self
$opts->{'extends'} $self
Truth table33%1/3
A || B
A= $opts->{'extends'}B= $self
ABresult
1X1
011
000
12881 2 ▶ my $parents = $self->_is_array( $parent ) ? $parent : [$parent];
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($parent) ? : 0 2 2
12882 2 ▶ for( my $i = 0; $i < scalar( @$parents ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$parents) 2 2 4
12883 {
12884 2 my $this = $parents->[$i];
12885 2 ▶ if( ref( $this ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this) 0 2 2
12886 {
12887 0 ▶ return( $self->error( "The parent value provided (", overload::StrVal( $this // 'undef' ), ") is a reference, but not an object. You should provide a parent class as a string, or a blessed object." ) ) if( !Scalar::Util::blessed( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($this) 0 0 0
Condition0%0/2
$this // "undef"
l!l
00
MC/DC0%0/1
$this // "undef"
$this
Truth table0%0/2
A
A= $this
Aresult
11
00
12888 0 $parents->[$i] = ref( $this );
12889 }
12890 }
12891 2 ▶ my $meths = CORE::delete( $opts->{method} ) // CORE::delete( $opts->{methods} );
Condition33%1/3
delete $opts->{"method"} // delete $opts->{"methods"}
l!l&&r!l&&!r
002
MC/DC0%0/2
delete $opts->{"method"} // delete $opts->{"methods"}
delete $opts->{"method"} delete $opts->{"methods"}
Truth table33%1/3
A // B
A= delete $opts->{"method"}B= delete $opts->{"methods"}
ABresult
1X1
011
000
12892 2 my $is_loaded = $self->_is_class_loaded( $class );
12893 2 ▶ if( $is_loaded )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_loaded) 0 2 2
12894 {
12895 # Make sure the parent is in the ISA
12896 0 ▶ unless( scalar( grep( ( $_ // '' ) eq $parent, @{"${class}::ISA"} ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar grep((($_ // "") eq $parent), @{"${class}::ISA";})) 0 0 0
Condition0%0/2
$_ // ""
l!l
00
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
12897 {
12898 38 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
12899 0 unshift( @{"${class}::ISA"}, $parent );
12900 }
12901 0 return( $class );
12902 }
12903 2 my $map =
12904 {
12905 array => '_set_get_array',
12906 # Alias for 'array_as_object'
12907 array_object => '_set_get_array_as_object',
12908 array_as_object => '_set_get_array_as_object',
12909 boolean => '_set_get_boolean',
12910 class => '_set_get_class',
12911 class_array => '_set_get_class_array',
12912 class_array_object => '_set_get_class_array_object',
12913 code => '_set_get_code',
12914 datetime => '_set_get_datetime',
12915 decimal => '_set_get_number',
12916 file => '_set_get_file',
12917 float => '_set_get_number',
12918 glob => '_set_get_glob',
12919 hash => '_set_get_hash',
12920 hash_as_object => '_set_get_hash_as_mix_object',
12921 integer => '_set_get_number',
12922 ip => '_set_get_ip',
12923 long => '_set_get_number',
12924 number => '_set_get_number',
12925 object => '_set_get_object',
12926 object_no_init => '_set_get_object_without_init',
12927 object_array => '_set_get_object_array',
12928 object_array_object => '_set_get_object_array_object',
12929 scalar => '_set_get_scalar',
12930 scalar_as_object => '_set_get_scalar_as_object',
12931 scalar_or_object => '_set_get_scalar_or_object',
12932 uri => '_set_get_uri',
12933 uuid => '_set_get_uuid',
12934 version => '_set_get_version',
12935 };
12936 2 my $prefix_class = '';
12937 2 local $" = ' ';
12938 2 my $perl = <<EOT;
12939 package ${class};
12940 BEGIN
12941 {
12942 use strict;
12943 use warnings;
12944 no warnings 'once';
12945 use vars qw( \@ISA );
12946 EOT
12947 # The user has declared a list of methods that use Module::Generic,
12948 # but Module::Generic is not among the parents
12949 # Technically, we do not really need to add it, since we are obviously already loaded
12950 # but this is in an abondance of concern of clean code rather than efficiency.
12951 2 ▶ if( ref( $meths // '' ) eq 'HASH' &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref($meths // "") eq "HASH" and scalar keys %$meths and not scalar grep((($_ // "") eq $self), @$parents)) 0 2 2
Condition33%3/9
ref($meths // "") eq "HASH" and scalar keys %$meths and not scalar grep((($_ // "") eq $self), @$parents)
!ll&&!rl&&r
200
ref($meths // "") eq "HASH" and scalar keys %$meths
!ll
20
$meths // ""
l!l
02
$_ // ""
l!l
00
MC/DC0%0/2
ref($meths // "") eq "HASH" and scalar keys %$meths and not scalar grep((($_ // "") eq $self), @$parents)
$meths not scalar grep((($_ // "") eq $self), @$parents)
MC/DC0%0/1
$_ // ""
$_
Truth table33%1/3
A and not(B)
A= $methsB= not scalar grep((($_ // "") eq $self), @$parents)
ABresult
0X0
100
111
Truth table0%0/2
A
A= $_
Aresult
11
00
12952 scalar( keys( %$meths ) ) &&
12953 !scalar( grep( ( $_ // '' ) eq $self, @$parents ) ) )
12954 {
12955 0 ▶ $prefix_class = ( ref( $self ) || $self ) . '::';
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
12956 0 $perl .= <<EOT;
12957 use Module::Generic;
12958 EOT
12959 }
12960 2 foreach my $c ( @$parents )
12961 {
12962 2 ▶ if( $self->_is_class_loadable( $c ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_class_loadable($c)) 1 1 2
12963 {
12964 1 $perl .= <<EOT;
12965 use $c;
12966 EOT
12967 }
12968 }
12969 2 $perl .= <<EOT;
12970 our \@ISA = qw( @$parents );
12971 };
12972  
12973 use strict;
12974 use warnings;
12975  
12976 EOT
12977  
12978 2 ▶ if( ref( $meths // '' ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref($meths // "") eq "HASH") 0 2 2
Condition50%1/2
$meths // ""
l!l
02
MC/DC0%0/1
$meths // ""
$meths
Truth table50%1/2
A
A= $meths
Aresult
11
00
12979 {
12980 0 my $code_lines = [];
12981 0 foreach my $meth ( sort( keys( %$meths ) ) )
12982 {
12983 0 my $info = $meths->{ $meth };
12984 0 my $def = {};
12985 0 ▶ if( ref( $info ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $info eq 'HASH') { } 0 0 0
elsif (not ref($info // '') or ref $info and $self->_can_overload($info, '""')) { } 0 0 0
12986 {
12987 0 $def = $info;
12988 0 ▶ if( !CORE::exists( $info->{type} ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $info->{"type"} and length($info->{"type"} // "")) 0 0 0
Condition0%0/5
exists $info->{"type"} and length($info->{"type"} // "")
!ll&&!rl&&r
000
$info->{"type"} // ""
l!l
00
MC/DC0%0/2
exists $info->{"type"} and length($info->{"type"} // "")
exists $info->{"type"} $info->{"type"}
Truth table0%0/3
A and B
A= exists $info->{"type"}B= $info->{"type"}
ABresult
0X0
100
111
12989 !CORE::length( $info->{type} // '' ) )
12990 {
12991 0 return( $self->error( "No type provided for class '${class}' and method '${meth}'." ) );
12992 }
12993 }
12994 ▶ elsif( !ref( $info // '' ) ||
Condition0%0/8
not ref($info // "") or ref $info and $self->_can_overload($info, "\"\"")
l!l&&r!l&&!r
000
$info // ""
l!l
00
ref $info and $self->_can_overload($info, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/3
not ref($info // "") or ref $info and $self->_can_overload($info, "\"\"")
$info ref $info $self->_can_overload($info, "\"\"")
Truth table0%0/4
not(A) or B and C
A= $infoB= ref $infoC= $self->_can_overload($info, "\"\"")
ABCresult
0XX1
1111
10X0
1100
12995 ( ref( $info ) && $self->_can_overload( $info => '""' ) ) )
12996 {
12997 0 ▶ if( !defined( $info ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $info) 0 0 0
12998 {
12999 0 return( $self->error( "The type provided for class '${class}' and method '${meth}' has an undefined value." ) );
13000 }
13001 0 $def->{type} = $info;
13002 }
13003 else
13004 {
13005 0 ▶ return( $self->error( "The type provided for class '${class}' and method '${meth}' is unsupported: '", overload::StrVal( $info // 'undef' ), "'" ) );
Condition0%0/2
$info // "undef"
l!l
00
MC/DC0%0/1
$info // "undef"
$info
Truth table0%0/2
A
A= $info
Aresult
11
00
13006 }
13007 0 my $type = lc( $def->{type} );
13008 0 ▶ $def->{class} = $def->{package} if( $def->{package} && !length( $def->{class} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"package"} and not length $def->{"class"} 0 0 0
Condition0%0/3
$def->{"package"} and not length $def->{"class"}
!ll&&!rl&&r
000
MC/DC0%0/2
$def->{"package"} and not length $def->{"class"}
$def->{"package"} not length $def->{"class"}
Truth table0%0/3
A and not(B)
A= $def->{"package"}B= not length $def->{"class"}
ABresult
0X0
100
111
13009 0 ▶ if( !defined( $type ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $type) { } 0 0 0
elsif (not exists $map->{$type}) { } 0 0 0
13010 {
13011 0 return( $self->error( "No type is defined for this class '${class}' and method '${meth}'" ) );
13012 }
13013 elsif( !CORE::exists( $map->{ $type } ) )
13014 {
13015 0 return( $self->error( "Unsupported method type '${type}' for class '${class}' and method '${meth}'" ) );
13016 }
13017 0 my $func = $prefix_class . $map->{ $type };
13018 0 ▶ if( $type eq 'object' ||
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'object' or $type eq 'object_no_init' or $type eq 'scalar_or_object' or $type eq 'object_array_object' or $type eq 'object_array') { } 0 0 0
elsif ($type eq 'class' or $type eq 'class_array' or $type eq 'class_array_object') { } 0 0 0
elsif ($type eq 'version' and exists $def->{'def'} || exists $def->{'definition'}) { } 0 0 0
Condition0%0/12
$type eq "object" or $type eq "object_no_init" or $type eq "scalar_or_object" or $type eq "object_array_object" or $type eq "object_array"
l!l&&r!l&&!r
000
$type eq "object" or $type eq "object_no_init" or $type eq "scalar_or_object" or $type eq "object_array_object"
l!l&&r!l&&!r
000
$type eq "object" or $type eq "object_no_init" or $type eq "scalar_or_object"
l!l&&r!l&&!r
000
$type eq "object" or $type eq "object_no_init"
l!l&&r!l&&!r
000
MC/DC0%0/5
$type eq "object" or $type eq "object_no_init" or $type eq "scalar_or_object" or $type eq "object_array_object" or $type eq "object_array"
$type eq "object" $type eq "object_no_init" $type eq "scalar_or_object" $type eq "object_array_object" $type eq "object_array"
Truth table0%0/6
A or B or C or D or E
A= $type eq "object"B= $type eq "object_no_init"C= $type eq "scalar_or_object"D= $type eq "object_array_object"E= $type eq "object_array"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
13019 $type eq 'object_no_init' ||
13020 $type eq 'scalar_or_object' ||
13021 $type eq 'object_array_object' ||
13022 $type eq 'object_array' )
13023 {
13024 0 ▶ if( !$info->{class} && !$info->{package} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($info->{"class"} or $info->{"package"}) 0 0 0
Condition0%0/3
$info->{"class"} or $info->{"package"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$info->{"class"} or $info->{"package"}
$info->{"class"} $info->{"package"}
Truth table0%0/3
A or B
A= $info->{"class"}B= $info->{"package"}
ABresult
1X1
011
000
13025 {
13026 0 return( $self->error( "A class '${class}' with method '${meth}' of type '${type}', but no class or package specified." ) );
13027 }
13028 0 ▶ my $this_class = $info->{class} || $info->{package};
Condition0%0/3
$info->{'class'} || $info->{'package'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$info->{'class'} || $info->{'package'}
$info->{'class'} $info->{'package'}
Truth table0%0/3
A || B
A= $info->{'class'}B= $info->{'package'}
ABresult
1X1
011
000
13029 0 CORE::push( @$code_lines, "sub ${meth} { return( shift->${func}( '${meth}', '${this_class}', \@_ ) ); }" );
13030 }
13031 ▶ elsif( $type eq 'class' || $type eq 'class_array' || $type eq 'class_array_object' )
Condition0%0/6
$type eq "class" or $type eq "class_array" or $type eq "class_array_object"
l!l&&r!l&&!r
000
$type eq "class" or $type eq "class_array"
l!l&&r!l&&!r
000
MC/DC0%0/3
$type eq "class" or $type eq "class_array" or $type eq "class_array_object"
$type eq "class" $type eq "class_array" $type eq "class_array_object"
Truth table0%0/4
A or B or C
A= $type eq "class"B= $type eq "class_array"C= $type eq "class_array_object"
ABCresult
1XX1
01X1
0011
0000
13032 {
13033 0 ▶ my $this_def = $info->{definition} // $info->{def};
Condition0%0/3
$info->{"definition"} // $info->{"def"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$info->{"definition"} // $info->{"def"}
$info->{"definition"} $info->{"def"}
Truth table0%0/3
A // B
A= $info->{"definition"}B= $info->{"def"}
ABresult
1X1
011
000
13034 0 ▶ if( !CORE::exists( $info->{definition} ) && !CORE::exists( $info->{def} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $info->{'definition'} || exists $info->{'def'}) { } 0 0 0
elsif (ref $this_def ne 'HASH') { } 0 0 0
Condition0%0/3
exists $info->{'definition'} || exists $info->{'def'}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $info->{'definition'} || exists $info->{'def'}
exists $info->{'definition'} exists $info->{'def'}
Truth table0%0/3
A || B
A= exists $info->{'definition'}B= exists $info->{'def'}
ABresult
1X1
011
000
13035 {
13036 0 return( $self->error( "No dynamic class fields definition was provided for this class '${class}' with method \"${meth}\" and type '${type}'." ) );
13037 }
13038 elsif( ref( $this_def ) ne 'HASH' )
13039 {
13040 0 return( $self->error( "I was expecting a fields definition hash reference for dynamic class in class '${class}' with method \"${meth}\", but instead got '${this_def}'." ) );
13041 }
13042 0 my $hash_str = Data::Dump::dump( $this_def );
13043 0 $self->__message( 112, "For field ${meth}, using dictionary definition string -> ${hash_str}" );
13044 0 CORE::push( @$code_lines, "sub ${meth} { return( shift->${func}( '${meth}', ${hash_str}, \@_ ) ); }" );
13045 }
13046 ▶ elsif( $type eq 'version' && ( exists( $def->{def} ) || exists( $def->{definition} ) ) )
Condition0%0/6
$type eq "version" and exists $def->{"def"} || exists $def->{"definition"}
!ll&&!rl&&r
000
exists $def->{"def"} or exists $def->{"definition"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$type eq "version" and exists $def->{"def"} || exists $def->{"definition"}
$type eq "version" exists $def->{"def"} exists $def->{"definition"}
Truth table0%0/4
A and B or C
A= $type eq "version"B= exists $def->{"def"}C= exists $def->{"definition"}
ABCresult
0XX0
1000
11X1
1011
13047 {
13048 0 ▶ my $this_def = $def->{definition} // $def->{def};
Condition0%0/3
$def->{"definition"} // $def->{"def"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$def->{"definition"} // $def->{"def"}
$def->{"definition"} $def->{"def"}
Truth table0%0/3
A // B
A= $def->{"definition"}B= $def->{"def"}
ABresult
1X1
011
000
13049 0 my $hash_str = Data::Dump::dump( $this_def );
13050 0 CORE::push( @$code_lines, "sub ${meth} { return( shift->${func}( '${meth}', ${hash_str}, \@_ ) ); }" );
13051 }
13052 else
13053 {
13054 0 CORE::push( @$code_lines, "sub ${meth} { return( shift->${func}( '${meth}', \@_ ) ); }" );
13055 }
13056 }
13057 0 $perl .= join( "\n\n", @$code_lines );
13058 }
13059 2 $perl .= <<EOT;
13060  
13061  
13062 sub TO_JSON
13063 {
13064 my \$self = shift( \@_ );
13065 return( \$self->${prefix_class}as_hash ) if( \$self->can( "${prefix_class}as_hash" ) );
13066 return( \$self );
13067 }
13068  
13069 1;
13070  
13071 EOT
13072 2 $self->__message( 112, "Evaluating code -> $perl" );
13073 2 ▶ $self->__message( 106, "Are we running under threads, switching to shared data ? ", ( HAS_THREADS ? 'yes' : 'no' ) );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 2 2
13074 2 ▶ my $key = HAS_THREADS ? join( ';', $class, threads->tid() ) : $class;
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 2 2
13075 2 ▶ my $repo = Module::Generic::Global->new( 'loaded_classes' => ( ref( $self ) || $self ), key => $key );
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
13076 {
13077 # try-catch
13078 2 local $@;
13079 2 my $rc = eval( $perl );
13080 2 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
13081 {
13082 0 return( $self->error( "Unable to instantiate class ${class}: $@" ) );
13083 }
13084 2 $repo->set(1);
13085 }
13086 2 return( $class );
13087 }
13088  
13089 # NOTE:: AUTOLOAD
13090 314 ▶sub AUTOLOAD : lvalue
Subroutine AUTOLOAD: called CC=60 SCAR=58.8
13091 {
13092 314 my $self;
13093 314 ▶ $self = shift( @_ ) if( Scalar::Util::blessed( $_[0] ) && $_[0]->isa( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) and $_[0]->isa("Module::Generic") 294 20 314
Condition66%2/3
builtin::blessed($_[0]) and $_[0]->isa("Module::Generic")
!ll&&!rl&&r
200294
MC/DC50%1/2
builtin::blessed($_[0]) and $_[0]->isa("Module::Generic")
builtin::blessed($_[0]) $_[0]->isa("Module::Generic")
Truth table66%2/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("Module::Generic")
ABresult
0X0
100
111
13094 314 my( $class, $meth );
13095 314 ▶ $class = ref( $self ) || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
294020
MC/DC50%1/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
13096 # Leave this here as we need it a little bit lower
13097 314 my( $pkg, $file, $line ) = caller();
13098 314 my $caller_sub = ( caller(1) )[3];
13099 38 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
13100 41 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
13101 314 ▶ if( CORE::defined( $caller_sub ) && $caller_sub eq 'Module::Generic::AUTOLOAD' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $caller_sub and $caller_sub eq "Module::Generic::AUTOLOAD") 0 314 314
Condition66%2/3
defined $caller_sub and $caller_sub eq "Module::Generic::AUTOLOAD"
!ll&&!rl&&r
63080
MC/DC0%0/2
defined $caller_sub and $caller_sub eq "Module::Generic::AUTOLOAD"
defined $caller_sub $caller_sub eq "Module::Generic::AUTOLOAD"
Truth table66%2/3
A and B
A= defined $caller_subB= $caller_sub eq "Module::Generic::AUTOLOAD"
ABresult
0X0
100
111
13102 {
13103 0 my $trace = $self->_get_stack_trace;
13104 0 my $mesg = "Module::Generic::AUTOLOAD (called at line '$line') is looping for autoloadable method '$AUTOLOAD' and args '" . join( "', '", @_ ) . "'. Trace is: " . $trace->as_string;
13105 0 ▶ if( $MOD_PERL )
Branch: 1 branch
BranchTrueFalseTotal
if ($MOD_PERL) { } 0 0 0
13106 {
13107 # try-catch
13108 0 local $@;
13109 eval
13110 0 {
13111 0 my $r = Apache2::RequestUtil->request;
13112 0 $r->log->debug( $mesg );
13113 };
13114 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
13115 {
13116 0 print( STDERR "Error trying to get the global Apache2::ApacheRec: $@\n" );
13117 }
13118 }
13119 else
13120 {
13121 0 print( $stderr $mesg, "\n" );
13122 }
13123 0 exit(0);
13124 }
13125 314 $meth = $AUTOLOAD;
13126 314 ▶ if( CORE::index( $meth, '::' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($meth, "::") != -1) 314 0 314
13127 {
13128 314 my $idx = rindex( $meth, '::' );
13129 314 $class = substr( $meth, 0, $idx );
13130 314 $meth = substr( $meth, $idx + 2 );
13131 }
13132  
13133 314 ▶ unless( $AUTOLOAD_SUBS )
Branch: 1 branch
BranchTrueFalseTotal
unless ($AUTOLOAD_SUBS) 23 291 314
13134 {
13135 23 &Module::Generic::_autoload_subs();
13136 }
13137  
13138 314 my $code;
13139 314 ▶ if( CORE::exists( $AUTOLOAD_SUBS->{ $meth } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $AUTOLOAD_SUBS->{$meth}) 96 218 314
13140 {
13141 96 $code = $AUTOLOAD_SUBS->{ $meth };
13142 96 my $saved = $@;
13143 96 local $@;
13144 {
13145 125 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13146 0 ▶ eval( $code );
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine __ANON__: called CC=4 SCAR=15.3
Subroutine __ANON__: called CC=10 SCAR=26.4
Subroutine __ANON__: called CC=4 SCAR=15.3
Subroutine __ANON__: called CC=4 SCAR=15.3
Subroutine _implement_freeze_thaw: called CC=6 SCAR=20.1
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine _can_overload: called CC=7 SCAR=21.9
Subroutine _error_callbacks: called CC=20 SCAR=35.8
Subroutine _is_empty: called CC=21 SCAR=36.5
Subroutine _on_error: called CC=1 SCAR=0.4
Subroutine clone: called CC=9 SCAR=25.0
Subroutine __ANON__: called CC=1 SCAR=0.4
Subroutine __ANON__: called CC=1 SCAR=0.4
Subroutine __ANON__: called CC=1 SCAR=0.4
Subroutine __ANON__: called CC=1 SCAR=0.4
Subroutine __ANON__: called CC=1 SCAR=0.4
Subroutine __ANON__: called CC=1 SCAR=0.4
Subroutine __ANON__: called CC=1 SCAR=0.4
Subroutine __ANON__: called CC=1 SCAR=0.4
Branch: 109 branches
BranchTrueFalseTotal
if $serialiser eq "Sereal" or $serialiser eq "CBOR" 60 6 66
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 62 10 72
defined $ref && ref $ref eq 'ARRAY' && scalar @$ref > 1 ? : 7 63 70
ref $ref eq 'ARRAY' ? : 5 4 9
if (ref $self) { } 54 10 64
if $serialiser eq "Sereal" or $serialiser eq "CBOR" 107 3 110
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 53 56 109
unless ref $self 56 8 64
unless (defined &{"${class}::STORABLE_freeze";}) 96 136 232
unless (defined &{"${class}::STORABLE_thaw";}) 38 128 166
unless (defined &{"${class}::FREEZE";}) 165 1 166
unless (defined &{"${class}::THAW";}) 38 3 41
unless scalar @_ 15 15 30
unless defined $_[0] 11 4 15
unless builtin::blessed($_[0]) 5 14 19
if ($self->_is_array($_[1])) { } 18 8 26
unless overload::Method($_[0], $op) 4 22 26
$this->{'_data_repo'} ? : 19 7 26
if (@_) 9 15 24
if (scalar @_ == 1 and ref $_[0] eq 'HASH') { } 15 4 19
elsif (scalar @_ == 1) { } 18 4 22
unless exists $data->{"_error_callbacks"} 14 5 19
if ref $data->{"_error_callbacks"} ne "ARRAY" 625 13 638
if ($i < scalar @{$data->{"_error_callbacks"};}) 0 637 637
unless defined $ref and ref $ref eq "HASH" 626 11 637
if (exists $ref->{"name"} and defined $ref->{"name"} and $ref->{"name"} eq $name) 6 5 11
if ($i < scalar @_) 559 75 634
unless exists $data->{"_error_callbacks"} and defined $data->{"_error_callbacks"} and ref $data->{"_error_callbacks"} eq "ARRAY" 5 69 74
unless @_ 1 3 4
unless defined $_[0] 4 31 35
if ((builtin::reftype($_[0]) // '') eq 'SCALAR' and not length(${$_[0];} // '') or not ref $_[0] || length($_[0] // '')) { } 14 4 18
elsif ((builtin::reftype($_[0]) // '') eq 'ARRAY' and not scalar @{$_[0];}) { } 10 8 18
elsif ((builtin::reftype($_[0]) // '') eq 'HASH' and builtin::blessed($_[0]) and $_[0]->can('is_empty') and $_[0]->is_empty ? 1 : 0) { } 4 0 4
elsif (ref $_[0] eq 'HASH' and not scalar keys %{$_[0];}) { } 20 0 20
$_[0]->is_empty ? : 12 8 20
if (@_) { } 2 18 20
if (scalar @_ > 1) { } 16 4 20
elsif (not defined $_[0]) { } 4 0 4
elsif (not ref $_[0]) { } 18 2 20
if ($@) 6 12 18
if ($self->_is_object($self)) { } 12 0 12
if ($@) 4 2 6
if ($col =~ / ^(?: (?<light>bright|light) [[:blank:]\_\-]+ )? (?<colour> (?: (?:[a-zA-Z]+)(?:[[:blank:]]+\w+)? ) | (?: (?<rgb_type> rgb[a]? ) \( [[:blank:]]*(?<red>\d{1,3})[[:blank:]]*\, [[:blank:]]*(?<green>\d{1,3})[[:blank:]]*\, [[:blank:]]*(?<blue>\d{1,3})[[:blank:]]* (?: \,[[:blank:]]* (?<opacity>\d(?:\.\d+)?) )? [[:blank:]]* \) ) )$ /xi) { } 0 12 12
elsif ($col =~ / ^ (?<rgb_type>rgb[a]?) \( [[:blank:]]*(?<red>\d{1,3})[[:blank:]]*\, [[:blank:]]*(?<green>\d{1,3})[[:blank:]]*\, [[:blank:]]*(?<blue>\d{1,3})[[:blank:]]* (?: \,[[:blank:]]* (?<opacity> \d(?:\.\d+)? ) )? [[:blank:]]* \)$ /xi) { } 0 0 0
if (length $+{"rgb_type"} and length $+{"red"} and length $+{"green"} and length $+{"blue"}) 0 0 0
if ($+{'opacity'} or $light) { } 0 0 0
length $+{'opacity'} ? : 0 0 0
$light ? : 0 0 0
if ($+{'opacity'}) { } 0 0 0
if ($col =~ /^rgb[a]?\((?<red>\d{3})(?<green>\d{3})(?<blue>\d{3})\)$/i) { } 0 0 0
elsif ($col =~ / ^rgba \( (?<red>\d{3}) (?<green>\d{3}) (?<blue>\d{3}) (?: [[:blank:]]*\,[[:blank:]]* (?<opacity> \d(?:\.\d)? ) )? \)$ /xi) { } 0 0 0
elsif ($self->__message(109, "Checking if rgb value exists for colour '${col}'") and $col_ref = $self->colour_to_rgb($col)) { } 0 0 0
if ($+{"opacity"}) 0 0 0
if ($opts->{"bgcolour"}) 0 0 0
unless defined $params and length($params // "") 0 0 0
if ($params =~ / ^[[:blank:]]* (?: (?<style1>$style_re) [[:blank:]]+ )? (?<fg_colour>$colour_re) (?: [[:blank:]]+ (?<style2>$style_re) )? (?: [[:blank:]]+on[[:blank:]]+ (?<bg_colour>$colour_re) )? [[:blank:]]*$ /xi) { } 4 2 6
if ($params =~ /[^a-zA-Z0-9_,\=>\s\h[:blank:]'"\|\(\)\.\-]/) { } 4 2 6
elsif ($params =~ /\b(?: qx|system|open|exec|fork|require|use|eval|do| package|sub|BEGIN|UNITCHECK|CHECK|INIT|END| readpipe|sysopen|unlink|rename|chmod|chown|utime|truncate|mkdir|rmdir|opendir|readdir|closedir|glob )\b/i) { } 10 0 10
if scalar @res and not scalar(@res) % 2 5 5 10
if ($@ or ref $def ne "HASH") 8 2 10
if (scalar keys %$def) 6 2 8
unless $ref and scalar @$ref 4 4 8
if $level > $max_depth 2 8 10
$args->{'open'} ? : 2 8 10
$args->{'close'} ? : 0 10 10
$args->{'format'} ? : 0 0 0
if (defined $args->{"open"} and defined $args->{"close"} and $chunk =~ s[^(?<content>.*?)($open_d/$close_d)][]) 0 0 0
substr($open_d, 0, 2) eq '\\{' || substr($open_d, 0, 2) eq '\\[' ? : 0 10 10
if ($content =~ /$open_re(?=[a-zA-Z]+)/) { } 0 10 10
elsif (not $is_tty) { } 0 0 0
$args->{'format'} ? : 0 0 0
if (my $fmt_ref = $args->{'format'}) { } 1 2 3
if (not scalar @$fmt_ref) { } 0 3 3
if (index($content, "\n") != -1) { } 0 7 7
if ($i < scalar @$text_parts) 0 7 7
unless length $text_parts->[$i] 0 0 0
$counter ? : 0 0 0
if $counter > 0 64 0 64
substr($open_d, 0, 2) eq '\\{' || substr($open_d, 0, 2) eq '\\[' ? : 64 0 64
unless ($args->{"open_d"}) 0 64 64
if (exists $args->{'open'} and exists $args->{'close'} and defined $args->{'open'} and defined $args->{'close'} and $before =~ m[$open_d/$close_d]) { } 29 27 56
if (not $is_tty) { } 4 29 33
elsif ($args->{'format'}) { } 0 0 0
if ($i < scalar @$text_parts) 0 0 0
unless length $text_parts->[$i] 0 0 0
if $counter > 0 0 0 0
if ($remaining =~ s/^(?<more_params>.*?)$close_d//) { } 0 0 0
if ($params2 =~ /(?:$open_d)(?=[a-zA-Z]+)/) { } 0 0 0
$fmt ? : 0 0 0
if ($is_tty and exists $args->{"format"} and defined $args->{"format"}) 0 0 0
if ($args->{"open"} and $args->{"close"} or $open_d and $close_d and $open_d ne $open) 0 7 7
if ($num >= 0) { } 2 5 7
if (ref $bg eq "HASH") 5 0 5
if ($col =~ /^(?:(?<light>bright|light)[[:blank:]\_]+)? (?<colour> (?:[a-zA-Z]+)(?:[[:blank:]]+\w+)? | (?<rgb_type>rgb[a]?)\([[:blank:]]*(?<red>\d{1,3})[[:blank:]]*\,[[:blank:]]*(?<green>\d{1,3})[[:blank:]]*\,[[:blank:]]*(?<blue>\d{1,3}) (?:[[:blank:]]*\,[[:blank:]]*(?<opacity>\d(?:\.\d+)?))?[[:blank:]]* \) )$/xi) { } 2 0 2
elsif ($col =~ /^(?<rgb_type>rgb[a]?)\([[:blank:]]*(?<red>\d{1,3})[[:blank:]]*\,[[:blank:]]*(?<green>\d{1,3})[[:blank:]]*\,[[:blank:]]*(?<blue>\d{1,3})[[:blank:]]*(?:\,[[:blank:]]*(?<opacity>\d(?:\.\d+)?))?[[:blank:]]*\)$/i) { } 0 0 0
if (length $+{'rgb_type'} and length $+{'red'} and length $+{'green'} and length $+{'blue'}) { } 2 0 2
if ($+{'opacity'} or $light) { } 2 0 2
length $+{'opacity'} ? : 0 2 2
$light ? : 0 2 2
if ($+{'opacity'}) { } 0 2 2
if ($col =~ /^rgb[a]?\((?<red>\d{3})(?<green>\d{3})(?<blue>\d{3})\)$/i) { } 0 2 2
elsif ($col =~ /^rgba\((?<red>\d{3})(?<green>\d{3})(?<blue>\d{3})[[:blank:]]*\,[[:blank:]]*(?<opacity>\d(?:\.\d)?)\)$/i) { } 0 7 7
elsif ($self->__message(109, "Checking if rgb value exists for colour '${col}'") and $col_ref = $self->colour_to_rgb($col)) { } 0 1 1
if ($+{"opacity"}) 0 1 1
if ($opts->{"bgcolour"}) 0 1 1
unless $self->_is_hash($opts) 0 1 1
if length $opts->{"message"} and not length $opts->{"text"} 9 9 18
unless length $opts->{"text"} 0 9 9
if ($opts->{"colour"} or $opts->{"color"} or $opts->{"fgcolour"} or $opts->{"fgcolor"} or $opts->{"fg_colour"} or $opts->{"fg_color"}) 0 9 9
Condition40%105/257
shift @_ // ""
l!l
50104
$serialiser eq "Sereal" or $serialiser eq "CBOR"
l!l&&r!l&&!r
1004
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
1244
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
9110
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
1105
ref $self or $self
l!l&&r!l&&!r
6559
shift @_ // ""
l!l
8159
$serialiser eq "Sereal" or $serialiser eq "CBOR"
l!l&&r!l&&!r
3360
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
6004
scalar @_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
1550
defined $ref and ref $ref eq "HASH"
!ll&&!rl&&r
3530
exists $ref->{"name"} and defined $ref->{"name"} and $ref->{"name"} eq $name
!ll&&!rl&&r
04641
exists $ref->{"name"} and defined $ref->{"name"}
!ll&&!rl&&r
3559020
$ref->{"cb"} // ""
l!l
705554
exists $data->{"_error_callbacks"} and defined $data->{"_error_callbacks"} and ref $data->{"_error_callbacks"} eq "ARRAY"
!ll&&!rl&&r
18657
exists $data->{"_error_callbacks"} and defined $data->{"_error_callbacks"}
!ll&&!rl&&r
1206
(builtin::reftype($_[0]) // "") eq "SCALAR" and not length(${$_[0];} // "") or not ref $_[0] || length($_[0] // "")
l!l&&r!l&&!r
1712
(builtin::reftype($_[0]) // "") eq "SCALAR" and not length(${$_[0];} // "")
!ll&&!rl&&r
6120
builtin::reftype($_[0]) // ""
l!l
40
${$_[0];} // ""
l!l
0012
ref $_[0] || length($_[0] // '')
l!l&&r!l&&!r
0012
$_[0] // ""
l!l
000
(builtin::reftype($_[0]) // "") eq "ARRAY" and not scalar @{$_[0];}
!ll&&!rl&&r
1200
builtin::reftype($_[0]) // ""
l!l
120
(builtin::reftype($_[0]) // "") eq "HASH" and builtin::blessed($_[0]) and $_[0]->can("is_empty") and $_[0]->is_empty ? 1 : 0
!ll&&!rl&&r
000
(builtin::reftype($_[0]) // "") eq "HASH" and builtin::blessed($_[0]) and $_[0]->can("is_empty")
!ll&&!rl&&r
000
(builtin::reftype($_[0]) // "") eq "HASH" and builtin::blessed($_[0])
!ll&&!rl&&r
000
builtin::reftype($_[0]) // ""
l!l
000
ref $_[0] eq "HASH" and not scalar keys %{$_[0];}
!ll&&!rl&&r
000
$self // "undef"
l!l
00
length $+{"rgb_type"} and length $+{"red"} and length $+{"green"} and length $+{"blue"}
!ll&&!rl&&r
240
length $+{"rgb_type"} and length $+{"red"} and length $+{"green"}
!ll&&!rl&&r
240
length $+{"rgb_type"} and length $+{"red"}
!ll&&!rl&&r
240
$+{"opacity"} or $light
l!l&&r!l&&!r
042
$self->__message(109, "Checking if rgb value exists for colour '${col}'") and $col_ref = $self->colour_to_rgb($col)
!ll&&!rl&&r
220
defined $params and length($params // "")
!ll&&!rl&&r
220
$params // ""
l!l
22
$+{'style1'} || $+{'style2'}
l!l&&r!l&&!r
505
scalar @res and not scalar(@res) % 2
!ll&&!rl&&r
800
$@ or ref $def ne "HASH"
l!l&&r!l&&!r
600
$@ || qq[Invalid styling "$params"]
l!l
60
$ref and scalar @$ref
!ll&&!rl&&r
400
shift @_ || {}
l!l
40
$args->{"level"} // 1
l!l
0100
$args->{"counter"} // 0
l!l
0010
$chunk // "undef"
l!l
000
defined $args->{"open"} and defined $args->{"close"} and $chunk =~ s[^(?<content>.*?)($open_d/$close_d)][]
!ll&&!rl&&r
000
defined $args->{"open"} and defined $args->{"close"}
!ll&&!rl&&r
000
$copy // "undef"
l!l
30
$chunk // "undef"
l!l
003
$content // "undef"
l!l
000
$content // "undef"
l!l
70
substr($open_d, 0, 2) eq "\\{" or substr($open_d, 0, 2) eq "\\["
l!l&&r!l&&!r
007
$content // "undef"
l!l
000
$content // "undef"
l!l
640
$chunk // "undef"
l!l
640
substr($open_d, 0, 2) eq "\\{" or substr($open_d, 0, 2) eq "\\["
l!l&&r!l&&!r
6400
exists $args->{"open"} and exists $args->{"close"} and defined $args->{"open"} and defined $args->{"close"} and $before =~ m[$open_d/$close_d]
!ll&&!rl&&r
0064
exists $args->{"open"} and exists $args->{"close"} and defined $args->{"open"} and defined $args->{"close"}
!ll&&!rl&&r
000
exists $args->{"open"} and exists $args->{"close"} and defined $args->{"open"}
!ll&&!rl&&r
1020
exists $args->{"open"} and exists $args->{"close"}
!ll&&!rl&&r
040
$after_close // ""
l!l
000
$before_close // ""
l!l
000
$after_close // ""
l!l
000
$remaining // "undef"
l!l
000
$params2 // "undef"
l!l
000
$copy // "undef"
l!l
00
$params // "undef"
l!l
000
$remaining // "undef"
l!l
00
$rv // "undef"
l!l
000
$copy // "undef"
l!l
00
$out // "undef"
l!l
700
$is_tty and exists $args->{"format"} and defined $args->{"format"}
!ll&&!rl&&r
052
$is_tty and exists $args->{"format"}
!ll&&!rl&&r
700
$args->{"open"} and $args->{"close"} or $open_d and $close_d and $open_d ne $open
l!l&&r!l&&!r
002
$args->{"open"} and $args->{"close"}
!ll&&!rl&&r
002
$open_d and $close_d and $open_d ne $open
!ll&&!rl&&r
002
$open_d and $close_d
!ll&&!rl&&r
002
$out // "undef"
l!l
002
$out // "undef"
l!l
200
length $+{"rgb_type"} and length $+{"red"} and length $+{"green"} and length $+{"blue"}
!ll&&!rl&&r
200
length $+{"rgb_type"} and length $+{"red"} and length $+{"green"}
!ll&&!rl&&r
200
length $+{"rgb_type"} and length $+{"red"}
!ll&&!rl&&r
000
$+{"opacity"} or $light
l!l&&r!l&&!r
010
$self->__message(109, "Checking if rgb value exists for colour '${col}'") and $col_ref = $self->colour_to_rgb($col)
!ll&&!rl&&r
010
-t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT))
!ll&&!rl&&r
010
-t STDOUT or not -f STDOUT || -c STDOUT
l!l&&r!l&&!r
010
-f STDOUT || -c STDOUT
l!l&&r!l&&!r
100
length $opts->{"message"} and not length $opts->{"text"}
!ll&&!rl&&r
100
$opts->{"colour"} //= delete $opts->{"color"} || delete $opts->{"fg_colour"} || delete $opts->{"fg_color"} || delete $opts->{"fgcolour"} || delete $opts->{"fgcolor"}
l!l&&r!l&&!r
010
MC/DC100%1/1
shift @_ // ""
shift @_
MC/DC50%1/2
$serialiser eq "Sereal" or $serialiser eq "CBOR"
$serialiser eq "Sereal" $serialiser eq "CBOR"
MC/DC50%1/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
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
MC/DC100%1/1
shift @_ // ""
shift @_
MC/DC0%0/2
$serialiser eq "Sereal" or $serialiser eq "CBOR"
$serialiser eq "Sereal" $serialiser eq "CBOR"
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1 ref $_[0] eq "HASH"
MC/DC100%2/2
defined $ref and ref $ref eq "HASH"
defined $ref ref $ref eq "HASH"
MC/DC33%1/3
exists $ref->{"name"} and defined $ref->{"name"} and $ref->{"name"} eq $name
exists $ref->{"name"} defined $ref->{"name"} $ref->{"name"} eq $name
MC/DC100%1/1
$ref->{"cb"} // ""
$ref->{"cb"}
MC/DC0%0/3
exists $data->{"_error_callbacks"} and defined $data->{"_error_callbacks"} and ref $data->{"_error_callbacks"} eq "ARRAY"
exists $data->{"_error_callbacks"} defined $data->{"_error_callbacks"} ref $data->{"_error_callbacks"} eq "ARRAY"
MC/DC0%0/4
(builtin::reftype($_[0]) // "") eq "SCALAR" and not length(${$_[0];} // "") or not ref $_[0] || length($_[0] // "")
builtin::reftype($_[0]) ${$_[0];} ref $_[0] $_[0]
MC/DC0%0/2
(builtin::reftype($_[0]) // "") eq "ARRAY" and not scalar @{$_[0];}
builtin::reftype($_[0]) not scalar @{$_[0];}
MC/DC0%0/4
(builtin::reftype($_[0]) // "") eq "HASH" and builtin::blessed($_[0]) and $_[0]->can("is_empty") and $_[0]->is_empty ? 1 : 0
builtin::reftype($_[0]) builtin::blessed($_[0]) $_[0]->can("is_empty") $_[0]->is_empty ? 1 : 0
MC/DC0%0/2
ref $_[0] eq "HASH" and not scalar keys %{$_[0];}
ref $_[0] eq "HASH" not scalar keys %{$_[0];}
MC/DC0%0/1
$self // "undef"
$self
MC/DC0%0/4
length $+{"rgb_type"} and length $+{"red"} and length $+{"green"} and length $+{"blue"}
length $+{"rgb_type"} length $+{"red"} length $+{"green"} length $+{"blue"}
MC/DC50%1/2
$+{"opacity"} or $light
$+{"opacity"} $light
MC/DC0%0/2
$self->__message(109, "Checking if rgb value exists for colour '${col}'") and $col_ref = $self->colour_to_rgb($col)
$self->__message(109, "Checking if rgb value exists for colour '${col}'") $col_ref = $self->colour_to_rgb($col)
MC/DC0%0/2
defined $params and length($params // "")
defined $params $params
MC/DC0%0/2
$+{'style1'} || $+{'style2'}
$+{'style1'} $+{'style2'}
MC/DC0%0/2
scalar @res and not scalar(@res) % 2
scalar @res not scalar(@res) % 2
MC/DC0%0/2
$@ or ref $def ne "HASH"
$@ ref $def ne "HASH"
MC/DC0%0/1
$@ || qq[Invalid styling "$params"]
$@
MC/DC0%0/2
$ref and scalar @$ref
$ref scalar @$ref
MC/DC0%0/1
shift @_ || {}
shift @_
MC/DC0%0/1
$args->{"level"} // 1
$args->{"level"}
MC/DC0%0/1
$args->{"counter"} // 0
$args->{"counter"}
MC/DC0%0/1
$chunk // "undef"
$chunk
MC/DC0%0/3
defined $args->{"open"} and defined $args->{"close"} and $chunk =~ s[^(?<content>.*?)($open_d/$close_d)][]
defined $args->{"open"} defined $args->{"close"} $chunk =~ s[^(?<content>.*?)($open_d/$close_d)][]
MC/DC0%0/1
$copy // "undef"
$copy
MC/DC0%0/1
$chunk // "undef"
$chunk
MC/DC0%0/1
$content // "undef"
$content
MC/DC0%0/1
$content // "undef"
$content
MC/DC0%0/2
substr($open_d, 0, 2) eq "\\{" or substr($open_d, 0, 2) eq "\\["
substr($open_d, 0, 2) eq "\\{" substr($open_d, 0, 2) eq "\\["
MC/DC0%0/1
$content // "undef"
$content
MC/DC0%0/1
$content // "undef"
$content
MC/DC0%0/1
$chunk // "undef"
$chunk
MC/DC0%0/2
substr($open_d, 0, 2) eq "\\{" or substr($open_d, 0, 2) eq "\\["
substr($open_d, 0, 2) eq "\\{" substr($open_d, 0, 2) eq "\\["
MC/DC0%0/5
exists $args->{"open"} and exists $args->{"close"} and defined $args->{"open"} and defined $args->{"close"} and $before =~ m[$open_d/$close_d]
exists $args->{"open"} exists $args->{"close"} defined $args->{"open"} defined $args->{"close"} $before =~ m[$open_d/$close_d]
MC/DC0%0/1
$after_close // ""
$after_close
MC/DC0%0/1
$before_close // ""
$before_close
MC/DC0%0/1
$after_close // ""
$after_close
MC/DC0%0/1
$remaining // "undef"
$remaining
MC/DC0%0/1
$params2 // "undef"
$params2
MC/DC0%0/1
$copy // "undef"
$copy
MC/DC0%0/1
$params // "undef"
$params
MC/DC0%0/1
$remaining // "undef"
$remaining
MC/DC0%0/1
$rv // "undef"
$rv
MC/DC0%0/1
$copy // "undef"
$copy
MC/DC0%0/1
$out // "undef"
$out
MC/DC0%0/3
$is_tty and exists $args->{"format"} and defined $args->{"format"}
$is_tty exists $args->{"format"} defined $args->{"format"}
MC/DC0%0/5
$args->{"open"} and $args->{"close"} or $open_d and $close_d and $open_d ne $open
$args->{"open"} $args->{"close"} $open_d $close_d $open_d ne $open
MC/DC0%0/1
$out // "undef"
$out
MC/DC0%0/1
$out // "undef"
$out
MC/DC0%0/4
length $+{"rgb_type"} and length $+{"red"} and length $+{"green"} and length $+{"blue"}
length $+{"rgb_type"} length $+{"red"} length $+{"green"} length $+{"blue"}
MC/DC0%0/2
$+{"opacity"} or $light
$+{"opacity"} $light
MC/DC0%0/2
$self->__message(109, "Checking if rgb value exists for colour '${col}'") and $col_ref = $self->colour_to_rgb($col)
$self->__message(109, "Checking if rgb value exists for colour '${col}'") $col_ref = $self->colour_to_rgb($col)
MC/DC0%0/4
-t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT))
-t STDIN -t STDOUT -f STDOUT -c STDOUT
MC/DC0%0/2
length $opts->{"message"} and not length $opts->{"text"}
length $opts->{"message"} not length $opts->{"text"}
MC/DC0%0/2
$opts->{"colour"} //= delete $opts->{"color"} || delete $opts->{"fg_colour"} || delete $opts->{"fg_color"} || delete $opts->{"fgcolour"} || delete $opts->{"fgcolor"}
$opts->{"colour"} delete $opts->{"color"} || delete $opts->{"fg_colour"} || delete $opts->{"fg_color"} || delete $opts->{"fgcolour"} || delete $opts->{"fgcolor"}
Truth table100%2/2
A
A= shift @_
Aresult
11
00
Truth table66%2/3
A or B
A= $serialiser eq "Sereal"B= $serialiser eq "CBOR"
ABresult
1X1
011
000
Truth table66%2/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
Truth table0%0/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
Truth table100%2/2
A
A= shift @_
Aresult
11
00
Truth table33%1/3
A or B
A= $serialiser eq "Sereal"B= $serialiser eq "CBOR"
ABresult
1X1
011
000
Truth table0%0/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
Truth table100%3/3
A and B
A= defined $refB= ref $ref eq "HASH"
ABresult
0X0
100
111
Truth table50%2/4
A and B and C
A= exists $ref->{"name"}B= defined $ref->{"name"}C= $ref->{"name"} eq $name
ABCresult
0XX0
10X0
1100
1111
Truth table100%2/2
A
A= $ref->{"cb"}
Aresult
11
00
Truth table0%0/4
A and B and C
A= exists $data->{"_error_callbacks"}B= defined $data->{"_error_callbacks"}C= ref $data->{"_error_callbacks"} eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/7
A and not(B) or not(C || D)
A= builtin::reftype($_[0])B= ${$_[0];}C= ref $_[0]D= $_[0]
ABCDresult
10XX1
0X001
11001
0X1X0
0X010
111X0
11010
Truth table0%0/3
A and not(B)
A= builtin::reftype($_[0])B= not scalar @{$_[0];}
ABresult
0X0
100
111
Truth table0%0/5
A and B and C and D
A= builtin::reftype($_[0])B= builtin::blessed($_[0])C= $_[0]->can("is_empty")D= $_[0]->is_empty ? 1 : 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/3
A and not(B)
A= ref $_[0] eq "HASH"B= not scalar keys %{$_[0];}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $self
Aresult
11
00
Truth table0%0/5
A and B and C and D
A= length $+{"rgb_type"}B= length $+{"red"}C= length $+{"green"}D= length $+{"blue"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table66%2/3
A or B
A= $+{"opacity"}B= $light
ABresult
1X1
011
000
Truth table0%0/3
A and B
A= $self->__message(109, "Checking if rgb value exists for colour '${col}'")B= $col_ref = $self->colour_to_rgb($col)
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $paramsB= $params
ABresult
0X0
100
111
Truth table0%0/3
A || B
A= $+{'style1'}B= $+{'style2'}
ABresult
1X1
011
000
Truth table0%0/3
A and not(B)
A= scalar @resB= not scalar(@res) % 2
ABresult
0X0
100
111
Truth table0%0/3
A or B
A= $@B= ref $def ne "HASH"
ABresult
1X1
011
000
Truth table50%1/2
A
A= $@
Aresult
11
00
Truth table0%0/3
A and B
A= $refB= scalar @$ref
ABresult
0X0
100
111
Truth table50%1/2
A
A= shift @_
Aresult
11
00
Truth table50%1/2
A
A= $args->{"level"}
Aresult
11
00
Truth table0%0/2
A
A= $args->{"counter"}
Aresult
11
00
Truth table0%0/2
A
A= $chunk
Aresult
11
00
Truth table0%0/4
A and B and C
A= defined $args->{"open"}B= defined $args->{"close"}C= $chunk =~ s[^(?<content>.*?)($open_d/$close_d)][]
ABCresult
0XX0
10X0
1100
1111
Truth table50%1/2
A
A= $copy
Aresult
11
00
Truth table50%1/2
A
A= $chunk
Aresult
11
00
Truth table0%0/2
A
A= $content
Aresult
11
00
Truth table50%1/2
A
A= $content
Aresult
11
00
Truth table33%1/3
A or B
A= substr($open_d, 0, 2) eq "\\{"B= substr($open_d, 0, 2) eq "\\["
ABresult
1X1
011
000
Truth table0%0/2
A
A= $content
Aresult
11
00
Truth table50%1/2
A
A= $content
Aresult
11
00
Truth table50%1/2
A
A= $chunk
Aresult
11
00
Truth table0%0/3
A or B
A= substr($open_d, 0, 2) eq "\\{"B= substr($open_d, 0, 2) eq "\\["
ABresult
1X1
011
000
Truth table0%0/6
A and B and C and D and E
A= exists $args->{"open"}B= exists $args->{"close"}C= defined $args->{"open"}D= defined $args->{"close"}E= $before =~ m[$open_d/$close_d]
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
Truth table0%0/2
A
A= $after_close
Aresult
11
00
Truth table0%0/2
A
A= $before_close
Aresult
11
00
Truth table0%0/2
A
A= $after_close
Aresult
11
00
Truth table0%0/2
A
A= $remaining
Aresult
11
00
Truth table0%0/2
A
A= $params2
Aresult
11
00
Truth table0%0/2
A
A= $copy
Aresult
11
00
Truth table0%0/2
A
A= $params
Aresult
11
00
Truth table0%0/2
A
A= $remaining
Aresult
11
00
Truth table0%0/2
A
A= $rv
Aresult
11
00
Truth table0%0/2
A
A= $copy
Aresult
11
00
Truth table50%1/2
A
A= $out
Aresult
11
00
Truth table0%0/4
A and B and C
A= $is_ttyB= exists $args->{"format"}C= defined $args->{"format"}
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/9
A and B or C and D and E
A= $args->{"open"}B= $args->{"close"}C= $open_dD= $close_dE= $open_d ne $open
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
Truth table50%1/2
A
A= $out
Aresult
11
00
Truth table50%1/2
A
A= $out
Aresult
11
00
Truth table0%0/5
A and B and C and D
A= length $+{"rgb_type"}B= length $+{"red"}C= length $+{"green"}D= length $+{"blue"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table33%1/3
A or B
A= $+{"opacity"}B= $light
ABresult
1X1
011
000
Truth table0%0/3
A and B
A= $self->__message(109, "Checking if rgb value exists for colour '${col}'")B= $col_ref = $self->colour_to_rgb($col)
ABresult
0X0
100
111
Truth table0%0/5
A && B or not(C || D)
A= -t STDINB= -t STDOUTC= -f STDOUTD= -c STDOUT
ABCDresult
0XXX0
101X0
10010
11XX1
10001
Truth table0%0/3
A and not(B)
A= length $opts->{"message"}B= not length $opts->{"text"}
ABresult
0X0
100
111
Truth table0%0/3
A //= B
A= $opts->{"colour"}B= delete $opts->{"color"} || delete $opts->{"fg_colour"} || delete $opts->{"fg_color"} || delete $opts->{"fgcolour"} || delete $opts->{"fgcolor"}
ABresult
1X1
011
000
13147 }
13148 96 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 96 96
13149 {
13150 0 $@ =~ s/ at .*\n//;
13151 0 die( $@ );
13152 }
13153 96 $@ = $saved;
13154 96 ▶ my $ref = $class->can( $meth ) || die( "AUTOLOAD inconsistency error for dynamic sub \"$meth\"." );
Condition50%1/2
$class->can($meth) || die(qq[AUTOLOAD inconsistency error for dynamic sub "$meth".])
l!l
960
MC/DC0%0/1
$class->can($meth) || die(qq[AUTOLOAD inconsistency error for dynamic sub "$meth".])
$class->can($meth)
Truth table50%1/2
A
A= $class->can($meth)
Aresult
11
00
13155 # Use goto &$ref to transfer execution to the newly-installed sub.
13156 96 ▶ unshift( @_, $self ) if( $self );
Branch: 1 branch
BranchTrueFalseTotal
if $self 76 20 96
13157 96 goto &$ref;
13158 }
13159  
13160 218 ▶ if( $self && $self->can( 'autoload' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self and $self->can("autoload")) 0 218 218
Condition33%1/3
$self and $self->can("autoload")
!ll&&!rl&&r
02180
MC/DC0%0/2
$self and $self->can("autoload")
$self $self->can("autoload")
Truth table33%1/3
A and B
A= $selfB= $self->can("autoload")
ABresult
0X0
100
111
13161 {
13162 0 ▶ if( my $code = $self->autoload( $meth ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $self->autoload($meth)) 0 0 0
13163 {
13164 0 ▶ return( $code->( $self, @_ ) ) if( $code );
Branch: 1 branch
BranchTrueFalseTotal
if $code 0 0 0
13165 }
13166 }
13167  
13168 218 $meth = lc( $meth );
13169 218 my $this;
13170 218 ▶ $this = $self->_obj2h if( defined( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 218 0 218
13171 218 my $data;
13172 218 ▶ if( $this )
Branch: 1 branch
BranchTrueFalseTotal
if ($this) 218 0 218
13173 {
13174 218 ▶ $data = $this->{_data_repo} ? $this->{ $this->{_data_repo} } : $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'_data_repo'} ? : 0 218 218
13175 }
13176 # Check if the object has a property some-thing for a given call to method some_thing
13177 218 my $meth_dashed = $meth;
13178 218 $meth_dashed =~ tr/_/-/;
13179 218 ▶ if( $data && CORE::exists( $data->{ $meth } ) )
Branch: 4 branches
BranchTrueFalseTotal
if ($data and exists $data->{$meth}) { } 218 0 218
elsif ($data and exists $data->{$meth_dashed}) { } 0 0 0
elsif ($self and $self->can($meth) and defined &{"${class}::$meth";}) { } 0 0 0
elsif (defined &$meth) { } 0 0 0
Condition33%1/3
$data and exists $data->{$meth}
!ll&&!rl&&r
00218
MC/DC0%0/2
$data and exists $data->{$meth}
$data exists $data->{$meth}
Truth table33%1/3
A and B
A= $dataB= exists $data->{$meth}
ABresult
0X0
100
111
13180 {
13181 218 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 218 218
13182 {
13183 0 ▶ my $val = ( @_ == 1 ) ? shift( @_ ) : [ @_ ];
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
13184 0 $data->{ $meth } = $val;
13185 }
13186 218 ▶ if( wantarray() )
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 3 215 218
13187 {
13188 3 ▶ if( ref( $data->{ $meth } ) eq 'ARRAY' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data->{$meth} eq 'ARRAY') { } 0 3 3
elsif (ref $data->{$meth} eq 'HASH') { } 0 3 3
13189 {
13190 0 return( @{ $data->{ $meth } } );
13191 }
13192 elsif( ref( $data->{ $meth } ) eq 'HASH' )
13193 {
13194 0 return( %{ $data->{ $meth } } );
13195 }
13196 else
13197 {
13198 3 return( ( $data->{ $meth } ) );
13199 }
13200 }
13201 else
13202 {
13203 215 return( $data->{ $meth } );
13204 }
13205 }
13206 ▶ elsif( $data && CORE::exists( $data->{ $meth_dashed } ) )
Condition0%0/3
$data and exists $data->{$meth_dashed}
!ll&&!rl&&r
000
MC/DC0%0/2
$data and exists $data->{$meth_dashed}
$data exists $data->{$meth_dashed}
Truth table0%0/3
A and B
A= $dataB= exists $data->{$meth_dashed}
ABresult
0X0
100
111
13207 {
13208 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
13209 {
13210 0 ▶ my $val = ( @_ == 1 ) ? shift( @_ ) : [ @_ ];
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
13211 0 $data->{ $meth_dashed } = $val;
13212 }
13213 0 ▶ if( wantarray() )
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
13214 {
13215 0 ▶ if( ref( $data->{ $meth_dashed } ) eq 'ARRAY' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data->{$meth_dashed} eq 'ARRAY') { } 0 0 0
elsif (ref $data->{$meth_dashed} eq 'HASH') { } 0 0 0
13216 {
13217 0 return( @{ $data->{ $meth_dashed } } );
13218 }
13219 elsif( ref( $data->{ $meth_dashed } ) eq 'HASH' )
13220 {
13221 0 return( %{ $data->{ $meth_dashed } } );
13222 }
13223 else
13224 {
13225 0 return( ( $data->{ $meth_dashed } ) );
13226 }
13227 }
13228 else
13229 {
13230 0 return( $data->{ $meth_dashed } );
13231 }
13232 }
13233 # Because, if it does not exist in the caller's package,
13234 # calling the method will get us here infinitly,
13235 # since UNIVERSAL::can will somehow return true even if it does not exist
13236 0 ▶ elsif( $self && $self->can( $meth ) && defined( &{ "$class\::$meth" } ) )
Condition0%0/6
$self and $self->can($meth) and defined &{"${class}::$meth";}
!ll&&!rl&&r
000
$self and $self->can($meth)
!ll&&!rl&&r
000
MC/DC0%0/3
$self and $self->can($meth) and defined &{"${class}::$meth";}
$self $self->can($meth) defined &{"${class}::$meth";}
Truth table0%0/4
A and B and C
A= $selfB= $self->can($meth)C= defined &{"${class}::$meth";}
ABCresult
0XX0
10X0
1100
1111
13237 {
13238 0 return( $self->$meth( @_ ) );
13239 }
13240 elsif( defined( &$meth ) )
13241 {
13242 40 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
13243 0 *$meth = \&$meth;
13244 0 ▶ return( &$meth( $self, @_ ) ) if( $self );
Branch: 1 branch
BranchTrueFalseTotal
if $self 0 0 0
13245 0 return( &$meth( @_ ) );
13246 }
13247 else
13248 {
13249 0 my $sub = $AUTOLOAD;
13250 0 my( $pkg, $func ) = ( $sub =~ /(.*)::([^:]+)$/ );
13251 0 my $mesg = "Module::Generic::AUTOLOAD(): Searching for routine '$func' from package '$pkg'.";
13252 0 ▶ if( $MOD_PERL )
Branch: 1 branch
BranchTrueFalseTotal
if ($MOD_PERL) { } 0 0 0
13253 {
13254 # try-catch
13255 0 local $@;
13256 eval
13257 0 {
13258 0 my $r = Apache2::RequestUtil->request;
13259 0 $r->log->debug( $mesg );
13260 };
13261 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
13262 {
13263 0 print( STDERR "Error trying to get the global Apache2::ApacheRec: $@\n" );
13264 }
13265 }
13266 else
13267 {
13268 0 ▶ print( STDERR $mesg . "\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 0 0
13269 }
13270 0 $pkg =~ s/::/\//g;
13271 0 my $filename;
13272 0 ▶ if( defined( $filename = $INC{ "$pkg.pm" } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($filename = $INC{"$pkg.pm"})) 0 0 0
13273 {
13274 0 $filename =~ s/^(.*)$pkg\.pm\z/$1auto\/$pkg\/$func.al/s;
13275 0 ▶ if( -r( $filename ) )
Branch: 1 branch
BranchTrueFalseTotal
if (-r $filename) { } 0 0 0
13276 {
13277 0 ▶ unless( $filename =~ m|^/|s )
Branch: 1 branch
BranchTrueFalseTotal
unless ($filename =~ m[^/]s) 0 0 0
13278 {
13279 0 $filename = "./$filename";
13280 }
13281 }
13282 else
13283 {
13284 0 $filename = undef();
13285 }
13286 }
13287 0 ▶ if( !defined( $filename ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $filename) 0 0 0
13288 {
13289 0 $filename = "auto/$sub.al";
13290 0 $filename =~ s/::/\//g;
13291 }
13292 0 my $save = $@;
13293 0 local $@;
13294 eval
13295 0 {
13296 0 ▶ local $SIG{__DIE__} = sub{ };
Subroutine __ANON__: called CC=1 SCAR=6.9
13297 0 ▶ local $SIG{__WARN__} = sub{ };
Subroutine __ANON__: called CC=1 SCAR=6.9
13298 0 require $filename;
13299 };
13300 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
13301 {
13302 0 ▶ if( substr( $sub, -9 ) eq '::DESTROY' )
Branch: 1 branch
BranchTrueFalseTotal
if (substr($sub, -9) eq '::DESTROY') { } 0 0 0
13303 {
13304 0 ▶ *$sub = sub {};
Subroutine __ANON__: called CC=1 SCAR=6.9
13305 }
13306 else
13307 {
13308 # The load might just have failed because the filename was too
13309 # long for some old SVR3 systems which treat long names as errors.
13310 # If we can succesfully truncate a long name then it's worth a go.
13311 # There is a slight risk that we could pick up the wrong file here
13312 # but autosplit should have warned about that when splitting.
13313 0 ▶ if( $filename =~ s/(\w{12,})\.al$/substr( $1, 0, 11 ) . ".al"/e )
Branch: 1 branch
BranchTrueFalseTotal
if ($filename =~ s/(\w{12,})\.al$/substr($1, 0, 11) . '.al';/e) 0 0 0
13314 {
13315 0 local $@;
13316 eval
13317 0 {
13318 0 ▶ local $SIG{__DIE__} = sub{ };
Subroutine __ANON__: called CC=1 SCAR=6.9
13319 0 ▶ local $SIG{__WARN__} = sub{ };
Subroutine __ANON__: called CC=1 SCAR=6.9
13320 0 require $filename
13321 };
13322 }
13323 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
13324 {
13325 ## Look up in our caller's @ISA to see if there is any package that has this special
13326 ## EXTRA_AUTOLOAD() sub routine
13327 0 my $sub_ref = '';
13328 0 ▶ die( "EXTRA_AUTOLOAD: ", join( "', '", @_ ), "\n" ) if( $func eq 'EXTRA_AUTOLOAD' );
Branch: 1 branch
BranchTrueFalseTotal
if $func eq "EXTRA_AUTOLOAD" 0 0 0
13329 0 ▶ if( $self && $func ne 'EXTRA_AUTOLOAD' && ( $sub_ref = $self->will( 'EXTRA_AUTOLOAD' ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self and $func ne 'EXTRA_AUTOLOAD' and $sub_ref = $self->will('EXTRA_AUTOLOAD')) { } 0 0 0
Condition0%0/6
$self and $func ne "EXTRA_AUTOLOAD" and $sub_ref = $self->will("EXTRA_AUTOLOAD")
!ll&&!rl&&r
000
$self and $func ne "EXTRA_AUTOLOAD"
!ll&&!rl&&r
000
MC/DC0%0/3
$self and $func ne "EXTRA_AUTOLOAD" and $sub_ref = $self->will("EXTRA_AUTOLOAD")
$self $func ne "EXTRA_AUTOLOAD" $sub_ref = $self->will("EXTRA_AUTOLOAD")
Truth table0%0/4
A and B and C
A= $selfB= $func ne "EXTRA_AUTOLOAD"C= $sub_ref = $self->will("EXTRA_AUTOLOAD")
ABCresult
0XX0
10X0
1100
1111
13330 {
13331 0 return( $sub_ref->( $self, $AUTOLOAD, @_ ) );
13332 }
13333 else
13334 {
13335 0 my $keys = CORE::join( ',', keys( %$data ) );
13336 0 my $msg = "Method $func() is not defined in class $class and not autoloadable in package $pkg in file $file at line $line.\n";
13337 0 ▶ $msg .= "There are actually the following fields in the object '" . overload::StrVal( $self // 'undef' ) . "': '$keys'\n";
Condition0%0/2
$self // "undef"
l!l
00
MC/DC0%0/1
$self // "undef"
$self
Truth table0%0/2
A
A= $self
Aresult
11
00
13338 0 die( $msg );
13339 }
13340 }
13341 }
13342 }
13343 0 $@ = $save;
13344 0 ▶ if( $DEBUG )
Branch: 1 branch
BranchTrueFalseTotal
if ($DEBUG) 0 0 0
13345 {
13346 0 my $mesg = "unshifting '$self' to args for sub '$sub'.";
13347 0 ▶ if( $MOD_PERL )
Branch: 1 branch
BranchTrueFalseTotal
if ($MOD_PERL) { } 0 0 0
13348 {
13349 # try-catch
13350 0 local $@;
13351 eval
13352 0 {
13353 0 my $r = Apache2::RequestUtil->request;
13354 0 $r->log->debug( $mesg );
13355 };
13356 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
13357 {
13358 0 print( STDERR "Error trying to get the global Apache2::ApacheRec: $@\n" );
13359 }
13360 }
13361 else
13362 {
13363 0 print( $stderr "$mesg\n" );
13364 }
13365 }
13366 0 ▶ unshift( @_, $self ) if( $self );
Branch: 1 branch
BranchTrueFalseTotal
if $self 0 0 0
13367 # if( $] >= 5.016 )
13368 # {
13369 # # goto &$sub;
13370 # }
13371 # In perl < v5.16, we lose the magic of goto called in AUTOLOAD, i.e. "pretend that the other subroutine had been called in the first place" (perlfunc/goto)
13372 # else
13373 # {
13374 0 &$sub( @_ );
13375 # }
13376 }
13377 };
13378  
13379 sub DEBUG
13380 4 ▶{
Subroutine DEBUG: called CC=2 SCAR=6.9
Pod documented
13381 440 my $self = shift( @_ );
13382 440 ▶ my $pkg = ref( $self ) || $self;
Condition100%3/3
ref $self || $self
l!l&&r!l&&!r
148112246
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
13383 442 my $this = $self->_obj2h;
13384 123 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
13385 440 return( ${ $pkg . '::DEBUG' } );
13386 }
13387  
13388 sub DESTROY
13389 1231 ▶{
Subroutine DESTROY: called CC=6 SCAR=17.9
13390 # <https://perldoc.perl.org/perlobj#Destructors>
13391 1429 CORE::local( $., $@, $!, $^E, $? );
13392 1319 ▶ CORE::return if( Module::Generic::_in_global_destruction() );
Branch: 1 branch
BranchTrueFalseTotal
if _in_global_destruction() 0 1671 1671
13393 1321 my $self = CORE::shift( @_ );
13394 1317 ▶ CORE::return if( !CORE::defined( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 91 1666 1757
13395 # If the Global repository has already been cleared by the END block, there is
13396 # nothing to clean up. We just bail out to avoid use-after-free.
13397 1317 ▶ CORE::return if( !CORE::defined( $Module::Generic::Global::REPO ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Module::Generic::Global::REPO 116 1641 1757
13398  
13399 1317 ▶ my $class = CORE::ref( $self ) || $self;
Condition100%3/3
ref $self || $self
l!l&&r!l&&!r
164744
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
13400 1559 ▶ my $err_key = HAS_THREADS() ? join( ';', $class, $$, threads->tid ) : join( ';', $class, $$ );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 4 1473 1477
13401 1403 my $repo = Module::Generic::Global->new( 'errors' => $class, key => $err_key );
13402 1468 $repo->cleanup;
13403  
13404 1382 my $log_repo = Module::Generic::Global->new( 'debug_log_io' => $class );
13405 1382 $log_repo->cleanup;
13406  
13407 1382 my $local_tz_repo = Module::Generic::Global->new( 'globals' => $class, key => 'has_local_tz' );
13408 1382 $local_tz_repo->cleanup;
13409  
13410 # We cannot cleanup here the 'loaded_classes', because we need the class that is cached to build the key, and we do not have it at this very moment.
13411 };
13412  
13413 # NOTE: Works with CBOR and Sereal <https://metacpan.org/pod/Sereal::Encoder#FREEZE/THAW-CALLBACK-MECHANISM>
13414 sub FREEZE
13415 1 ▶{
Subroutine FREEZE: called CC=6 SCAR=17.9
Pod undocumented
13416 5 my $self = CORE::shift( @_ );
13417 5 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition100%3/3
shift @_ // ""
l!l
643545
MC/DC100%1/1
shift @_ // ""
shift @_
Truth table100%2/2
A
A= shift @_
Aresult
11
00
13418 5 my $class = CORE::ref( $self );
13419 5 my $ref = $self->_obj2h;
13420 5 my %hash = %$ref;
13421 5 delete( $hash{_error_callbacks} );
13422 5 ▶ $hash{_is_glob} = ( Scalar::Util::reftype( $self ) // '' ) eq 'GLOB' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
(builtin::reftype($self) // '') eq 'GLOB' ? : 4 243 247
Condition66%2/3
builtin::reftype($self) // ""
l!l
6405
MC/DC0%0/1
builtin::reftype($self) // ""
builtin::reftype($self)
Truth table50%1/2
A
A= builtin::reftype($self)
Aresult
11
00
13423 # Return an array reference rather than a list so this works with Sereal and CBOR
13424 # On or before Sereal version 4.023, Sereal did not support multiple values returned
13425 2 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 4 485 489
13426 {
13427 2 require Sereal::Encoder;
13428 2 require version;
13429
13430 149 ▶ if( version->parse( Sereal::Encoder->VERSION ) <= version->parse( '4.023' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ("version"->parse("Sereal::Encoder"->VERSION) <= "version"->parse("4.023")) 1 6 7
13431 {
13432 148 CORE::return( [$class, \%hash] );
13433 }
13434 }
13435 # But Storable want a list with the first element being the serialised element
13436 148 CORE::return( $class, \%hash );
13437 }
13438  
13439 # sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
13440  
13441 # sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
13442  
13443 # NOTE: Works with CBOR and Sereal <https://metacpan.org/pod/Sereal::Encoder#FREEZE/THAW-CALLBACK-MECHANISM>
13444 sub THAW
13445 1 ▶{
Subroutine THAW: called CC=13 SCAR=26.1
Pod undocumented
13446 1 my( $self, undef, @args ) = @_;
13447 149 ▶ 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 151 151
Condition100%3/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
62242112
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
13448 1 ▶ 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 ? : 1 4 5
Condition77%7/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
474249
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
364051
ref $self or $self
l!l&&r!l&&!r
024282
MC/DC66%2/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 table75%3/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
ABCresult
0XX0
10X0
1100
1111
Truth table33%1/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
13449 230 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 1 1 2
13450 83 my $is_glob = CORE::delete( $hash->{_is_glob} );
13451 83 my $new;
13452 83 ▶ if( $is_glob )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_glob) { } 0 1 1
13453 {
13454 0 ▶ $new = CORE::ref( $self ) ? $self : $class->new_glob;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 134 34 168
13455 0 foreach( CORE::keys( %$hash ) )
13456 {
13457 86 *$new->{ $_ } = CORE::delete( $hash->{ $_ } );
13458 }
13459 }
13460 else
13461 {
13462 # Storable pattern requires to modify the object it created rather than returning a new one
13463 87 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 147 37 184
13464 {
13465 86 foreach( CORE::keys( %$hash ) )
13466 {
13467 86 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
13468 }
13469 86 $new = $self;
13470 }
13471 else
13472 {
13473 87 $new = bless( $hash => $class );
13474 }
13475 }
13476 87 CORE::return( $new );
13477 }
13478  
13479 sub VERBOSE
13480 0 ▶{
Subroutine VERBOSE: not called CC=2 SCAR=6.9
Pod documented
13481 7 my $self = shift( @_ );
13482 7 ▶ my $pkg = ref( $self ) || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
24920
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
13483 7 my $this = $self->_obj2h;
13484 40 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
13485 7 return( ${ $pkg . '::VERBOSE' } );
13486 }
13487  
13488 {
13489 # Credits to the module Sentinel for the idea of using a tied scalar.
13490 # NOTE: Module::Generic::LvalueGuard
13491 package
13492 Module::Generic::LvalueGuard;
13493 123 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13494 40 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13495 123 ▶ use vars qw( $LOCK );
Subroutine BEGIN: called CC=1 SCAR=0.0
13496 123 ▶ use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13497 38 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13498 38 ▶ use Storable::Improved qw( freeze thaw );
Subroutine BEGIN: called CC=1 SCAR=0.0
13499 38 ▶ use constant CAN_THREADS => $Config{useithreads};
Subroutine BEGIN: called CC=1 SCAR=0.0
13500 40 ▶ sub HAS_THREADS { return( $Config{useithreads} && $INC{'threads.pm'} ); };
Subroutine HAS_THREADS: called CC=2 SCAR=6.9
Condition100%3/3
$Module::Generic::LvalueGuard::Config{'useithreads'} && $INC{'threads.pm'}
!ll&&!rl&&r
286161
MC/DC0%0/2
$Module::Generic::LvalueGuard::Config{'useithreads'} && $INC{'threads.pm'}
$Module::Generic::LvalueGuard::Config{'useithreads'} $INC{'threads.pm'}
Truth table33%1/3
A && B
A= $Module::Generic::LvalueGuard::Config{'useithreads'}B= $INC{'threads.pm'}
ABresult
0X0
100
111
13501 130 ▶ sub IN_THREAD { return( $Config{useithreads} && $INC{'threads.pm'} && threads->tid != 0 ); };
Subroutine IN_THREAD: called CC=3 SCAR=11.1
Condition83%5/6
$Module::Generic::LvalueGuard::Config{'useithreads'} && $INC{'threads.pm'} && 'threads'->tid != 0
!ll&&!rl&&r
371063
$Module::Generic::LvalueGuard::Config{"useithreads"} and $INC{"threads.pm"}
!ll&&!rl&&r
13224259
MC/DC0%0/3
$Module::Generic::LvalueGuard::Config{'useithreads'} && $INC{'threads.pm'} && 'threads'->tid != 0
$Module::Generic::LvalueGuard::Config{"useithreads"} $INC{"threads.pm"} 'threads'->tid != 0
Truth table25%1/4
A and B && C
A= $Module::Generic::LvalueGuard::Config{"useithreads"}B= $INC{"threads.pm"}C= 'threads'->tid != 0
ABCresult
0XX0
10X0
1100
1111
13502 37 ▶ if( HAS_THREADS )
Branch: 1 branch
BranchTrueFalseTotal
if (HAS_THREADS()) 10 45 55
13503 {
13504 20 require threads;
13505 20 require threads::shared;
13506 20 threads->import();
13507 20 threads::shared->import();
13508 20 my $lock :shared;
13509 20 $LOCK = \$lock;
13510 }
13511  
13512 sub TIESCALAR
13513 35 ▶ {
Subroutine TIESCALAR: called CC=5 SCAR=16.4
13514 39 my( $class, %args ) = @_;
13515 42 ▶ if( defined( $args{obj} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"obj"}) 35 229 264
13516 {
13517 42 ▶ if( !Scalar::Util::blessed( $args{obj} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not builtin::blessed($args{'obj'})) { } 0 37 37
elsif (IN_THREAD()) { } 86 37 123
13518 {
13519 5 ▶ die( "The object provided (", overload::StrVal( $args{obj} // 'undef' ), ") is not a class object." );
Condition33%1/3
$args{"obj"} // "undef"
l!l
25100
MC/DC100%1/1
$args{"obj"} // "undef"
$args{"obj"}
Truth table100%2/2
A
A= $args{"obj"}
Aresult
11
00
13520 }
13521 elsif( IN_THREAD )
13522 {
13523 4 $args{obj} = freeze( $args{obj} );
13524 }
13525 }
13526 my $self = bless({
13527 value => $args{value}, # Current value
13528 get => $args{get}, # Getter callback
13529 set => $args{set}, # Setter callback
13530 obj => $args{obj}, # Optional object associated
13531 39 }, $class );
13532 39 return( $self );
13533 }
13534  
13535 sub FETCH
13536 18 ▶ {
Subroutine FETCH: called CC=12 SCAR=25.3
13537 22 my $self = shift( @_ );
13538 22 my $get = $self->{get};
13539 22 my $obj = $self->{obj};
13540 22 ▶ if( defined( $obj ) && IN_THREAD )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj and IN_THREAD()) 7 97 104
Condition66%2/3
defined $obj and IN_THREAD()
!ll&&!rl&&r
4180
MC/DC0%0/2
defined $obj and IN_THREAD()
defined $obj IN_THREAD()
Truth table33%1/3
A and B
A= defined $objB= IN_THREAD()
ABresult
0X0
100
111
13541 {
13542 4 $obj = thaw( $obj );
13543 }
13544  
13545 # 'get' refers to a method name in the object class
13546 18 ▶ if( defined( $get ) && !ref( $get ) && defined( $obj ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $get and not ref $get and defined $obj) { } 8 89 97
elsif (defined $get and ref $get eq 'CODE') { } 18 71 89
Condition50%3/6
defined $get and not ref $get and defined $obj
!ll&&!rl&&r
2200
defined $get and not ref $get
!ll&&!rl&&r
0181
MC/DC0%0/3
defined $get and not ref $get and defined $obj
defined $get not ref $get defined $obj
Truth table25%1/4
A and not(B) and C
A= defined $getB= not ref $getC= defined $obj
ABCresult
0XX0
10X0
1100
1111
13547 {
13548 1 ▶ if( my $code = $obj->can( $get ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $obj->can($get)) { } 2 69 71
13549 {
13550 1 ▶ lock( $LOCK ) if( IN_THREAD );
Branch: 1 branch
BranchTrueFalseTotal
if IN_THREAD() 20 49 69
13551 1 return( $code->( $obj ) );
13552 }
13553 else
13554 {
13555 1 die( "Method '$get' is not defined in the class ", ref( $obj ) );
13556 }
13557 }
13558 # Callback
13559 ▶ elsif( defined( $get ) && ref( $get ) eq 'CODE' )
Condition66%2/3
defined $get and ref $get eq "CODE"
!ll&&!rl&&r
1018
MC/DC0%0/2
defined $get and ref $get eq "CODE"
defined $get ref $get eq "CODE"
Truth table33%1/3
A and B
A= defined $getB= ref $get eq "CODE"
ABresult
0X0
100
111
13560 {
13561 19 ▶ lock( $LOCK ) if( IN_THREAD );
Branch: 1 branch
BranchTrueFalseTotal
if IN_THREAD() 0 67 67
13562 18 ▶ return( $get->( defined( $obj ) ? ( $obj ) : () ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $obj ? : 24 43 67
13563 }
13564 # Direct value
13565 else
13566 {
13567 1 return( $self->{value} );
13568 }
13569 }
13570  
13571 sub STORE
13572 26 ▶ {
Subroutine STORE: called CC=12 SCAR=25.1
13573 27 my $self = shift( @_ );
13574 27 my( $value ) = @_;
13575 33 my $set = $self->{set};
13576 33 my $obj = $self->{obj};
13577 33 ▶ if( defined( $obj ) && IN_THREAD )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj and IN_THREAD()) 2 67 69
Condition66%2/3
defined $obj and IN_THREAD()
!ll&&!rl&&r
0261
MC/DC0%0/2
defined $obj and IN_THREAD()
defined $obj IN_THREAD()
Truth table33%1/3
A and B
A= defined $objB= IN_THREAD()
ABresult
0X0
100
111
13578 {
13579 8 $obj = thaw( $obj );
13580 }
13581  
13582 # 'set' refers to a method name in the object class
13583 34 ▶ if( defined( $set ) && !ref( $set ) && defined( $obj ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $set and not ref $set and defined $obj) { } 2 65 67
elsif (defined $set and ref $set eq 'CODE') { } 28 37 65
Condition50%3/6
defined $set and not ref $set and defined $obj
!ll&&!rl&&r
2600
defined $set and not ref $set
!ll&&!rl&&r
1260
MC/DC0%0/3
defined $set and not ref $set and defined $obj
defined $set not ref $set defined $obj
Truth table25%1/4
A and not(B) and C
A= defined $setB= not ref $setC= defined $obj
ABCresult
0XX0
10X0
1100
1111
13584 {
13585 8 ▶ if( my $code = $obj->can( $set ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $obj->can($set)) { } 3 34 37
13586 {
13587 8 ▶ lock( $LOCK ) if( IN_THREAD );
Branch: 1 branch
BranchTrueFalseTotal
if IN_THREAD() 6 28 34
13588 8 return( $code->( $obj, $value ) );
13589 }
13590 else
13591 {
13592 4 die( "Method '$set' is not defined in the class ", ref( $obj ) );
13593 }
13594 }
13595 # Callback
13596 ▶ elsif( defined( $set ) && ref( $set ) eq 'CODE' )
Condition66%2/3
defined $set and ref $set eq "CODE"
!ll&&!rl&&r
1026
MC/DC0%0/2
defined $set and ref $set eq "CODE"
defined $set ref $set eq "CODE"
Truth table33%1/3
A and B
A= defined $setB= ref $set eq "CODE"
ABresult
0X0
100
111
13597 {
13598 30 ▶ lock( $LOCK ) if( IN_THREAD );
Branch: 1 branch
BranchTrueFalseTotal
if IN_THREAD() 4 50 54
13599 34 ▶ $set->( defined( $obj ) ? ( $obj ) : (), $value );
Branch: 1 branch
BranchTrueFalseTotal
defined $obj ? : 28 22 50
13600 }
13601 # Store the value
13602 34 $self->{value} = $value;
13603 }
13604 }
13605  
13606 37 1;
13607 # NOTE: POD
13608 __END__
↑ Summary lib/Module/Generic/File.pm »