lib/Module/Generic/Global.pm

filter: Statementstmt 55.0% 613 / 1113 Branchbran 35.3% 212 / 600 Conditioncond 35.3% 157 / 444 MC/DCmcdc 8.3% 20 / 241 Subroutinesub 68.7% 77 / 112 Podpod 84.0% 21 / 25 totaltotal 43.3% 1100 / 2535 CC 472 SCAR 49.2
CC
472
Cov
46%
cleanup_register
462.0
new
396.0
_share_repo
247.1
CRAP 136.9
« lib/Module/Generic/Number/Format.pm ↑ Summary lib/Module/Generic/SharedMemXS.pm »
1 ##----------------------------------------------------------------------------
2 ## Module Generic - ~/lib/Module/Generic/Global.pm
3 ## Version v1.2.2
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2025/05/06
7 ## Modified 2026/06/04
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package Module::Generic::Global;
14 BEGIN
15 33 ▶{
Subroutine BEGIN: called CC=18 SCAR=47.3
16 33 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 33 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 33 warnings::register_categories( 'Module::Generic' );
19 33 ▶ use parent qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 33 ▶ use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 $MOD_PERL $REPO $MUTEX $ERRORS $LOCKS $STATS $ORDER $SIZES $CLEANUP $NS_LOCKS
22 $LOCK_MUTEX $REFCOUNTS $DEBUG $PerlConfig $DEFAULT_SERIALISER $MAX_STORE_BYTES
23 @EXPORT_OK %EXPORT_TAGS $VERSION
24 33 );
25 33 ▶ use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 33 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 33 ▶ use Storable::Improved ();
Subroutine BEGIN: called CC=1 SCAR=0.0
28 # mod_perl/2.0.10
29 33 ▶ if( CORE::exists( $ENV{MOD_PERL} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"MOD_PERL"} and ($Module::Generic::Global::MOD_PERL) = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]) 0 33 33
Condition33%1/3
exists $ENV{"MOD_PERL"} and ($Module::Generic::Global::MOD_PERL) = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
!ll&&!rl&&r
3300
MC/DC0%0/2
exists $ENV{"MOD_PERL"} and ($Module::Generic::Global::MOD_PERL) = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
exists $ENV{"MOD_PERL"} ($Module::Generic::Global::MOD_PERL) = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
Truth table33%1/3
A and B
A= exists $ENV{"MOD_PERL"}B= ($Module::Generic::Global::MOD_PERL) = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
ABresult
0X0
100
111
30 &&
31 ( ( $MOD_PERL ) = $ENV{MOD_PERL} =~ /^mod_perl\/(\d+\.[\d\.]+)/ ) )
32 {
33 0 select( ( select( STDOUT ), $| = 1 )[0] );
34 0 require Apache2::Log;
35 0 require Apache2::ServerUtil;
36 0 require Apache2::RequestRec;
37 0 require Apache2::RequestUtil;
38 0 require Apache2::ServerRec;
39 0 require ModPerl::Util;
40 0 require Apache2::MPM;
41 0 require Apache2::Const;
42 0 Apache2::Const->import( compile => qw( :log OK ) );
43 }
44 33 our $PerlConfig = { %Config };
45 # Maximum retries and delay (microseconds) for locking with APR mutex
46 33 ▶ use constant MAX_RETRIES => ( ( $ENV{MG_MAX_RETRIES} && $ENV{MG_MAX_RETRIES} =~ /^\d+$/ ) ? $ENV{MG_MAX_RETRIES} : 10 );
Subroutine BEGIN: called CC=3 SCAR=12.5
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'MG_MAX_RETRIES'} && $ENV{'MG_MAX_RETRIES'} =~ /^\d+$/ ? : 0 33 33
Condition33%1/3
$ENV{"MG_MAX_RETRIES"} and $ENV{"MG_MAX_RETRIES"} =~ /^\d+$/
!ll&&!rl&&r
3300
MC/DC0%0/2
$ENV{"MG_MAX_RETRIES"} and $ENV{"MG_MAX_RETRIES"} =~ /^\d+$/
$ENV{"MG_MAX_RETRIES"} $ENV{"MG_MAX_RETRIES"} =~ /^\d+$/
Truth table33%1/3
A and B
A= $ENV{"MG_MAX_RETRIES"}B= $ENV{"MG_MAX_RETRIES"} =~ /^\d+$/
ABresult
0X0
100
111
47 33 ▶ use constant RETRY_DELAY => ( ( $ENV{MG_RETRY_DELAY} && $ENV{MG_RETRY_DELAY} =~ /^\d+$/ ) ? $ENV{MG_RETRY_DELAY} : 10_000 ); # 10ms
Subroutine BEGIN: called CC=3 SCAR=12.5
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'MG_RETRY_DELAY'} && $ENV{'MG_RETRY_DELAY'} =~ /^\d+$/ ? : 0 33 33
Condition33%1/3
$ENV{"MG_RETRY_DELAY"} and $ENV{"MG_RETRY_DELAY"} =~ /^\d+$/
!ll&&!rl&&r
3300
MC/DC0%0/2
$ENV{"MG_RETRY_DELAY"} and $ENV{"MG_RETRY_DELAY"} =~ /^\d+$/
$ENV{"MG_RETRY_DELAY"} $ENV{"MG_RETRY_DELAY"} =~ /^\d+$/
Truth table33%1/3
A and B
A= $ENV{"MG_RETRY_DELAY"}B= $ENV{"MG_RETRY_DELAY"} =~ /^\d+$/
ABresult
0X0
100
111
48 33 ▶ use constant ERROR_DELAY => ( ( $ENV{MG_ERROR_DELAY} && $ENV{MG_ERROR_DELAY} =~ /^\d+$/ ) ? $ENV{MG_ERROR_DELAY} : 5_000 ); # 5ms (faster for errors)
Subroutine BEGIN: called CC=3 SCAR=12.5
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'MG_ERROR_DELAY'} && $ENV{'MG_ERROR_DELAY'} =~ /^\d+$/ ? : 0 33 33
Condition33%1/3
$ENV{"MG_ERROR_DELAY"} and $ENV{"MG_ERROR_DELAY"} =~ /^\d+$/
!ll&&!rl&&r
3300
MC/DC0%0/2
$ENV{"MG_ERROR_DELAY"} and $ENV{"MG_ERROR_DELAY"} =~ /^\d+$/
$ENV{"MG_ERROR_DELAY"} $ENV{"MG_ERROR_DELAY"} =~ /^\d+$/
Truth table33%1/3
A and B
A= $ENV{"MG_ERROR_DELAY"}B= $ENV{"MG_ERROR_DELAY"} =~ /^\d+$/
ABresult
0X0
100
111
49 # use constant CAN_THREADS => ( $Config{useithreads} ? 1 : 0 );
50 294 ▶ sub CAN_THREADS () { CORE::return( $PerlConfig->{useithreads} ? 1 : 0 ); }
Subroutine CAN_THREADS: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$Module::Generic::Global::PerlConfig->{'useithreads'} ? : 0 294 294
51 # NOTE: Broken threads::shared ABI detection
52 # Perl built with both -Duseithreads and -Duselongdouble (or -Dusequadmath) has a
53 # defect in threads::shared on older releases (5.16.0 and earlier are known to be
54 # affected): locking or marking a variable as shared triggers the assertion
55 # 'SvTYPE(_svmagic) >= SVt_PVMG' at shared.xs and aborts the interpreter with SIGABRT.
56 # The boundary below is set empirically from CPAN Testers reports, since no single
57 # upstream ticket pins the exact release where this was resolved. It can be raised
58 # later should a newer long double build report the same abort.
59 # On such a build we must not promote our global repositories to :shared unless
60 # threads are genuinely in use.
61 0 ▶ sub BROKEN_SHARED_ABI () { CORE::return( $PerlConfig->{useithreads} && ( $PerlConfig->{uselongdouble} || $PerlConfig->{usequadmath} ) && $] < 5.018000 ? 1 : 0 ); }
Subroutine BROKEN_SHARED_ABI: not called CC=5 SCAR=34.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$Module::Generic::Global::PerlConfig->{'useithreads'} && ($Module::Generic::Global::PerlConfig->{'uselongdouble'} || $Module::Generic::Global::PerlConfig->{'usequadmath'}) && $] < 5.018 ? : 0 0 0
Condition0%0/9
$Module::Generic::Global::PerlConfig->{"useithreads"} and $Module::Generic::Global::PerlConfig->{"uselongdouble"} || $Module::Generic::Global::PerlConfig->{"usequadmath"} and $] < "5.018"
!ll&&!rl&&r
000
$Module::Generic::Global::PerlConfig->{"useithreads"} and $Module::Generic::Global::PerlConfig->{"uselongdouble"} || $Module::Generic::Global::PerlConfig->{"usequadmath"}
!ll&&!rl&&r
000
$Module::Generic::Global::PerlConfig->{"uselongdouble"} or $Module::Generic::Global::PerlConfig->{"usequadmath"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$Module::Generic::Global::PerlConfig->{"useithreads"} and $Module::Generic::Global::PerlConfig->{"uselongdouble"} || $Module::Generic::Global::PerlConfig->{"usequadmath"} and $] < "5.018"
$Module::Generic::Global::PerlConfig->{"useithreads"} $Module::Generic::Global::PerlConfig->{"uselongdouble"} $Module::Generic::Global::PerlConfig->{"usequadmath"} $] < "5.018"
Truth table0%0/6
A and B or C and D
A= $Module::Generic::Global::PerlConfig->{"useithreads"}B= $Module::Generic::Global::PerlConfig->{"uselongdouble"}C= $Module::Generic::Global::PerlConfig->{"usequadmath"}D= $] < "5.018"
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
62 # The following 2 constants are defined as not immutable, because whether threads has been loaded or not could change during runtime. Using 'constant' would not cut it.
63 52777 ▶ sub HAS_THREADS () { CORE::return( $PerlConfig->{useithreads} && $INC{'threads.pm'} ? 1 : 0 ); }
Subroutine HAS_THREADS: called CC=3 SCAR=14.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$Module::Generic::Global::PerlConfig->{'useithreads'} && $INC{'threads.pm'} ? : 0 52777 52777
Condition33%1/3
$Module::Generic::Global::PerlConfig->{"useithreads"} and $INC{"threads.pm"}
!ll&&!rl&&r
5277700
MC/DC0%0/2
$Module::Generic::Global::PerlConfig->{"useithreads"} and $INC{"threads.pm"}
$Module::Generic::Global::PerlConfig->{"useithreads"} $INC{"threads.pm"}
Truth table33%1/3
A and B
A= $Module::Generic::Global::PerlConfig->{"useithreads"}B= $INC{"threads.pm"}
ABresult
0X0
100
111
64  
65 0 ▶ sub IN_THREAD () { CORE::return( $PerlConfig->{useithreads} && $INC{'threads.pm'} && threads->tid != 0 ? 1 : 0 ); }
Subroutine IN_THREAD: not called CC=4 SCAR=30.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$Module::Generic::Global::PerlConfig->{'useithreads'} && $INC{'threads.pm'} && 'threads'->tid != 0 ? : 0 0 0
Condition0%0/6
$Module::Generic::Global::PerlConfig->{"useithreads"} and $INC{"threads.pm"} and "threads"->tid != 0
!ll&&!rl&&r
000
$Module::Generic::Global::PerlConfig->{"useithreads"} and $INC{"threads.pm"}
!ll&&!rl&&r
000
MC/DC0%0/3
$Module::Generic::Global::PerlConfig->{"useithreads"} and $INC{"threads.pm"} and "threads"->tid != 0
$Module::Generic::Global::PerlConfig->{"useithreads"} $INC{"threads.pm"} "threads"->tid != 0
Truth table0%0/4
A and B and C
A= $Module::Generic::Global::PerlConfig->{"useithreads"}B= $INC{"threads.pm"}C= "threads"->tid != 0
ABCresult
0XX0
10X0
1100
1111
66  
67 1 ▶ sub MOD_PERL () { CORE::return( $MOD_PERL ); }
Subroutine MOD_PERL: called CC=1 SCAR=0.0
Pod documented
68  
69 # NOTE: _in_end_phase, _in_global_destruction
70 # These two helpers tell whether the interpreter is running END blocks
71 # (${^GLOBAL_PHASE} eq 'END') or in global destruction (${^GLOBAL_PHASE} eq 'DESTRUCT').
72 # They are used by _share_repo() and _lock() to avoid operations that abort or corrupt
73 # threads::shared during the exit dance.
74 # They are defined here rather than imported from Module::Generic to keep this
75 # package self-contained: Module::Generic depends on this one, not the other way
76 # around. Module::Generic also provides the same helpers for its own callers, and the
77 # implementations must match.
78 # Module::Generic requires perl v5.16, where ${^GLOBAL_PHASE} is always defined, so
79 # no fallback through B::main_cv() is needed as I did before.
80 0 ▶ sub _in_end_phase () { CORE::return( ${^GLOBAL_PHASE} eq 'END' ? 1 : 0 ); }
Subroutine _in_end_phase: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
${^GLOBAL_PHASE} eq 'END' ? : 0 0 0
81 0 ▶ sub _in_global_destruction () { CORE::return( ${^GLOBAL_PHASE} eq 'DESTRUCT' ? 1 : 0 ); }
Subroutine _in_global_destruction: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
${^GLOBAL_PHASE} eq 'DESTRUCT' ? : 0 0 0
82  
83 33 my $mpm;
84 33 my $mpm_threaded = 0;
85 33 my $use_mutex = 0;
86 # NOTE: We promote our globals to :shared only when the running Perl can use threads
87 # and is not affected by the broken threads::shared ABI described above.
88 # On an affected build, all sharing is deferred to genuine thread usage, which is
89 # gated elsewhere on HAS_THREADS, so a single-threaded process never triggers the abort.
90 # my $need_shared = ( CAN_THREADS() && !BROKEN_SHARED_ABI() ) ? 1 : 0;
91 33 ▶ my $need_shared = CAN_THREADS() ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
&CAN_THREADS() ? : 0 33 33
92 33 our( $MUTEX, $LOCK_MUTEX );
93 # The user data repository
94 33 our $REPO = {};
95 # Special repository for error objects
96 33 our $ERRORS = {};
97 # Used for repositories locking mechanism
98 33 our $LOCKS = {};
99 # Light data used to collect statistic for reporting with stat()
100 33 our $STATS = {};
101 # To keep track of the keys, and order them by age
102 33 our $ORDER = {};
103 # To put a cap on data size in bytes
104 33 our $SIZES = {};
105 # For cleanup_register
106 33 our $CLEANUP = {};
107 # To perform locking on namespaces
108 33 our $NS_LOCKS = {};
109 # To keep track of repositories that use a shared key. When it hits 0, it gets removed
110 33 our $REFCOUNTS = {};
111 33 our $MAX_STORE_BYTES= 5242880;
112 # Check if we are running under Apache Worker/Event MPM
113 33 ▶ if( $MOD_PERL )
Branch: 1 branch
BranchTrueFalseTotal
if ($Module::Generic::Global::MOD_PERL) 0 33 33
114 {
115 0 my $rc;
116 0 local $@;
117 0 eval{ $rc = Apache2::MPM->is_threaded };
118 0 ▶ if( $rc )
Branch: 2 branches
BranchTrueFalseTotal
if ($rc) { } 0 0 0
elsif ($@) { } 0 0 0
119 {
120 0 $mpm_threaded = 1;
121 # Normally, Perl must be compiled with -Duseithreads to work under threaded Apache, but we double check that
122 0 ▶ if( $PerlConfig->{useithreads} )
Branch: 1 branch
BranchTrueFalseTotal
if ($Module::Generic::Global::PerlConfig->{"useithreads"}) 0 0 0
123 {
124 0 local $@;
125 # try-catch
126 eval
127 0 {
128 0 require threads;
129 0 require threads::shared;
130 0 threads->import();
131 0 threads::shared->import();
132 };
133  
134 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
135 {
136 0 warn( "Unable to initialise mod_perl threading support: $@" );
137 }
138 else
139 {
140 0 $need_shared = 1;
141 }
142 }
143 # Somehow, a race condition occurred, and we need to fallback to APR::ThreadRWLock as mutex
144 0 ▶ unless( $need_shared )
Branch: 1 branch
BranchTrueFalseTotal
unless ($need_shared) 0 0 0
145 {
146 0 require APR::ThreadRWLock;
147 0 require APR::Const;
148 0 APR::Const->import( compile => qw( :error ) );
149 0 my $pool = Apache2::ServerUtil->server->process->pool;
150 # For our main repository
151 0 $MUTEX = APR::ThreadRWLock->new( $pool );
152 # For the lock service
153 0 $LOCK_MUTEX = APR::ThreadRWLock->new( $pool );
154 0 $use_mutex = 1;
155 }
156 # else the user is running under Apache Prefork, which is safe for global variables
157 0 ▶ if( !$need_shared && !$MUTEX )
Branch: 1 branch
BranchTrueFalseTotal
unless ($need_shared or $Module::Generic::Global::MUTEX) 0 0 0
Condition0%0/3
$need_shared or $Module::Generic::Global::MUTEX
l!l&&r!l&&!r
000
MC/DC0%0/2
$need_shared or $Module::Generic::Global::MUTEX
$need_shared $Module::Generic::Global::MUTEX
Truth table0%0/3
A or B
A= $need_sharedB= $Module::Generic::Global::MUTEX
ABresult
1X1
011
000
158 {
159 0 warn( "mod_perl detected with threaded MPM, but Perl is not threaded ($PerlConfig->{useithreads}=0) and mutex creation failed. Global repositories may be corrupted, and locks may be inefficient without thread-safety." );
160 }
161 }
162 elsif( $@ )
163 {
164 0 warn( "ModPerl seems to be enabled, but could not get the threaded status of Apache: $@" );
165 }
166 # otherwise, we are running under Apache Prefork, and no locking is required
167  
168 eval
169 0 {
170 0 my $type = Apache2::MPM->show;
171 0 ▶ $mpm = lc( $type ) if( defined( $type ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $type 0 0 0
172 };
173 }
174  
175 33 ▶ if( $need_shared )
Branch: 1 branch
BranchTrueFalseTotal
if ($need_shared) 0 33 33
176 {
177 0 ▶ unless( $INC{'threads.pm'} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($INC{"threads.pm"}) 0 0 0
178 {
179 0 local $@;
180 # try-catch
181 eval
182 0 {
183 0 require threads;
184 0 threads->import();
185 };
186 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
187 {
188 0 warn( "Unable to load threads: $@" );
189 }
190 }
191 0 ▶ unless( $INC{'threads/shared.pm'} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($INC{"threads/shared.pm"}) 0 0 0
192 {
193 0 local $@;
194 # try-catch
195 eval
196 0 {
197 0 require threads::shared;
198 0 threads::shared->import();
199 };
200 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
201 {
202 0 warn( "Unable to load threads::shared: $@" );
203 }
204 }
205 0 my %repo :shared;
206 0 my %errs :shared;
207 0 my %locks :shared;
208 0 my %stats :shared;
209 0 my %order :shared;
210 0 my %sizes :shared;
211 0 my %cleanup :shared;
212 0 my %ns_locks :shared;
213 0 my %refcounts :shared;
214 0 $REPO = \%repo;
215 0 $ERRORS = \%errs;
216 0 $LOCKS = \%locks;
217 0 $STATS = \%stats;
218 # To keep track of the keys
219 0 $ORDER = \%order;
220 0 $SIZES = \%sizes;
221 0 $CLEANUP = \%cleanup;
222 0 $NS_LOCKS = \%ns_locks;
223 0 $REFCOUNTS = \%refcounts;
224 }
225  
226 25794 ▶ sub _NEED_SHARED () { CORE::return( $need_shared ); }
Subroutine _NEED_SHARED: called CC=1 SCAR=0.0
227 23050 ▶ sub USE_MUTEX () { CORE::return( $use_mutex ); }
Subroutine USE_MUTEX: called CC=1 SCAR=0.0
Pod undocumented
228 0 ▶ sub MPM () { CORE::return( $mpm ); }
Subroutine MPM: not called CC=1 SCAR=6.9
Pod documented
229 0 ▶ sub HAS_MPM_THREADS () { CORE::return( $mpm_threaded ); }
Subroutine HAS_MPM_THREADS: not called CC=1 SCAR=6.9
Pod documented
230  
231 33 our @EXPORT_OK = qw( CAN_THREADS HAS_THREADS IN_THREAD MOD_PERL MPM HAS_MPM_THREADS );
232 33 our %EXPORT_TAGS = ( 'const' => [@EXPORT_OK] );
233 33 our $DEFAULT_SERIALISER = 'Storable::Improved';
234 33 our $VERSION = 'v1.2.2';
235 };
236  
237 33 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
238 33 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
239  
240 # Object-level:
241 # Module::Generic::Global->new( 'my_repo' => $blessed_object ) || die( Module::Generic::Global->error );
242 # Class-level:
243 # Module::Generic::Global->new( 'my_repo' => 'My::Module' ) || die( Module::Generic::Global->error );
244 sub new
245 18493 ▶{
Subroutine new: called CC=63 SCAR=59.8
Pod documented
246 18493 my $this = shift( @_ );
247 18493 ▶ my $ns = shift( @_ ) || return( $this->error( "No namespace was provided." ) );
Condition100%2/2
shift @_ || (return $this->error('No namespace was provided.'))
l!l
184921
MC/DC100%1/1
shift @_ || (return $this->error('No namespace was provided.'))
shift @_
Truth table100%2/2
A
A= shift @_
Aresult
11
00
248 18492 my $what = shift( @_ );
249 18492 ▶ unless( defined( $what ) && CORE::ref( $what ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $what and ref $what) 13283 5209 18492
Condition66%2/3
defined $what and ref $what
!ll&&!rl&&r
0132835209
MC/DC50%1/2
defined $what and ref $what
defined $what ref $what
Truth table66%2/3
A and B
A= defined $whatB= ref $what
ABresult
0X0
100
111
250 {
251 13283 ▶ return( $this->error( "No controller element was provided for this namespace $ns" ) ) if( !CORE::length( $what // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::length($what // "") 0 13283 13283
Condition50%1/2
$what // ""
l!l
132830
MC/DC0%0/1
$what // ""
$what
Truth table50%1/2
A
A= $what
Aresult
11
00
252 }
253 18492 my $opts = $this->_get_args_as_hash( @_ );
254  
255 my $ref =
256 {
257 _namespace => $ns,
258 _key => undef,
259 _mode => undef,
260 _error => undef,
261 18492 ▶ debug => ( $opts->{debug} // $DEBUG // 0 ),
Condition66%6/9
($opts->{"debug"} // $Module::Generic::Global::DEBUG) // 0
l!l
1218480
$opts->{"debug"} // $Module::Generic::Global::DEBUG
l!l&&r!l&&!r
12018480
$Module::Generic::Global::DEFAULT_SERIALISER || 'Storable::Improved'
l!l
184920
$Module::Generic::Global::MAX_STORE_BYTES // 0
l!l
184920
MC/DC50%1/2
($opts->{"debug"} // $Module::Generic::Global::DEBUG) // 0
$opts->{"debug"} $Module::Generic::Global::DEBUG
MC/DC0%0/1
$Module::Generic::Global::DEFAULT_SERIALISER || 'Storable::Improved'
$Module::Generic::Global::DEFAULT_SERIALISER
MC/DC0%0/1
$Module::Generic::Global::MAX_STORE_BYTES // 0
$Module::Generic::Global::MAX_STORE_BYTES
Truth table66%2/3
A // B
A= $opts->{"debug"}B= $Module::Generic::Global::DEBUG
ABresult
1X1
011
000
Truth table50%1/2
A
A= $Module::Generic::Global::DEFAULT_SERIALISER
Aresult
11
00
Truth table50%1/2
A
A= $Module::Generic::Global::MAX_STORE_BYTES
Aresult
11
00
262 serialiser => ( $DEFAULT_SERIALISER || 'Storable::Improved' ),
263 # Default value
264 max_store_bytes => ( $MAX_STORE_BYTES // 0 ),
265 };
266 18492 ▶ if( CORE::exists( $opts->{on_get} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"on_get"} and defined $opts->{"on_get"}) 0 18492 18492
Condition33%1/3
exists $opts->{"on_get"} and defined $opts->{"on_get"}
!ll&&!rl&&r
1849200
MC/DC0%0/2
exists $opts->{"on_get"} and defined $opts->{"on_get"}
exists $opts->{"on_get"} defined $opts->{"on_get"}
Truth table33%1/3
A and B
A= exists $opts->{"on_get"}B= defined $opts->{"on_get"}
ABresult
0X0
100
111
267 CORE::defined( $opts->{on_get} ) )
268 {
269 0 my( $cb, $args ) = $this->_get_args_for_callback( $opts->{on_get} );
270 0 ▶ return if( !$cb && $this->error );
Branch: 1 branch
BranchTrueFalseTotal
if not $cb and $this->error 0 0 0
Condition0%0/3
not $cb and $this->error
!ll&&!rl&&r
000
MC/DC0%0/2
not $cb and $this->error
not $cb $this->error
Truth table0%0/3
not(A) and B
A= not $cbB= $this->error
ABresult
0X0
100
111
271 0 ▶ $ref->{on_get} = $cb if( defined( $cb ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $cb 0 0 0
272 0 ▶ $ref->{on_get_args} = $args if( defined( $args ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $args 0 0 0
273 }
274  
275 18492 ▶ if( CORE::exists( $opts->{serialiser} ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opts->{'serialiser'} and defined $opts->{'serialiser'}) { } 0 18492 18492
elsif (exists $opts->{'serializer'} and defined $opts->{'serializer'}) { } 0 36984 36984
Condition33%1/3
exists $opts->{"serialiser"} and defined $opts->{"serialiser"}
!ll&&!rl&&r
1849200
MC/DC0%0/2
exists $opts->{"serialiser"} and defined $opts->{"serialiser"}
exists $opts->{"serialiser"} defined $opts->{"serialiser"}
Truth table33%1/3
A and B
A= exists $opts->{"serialiser"}B= defined $opts->{"serialiser"}
ABresult
0X0
100
111
276 CORE::defined( $opts->{serialiser} ) )
277 {
278 0 $ref->{serialiser} = $opts->{serialiser};
279 }
280 ▶ elsif( CORE::exists( $opts->{serializer} ) &&
Condition33%1/3
exists $opts->{"serializer"} and defined $opts->{"serializer"}
!ll&&!rl&&r
1849200
MC/DC0%0/2
exists $opts->{"serializer"} and defined $opts->{"serializer"}
exists $opts->{"serializer"} defined $opts->{"serializer"}
Truth table33%1/3
A and B
A= exists $opts->{"serializer"}B= defined $opts->{"serializer"}
ABresult
0X0
100
111
281 CORE::defined( $opts->{serializer} ) )
282 {
283 0 $ref->{serialiser} = $opts->{serializer};
284 }
285  
286 18492 ▶ if( CORE::exists( $opts->{max_size} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"max_size"} and $opts->{"max_size"} =~ /^\d+$/) 5 18487 18492
Condition66%2/3
exists $opts->{"max_size"} and $opts->{"max_size"} =~ /^\d+$/
!ll&&!rl&&r
1848705
MC/DC50%1/2
exists $opts->{"max_size"} and $opts->{"max_size"} =~ /^\d+$/
exists $opts->{"max_size"} $opts->{"max_size"} =~ /^\d+$/
Truth table66%2/3
A and B
A= exists $opts->{"max_size"}B= $opts->{"max_size"} =~ /^\d+$/
ABresult
0X0
100
111
287 $opts->{max_size} =~ /^\d+$/ )
288 {
289 5 $ref->{max_size} = $opts->{max_size};
290 }
291  
292 18492 ▶ if( CORE::exists( $opts->{max_store_bytes} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"max_store_bytes"} and $opts->{"max_store_bytes"} =~ /^\d+$/) 6 18486 18492
Condition66%2/3
exists $opts->{"max_store_bytes"} and $opts->{"max_store_bytes"} =~ /^\d+$/
!ll&&!rl&&r
1848606
MC/DC50%1/2
exists $opts->{"max_store_bytes"} and $opts->{"max_store_bytes"} =~ /^\d+$/
exists $opts->{"max_store_bytes"} $opts->{"max_store_bytes"} =~ /^\d+$/
Truth table66%2/3
A and B
A= exists $opts->{"max_store_bytes"}B= $opts->{"max_store_bytes"} =~ /^\d+$/
ABresult
0X0
100
111
293 $opts->{max_store_bytes} =~ /^\d+$/ )
294 {
295 6 $ref->{max_store_bytes} = $opts->{max_store_bytes};
296 }
297  
298 18492 ▶ if( CORE::exists( $opts->{max_total_bytes} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"max_total_bytes"} and $opts->{"max_total_bytes"} =~ /^\d+$/) 5 18487 18492
Condition66%2/3
exists $opts->{"max_total_bytes"} and $opts->{"max_total_bytes"} =~ /^\d+$/
!ll&&!rl&&r
1848705
MC/DC50%1/2
exists $opts->{"max_total_bytes"} and $opts->{"max_total_bytes"} =~ /^\d+$/
exists $opts->{"max_total_bytes"} $opts->{"max_total_bytes"} =~ /^\d+$/
Truth table66%2/3
A and B
A= exists $opts->{"max_total_bytes"}B= $opts->{"max_total_bytes"} =~ /^\d+$/
ABresult
0X0
100
111
299 $opts->{max_total_bytes} =~ /^\d+$/ )
300 {
301 5 $ref->{max_total_bytes} = $opts->{max_total_bytes};
302 }
303  
304 # Are we expected to keep a counter of callers using a given namespace, so that upon reaching 0, it gets automatically removed?
305 18492 ▶ if( CORE::exists( $opts->{refcount} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"refcount"}) 0 18492 18492
306 {
307 0 ▶ if( ( defined( $opts->{refcount} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{'refcount'} and CORE::length $opts->{'refcount'} and $opts->{'refcount'} =~ /^0|1$/ or not defined $opts->{'refcount'} or not CORE::length($opts->{'refcount'} // '')) { } 0 0 0
Condition0%0/14
defined $opts->{"refcount"} and CORE::length $opts->{"refcount"} and $opts->{"refcount"} =~ /^0|1$/ or not defined $opts->{"refcount"} or not CORE::length($opts->{"refcount"} // "")
l!l&&r!l&&!r
000
defined $opts->{"refcount"} and CORE::length $opts->{"refcount"} and $opts->{"refcount"} =~ /^0|1$/ or not defined $opts->{"refcount"}
l!l&&r!l&&!r
000
defined $opts->{"refcount"} and CORE::length $opts->{"refcount"} and $opts->{"refcount"} =~ /^0|1$/
!ll&&!rl&&r
000
defined $opts->{"refcount"} and CORE::length $opts->{"refcount"}
!ll&&!rl&&r
000
$opts->{"refcount"} // ""
l!l
00
MC/DC0%0/5
defined $opts->{"refcount"} and CORE::length $opts->{"refcount"} and $opts->{"refcount"} =~ /^0|1$/ or not defined $opts->{"refcount"} or not CORE::length($opts->{"refcount"} // "")
defined $opts->{"refcount"} CORE::length $opts->{"refcount"} $opts->{"refcount"} =~ /^0|1$/ not defined $opts->{"refcount"} $opts->{"refcount"}
Truth table0%0/10
A and B and C or not(D) or not(E)
A= defined $opts->{"refcount"}B= CORE::length $opts->{"refcount"}C= $opts->{"refcount"} =~ /^0|1$/D= not defined $opts->{"refcount"}E= $opts->{"refcount"}
ABCDEresult
111XX1
0XX1X1
10X1X1
1101X1
0XX001
10X001
110001
0XX010
10X010
110010
308 CORE::length( $opts->{refcount} ) &&
309 $opts->{refcount} =~ /^0|1$/
310 )
311 ||
312 !defined( $opts->{refcount} )
313 ||
314 !CORE::length( $opts->{refcount} // '' ) )
315 {
316 0 $ref->{refcount} = $opts->{refcount};
317 }
318 else
319 {
320 0 require overload;
321 0 ▶ return( $this->error( "Unsupported value for 'refcount' (", overload::StrVal( $opts->{refcount} // 'undef' ), "). It must be either 1, 0, undef or an empty string." ) );
Condition0%0/2
$opts->{"refcount"} // "undef"
l!l
00
MC/DC0%0/1
$opts->{"refcount"} // "undef"
$opts->{"refcount"}
Truth table0%0/2
A
A= $opts->{"refcount"}
Aresult
11
00
322 }
323 }
324  
325 18492 ▶ if( defined( $ref->{max_store_bytes} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"max_store_bytes"} and $ref->{"max_store_bytes"} =~ /^\d+$/ and $ref->{"max_store_bytes"} > 0 and defined $ref->{"max_total_bytes"} and $ref->{"max_total_bytes"} =~ /^\d+$/ and $ref->{"max_total_bytes"} > 0 and $ref->{"max_store_bytes"} > $ref->{"max_total_bytes"}) 0 18492 18492
Condition55%10/18
defined $ref->{"max_store_bytes"} and $ref->{"max_store_bytes"} =~ /^\d+$/ and $ref->{"max_store_bytes"} > 0 and defined $ref->{"max_total_bytes"} and $ref->{"max_total_bytes"} =~ /^\d+$/ and $ref->{"max_total_bytes"} > 0 and $ref->{"max_store_bytes"} > $ref->{"max_total_bytes"}
!ll&&!rl&&r
1848750
defined $ref->{"max_store_bytes"} and $ref->{"max_store_bytes"} =~ /^\d+$/ and $ref->{"max_store_bytes"} > 0 and defined $ref->{"max_total_bytes"} and $ref->{"max_total_bytes"} =~ /^\d+$/ and $ref->{"max_total_bytes"} > 0
!ll&&!rl&&r
1848705
defined $ref->{"max_store_bytes"} and $ref->{"max_store_bytes"} =~ /^\d+$/ and $ref->{"max_store_bytes"} > 0 and defined $ref->{"max_total_bytes"} and $ref->{"max_total_bytes"} =~ /^\d+$/
!ll&&!rl&&r
1848705
defined $ref->{"max_store_bytes"} and $ref->{"max_store_bytes"} =~ /^\d+$/ and $ref->{"max_store_bytes"} > 0 and defined $ref->{"max_total_bytes"}
!ll&&!rl&&r
0184875
defined $ref->{"max_store_bytes"} and $ref->{"max_store_bytes"} =~ /^\d+$/ and $ref->{"max_store_bytes"} > 0
!ll&&!rl&&r
0018492
defined $ref->{"max_store_bytes"} and $ref->{"max_store_bytes"} =~ /^\d+$/
!ll&&!rl&&r
0018492
MC/DC0%0/7
defined $ref->{"max_store_bytes"} and $ref->{"max_store_bytes"} =~ /^\d+$/ and $ref->{"max_store_bytes"} > 0 and defined $ref->{"max_total_bytes"} and $ref->{"max_total_bytes"} =~ /^\d+$/ and $ref->{"max_total_bytes"} > 0 and $ref->{"max_store_bytes"} > $ref->{"max_total_bytes"}
defined $ref->{"max_store_bytes"} $ref->{"max_store_bytes"} =~ /^\d+$/ $ref->{"max_store_bytes"} > 0 defined $ref->{"max_total_bytes"} $ref->{"max_total_bytes"} =~ /^\d+$/ $ref->{"max_total_bytes"} > 0 $ref->{"max_store_bytes"} > $ref->{"max_total_bytes"}
Truth table25%2/8
A and B and C and D and E and F and G
A= defined $ref->{"max_store_bytes"}B= $ref->{"max_store_bytes"} =~ /^\d+$/C= $ref->{"max_store_bytes"} > 0D= defined $ref->{"max_total_bytes"}E= $ref->{"max_total_bytes"} =~ /^\d+$/F= $ref->{"max_total_bytes"} > 0G= $ref->{"max_store_bytes"} > $ref->{"max_total_bytes"}
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
326 $ref->{max_store_bytes} =~ /^\d+$/ &&
327 $ref->{max_store_bytes} > 0 &&
328 defined( $ref->{max_total_bytes} ) &&
329 $ref->{max_total_bytes} =~ /^\d+$/ &&
330 $ref->{max_total_bytes} > 0 &&
331 $ref->{max_store_bytes} > $ref->{max_total_bytes} )
332 {
333 0 ▶ warn( "You have set the maximum byte size of an element ($ref->{max_store_bytes}) to be greater than the total byte size alllwed for all elements ($ref->{max_total_bytes}" ) if( warnings::enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("Module::Generic") 0 0 0
334 }
335  
336 # The 'key', if any, must NOT be any reference. It must be a plain scalar.
337 18492 ▶ if( CORE::exists( $opts->{key} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"key"} and defined $opts->{"key"} and CORE::length $opts->{"key"} and ref $opts->{"key"}) 0 18492 18492
Condition66%6/9
exists $opts->{"key"} and defined $opts->{"key"} and CORE::length $opts->{"key"} and ref $opts->{"key"}
!ll&&!rl&&r
6435120570
exists $opts->{"key"} and defined $opts->{"key"} and CORE::length $opts->{"key"}
!ll&&!rl&&r
6435012057
exists $opts->{"key"} and defined $opts->{"key"}
!ll&&!rl&&r
6435012057
MC/DC0%0/4
exists $opts->{"key"} and defined $opts->{"key"} and CORE::length $opts->{"key"} and ref $opts->{"key"}
exists $opts->{"key"} defined $opts->{"key"} CORE::length $opts->{"key"} ref $opts->{"key"}
Truth table40%2/5
A and B and C and D
A= exists $opts->{"key"}B= defined $opts->{"key"}C= CORE::length $opts->{"key"}D= ref $opts->{"key"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
338 defined( $opts->{key} ) &&
339 CORE::length( $opts->{key} ) &&
340 ref( $opts->{key} ) )
341 {
342 0 require overload;
343 0 ▶ if( Scalar::Util::blessed( $opts->{key} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($opts->{'key'}) and overload::Method($opts->{'key'}, '""')) { } 0 0 0
Condition0%0/3
builtin::blessed($opts->{"key"}) and overload::Method($opts->{"key"}, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($opts->{"key"}) and overload::Method($opts->{"key"}, "\"\"")
builtin::blessed($opts->{"key"}) overload::Method($opts->{"key"}, "\"\"")
Truth table0%0/3
A and B
A= builtin::blessed($opts->{"key"})B= overload::Method($opts->{"key"}, "\"\"")
ABresult
0X0
100
111
344 overload::Method( $opts->{key} => '""' ) )
345 {
346 0 $opts->{key} = "$opts->{key}";
347 }
348 else
349 {
350 0 return( $this->error( "The key you provided '$opts->{key}' (", overload::StrVal( $opts->{key} ), ") is a reference. You must pass a key as a plain scalar imstead." ) );
351 }
352 }
353  
354 18492 ▶ my $self = bless( $ref => ( ref( $this ) || $this ) );
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0184920
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
355  
356 # Special case if the context is 'system', and neither a class name, nor an object
357 33 ▶ if( do{ no warnings; "$what" eq 'system' } )
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 3 branches
BranchTrueFalseTotal
if (do { no warnings; "$what" eq 'system' }) { } 230 18262 18492
elsif (builtin::blessed($what)) { } 5208 13054 18262
elsif (not ref $what) { } 13053 1 13054
358 {
359 230 $self->{_key} = 'system';
360 230 $self->{_mode} = 'system';
361 # Enabled reference counts, so this repository gets removed when its count hits 0
362 230 $self->{refcount} = 1;
363 }
364 elsif( Scalar::Util::blessed( $what ) )
365 {
366 5208 my $id = Scalar::Util::refaddr( $what );
367 # Object-level keys have granular identification down to the thread ID if possible
368 5208 ▶ $self->{_key} = $opts->{key} ? $opts->{key} : join( ';', $id, $$, ( HAS_THREADS ? threads->tid : () ) );
Branch: 2 branches
BranchTrueFalseTotal
$opts->{'key'} ? : 241 4967 5208
&HAS_THREADS() ? : 0 4967 4967
369 5208 $self->{_mode} = 'object';
370 # For locks
371 5208 $self->{_class_key} = join( ';', ref( $what ), $$ );
372 }
373 # I am not going to do a sanity check on the class name provided.
374 elsif( !ref( $what ) )
375 {
376 13053 my $class = $what;
377 # Class-level keys have granular identification only down to the process ID, so they can be shared among threads, if need be.
378 13053 ▶ $self->{_key} = $opts->{key} ? $opts->{key} : join( ';', $class, $$ );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'key'} ? : 11808 1245 13053
379 13053 $self->{_mode} = 'class';
380 # Enabled reference counts, so this repository gets removed when its count hits 0
381 13053 $self->{refcount} = 1;
382 }
383 else
384 {
385 1 return( $self->error( "Module::Generic::Global->new requires either a class name or an object to be provided." ) );
386 }
387  
388 # We are being required to keep track of reference counts, either explicitly by the caller, or implicitly by ourself based on the arguments we received.
389 18491 ▶ if( $self->{refcount} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"refcount"}) 13283 5208 18491
390 {
391 13283 my $ns = $self->{_namespace};
392 13283 ▶ my $key = $self->{_key} // '';
Condition50%1/2
$self->{"_key"} // ""
l!l
132830
MC/DC0%0/1
$self->{"_key"} // ""
$self->{"_key"}
Truth table50%1/2
A
A= $self->{"_key"}
Aresult
11
00
393 13283 ▶ if( !CORE::exists( $REFCOUNTS->{ $ns } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Module::Generic::Global::REFCOUNTS->{$ns}) 150 13133 13283
394 {
395 # $self->__message( 4, "The repository for namespace '$ns' does not exist yet, creating it now." );
396 # $self->__message( 4, "_NEED_SHARED has value '", ( _NEED_SHARED // 'undef' ), "'" );
397 150 ▶ if( _NEED_SHARED() )
Branch: 1 branch
BranchTrueFalseTotal
if (&_NEED_SHARED()) { } 0 150 150
398 {
399 # $self->__message( 4, "Initialising shared repository for namespace '$ns'." );
400 0 my %refcount :shared;
401 0 $REFCOUNTS->{ $ns } = \%refcount;
402 }
403 else
404 {
405 # $self->__message( 4, "Initialising non-shared repository for namespace '$ns'." );
406 150 $REFCOUNTS->{ $ns } = {};
407 }
408 }
409 13283 my $refns = $REFCOUNTS->{ $ns };
410 # NOTE: Refcount update under a single hash-level lock
411 # We lock the namespace hash $refns (a :shared hash, safe to lock on all
412 # threads::shared releases) rather than \$refns->{ $key } (a reference to a
413 # scalar entry inside a :shared hash). The latter SIGSEGV on
414 # threads::shared 1.4 bundled with perl 5.16, particularly on long-double builds,
415 # and there is no catchable exception we can rescue. Locking the parent hash
416 # trades per-key contention for per-namespace contention, which is acceptable for
417 # refcount tracking where simultaneous writes are rare.
418 # We also avoid taking a reference to the scalar entry at all: the entry is read
419 # and written by name in a single locked section.
420 13283 ▶ $self->_lock_write( $refns ) || return( $self->error( "Unable to lock namespace for refcount update." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($refns) or return $self->error("Unable to lock namespace for refcount update.") 13283 0 13283
421 13283 ▶ $refns->{ $key } //= 0;
Condition100%2/2
$refns->{$key} //= 0
l!l
98203463
MC/DC100%1/1
$refns->{$key} //= 0
$refns->{$key}
Truth table100%2/2
A
A= $refns->{$key}
Aresult
11
00
422 13283 $refns->{ $key } = $refns->{ $key } + 1;
423 13283 $self->_unlock;
424 }
425  
426 18491 ▶ if( $opts->{auto_cleanup} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"auto_cleanup"}) 0 18491 18491
427 {
428 my %cleanup_opts = ref( $opts->{auto_cleanup} ) eq 'HASH'
429 0 ▶ ? %{$opts->{auto_cleanup}}
Branch: 1 branch
BranchTrueFalseTotal
ref $opts->{'auto_cleanup'} eq 'HASH' ? : 0 0 0
430 : ();
431 0 $self->cleanup_register( %cleanup_opts );
432 }
433 18491 return( $self );
434 }
435  
436 {
437 33 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
438 33 *clear = \&remove;
439 }
440  
441 sub cleanup
442 4170 ▶{
Subroutine cleanup: called CC=1 SCAR=0.0
Pod undocumented
443 4170 my $self = shift( @_ );
444 4170 $self->_decrement;
445 4170 return( $self );
446 }
447  
448 # Only for Apache/mod_perl
449 sub cleanup_register
450 0 ▶{
Subroutine cleanup_register: not called CC=21 SCAR=61.4
Pod documented
451 0 my $self = shift( @_ );
452 0 my $opts = {};
453 0 my $r;
454 # Legacy
455 0 ▶ if( @_ == 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and defined $_[0] and builtin::blessed($_[0]) and $_[0]->isa('Apache2::RequestRec')) { } 0 0 0
Condition0%0/9
@_ == 1 and defined $_[0] and builtin::blessed($_[0]) and $_[0]->isa("Apache2::RequestRec")
!ll&&!rl&&r
000
@_ == 1 and defined $_[0] and builtin::blessed($_[0])
!ll&&!rl&&r
000
@_ == 1 and defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/4
@_ == 1 and defined $_[0] and builtin::blessed($_[0]) and $_[0]->isa("Apache2::RequestRec")
@_ == 1 defined $_[0] builtin::blessed($_[0]) $_[0]->isa("Apache2::RequestRec")
Truth table0%0/5
A and B and C and D
A= @_ == 1B= defined $_[0]C= builtin::blessed($_[0])D= $_[0]->isa("Apache2::RequestRec")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
456 defined( $_[0] ) &&
457 Scalar::Util::blessed( $_[0] ) &&
458 $_[0]->isa( 'Apache2::RequestRec' ) )
459 {
460 0 $r = shift( @_ );
461 }
462 else
463 {
464 0 $opts = $self->_get_args_as_hash( @_ );
465 0 $r = $opts->{r}; # Allow explicit
466 }
467  
468 0 ▶ if( !ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 0 0 0
469 {
470 0 ▶ warn( "${self}::cleanup_register() cannot be called as a class function anymore. Use an instance instead." ) if( warnings::enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("Module::Generic") 0 0 0
471 0 return;
472 }
473  
474 0 ▶ my $callback = $opts->{callback} if( ref( $opts->{callback} ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $opts->{"callback"} eq "CODE" 0 0 0
475 0 ▶ my $namespaces = $opts->{namespaces} // [$self->{_namespace}]; # Default to self ns
Condition0%0/2
$opts->{"namespaces"} // [$self->{"_namespace"}]
l!l
00
MC/DC0%0/1
$opts->{"namespaces"} // [$self->{"_namespace"}]
$opts->{"namespaces"}
Truth table0%0/2
A
A= $opts->{"namespaces"}
Aresult
11
00
476 0 ▶ my %keep = map{ $_ => 1 } @{$opts->{keep} || []};
Condition0%0/2
$opts->{'keep'} || []
l!l
00
MC/DC0%0/1
$opts->{'keep'} || []
$opts->{'keep'}
Truth table0%0/2
A
A= $opts->{'keep'}
Aresult
11
00
477 0 ▶ if( !$r && $MOD_PERL )
Branch: 1 branch
BranchTrueFalseTotal
if (not $r and $Module::Generic::Global::MOD_PERL) 0 0 0
Condition0%0/3
not $r and $Module::Generic::Global::MOD_PERL
!ll&&!rl&&r
000
MC/DC0%0/2
not $r and $Module::Generic::Global::MOD_PERL
not $r $Module::Generic::Global::MOD_PERL
Truth table0%0/3
not(A) and B
A= not $rB= $Module::Generic::Global::MOD_PERL
ABresult
0X0
100
111
478 {
479 0 local $@;
480 0 $r = eval{ Apache2::RequestUtil->request };
481 0 ▶ if( $@ || !$r || !Scalar::Util::blessed($r) || !$r->isa('Apache2::RequestRec') )
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $r or not builtin::blessed($r) or not $r->isa("Apache2::RequestRec")) 0 0 0
Condition0%0/9
$@ or not $r or not builtin::blessed($r) or not $r->isa("Apache2::RequestRec")
l!l&&r!l&&!r
000
$@ or not $r or not builtin::blessed($r)
l!l&&r!l&&!r
000
$@ or not $r
l!l&&r!l&&!r
000
MC/DC0%0/4
$@ or not $r or not builtin::blessed($r) or not $r->isa("Apache2::RequestRec")
$@ not $r not builtin::blessed($r) not $r->isa("Apache2::RequestRec")
Truth table0%0/5
A or not(B) or not(C) or not(D)
A= $@B= not $rC= not builtin::blessed($r)D= not $r->isa("Apache2::RequestRec")
ABCDresult
1XXX1
01XX1
001X1
00011
00000
482 {
483 0 $self->__message( 3, "No valid Apache request for cleanup: $@" );
484 0 return(1); # Skip
485 }
486 }
487 0 ▶ return(1) unless( $r ); # Non-mod_perl: Rely on END
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 0 0
488  
489 0 my $r_id = Scalar::Util::refaddr( $r );
490 # NOTE: Lock the parent :shared hash, not a reference to a leaf entry.
491 # On threads::shared 1.4 (perl 5.16-ld), CORE::lock( \$shared_hash->{$k} ) SIGSEGVs.
492 # Locking $CLEANUP itself is safe across all releases.
493 # FIXME: storing a plain hashref into $CLEANUP->{ $r_id } also fails on modern
494 # threads::shared with "Invalid value for shared scalar". This code path is
495 # mod_perl-only and not currently exercised in the test suite, so we defer the fix to
496 # a separate change.
497 0 ▶ $self->_lock_write( $CLEANUP ) || return( $self->error( 'Lock fail for cleanup track.' ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::CLEANUP) or return $self->error("Lock fail for cleanup track.") 0 0 0
498 0 ▶ $CLEANUP->{ $r_id } //= { ns => {}, keep => {} };
Condition0%0/2
$Module::Generic::Global::CLEANUP->{$r_id} //= {"ns", {}, "keep", {}}
l!l
00
MC/DC0%0/1
$Module::Generic::Global::CLEANUP->{$r_id} //= {"ns", {}, "keep", {}}
$Module::Generic::Global::CLEANUP->{$r_id}
Truth table0%0/2
A
A= $Module::Generic::Global::CLEANUP->{$r_id}
Aresult
11
00
499 0 $CLEANUP->{ $r_id }->{ns}->{ $_ } = 1 for( @$namespaces );
500 0 %{$CLEANUP->{ $r_id }->{keep}} = %keep;
501 0 $self->_unlock;
502  
503 0 my $weaken_self = $self;
504 0 Scalar::Util::weaken( $weaken_self );
505 0 local $@;
506 eval
507 0 {
508 $r->pool->cleanup_register(sub
509 0 ▶ {
Subroutine __ANON__: not called CC=11 SCAR=48.8
510 0 my $args = shift( @_ );
511 0 my( $me, $this_r, $cb ) = @$args;
512 0 ▶ return if( !$me );
Branch: 1 branch
BranchTrueFalseTotal
unless $me 0 0 0
513  
514 0 my $this_r_id = Scalar::Util::refaddr( $this_r );
515 0 ▶ $me->_lock_read( $CLEANUP ) || return;
Branch: 1 branch
BranchTrueFalseTotal
$me->_lock_read($Module::Generic::Global::CLEANUP) or return 0 0 0
516 0 my $data = $CLEANUP->{ $this_r_id };
517 0 $me->_unlock;
518 0 ▶ if( $data )
Branch: 1 branch
BranchTrueFalseTotal
if ($data) 0 0 0
519 {
520 0 my @to_clear = grep{ !$data->{keep}->{ $_ } } keys( %{$data->{ns}} );
521 0 ▶ if( @to_clear )
Branch: 1 branch
BranchTrueFalseTotal
if (@to_clear) 0 0 0
522 {
523 0 ▶ $this_r->log->notice( "Clearing namespaces: ", join( ', ', @to_clear) ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Module::Generic::Global::DEBUG 0 0 0
524 0 foreach my $ns ( @to_clear )
525 {
526 0 delete( $REPO->{ $ns } );
527 0 delete( $ORDER->{ $ns } );
528 0 delete( $SIZES->{ $ns } );
529 0 delete( $NS_LOCKS->{ $ns } );
530  
531 0 foreach my $k ( keys( %$STATS ) )
532 {
533 0 ▶ next if( index( $k, $ns . ';' ) != 0 );
Branch: 1 branch
BranchTrueFalseTotal
if index($k, $ns . ';') != 0 0 0 0
534 0 delete( $STATS->{ $k } );
535 }
536 }
537 }
538 0 ▶ $me->_lock_write( $CLEANUP ) || return;
Branch: 1 branch
BranchTrueFalseTotal
$me->_lock_write($Module::Generic::Global::CLEANUP) or return 0 0 0
539 0 delete( $CLEANUP->{ $this_r_id } );
540 0 $me->_unlock;
541 }
542 0 ▶ $cb->( $me, $this_r ) if( $cb );
Branch: 1 branch
BranchTrueFalseTotal
if $cb 0 0 0
543 0 }, [ $weaken_self, $r, $callback ] );
544 };
545 0 ▶ $self->__message( 3, "Cleanup register error: $@" ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
546 0 return(1);
547 }
548  
549 sub clear_error
550 1 ▶{
Subroutine clear_error: called CC=5 SCAR=17.1
Pod documented
551 1 my $self = shift( @_ );
552 1 ▶ my $class = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
553 1 ▶ my $err_key = HAS_THREADS() ? join( ';', $class, $$, threads->tid ) : join( ';', $class, $$ );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 1 1
554 1 ▶ $self->{_error} = undef if( ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 1 0 1
555  
556 1 ▶ $self->_lock_write( $ERRORS, delay => ERROR_DELAY ) || die( "Unable to get a lock on \$ERRORS" );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::ERRORS, "delay", 5000) or die "Unable to get a lock on \$ERRORS" 1 0 1
557 eval
558 1 {
559 1 CORE::delete( $ERRORS->{ $err_key } );
560 };
561 1 $self->_unlock;
562 1 return( $self );
563 }
564  
565 sub debug
566 0 ▶{
Subroutine debug: not called CC=2 SCAR=17.9
Pod undocumented
567 0 my $self = shift( @_ );
568 0 ▶ $self->{debug} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
569 0 return( $self->{debug} );
570 }
571  
572 sub error
573 9 ▶{
Subroutine error: called CC=15 SCAR=28.5
Pod documented
574 9 my $self = shift( @_ );
575 9 ▶ my $class = ref( $self ) || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
630
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
576 9 ▶ my $err_key = HAS_THREADS ? join( ';', $class, $$, threads->tid ) : join( ';', $class, $$ );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 9 9
577 9 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 5 9
578 {
579 4 my $msg = join( '', @_ );
580 4 my $ex = Module::Generic::Global::Exception->new({ message => $msg, code => 500, skip_frames => 1 });
581 4 ▶ warn( $ex ) if( warnings::enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("Module::Generic") 1 3 4
582 # $self->__message( 4, "Is \$ERRORS shared ? ", ( HAS_THREADS && threads::shared::is_shared( $ERRORS ) ? 'yes' : 'no' ) );
583 4 ▶ $self->{_error} = $ex if( ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 3 1 4
584 4 ▶ $self->_lock_write( $ERRORS, delay => ERROR_DELAY ) || die( "Unable to get a lock on \$ERRORS" );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::ERRORS, "delay", 5000) or die "Unable to get a lock on \$ERRORS" 4 0 4
585 eval
586 4 {
587 4 $ERRORS->{ $err_key } = Storable::Improved::freeze( $ex );
588 };
589 4 $self->_unlock;
590 4 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
591 {
592 0 ▶ warn( "Error serialising exception object: $@" ) if( warnings::enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("Module::Generic") 0 0 0
593 }
594 4 return;
595 }
596 5 my $o;
597 5 ▶ $o = $self->{_error} if( ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 3 2 5
598 5 ▶ unless( $o )
Branch: 1 branch
BranchTrueFalseTotal
unless ($o) 3 2 5
599 {
600 3 ▶ $self->_lock_read( $ERRORS, delay => ERROR_DELAY ) || die( "Unable to get a lock on \$ERRORS" );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_read($Module::Generic::Global::ERRORS, "delay", 5000) or die "Unable to get a lock on \$ERRORS" 3 0 3
601 3 ▶ if( my $store = $ERRORS->{ $err_key } )
Branch: 1 branch
BranchTrueFalseTotal
if (my $store = $Module::Generic::Global::ERRORS->{$err_key}) 2 1 3
602 {
603 # try-catch
604 2 local $@;
605 eval
606 2 {
607 2 $o = Storable::Improved::thaw( $store );
608 };
609 2 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
610 {
611 0 ▶ warn( "Error deserialising stored exception object: $@" ) if( warnings::enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("Module::Generic") 0 0 0
612 }
613 }
614 }
615 5 return( $o );
616 }
617  
618 sub exists
619 3149 ▶{
Subroutine exists: called CC=6 SCAR=18.8
Pod documented
620 3149 my $self = shift( @_ );
621 3149 ▶ my $ns = $self->{_namespace} || die( "No namespace is set." );
Condition50%1/2
$self->{'_namespace'} || die('No namespace is set.')
l!l
31490
MC/DC0%0/1
$self->{'_namespace'} || die('No namespace is set.')
$self->{'_namespace'}
Truth table50%1/2
A
A= $self->{'_namespace'}
Aresult
11
00
622 3149 ▶ my $key = $self->{_key} || die( "No key is set." );
Condition50%1/2
$self->{'_key'} || die('No key is set.')
l!l
31490
MC/DC0%0/1
$self->{'_key'} || die('No key is set.')
$self->{'_key'}
Truth table50%1/2
A
A= $self->{'_key'}
Aresult
11
00
623 # Make sure the repository is shared if needed
624 # If _share_repo returns false, we do too, because something went wrong.
625 3149 ▶ $self->_share_repo( $ns ) || return(0);
Branch: 1 branch
BranchTrueFalseTotal
$self->_share_repo($ns) or return 0 3149 0 3149
626 3149 ▶ return(0) if( !CORE::exists( $REPO->{ $ns } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Module::Generic::Global::REPO->{$ns} 0 3149 3149
627 3149 ▶ return( CORE::exists( $REPO->{ $ns }->{ $key } ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
exists $Module::Generic::Global::REPO->{$ns}{$key} ? : 2742 407 3149
628 }
629  
630 sub get
631 3678 ▶{
Subroutine get: called CC=23 SCAR=42.5
Pod documented
632 3678 my $self = shift( @_ );
633 3678 my $opts = $self->_get_args_as_hash( @_ );
634 3678 ▶ my $ns = $self->{_namespace} || die( "No namespace is set." );
Condition50%1/2
$self->{'_namespace'} || die('No namespace is set.')
l!l
36780
MC/DC0%0/1
$self->{'_namespace'} || die('No namespace is set.')
$self->{'_namespace'}
Truth table50%1/2
A
A= $self->{'_namespace'}
Aresult
11
00
635 3678 ▶ my $key = $self->{_key} || die( "No key is set." );
Condition50%1/2
$self->{'_key'} || die('No key is set.')
l!l
36780
MC/DC0%0/1
$self->{'_key'} || die('No key is set.')
$self->{'_key'}
Truth table50%1/2
A
A= $self->{'_key'}
Aresult
11
00
636 3678 my( $cb, $args );
637 3678 ▶ if( CORE::exists( $opts->{on_get} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'on_get'} and defined $opts->{'on_get'}) { } 0 3678 3678
Condition33%1/3
exists $opts->{"on_get"} and defined $opts->{"on_get"}
!ll&&!rl&&r
367800
MC/DC0%0/2
exists $opts->{"on_get"} and defined $opts->{"on_get"}
exists $opts->{"on_get"} defined $opts->{"on_get"}
Truth table33%1/3
A and B
A= exists $opts->{"on_get"}B= defined $opts->{"on_get"}
ABresult
0X0
100
111
638 CORE::defined( $opts->{on_get} ) )
639 {
640 0 ( $cb, $args ) = $self->_get_args_for_callback( $opts->{on_get} );
641 0 ▶ return if( !$cb && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not $cb and $self->error 0 0 0
Condition0%0/3
not $cb and $self->error
!ll&&!rl&&r
000
MC/DC0%0/2
not $cb and $self->error
not $cb $self->error
Truth table0%0/3
not(A) and B
A= not $cbB= $self->error
ABresult
0X0
100
111
642 }
643 else
644 {
645 3678 ▶ $cb = $self->{on_get} if( CORE::exists( $self->{on_get} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"on_get"} 0 3678 3678
646 3678 ▶ $args = $self->{on_get_args} if( CORE::exists( $self->{on_get_args} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"on_get_args"} 0 3678 3678
647 }
648 3678 $self->__message( 7, "Called for namespace '$ns' and key '$key' from class ", [caller]->[0], " at line ", [caller]->[2], " in sub ", [caller(1)]->[3] );
649 # Make sure the repository is shared if needed
650 3678 ▶ $self->_share_repo( $ns ) || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_share_repo($ns) or return 3678 0 3678
651
652 # We avoid autovivification
653 3678 ▶ if( !CORE::exists( $REPO->{ $ns }->{ $key } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Module::Generic::Global::REPO->{$ns}{$key}) 717 2961 3678
654 {
655 717 $self->__message( 7, "No data to deserialise yet." );
656 717 return;
657 }
658  
659 # $self->__message( 4, "\$REPO->{ $ns } is ", overload::StrVal( $REPO->{ $ns } ) );
660 # $self->__message( 4, "HAS_THREADS is '", ( HAS_THREADS // 'undef' ), "'" );
661 # $self->__message( 4, "Is \$REPO->{ $ns } shared already ? ", ( HAS_THREADS && threads::shared::is_shared( $REPO->{ $ns } ) ? 'yes' : 'no' ) );
662 # NOTE: Lock the parent :shared hash, not a reference to a leaf scalar.
663 # On threads::shared 1.4 (perl 5.16-ld), CORE::lock( \$shared_hash->{$k} ) SIGSEGVs.
664 # Locking $REPO->{ $ns } itself is safe across all releases.
665 # The leaf value is accessed by name inside the locked section.
666 2961 ▶ $self->_lock_read( $REPO->{ $ns } ) || return( $self->error( "Unable to lock the repository to read from it." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_read($Module::Generic::Global::REPO->{$ns}) or return $self->error("Unable to lock the repository to read from it.") 2961 0 2961
667 2961 ▶ my $store = CORE::exists( $REPO->{ $ns }->{ $key } ) ? $REPO->{ $ns }->{ $key } : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $Module::Generic::Global::REPO->{$ns}{$key} ? : 2961 0 2961
668 2961 $self->_unlock;
669 2961 ▶ if( CORE::length( $store // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::length($store // '')) { } 2961 0 2961
Condition50%1/2
$store // ""
l!l
29610
MC/DC0%0/1
$store // ""
$store
Truth table50%1/2
A
A= $store
Aresult
11
00
670 {
671 2961 $self->__message( 7, "Deserialising stored data '$store'" );
672 2961 my $value = $self->_deserialise( $store );
673 2961 ▶ if( !defined( $value ) && $self->error )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value and $self->error) 0 2961 2961
Condition33%1/3
not defined $value and $self->error
!ll&&!rl&&r
296100
MC/DC0%0/2
not defined $value and $self->error
not defined $value $self->error
Truth table33%1/3
not(A) and B
A= not defined $valueB= $self->error
ABresult
0X0
100
111
674 {
675 0 return;
676 }
677  
678 2961 ▶ if( defined( $value ) && Scalar::Util::blessed( $value ) && $value->isa( 'Module::Generic::Global::Scalar' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and builtin::blessed($value) and $value->isa("Module::Generic::Global::Scalar")) 2808 153 2961
Condition83%5/6
defined $value and builtin::blessed($value) and $value->isa("Module::Generic::Global::Scalar")
!ll&&!rl&&r
115382808
defined $value and builtin::blessed($value)
!ll&&!rl&&r
01152846
MC/DC66%2/3
defined $value and builtin::blessed($value) and $value->isa("Module::Generic::Global::Scalar")
defined $value builtin::blessed($value) $value->isa("Module::Generic::Global::Scalar")
Truth table75%3/4
A and B and C
A= defined $valueB= builtin::blessed($value)C= $value->isa("Module::Generic::Global::Scalar")
ABCresult
0XX0
10X0
1100
1111
679 {
680 2808 $value = $value->as_string;
681 }
682 2961 ▶ if( defined( $cb ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cb) 0 2961 2961
683 {
684 0 local $@;
685 my $rv = eval
686 0 {
687 0 local $_ = $self;
688 0 ▶ $cb->( $value, ( defined( $args ) ? @$args : () ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $args ? : 0 0 0
689 };
690 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
691 {
692 0 return( $self->error( "Error with callback after deserialising object: $@" ) );
693 }
694 0 return( $rv );
695 }
696 2961 return( $value );
697 }
698 else
699 {
700 0 $self->__message( 7, "No data to deserialise yet." );
701 0 return( $store );
702 }
703 }
704  
705 0 ▶sub key { return( shift->{_key} ); }
Subroutine key: not called CC=1 SCAR=6.9
Pod documented
706  
707 sub length
708 302 ▶{
Subroutine length: called CC=9 SCAR=23.6
Pod documented
709 302 my( $self ) = @_;
710 302 ▶ my $ns = $self->{_namespace} || die( "No namespace is set." );
Condition50%1/2
$self->{'_namespace'} || die('No namespace is set.')
l!l
3020
MC/DC0%0/1
$self->{'_namespace'} || die('No namespace is set.')
$self->{'_namespace'}
Truth table50%1/2
A
A= $self->{'_namespace'}
Aresult
11
00
711  
712 302 ▶ $self->_share_repo( $ns ) || return(0);
Branch: 1 branch
BranchTrueFalseTotal
$self->_share_repo($ns) or return 0 302 0 302
713  
714 302 ▶ if( !CORE::exists( $REPO->{ $ns } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Module::Generic::Global::REPO->{$ns}) 0 302 302
715 {
716 0 $self->__message( 7, "The following keys were found for namespace '$ns': ''" );
717 0 $self->__message( 7, "ORDER repo contains: ''" );
718 0 return(0);
719 }
720  
721 302 my @keys = CORE::keys( %{ $REPO->{ $ns } } );
722 302 $self->__message( 5, "Found ", scalar( @keys ), " keys: '", join( ', ', @keys ), "'" );
723  
724 # Optional: if your "deleted" state is empty string, you probably want to exclude them
725 # to avoid resurrected empty slots being counted.
726 # This requires reading each value carefully without autoviv: we already have keys, so it's safe.
727 # NOTE: Lock the parent :shared hash once around the whole scan, rather than taking a
728 # leaf-scalar lock per key. The latter SIGSEGVs on threads::shared 1.4
729 # (perl 5.16-ld), and is also more expensive.
730 302 my @alive;
731 302 ▶ $self->_lock_read( $REPO->{ $ns } ) || return( $self->error( "Unable to lock repository to scan keys." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_read($Module::Generic::Global::REPO->{$ns}) or return $self->error("Unable to lock repository to scan keys.") 302 0 302
732 302 foreach my $k ( @keys )
733 {
734 56 ▶ next if( !CORE::exists( $REPO->{ $ns }->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Module::Generic::Global::REPO->{$ns}{$k} 0 56 56
735 56 my $v = $REPO->{ $ns }->{ $k };
736 # next if( !defined( $v ) || $v eq '' );
737 56 push( @alive, $k );
738 }
739 302 $self->_unlock;
740  
741 302 $self->__message( 7, "The following keys were found for namespace '$ns': '", join( ', ', sort( @alive ) ), "'" );
742  
743 302 ▶ if( CORE::exists( $ORDER->{ $ns } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Module::Generic::Global::ORDER->{$ns}) { } 302 0 302
744 {
745 302 my $order_ref = $ORDER->{ $ns };
746 302 ▶ $self->_lock_read( $order_ref ) || return( $self->error( "Unable to lock order to read it." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_read($order_ref) or return $self->error("Unable to lock order to read it.") 302 0 302
747 302 my @order = @{$ORDER->{ $ns }};
748 302 $self->_unlock;
749 302 $self->__message( 7, "ORDER repo contains: '", join( ', ', @order ), "'" );
750 }
751 else
752 {
753 0 $self->__message( 7, "ORDER repo contains: ''" );
754 }
755  
756 302 return( scalar( @alive ) );
757 }
758  
759 sub lock
760 53 ▶{
Subroutine lock: called CC=10 SCAR=37.9
Pod documented
761 53 my $self = shift( @_ );
762 # A lock is class and process-wide, so if our object was created for object-scope, we use the class key instead of the key
763 53 ▶ my $key = ( $self->{_mode} eq 'class' || $self->{_mode} eq 'system' ) ? $self->{_key} : $self->{_class_key};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_mode'} eq 'class' || $self->{'_mode'} eq 'system' ? : 53 0 53
Condition66%2/3
$self->{"_mode"} eq "class" or $self->{"_mode"} eq "system"
l!l&&r!l&&!r
5030
MC/DC0%0/2
$self->{"_mode"} eq "class" or $self->{"_mode"} eq "system"
$self->{"_mode"} eq "class" $self->{"_mode"} eq "system"
Truth table66%2/3
A or B
A= $self->{"_mode"} eq "class"B= $self->{"_mode"} eq "system"
ABresult
1X1
011
000
764 53 ▶ die( "No key found in our object!" ) if( !$key );
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 53 53
765 53 ▶ if( HAS_THREADS && !$MUTEX )
Branch: 2 branches
BranchTrueFalseTotal
if (&HAS_THREADS() and not $Module::Generic::Global::MUTEX) { } 0 53 53
elsif ($Module::Generic::Global::MUTEX) { } 0 53 53
Condition33%1/3
&HAS_THREADS() and not $Module::Generic::Global::MUTEX
!ll&&!rl&&r
5300
MC/DC0%0/2
&HAS_THREADS() and not $Module::Generic::Global::MUTEX
&HAS_THREADS() not $Module::Generic::Global::MUTEX
Truth table33%1/3
A and not(B)
A= &HAS_THREADS()B= not $Module::Generic::Global::MUTEX
ABresult
0X0
100
111
766 {
767 # NOTE: Lock the top-level :shared $LOCKS hash itself, not a reference to a leaf
768 # scalar entry. CORE::lock( \$LOCKS->{$key} ) SIGSEGVs on threads::shared 1.4
769 # (perl 5.16-ld). Locking $LOCKS trades per-key contention for hash-wide
770 # contention; this is acceptable because the public lock() method is rarely on a
771 # hot path and provides advisory locking semantics rather than fine-grained
772 # synchronisation.
773 0 ▶ $LOCKS->{ $key } //= 0;
Condition0%0/2
$Module::Generic::Global::LOCKS->{$key} //= 0
l!l
00
MC/DC0%0/1
$Module::Generic::Global::LOCKS->{$key} //= 0
$Module::Generic::Global::LOCKS->{$key}
Truth table0%0/2
A
A= $Module::Generic::Global::LOCKS->{$key}
Aresult
11
00
774 # try-catch
775 0 my $rv;
776 0 eval{ $rv = CORE::lock( $LOCKS ) };
777 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
778 {
779 0 $self->__message( 3, "Error locking \$LOCKS for key $key: $@" );
780 0 return( $self->error({
781 message => "Failed to acquire shared lock for key $key: $@",
782 class => 'Module::Generic::Global::Exception',
783 code => 503
784 }) );
785 }
786 0 $self->__message( 4, "Acquired shared lock for key $key" );
787 # We return the value returned by CORE::lock, which, when it goes out of scopre in the caller's block, the lock also will be automatically removed.
788 0 return( $rv );
789 }
790 elsif( $MUTEX )
791 {
792 0 my $rv = $self->_lock_mutex( $LOCK_MUTEX, delay => RETRY_DELAY, rw => 1 );
793 0 ▶ if( !$rv )
Branch: 1 branch
BranchTrueFalseTotal
unless ($rv) 0 0 0
794 {
795 0 $self->__message( 3, "Failed to acquire shared lock for key $key after ", MAX_RETRIES, " retries" );
796 0 return( $self->error( {
797 message => "Failed to acquire shared lock for key $key after ", MAX_RETRIES, " retries",
798 class => 'Module::Generic::Global::Exception',
799 code => 503
800 } ) );
801 }
802 0 $self->__message( 4, "Acquired shared lock for key $key with mutex" );
803 # Return a special private object that will unlock the mutex when it gets out of scope, just like CORE::lock() does, so the user does not have to worry about calling unlock()
804 0 return( Module::Generic::Global::Guard->new( $LOCK_MUTEX ) );
805 }
806 53 return(1);
807 }
808  
809 sub max_store_bytes
810 359 ▶{
Subroutine max_store_bytes: called CC=2 SCAR=7.1
Pod documented
811 359 my $self = shift( @_ );
812 359 ▶ $self->{max_store_bytes} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 359 359
813 359 return( $self->{max_store_bytes} );
814 }
815  
816 0 ▶sub namespace { return( shift->{_namespace} ); }
Subroutine namespace: not called CC=1 SCAR=6.9
Pod documented
817  
818 sub remove
819 13603 ▶{
Subroutine remove: called CC=14 SCAR=27.7
Pod documented
820 13603 my $self = shift( @_ );
821 13603 ▶ my $ns = $self->{_namespace} || die( "No namespace is set." );
Condition50%1/2
$self->{'_namespace'} || die('No namespace is set.')
l!l
136030
MC/DC0%0/1
$self->{'_namespace'} || die('No namespace is set.')
$self->{'_namespace'}
Truth table50%1/2
A
A= $self->{'_namespace'}
Aresult
11
00
822 13603 ▶ my $key = $self->{_key} || die( "No key is set." );
Condition50%1/2
$self->{'_key'} || die('No key is set.')
l!l
136030
MC/DC0%0/1
$self->{'_key'} || die('No key is set.')
$self->{'_key'}
Truth table50%1/2
A
A= $self->{'_key'}
Aresult
11
00
823 # Make sure the repository is shared if needed
824 13603 ▶ $self->_share_repo( $ns ) || return(1);
Branch: 1 branch
BranchTrueFalseTotal
$self->_share_repo($ns) or return 1 13603 0 13603
825  
826 13603 ▶ if( !CORE::exists( $REPO->{ $ns }->{ $key } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Module::Generic::Global::REPO->{$ns}{$key}) 13491 112 13603
827 {
828 # $self->__message( 4, "The repository \$REPO->{ $ns }->{ $key } does not exist, so there is nothing to remove." );
829 13491 return(1);
830 }
831 # NOTE: Lock the parent :shared hash, not a leaf scalar reference.
832 # See similar comment in get() for the rationale.
833 112 ▶ $self->_lock_write( $REPO->{ $ns } ) || return( $self->error( "Unable to lock the repository to write to it." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::REPO->{$ns}) or return $self->error("Unable to lock the repository to write to it.") 112 0 112
834 112 ▶ my $removed_len = CORE::length( $REPO->{ $ns }->{ $key } // '' );
Condition50%1/2
$Module::Generic::Global::REPO->{$ns}{$key} // ""
l!l
1120
MC/DC0%0/1
$Module::Generic::Global::REPO->{$ns}{$key} // ""
$Module::Generic::Global::REPO->{$ns}{$key}
Truth table50%1/2
A
A= $Module::Generic::Global::REPO->{$ns}{$key}
Aresult
11
00
835 112 CORE::delete( $REPO->{ $ns }->{ $key } );
836 112 $self->_unlock;
837  
838 # The last one out of the door, please shut the light: we remove the namespace if re are using refcounts.
839 # It can be called in void.
840 112 $self->_decrement;
841  
842 # Housekeeping
843 112 ▶ if( $removed_len > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($removed_len > 0) 112 0 112
844 {
845 112 ▶ $self->_lock_write( $SIZES->{ $ns } ) || return( $self->error( "Unable to update sizes on remove." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::SIZES->{$ns}) or return $self->error("Unable to update sizes on remove.") 112 0 112
846 112 ${$SIZES->{ $ns }} -= $removed_len;
847 112 $self->_unlock;
848 }
849  
850 # We remove from order array to keep it clean
851 112 my $order_ref = $ORDER->{ $ns };
852 112 ▶ $self->_lock_write( $order_ref ) || return( $self->error( "Unable to lock order array for removal." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($order_ref) or return $self->error("Unable to lock order array for removal.") 112 0 112
853 112 ▶ @{$ORDER->{ $ns }} = grep{ CORE::length( $_ // '' ) && $_ ne $key } @{$ORDER->{ $ns }};
Condition60%3/5
CORE::length($_ // '') && $_ ne $key
!ll&&!rl&&r
0112366
$_ // ""
l!l
4780
MC/DC50%1/2
CORE::length($_ // '') && $_ ne $key
$_ $_ ne $key
Truth table66%2/3
A && B
A= $_B= $_ ne $key
ABresult
0X0
100
111
854 112 $self->_unlock;
855  
856 # Collect some statistics
857 112 my $stat_key = join( ';', $ns, $key );
858 112 ▶ if( CORE::exists( $STATS->{ $stat_key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Module::Generic::Global::STATS->{$stat_key}) 112 0 112
859 {
860 112 ▶ $self->_lock_write( $STATS ) || return( $self->error( "Unable to lock stats for share check." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::STATS) or return $self->error("Unable to lock stats for share check.") 112 0 112
861 112 CORE::delete( $STATS->{ $stat_key } );
862 112 $self->_unlock;
863 }
864 112 return(1);
865 }
866  
867 sub set
868 359 ▶{
Subroutine set: called CC=66 SCAR=49.8
Pod documented
869 359 my( $self, $value ) = @_;
870 359 ▶ my $ns = $self->{_namespace} || die( "No namespace is set." );
Condition50%1/2
$self->{'_namespace'} || die('No namespace is set.')
l!l
3590
MC/DC0%0/1
$self->{'_namespace'} || die('No namespace is set.')
$self->{'_namespace'}
Truth table50%1/2
A
A= $self->{'_namespace'}
Aresult
11
00
871 359 ▶ my $key = $self->{_key} || die( "No key is set." );
Condition50%1/2
$self->{'_key'} || die('No key is set.')
l!l
3590
MC/DC0%0/1
$self->{'_key'} || die('No key is set.')
$self->{'_key'}
Truth table50%1/2
A
A= $self->{'_key'}
Aresult
11
00
872 359 $self->__message( 7, "Called for namespace '$ns' and key '$key' from class ", [caller]->[0], " at line ", [caller]->[2], " in sub ", [caller(1)]->[3] );
873 359 ▶ $self->__message( 7, "Requested to store value '", overload::StrVal( $value // 'undef' ), "'" );
Condition50%1/2
$value // "undef"
l!l
3590
MC/DC0%0/1
$value // "undef"
$value
Truth table50%1/2
A
A= $value
Aresult
11
00
874 359 my $raw_len;
875 359 ▶ if( !ref( $value ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value) 191 168 359
876 {
877 191 ▶ $raw_len = CORE::length( $value // '' );
Condition50%1/2
$value // ""
l!l
1910
MC/DC0%0/1
$value // ""
$value
Truth table50%1/2
A
A= $value
Aresult
11
00
878 191 $value = Module::Generic::Global::Scalar->new( \$value );
879 }
880 359 local $@;
881 359 my $store = $self->_serialise( $value );
882 359 ▶ if( !defined( $store ) && $self->error )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $store and $self->error) 0 359 359
Condition33%1/3
not defined $store and $self->error
!ll&&!rl&&r
35900
MC/DC0%0/2
not defined $store and $self->error
not defined $store $self->error
Truth table33%1/3
not(A) and B
A= not defined $storeB= $self->error
ABresult
0X0
100
111
883 {
884 0 return;
885 }
886  
887 # Source of truth for accounting: actual stored bytes
888 359 ▶ my $len = CORE::length( $store // '' );
Condition50%1/2
$store // ""
l!l
3590
MC/DC0%0/1
$store // ""
$store
Truth table50%1/2
A
A= $store
Aresult
11
00
889 359 ▶ $raw_len //= $len;
Condition66%2/3
$raw_len //= $len
l!l&&r!l&&!r
1911680
MC/DC0%0/2
$raw_len //= $len
$raw_len $len
Truth table66%2/3
A //= B
A= $raw_lenB= $len
ABresult
1X1
011
000
890 # Check for the total bytes stores in this namespace, and if we exceed or not our threshold
891 359 my $max = $self->max_store_bytes;
892 # Warn about some nonsense whereby the maximum bytes size of an element is higher than the total byte size of all elements.
893 359 ▶ if( defined( $max ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max and $max =~ /^\d+$/ and $max > 0 and defined $self->{"max_total_bytes"} and $self->{"max_total_bytes"} =~ /^\d+$/ and $self->{"max_total_bytes"} > 0 and $max > $self->{"max_total_bytes"}) 0 359 359
Condition55%10/18
defined $max and $max =~ /^\d+$/ and $max > 0 and defined $self->{"max_total_bytes"} and $self->{"max_total_bytes"} =~ /^\d+$/ and $self->{"max_total_bytes"} > 0 and $max > $self->{"max_total_bytes"}
!ll&&!rl&&r
35270
defined $max and $max =~ /^\d+$/ and $max > 0 and defined $self->{"max_total_bytes"} and $self->{"max_total_bytes"} =~ /^\d+$/ and $self->{"max_total_bytes"} > 0
!ll&&!rl&&r
35207
defined $max and $max =~ /^\d+$/ and $max > 0 and defined $self->{"max_total_bytes"} and $self->{"max_total_bytes"} =~ /^\d+$/
!ll&&!rl&&r
35207
defined $max and $max =~ /^\d+$/ and $max > 0 and defined $self->{"max_total_bytes"}
!ll&&!rl&&r
03527
defined $max and $max =~ /^\d+$/ and $max > 0
!ll&&!rl&&r
00359
defined $max and $max =~ /^\d+$/
!ll&&!rl&&r
00359
MC/DC0%0/7
defined $max and $max =~ /^\d+$/ and $max > 0 and defined $self->{"max_total_bytes"} and $self->{"max_total_bytes"} =~ /^\d+$/ and $self->{"max_total_bytes"} > 0 and $max > $self->{"max_total_bytes"}
defined $max $max =~ /^\d+$/ $max > 0 defined $self->{"max_total_bytes"} $self->{"max_total_bytes"} =~ /^\d+$/ $self->{"max_total_bytes"} > 0 $max > $self->{"max_total_bytes"}
Truth table25%2/8
A and B and C and D and E and F and G
A= defined $maxB= $max =~ /^\d+$/C= $max > 0D= defined $self->{"max_total_bytes"}E= $self->{"max_total_bytes"} =~ /^\d+$/F= $self->{"max_total_bytes"} > 0G= $max > $self->{"max_total_bytes"}
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
894 $max =~ /^\d+$/ &&
895 $max > 0 &&
896 defined( $self->{max_total_bytes} ) &&
897 $self->{max_total_bytes} =~ /^\d+$/ &&
898 $self->{max_total_bytes} > 0 &&
899 $max > $self->{max_total_bytes} )
900 {
901 0 ▶ warn( "You have set the maximum byte size of an element ($max) to be greater than the total byte size alllwed for all elements ($self->{max_total_bytes}" ) if( warnings::enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("Module::Generic") 0 0 0
902 }
903  
904 359 $self->__message( 4, "Checking if byte length of value provided ($raw_len) is bigger than maximum allowed ($max)" );
905 359 ▶ if( defined( $max ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max and $max =~ /^\d+$/ and $max > 0 and $raw_len > $max) 1 358 359
Condition44%4/9
defined $max and $max =~ /^\d+$/ and $max > 0 and $raw_len > $max
!ll&&!rl&&r
03581
defined $max and $max =~ /^\d+$/ and $max > 0
!ll&&!rl&&r
00359
defined $max and $max =~ /^\d+$/
!ll&&!rl&&r
00359
MC/DC25%1/4
defined $max and $max =~ /^\d+$/ and $max > 0 and $raw_len > $max
defined $max $max =~ /^\d+$/ $max > 0 $raw_len > $max
Truth table40%2/5
A and B and C and D
A= defined $maxB= $max =~ /^\d+$/C= $max > 0D= $raw_len > $max
ABCDresult
0XXX0
10XX0
110X0
11100
11111
906 $max =~ /^\d+$/ &&
907 $max > 0 &&
908 $raw_len > $max )
909 {
910 1 $self->__message( 4, "The value to be stored is $raw_len bytes, which exceeds the maximum allowed of $max bytes. Returning an error now." );
911 1 return( $self->error( "Refusing to store ${raw_len} bytes in Module::Generic::Global (limit ${max})." ) );
912 }
913  
914 # Make sure the repository is shared if needed (moved up for early init)
915 358 ▶ $self->_share_repo( $ns ) || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_share_repo($ns) or return 358 0 358
916  
917 # Pre-create shared slot if new key and in shared mode (fixes invalid shared scalar on autoviv)
918 358 ▶ my $is_new_key = CORE::exists( $REPO->{ $ns }->{ $key } ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $Module::Generic::Global::REPO->{$ns}{$key} ? : 73 285 358
919  
920 358 ▶ if( !CORE::exists( $REPO->{ $ns }->{ $key } ) && _NEED_SHARED() )
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $Module::Generic::Global::REPO->{$ns}{$key} and &_NEED_SHARED()) 0 358 358
Condition66%2/3
not exists $Module::Generic::Global::REPO->{$ns}{$key} and &_NEED_SHARED()
!ll&&!rl&&r
732850
MC/DC0%0/2
not exists $Module::Generic::Global::REPO->{$ns}{$key} and &_NEED_SHARED()
not exists $Module::Generic::Global::REPO->{$ns}{$key} &_NEED_SHARED()
Truth table66%2/3
not(A) and B
A= not exists $Module::Generic::Global::REPO->{$ns}{$key}B= &_NEED_SHARED()
ABresult
0X0
100
111
921 {
922 # Lock per-ns shared scalar
923 0 ▶ $self->_lock_write( $NS_LOCKS->{ $ns } ) || return( $self->error( "Unable to lock namespace for new shared slot." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::NS_LOCKS->{$ns}) or return $self->error("Unable to lock namespace for new shared slot.") 0 0 0
924 0 my $shared_slot :shared = '';
925 0 $REPO->{ $ns }->{ $key } = $shared_slot;
926 0 $self->_unlock;
927 0 $self->__message( 5, "Pre-shared new slot for key '$key' in namespace '$ns'." );
928 }
929  
930 358 $self->__message( 7, "Value to store is ", $len, " bytes long (", overload::StrVal( $store ), ")." );
931 358 my $old_len = 0;
932 358 ▶ if( CORE::exists( $REPO->{ $ns }->{ $key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Module::Generic::Global::REPO->{$ns}{$key}) 73 285 358
933 {
934 # NOTE: Lock the parent :shared hash instead of taking a reference to
935 # a leaf scalar; the latter SIGSEGVs on threads::shared 1.4.
936 73 ▶ $self->_lock_read( $REPO->{ $ns } ) || return( $self->error( "Unable to read old len." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_read($Module::Generic::Global::REPO->{$ns}) or return $self->error("Unable to read old len.") 73 0 73
937 73 ▶ $old_len = CORE::length( $REPO->{ $ns }->{ $key } // '' );
Condition50%1/2
$Module::Generic::Global::REPO->{$ns}{$key} // ""
l!l
730
MC/DC0%0/1
$Module::Generic::Global::REPO->{$ns}{$key} // ""
$Module::Generic::Global::REPO->{$ns}{$key}
Truth table50%1/2
A
A= $Module::Generic::Global::REPO->{$ns}{$key}
Aresult
11
00
938 73 $self->_unlock;
939 }
940  
941 358 my $delta = $len - $old_len;
942 358 ▶ if( $self->{max_total_bytes} && $self->{max_total_bytes} > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max_total_bytes"} and $self->{"max_total_bytes"} > 0) 7 351 358
Condition66%2/3
$self->{"max_total_bytes"} and $self->{"max_total_bytes"} > 0
!ll&&!rl&&r
35107
MC/DC50%1/2
$self->{"max_total_bytes"} and $self->{"max_total_bytes"} > 0
$self->{"max_total_bytes"} $self->{"max_total_bytes"} > 0
Truth table66%2/3
A and B
A= $self->{"max_total_bytes"}B= $self->{"max_total_bytes"} > 0
ABresult
0X0
100
111
943 {
944 7 ▶ $self->_lock_read( $SIZES->{ $ns } ) || return( $self->error( "Unable to lock sizes." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_read($Module::Generic::Global::SIZES->{$ns}) or return $self->error("Unable to lock sizes.") 7 0 7
945 7 ▶ my $current_total = ${$SIZES->{ $ns }} // 0;
Condition50%1/2
${$Module::Generic::Global::SIZES->{$ns};} // 0
l!l
70
MC/DC0%0/1
${$Module::Generic::Global::SIZES->{$ns};} // 0
${$Module::Generic::Global::SIZES->{$ns};}
Truth table50%1/2
A
A= ${$Module::Generic::Global::SIZES->{$ns};}
Aresult
11
00
946 7 $self->_unlock;
947 # No need to check for previous entry to evictate, since this new one already exceeds the tal
948 7 ▶ if( $len > $self->{max_total_bytes} )
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $self->{"max_total_bytes"}) 0 7 7
949 {
950 0 $self->__message( 6, "The new value has a size of ${len} bytes, which exceeds the maximum total bytes allowed ($self->{max_total_bytes})." );
951 0 return( $self->error( "Refusing to store ", ( $len ), " bytes; The byte size of this value exceeds in itself the total byte value size of $self->{max_total_bytes} bytes for this key ${key}." ) );
952 }
953  
954 # Only o this if we exceed the threshold. Very straightforward, very fast.
955 # We make sure that this one new item byte size does not exceed as itself, the maximum allowed.
956 7 ▶ if( ( $current_total + $delta ) > $self->{max_total_bytes} )
Branch: 1 branch
BranchTrueFalseTotal
if ($current_total + $delta > $self->{"max_total_bytes"}) 2 5 7
957 {
958 2 $self->__message( 4, "The new total byte size (", ( $current_total + $delta ), ") would exceed the maximum of '$self->{max_total_bytes}'. Evicting older entries." );
959 2 my $order_ref = $ORDER->{ $ns };
960 2 ▶ $self->_lock_write( $order_ref ) || return( $self->error( "Unable to lock order for total eviction." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($order_ref) or return $self->error("Unable to lock order for total eviction.") 2 0 2
961 2 ▶ while( @{$ORDER->{ $ns }} && $current_total + $delta > $self->{max_total_bytes} )
Branch: 1 branch
BranchTrueFalseTotal
if (@{$Module::Generic::Global::ORDER->{$ns};} and $current_total + $delta > $self->{"max_total_bytes"}) 3 2 5
Condition66%2/3
@{$Module::Generic::Global::ORDER->{$ns};} and $current_total + $delta > $self->{"max_total_bytes"}
!ll&&!rl&&r
023
MC/DC50%1/2
@{$Module::Generic::Global::ORDER->{$ns};} and $current_total + $delta > $self->{"max_total_bytes"}
@{$Module::Generic::Global::ORDER->{$ns};} $current_total + $delta > $self->{"max_total_bytes"}
Truth table66%2/3
A and B
A= @{$Module::Generic::Global::ORDER->{$ns};}B= $current_total + $delta > $self->{"max_total_bytes"}
ABresult
0X0
100
111
962 {
963 3 my $evict_key = shift( @{$ORDER->{ $ns }} );
964 # Do not evict self if overwrite
965 3 ▶ if( CORE::exists( $REPO->{ $ns }->{ $evict_key } ) && $evict_key ne $key )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Module::Generic::Global::REPO->{$ns}{$evict_key} and $evict_key ne $key) 3 0 3
Condition33%1/3
exists $Module::Generic::Global::REPO->{$ns}{$evict_key} and $evict_key ne $key
!ll&&!rl&&r
003
MC/DC0%0/2
exists $Module::Generic::Global::REPO->{$ns}{$evict_key} and $evict_key ne $key
exists $Module::Generic::Global::REPO->{$ns}{$evict_key} $evict_key ne $key
Truth table33%1/3
A and B
A= exists $Module::Generic::Global::REPO->{$ns}{$evict_key}B= $evict_key ne $key
ABresult
0X0
100
111
966 {
967 # NOTE: Lock the parent :shared hash, not a leaf scalar ref.
968 3 ▶ $self->_lock_write( $REPO->{ $ns } ) || last;
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::REPO->{$ns}) or last 3 0 3
969 3 ▶ my $evict_len = CORE::length( $REPO->{ $ns }->{ $evict_key } // '' );
Condition50%1/2
$Module::Generic::Global::REPO->{$ns}{$evict_key} // ""
l!l
30
MC/DC0%0/1
$Module::Generic::Global::REPO->{$ns}{$evict_key} // ""
$Module::Generic::Global::REPO->{$ns}{$evict_key}
Truth table50%1/2
A
A= $Module::Generic::Global::REPO->{$ns}{$evict_key}
Aresult
11
00
970 3 CORE::delete( $REPO->{ $ns }->{ $evict_key } );
971 3 $self->_unlock;
972 # Update sizes (lock separately to avoid deep nest)
973 3 ▶ $self->_lock_write( $SIZES->{ $ns } ) || last;
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::SIZES->{$ns}) or last 3 0 3
974 3 ${$SIZES->{ $ns }} -= $evict_len;
975 3 $self->_unlock;
976 # Clear stat too
977 3 my $evict_stat_key = join( ';', $ns, $evict_key );
978 3 ▶ if( CORE::exists( $STATS->{ $evict_stat_key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Module::Generic::Global::STATS->{$evict_stat_key}) 3 0 3
979 {
980 # NOTE: Lock $STATS (top-level :shared hash) directly.
981 3 ▶ $self->_lock_write( $STATS ) || last;
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::STATS) or last 3 0 3
982 3 CORE::delete( $STATS->{ $evict_stat_key } );
983 3 $self->_unlock;
984 }
985 3 $current_total -= $evict_len;
986 3 $self->__message( 4, "Evicted '$evict_key' ($evict_len bytes) from '$ns' for max_total_bytes ($self->{max_total_bytes})." );
987 }
988 }
989 2 $self->_unlock; # Unlock order
990 2 ▶ if( $current_total + $delta > $self->{max_total_bytes} )
Branch: 1 branch
BranchTrueFalseTotal
if ($current_total + $delta > $self->{"max_total_bytes"}) 0 2 2
991 {
992 0 return( $self->error( "Refusing to store ", ( $len ), " bytes; the new total (", ( $current_total + $delta ), ") would exceed max_total_bytes ($self->{max_total_bytes}) even after eviction." ) );
993 }
994 }
995 }
996  
997 358 ▶ if( $self->{max_size} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max_size"} and $self->{"max_size"} =~ /^\d+$/ and $self->{"max_size"} > 0 and $is_new_key and scalar grep({$_ ne $key;} keys %{$$Module::Generic::Global::REPO{$ns};}) >= $self->{"max_size"}) 1 357 358
Condition83%10/12
$self->{"max_size"} and $self->{"max_size"} =~ /^\d+$/ and $self->{"max_size"} > 0 and $is_new_key and scalar grep({$_ ne $key;} keys %{$$Module::Generic::Global::REPO{$ns};}) >= $self->{"max_size"}
!ll&&!rl&&r
35431
$self->{"max_size"} and $self->{"max_size"} =~ /^\d+$/ and $self->{"max_size"} > 0 and $is_new_key
!ll&&!rl&&r
35314
$self->{"max_size"} and $self->{"max_size"} =~ /^\d+$/ and $self->{"max_size"} > 0
!ll&&!rl&&r
35305
$self->{"max_size"} and $self->{"max_size"} =~ /^\d+$/
!ll&&!rl&&r
35305
MC/DC60%3/5
$self->{"max_size"} and $self->{"max_size"} =~ /^\d+$/ and $self->{"max_size"} > 0 and $is_new_key and scalar grep({$_ ne $key;} keys %{$$Module::Generic::Global::REPO{$ns};}) >= $self->{"max_size"}
$self->{"max_size"} $self->{"max_size"} =~ /^\d+$/ $self->{"max_size"} > 0 $is_new_key scalar grep({$_ ne $key;} keys %{$$Module::Generic::Global::REPO{$ns};}) >= $self->{"max_size"}
Truth table66%4/6
A and B and C and D and E
A= $self->{"max_size"}B= $self->{"max_size"} =~ /^\d+$/C= $self->{"max_size"} > 0D= $is_new_keyE= scalar grep({$_ ne $key;} keys %{$$Module::Generic::Global::REPO{$ns};}) >= $self->{"max_size"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
998 $self->{max_size} =~ /^\d+$/ &&
999 $self->{max_size} > 0 &&
1000 $is_new_key &&
1001 6 scalar( grep{ $_ ne $key } keys( %{$REPO->{ $ns }} ) ) >= $self->{max_size} )
1002 {
1003 1 $self->__message( 4, "The size of repository for namespace '$ns' is '", scalar( keys( %{$REPO->{ $ns }} ) ), "', which exceeds the maximum size allowed ($self->{max_size})." );
1004 1 my $order_ref = $ORDER->{ $ns };
1005 1 ▶ $self->_lock_write( $order_ref ) || return( $self->error( "Unable to lock order array for eviction." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($order_ref) or return $self->error("Unable to lock order array for eviction.") 1 0 1
1006 1 ▶ while( @{$ORDER->{ $ns }} )
Branch: 1 branch
BranchTrueFalseTotal
if (@{$Module::Generic::Global::ORDER->{$ns};}) 1 0 1
1007 {
1008 1 my $old_key = shift( @{$ORDER->{ $ns }} );
1009 1 $self->__message( 4, "Checking keys to evit: processing key '$old_key' with namespace size of '", scalar( keys( %{$REPO->{ $ns }} ) ), "'" );
1010 1 ▶ if( CORE::exists( $REPO->{ $ns }->{ $old_key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Module::Generic::Global::REPO->{$ns}{$old_key}) 1 0 1
1011 {
1012 # NOTE: Lock the parent :shared hash, not a leaf scalar ref.
1013 1 ▶ $self->_lock_write( $REPO->{ $ns } ) || last;
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::REPO->{$ns}) or last 1 0 1
1014 1 ▶ my $old_bytes = CORE::length( $REPO->{ $ns }->{ $old_key } // '' );
Condition50%1/2
$Module::Generic::Global::REPO->{$ns}{$old_key} // ""
l!l
10
MC/DC0%0/1
$Module::Generic::Global::REPO->{$ns}{$old_key} // ""
$Module::Generic::Global::REPO->{$ns}{$old_key}
Truth table50%1/2
A
A= $Module::Generic::Global::REPO->{$ns}{$old_key}
Aresult
11
00
1015 1 CORE::delete( $REPO->{ $ns }->{ $old_key } );
1016 1 $self->_unlock;
1017  
1018 1 ▶ $self->_lock_write( $SIZES->{ $ns } ) || last;
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::SIZES->{$ns}) or last 1 0 1
1019 1 ${$SIZES->{ $ns }} -= $old_bytes;
1020 1 $self->_unlock;
1021  
1022 1 my $old_stat_key = join( ';', $ns, $old_key );
1023 1 ▶ if( CORE::exists( $STATS->{ $old_stat_key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Module::Generic::Global::STATS->{$old_stat_key}) 1 0 1
1024 {
1025 # NOTE: Lock $STATS (top-level :shared hash) directly.
1026 1 ▶ $self->_lock_write( $STATS ) || last;
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::STATS) or last 1 0 1
1027 1 CORE::delete( $STATS->{ $old_stat_key } );
1028 1 $self->_unlock;
1029 }
1030  
1031 1 $self->__message( 4, "The total number of items in namespace '$ns' is now ", scalar( keys( %{$REPO->{ $ns }} ) ), ". Evicted oldest key '$old_key' from namespace '$ns' to enforce max_size of '$self->{max_size}'." );
1032 1 last;
1033 }
1034 }
1035 1 $self->_unlock;
1036 }
1037  
1038 # $self->__message( 4, "\$REPO->{ $ns } is ", overload::StrVal( $REPO->{ $ns } ) );
1039 # NOTE: Lock the parent :shared hash, not a leaf scalar reference.
1040 358 ▶ $self->_lock_write( $REPO->{ $ns } ) || return( $self->error( "Unable to lock the repository to write to it." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::REPO->{$ns}) or return $self->error("Unable to lock the repository to write to it.") 358 0 358
1041 358 $REPO->{ $ns }->{ $key } = $store;
1042 358 $self->_unlock;
1043  
1044 358 ▶ if( $delta != 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($delta != 0) 339 19 358
1045 {
1046 339 ▶ $self->_lock_write( $SIZES->{ $ns } ) || return( $self->error( "Unable to update sizes." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::SIZES->{$ns}) or return $self->error("Unable to update sizes.") 339 0 339
1047 339 ${$SIZES->{ $ns }} += $delta;
1048 339 $self->_unlock;
1049 }
1050  
1051 # Refresh recency: move key to the end (new OR overwrite)
1052 358 my $order_ref = $ORDER->{ $ns };
1053 358 ▶ $self->_lock_write( $order_ref ) || return( $self->error( "Unable to lock order array for insertion." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($order_ref) or return $self->error("Unable to lock order array for insertion.") 358 0 358
1054  
1055 358 ▶ @{$ORDER->{ $ns }} = grep{ ( $_ // '' ) ne $key } @{$ORDER->{ $ns }};
Condition50%1/2
$_ // ""
l!l
9150
MC/DC0%0/1
$_ // ""
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
1056 358 push( @{$ORDER->{ $ns }}, $key );
1057  
1058 358 $self->_unlock;
1059  
1060 # Collect some statistics
1061 # NOTE: Lock $STATS (top-level :shared hash) directly.
1062 358 my $stat_key = join( ';', $ns, $key );
1063 358 ▶ $self->_lock_write( $STATS ) || return( $self->error( "Unable to lock stats." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($Module::Generic::Global::STATS) or return $self->error("Unable to lock stats.") 358 0 358
1064 358 $STATS->{ $stat_key } = $len;
1065 358 $self->_unlock;
1066 358 return(1);
1067 }
1068  
1069 sub stat
1070 6 ▶{
Subroutine stat: called CC=8 SCAR=20.8
Pod documented
1071 6 my( $self, $limit ) = @_;
1072 6 ▶ $limit ||= 20;
Condition100%2/2
$limit ||= 20
l!l
15
MC/DC100%1/1
$limit ||= 20
$limit
Truth table100%2/2
A
A= $limit
Aresult
11
00
1073  
1074 6 my @items;
1075 6 ▶ $self->_lock_read( $STATS ) || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_read($Module::Generic::Global::STATS) or return 6 0 6
1076 6 ▶ @items = sort{ ( $STATS->{ $b } || 0 ) <=> ( $STATS->{ $a } || 0 ) } keys( %$STATS );
Condition100%4/4
$Module::Generic::Global::STATS->{$b} || 0
l!l
632
$Module::Generic::Global::STATS->{$a} || 0
l!l
641
MC/DC100%1/1
$Module::Generic::Global::STATS->{$b} || 0
$Module::Generic::Global::STATS->{$b}
MC/DC100%1/1
$Module::Generic::Global::STATS->{$a} || 0
$Module::Generic::Global::STATS->{$a}
Truth table100%2/2
A
A= $Module::Generic::Global::STATS->{$b}
Aresult
11
00
Truth table100%2/2
A
A= $Module::Generic::Global::STATS->{$a}
Aresult
11
00
1077 6 $self->_unlock;
1078 6 $self->__message( 4, "STATS contains ", scalar( @items ) );
1079  
1080 6 ▶ splice( @items, $limit ) if( @items > $limit );
Branch: 1 branch
BranchTrueFalseTotal
if @items > $limit 1 5 6
1081  
1082 6 my $out = [];
1083 6 foreach my $k ( @items )
1084 {
1085 36 ▶ push( @$out, { key => $k, bytes => ( $STATS->{ $k } || 0 ) } );
Condition100%2/2
$Module::Generic::Global::STATS->{$k} || 0
l!l
351
MC/DC100%1/1
$Module::Generic::Global::STATS->{$k} || 0
$Module::Generic::Global::STATS->{$k}
Truth table100%2/2
A
A= $Module::Generic::Global::STATS->{$k}
Aresult
11
00
1086 }
1087 6 return( $out );
1088 }
1089  
1090 sub unlock
1091 47 ▶{
Subroutine unlock: called CC=3 SCAR=18.7
Pod documented
1092 47 my $self = shift( @_ );
1093 47 ▶ return(1) unless( defined( $LOCK_MUTEX ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Module::Generic::Global::LOCK_MUTEX 47 0 47
1094 0 local $@;
1095 eval
1096 0 {
1097 0 $LOCK_MUTEX->unlock;
1098 };
1099 0 ▶ $self->__message( 3, "Unlock error: $@" ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1100 0 return(1);
1101 }
1102  
1103 sub _decrement
1104 4282 ▶{
Subroutine _decrement: called CC=10 SCAR=24.7
1105 4282 my $self = shift( @_ );
1106 4282 ▶ return(1) unless( $self->{refcount} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"refcount"} 46 4236 4282
1107 4236 my $ns = $self->{_namespace};
1108 4236 ▶ my $key = $self->{_key} // '';
Condition50%1/2
$self->{"_key"} // ""
l!l
42360
MC/DC0%0/1
$self->{"_key"} // ""
$self->{"_key"}
Truth table50%1/2
A
A= $self->{"_key"}
Aresult
11
00
1109 4236 ▶ $self->_share_repo( $ns ) || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_share_repo($ns) or return 4236 0 4236
1110 4236 ▶ return(1) if( !CORE::exists( $REFCOUNTS->{ $ns }->{ $key } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Module::Generic::Global::REFCOUNTS->{$ns}{$key} 1 4235 4236
1111 4235 my $refns = $REFCOUNTS->{ $ns };
1112 # NOTE: Refcount decrement under a single hash-level lock.
1113 # See the corresponding NOTE in new() for the rationale: we lock $refns
1114 # (a :shared hash, safe everywhere) rather than \$refns->{ $key }
1115 # (a reference to a scalar inside a :shared hash, which SIGSEGV on
1116 # threads::shared 1.4 / perl 5.16-ld).
1117 4235 ▶ $self->_lock_write( $refns ) || return( $self->error( "Unable to lock refcounts namespace for update." ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock_write($refns) or return $self->error("Unable to lock refcounts namespace for update.") 4235 0 4235
1118 4235 ▶ my $current = $refns->{ $key } // 0;
Condition50%1/2
$refns->{$key} // 0
l!l
42350
MC/DC0%0/1
$refns->{$key} // 0
$refns->{$key}
Truth table50%1/2
A
A= $refns->{$key}
Aresult
11
00
1119 4235 ▶ if( $current > 0 )
Branch: 2 branches
BranchTrueFalseTotal
if ($current > 0) { } 4235 0 4235
elsif ($current < 0) { } 0 0 0
1120 {
1121 4235 $refns->{ $key } = $current - 1;
1122 4235 $current = $refns->{ $key };
1123 }
1124 elsif( $current < 0 )
1125 {
1126 0 $self->__message( 6, "Refcount underflow with value '", $current, "' for $ns;$key" );
1127 0 $refns->{ $key } = 0;
1128 0 $current = 0;
1129 }
1130 4235 ▶ if( $current == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($current == 0) 3181 1054 4235
1131 {
1132 3181 $self->remove;
1133 3181 CORE::delete( $refns->{ $key } );
1134 }
1135 4235 $self->_unlock;
1136 4235 return(1);
1137 }
1138  
1139 sub _deserialise
1140 2961 ▶{
Subroutine _deserialise: called CC=25 SCAR=54.0
1141 2961 my $self = shift( @_ );
1142 2961 my $data = shift( @_ );
1143 2961 ▶ return( '' ) if( !CORE::length( $data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::length $data 0 2961 2961
1144 2961 ▶ my $serialiser = $self->{serialiser} || $DEFAULT_SERIALISER || 'Storable::Improved';
Condition40%2/5
$self->{'serialiser'} || $Module::Generic::Global::DEFAULT_SERIALISER || 'Storable::Improved'
l!l
29610
$self->{"serialiser"} or $Module::Generic::Global::DEFAULT_SERIALISER
l!l&&r!l&&!r
296100
MC/DC0%0/2
$self->{'serialiser'} || $Module::Generic::Global::DEFAULT_SERIALISER || 'Storable::Improved'
$self->{"serialiser"} $Module::Generic::Global::DEFAULT_SERIALISER
Truth table33%1/3
A or B
A= $self->{"serialiser"}B= $Module::Generic::Global::DEFAULT_SERIALISER
ABresult
1X1
011
000
1145 # try-catch
1146 2961 local $@;
1147 2961 ▶ if( $serialiser eq 'CBOR' || $serialiser eq 'CBOR::XS' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq 'CBOR' or $serialiser eq 'CBOR::XS') { } 0 2961 2961
Condition33%1/3
$serialiser eq "CBOR" or $serialiser eq "CBOR::XS"
l!l&&r!l&&!r
002961
MC/DC0%0/2
$serialiser eq "CBOR" or $serialiser eq "CBOR::XS"
$serialiser eq "CBOR" $serialiser eq "CBOR::XS"
Truth table33%1/3
A or B
A= $serialiser eq "CBOR"B= $serialiser eq "CBOR::XS"
ABresult
1X1
011
000
1148 {
1149 0 eval( "require CBOR::XS;" );
1150 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1151 {
1152 0 return( $self->error( "Unable to load serialiser CBOR::XS: $@" ) );
1153 }
1154 }
1155 else
1156 {
1157 2961 eval( "require $serialiser;" );
1158 2961 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2961 2961
1159 {
1160 0 return( $self->error( "Unable to load serialiser $serialiser: $@" ) );
1161 }
1162 2961 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 0 2961 2961
1163 {
1164 0 eval( "require Sereal::Decoder;" );
1165 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1166 {
1167 0 return( $self->error( "Unable to load serialiser Sereal::Decoder: $@" ) );
1168 }
1169 }
1170 }
1171  
1172 2961 ▶ if( ref( $serialiser ) eq 'CODE' )
Branch: 5 branches
BranchTrueFalseTotal
if (ref $serialiser eq 'CODE') { } 0 2961 2961
elsif ($serialiser eq 'CBOR' or $serialiser eq 'CBOR::XS') { } 0 2961 2961
elsif ($serialiser eq 'CBOR::Free') { } 0 2961 2961
elsif ($serialiser eq 'Sereal') { } 0 2961 2961
elsif ($serialiser eq 'Storable::Improved' or $serialiser eq 'Storable') { } 2961 0 2961
1173 {
1174 my $ref = eval
1175 0 {
1176 0 return( $serialiser->( $data, 'thaw' ) );
1177 };
1178 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1179 {
1180 0 return( $self->error( "Error trying to deserialise data with user-provided callback: $@" ) );
1181 }
1182 0 return( $ref );
1183 }
1184 ▶ elsif( $serialiser eq 'CBOR' || $serialiser eq 'CBOR::XS' )
Condition33%1/3
$serialiser eq "CBOR" or $serialiser eq "CBOR::XS"
l!l&&r!l&&!r
002961
MC/DC0%0/2
$serialiser eq "CBOR" or $serialiser eq "CBOR::XS"
$serialiser eq "CBOR" $serialiser eq "CBOR::XS"
Truth table33%1/3
A or B
A= $serialiser eq "CBOR"B= $serialiser eq "CBOR::XS"
ABresult
1X1
011
000
1185 {
1186 0 my $cbor = CBOR::XS->new;
1187 0 $cbor->allow_sharing(1);
1188 0 my $ref;
1189 eval
1190 0 {
1191 0 ( $ref, my $bytes ) = $cbor->decode_prefix( $data );
1192 };
1193 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1194 {
1195 0 return( $self->error( "Error trying to deserialise data with $serialiser: $@" ) );
1196 }
1197 0 return( $ref );
1198 }
1199 elsif( $serialiser eq 'CBOR::Free' )
1200 {
1201 my $ref = eval
1202 0 {
1203 33 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1204 0 return( CBOR::Free::decode( $data ) );
1205 };
1206 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1207 {
1208 0 return( $self->error( "Error trying to deserialise data with $serialiser: $@" ) );
1209 }
1210 0 return( $ref );
1211 }
1212 elsif( $serialiser eq 'Sereal' )
1213 {
1214 0 my $dec = Sereal::Decoder->new;
1215 my $is_sereal = sub
1216 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1217 0 my $type = Sereal::Decoder->looks_like_sereal( $_[0] );
1218 0 };
1219 0 my $decoded;
1220 eval
1221 0 {
1222 0 ▶ $is_sereal->( $data ) if( $self->debug );
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
1223 0 $dec->decode( $data => $decoded );
1224 };
1225 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1226 {
1227 0 ▶ return( $self->error( "Error trying to deserialise with $serialiser ", CORE::length( $data ), " bytes of data (", ( CORE::length( $data ) > 128 ? ( substr( $data, 0, 128 ) . '(trimmed)' ) : $data ), ": $@" ) );
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $data > 128 ? : 0 0 0
1228 }
1229 0 return( $decoded );
1230 }
1231 ▶ elsif( $serialiser eq 'Storable::Improved' || $serialiser eq 'Storable' )
Condition33%1/3
$serialiser eq "Storable::Improved" or $serialiser eq "Storable"
l!l&&r!l&&!r
296100
MC/DC0%0/2
$serialiser eq "Storable::Improved" or $serialiser eq "Storable"
$serialiser eq "Storable::Improved" $serialiser eq "Storable"
Truth table33%1/3
A or B
A= $serialiser eq "Storable::Improved"B= $serialiser eq "Storable"
ABresult
1X1
011
000
1232 {
1233 my $rv = eval
1234 2961 {
1235 2961 my $code = $serialiser->can( 'thaw' );
1236 2961 ▶ if( !defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 2961 2961
1237 {
1238 0 die( "The class $serialiser does not support the method 'thaw'." );
1239 }
1240 2961 return( $code->( $data ) );
1241 };
1242 2961 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2961 2961
1243 {
1244 0 return( $self->error( "Error trying to deserialise data with $serialiser: $@" ) );
1245 }
1246 2961 return( $rv );
1247 }
1248 else
1249 {
1250 0 return( $self->error( "Unsupporterd serialiser \"$serialiser\"." ) );
1251 }
1252 }
1253  
1254 sub _get_args_as_hash
1255 68276 ▶{
Subroutine _get_args_as_hash: called CC=4 SCAR=16.1
1256 68276 my $self = shift( @_ );
1257 68276 my $ref = {};
1258 68276 ▶ if( scalar( @_ ) == 1 && defined( $_[0] ) && ref( $_[0] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and defined $_[0] and ref $_[0] eq 'HASH') { } 0 68276 68276
Condition33%2/6
scalar @_ == 1 and defined $_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
6827600
scalar @_ == 1 and defined $_[0]
!ll&&!rl&&r
6827600
MC/DC0%0/3
scalar @_ == 1 and defined $_[0] and ref $_[0] eq "HASH"
scalar @_ == 1 defined $_[0] ref $_[0] eq "HASH"
Truth table25%1/4
A and B and C
A= scalar @_ == 1B= defined $_[0]C= ref $_[0] eq "HASH"
ABCresult
0XX0
10X0
1100
1111
1259 {
1260 0 $ref = shift( @_ );
1261 }
1262 else
1263 {
1264 68276 my %args = @_;
1265 68276 $ref = \%args;
1266 }
1267 68276 return( $ref );
1268 }
1269  
1270 sub _get_args_for_callback
1271 0 ▶{
Subroutine _get_args_for_callback: not called CC=11 SCAR=48.8
1272 0 my $self = shift( @_ );
1273 0 ▶ my $this = shift( @_ ) || return;
Condition0%0/2
shift @_ || (return)
l!l
00
MC/DC0%0/1
shift @_ || (return)
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1274 0 my( $cb, $args );
1275 # The user has provided the callback as an array. For example:
1276 # on_get => [
1277 # sub{ "Hello world!" },
1278 # [qw( arg1 arg2 arg3 )],
1279 # ];
1280 #
1281 # or:
1282 # on_get => [
1283 # sub{ "Hello world!" },
1284 # qw( arg1 arg2 arg3 ),
1285 # ];
1286 0 ▶ if( CORE::ref( $this ) eq 'ARRAY' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $this eq 'ARRAY') { } 0 0 0
elsif (ref $this eq 'CODE') { } 0 0 0
1287 {
1288 0 ▶ if( scalar( @$this ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$this) 0 0 0
1289 {
1290 0 ▶ if( CORE::ref( $this->[0] ) ne 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this->[0] ne "CODE") 0 0 0
1291 {
1292 0 return( $self->error( "Option on_get must be a CODE reference." ) );
1293 }
1294 0 $cb = $this->[0];
1295 0 ▶ if( scalar( @$this ) > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$this > 1) 0 0 0
1296 {
1297 # If the user provided an array reference as the second argument, we use it as the list of parameters to pass the callback
1298 0 ▶ if( scalar( @$this ) == 2 &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$this == 2 and ref $this->[1] eq 'ARRAY') { } 0 0 0
Condition0%0/3
scalar @$this == 2 and ref $this->[1] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$this == 2 and ref $this->[1] eq "ARRAY"
scalar @$this == 2 ref $this->[1] eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @$this == 2B= ref $this->[1] eq "ARRAY"
ABresult
0X0
100
111
1299 CORE::ref( $this->[1] ) eq 'ARRAY' )
1300 {
1301 0 $args = $this->[1];
1302 }
1303 # Otherwise, the user has passed a list of arguments that will become the list of parameters to pass the callback
1304 else
1305 {
1306 0 $args = [@$this[1..$#$this]];
1307 }
1308 }
1309 }
1310 }
1311 # The user has provided just on argument, and it is the callback itself
1312 elsif( CORE::ref( $this ) eq 'CODE' )
1313 {
1314 0 $cb = $this;
1315 }
1316 else
1317 {
1318 0 return( $self->error( "Option on_get must be a CODE reference." ) );
1319 }
1320 # We make sure that if there is no $args, then there is no second argument whose value would be undef.
1321 # Instead, the callback would see only 1 argument.
1322 0 ▶ return( $cb, ( defined( $args ) ? $args : () ) ) if( defined( $cb ) );
Branch: 2 branches
BranchTrueFalseTotal
if defined $cb 0 0 0
defined $args ? : 0 0 0
1323 0 return;
1324 }
1325  
1326 sub _lock
1327 23053 ▶{
Subroutine _lock: called CC=9 SCAR=36.2
1328 23053 my $self = shift( @_ );
1329 23053 my $ref = shift( @_ );
1330 23053 my $opts = $self->_get_args_as_hash( @_ );
1331 23053 ▶ my $rw = $opts->{rw} // 0;
Condition50%1/2
$opts->{"rw"} // 0
l!l
230530
MC/DC0%0/1
$opts->{"rw"} // 0
$opts->{"rw"}
Truth table50%1/2
A
A= $opts->{"rw"}
Aresult
11
00
1332 23053 ▶ if( HAS_THREADS && !$MUTEX )
Branch: 2 branches
BranchTrueFalseTotal
if (&HAS_THREADS() and not $Module::Generic::Global::MUTEX) { } 0 23053 23053
elsif ($Module::Generic::Global::MUTEX) { } 0 23053 23053
Condition33%1/3
&HAS_THREADS() and not $Module::Generic::Global::MUTEX
!ll&&!rl&&r
2305300
MC/DC0%0/2
&HAS_THREADS() and not $Module::Generic::Global::MUTEX
&HAS_THREADS() not $Module::Generic::Global::MUTEX
Truth table33%1/3
A and not(B)
A= &HAS_THREADS()B= not $Module::Generic::Global::MUTEX
ABresult
0X0
100
111
1333 {
1334 # NOTE: Locking safely when shared structures may not have been promoted
1335 # During the END phase and global destruction, _share_repo() deliberately
1336 # creates plain refs rather than :shared ones, because marking new variables as
1337 # :shared at that point aborts the interpreter on older threads::shared releases.
1338 # CORE::lock on a plain ref dies with the message "lock can only be used on
1339 # shared values", so during those phases we treat the operation as a silent no-op
1340 # and return 1, which lets callers using "_lock_write(...) || die" complete their
1341 # cleanup paths normally. Outside those phases, the same error reflects a real
1342 # upstream bug (a missed share()), and we keep the historical behaviour of
1343 # warning and returning undef so the caller's "|| die" fires.
1344 0 local $@;
1345 0 my $rv;
1346 0 eval{ $rv = CORE::lock( $ref ) };
1347 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1348 {
1349 0 ▶ warn( "Unable to lock \$ref (", overload::StrVal( $ref // 'undef' ), ") outside END or DESTRUCT phase, which suggests a missed share() upstream: $@" ) if( warnings::enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("Module::Generic") 0 0 0
Condition0%0/2
$ref // "undef"
l!l
00
MC/DC0%0/1
$ref // "undef"
$ref
Truth table0%0/2
A
A= $ref
Aresult
11
00
1350 0 return;
1351 0 return;
1352 }
1353 0 return( $rv );
1354 }
1355 elsif( $MUTEX )
1356 {
1357 0 ▶ $opts->{delay} //= RETRY_DELAY;
Condition0%0/2
$opts->{"delay"} //= 10000
l!l
00
MC/DC0%0/1
$opts->{"delay"} //= 10000
$opts->{"delay"}
Truth table0%0/2
A
A= $opts->{"delay"}
Aresult
11
00
1358 0 return( $self->_lock_mutex( $MUTEX, %$opts ) );
1359 }
1360 23053 return(1);
1361 }
1362  
1363 sub _lock_mutex
1364 0 ▶{
Subroutine _lock_mutex: not called CC=14 SCAR=53.5
1365 0 my $self = shift( @_ );
1366 0 my $mutex = shift( @_ );
1367 0 my $opts = $self->_get_args_as_hash( @_ );
1368 # Mutex is not defined
1369 0 ▶ return(0) unless( $mutex );
Branch: 1 branch
BranchTrueFalseTotal
unless $mutex 0 0 0
1370 0 ▶ warn( "No base delay was specified." ) if( !CORE::exists( $opts->{delay} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"delay"} 0 0 0
1371 0 ▶ my $base_delay = $opts->{delay} // RETRY_DELAY;
Condition0%0/2
$opts->{"delay"} // 10000
l!l
00
MC/DC0%0/1
$opts->{"delay"} // 10000
$opts->{"delay"}
Truth table0%0/2
A
A= $opts->{"delay"}
Aresult
11
00
1372 0 ▶ die( "No read or write mode was specified." ) if( !CORE::exists( $opts->{rw} ) || !CORE::length( $opts->{rw} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"rw"} and CORE::length $opts->{"rw"} 0 0 0
Condition0%0/3
exists $opts->{"rw"} and CORE::length $opts->{"rw"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"rw"} and CORE::length $opts->{"rw"}
exists $opts->{"rw"} CORE::length $opts->{"rw"}
Truth table0%0/3
A and B
A= exists $opts->{"rw"}B= CORE::length $opts->{"rw"}
ABresult
0X0
100
111
1373 0 my $rw = $opts->{rw};
1374 0 ▶ for( my $retry = 0 ; $retry < MAX_RETRIES ; $retry++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($retry < 10) 0 0 0
1375 {
1376 # try-catch
1377 0 local $@;
1378 0 ▶ my $rc = eval{ $rw ? $mutex->trywrlock : $mutex->tryrdlock };
Branch: 1 branch
BranchTrueFalseTotal
$rw ? : 0 0 0
1379 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1380 {
1381 0 ▶ warn( "Unable to acquire ", ( $rw ? 'write' : 'read' ), " lock using mutex from APR::ThreadRWLock: $@" );
Branch: 1 branch
BranchTrueFalseTotal
$rw ? : 0 0 0
1382 0 return;
1383 }
1384  
1385 0 ▶ if( !$rc )
Branch: 1 branch
BranchTrueFalseTotal
unless ($rc) 0 0 0
1386 {
1387 0 ▶ $self->__message( 4, 'Acquired ' . ( $rw ? 'write' : 'read' ) . ' lock.' );
Branch: 1 branch
BranchTrueFalseTotal
$rw ? : 0 0 0
1388 0 return(1);
1389 }
1390  
1391 0 ▶ if( $rc == &APR::Const::EAGAIN || $rc == &APR::Const::EBUSY )
Branch: 1 branch
BranchTrueFalseTotal
if ($rc == &APR::Const::EAGAIN or $rc == &APR::Const::EBUSY) 0 0 0
Condition0%0/3
$rc == &APR::Const::EAGAIN or $rc == &APR::Const::EBUSY
l!l&&r!l&&!r
000
MC/DC0%0/2
$rc == &APR::Const::EAGAIN or $rc == &APR::Const::EBUSY
$rc == &APR::Const::EAGAIN $rc == &APR::Const::EBUSY
Truth table0%0/3
A or B
A= $rc == &APR::Const::EAGAINB= $rc == &APR::Const::EBUSY
ABresult
1X1
011
000
1392 {
1393 # Exponential backoff
1394 0 my $delay = $base_delay * ( 2 ** $retry );
1395 # Sleep for delay µs
1396 0 select( undef, undef, undef, $delay / 1_000_000.0 );
1397 0 next;
1398 }
1399 }
1400  
1401 0 $self->__message( 3, 'Failed to acquire lock after ' . MAX_RETRIES . ' retries.' );
1402 0 warn( "Failed to acquire write lock" );
1403 0 return(0);
1404 }
1405  
1406 sub _lock_write
1407 19399 ▶{
Subroutine _lock_write: called CC=1 SCAR=0.0
1408 19399 my $self = shift( @_ );
1409 19399 my $ref = shift( @_ );
1410 19399 my $opts = $self->_get_args_as_hash( @_ );
1411 19399 $opts->{rw} = 1;
1412 19399 return( $self->_lock( $ref, %$opts ) );
1413 }
1414  
1415 sub _lock_read
1416 3654 ▶{
Subroutine _lock_read: called CC=1 SCAR=0.0
1417 3654 my $self = shift( @_ );
1418 3654 my $ref = shift( @_ );
1419 3654 my $opts = $self->_get_args_as_hash( @_ );
1420 3654 $opts->{rw} = 0;
1421 3654 return( $self->_lock( $ref, %$opts ) );
1422 }
1423  
1424 sub __message
1425 9712 ▶{
Subroutine __message: called CC=13 SCAR=48.1
1426 9712 my $self = shift( @_ );
1427 9712 my $required_level;
1428 9712 ▶ if( $_[0] =~ /^\d{1,2}$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d{1,2}$/) { } 9712 0 9712
1429 {
1430 9712 $required_level = shift( @_ );
1431 }
1432 else
1433 {
1434 0 $required_level = 0;
1435 }
1436 9712 ▶ return if( !$self->{debug} || $self->{debug} < $required_level );
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"debug"} or $self->{"debug"} < $required_level 9712 0 9712
Condition33%1/3
not $self->{"debug"} or $self->{"debug"} < $required_level
l!l&&r!l&&!r
971200
MC/DC0%0/2
not $self->{"debug"} or $self->{"debug"} < $required_level
not $self->{"debug"} $self->{"debug"} < $required_level
Truth table33%1/3
not(A) or B
A= not $self->{"debug"}B= $self->{"debug"} < $required_level
ABresult
1X1
011
000
1437 0 ▶ my $msg = join( '', map( ref( $_ ) eq 'CODE' ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
1438 0 my $frame = 0;
1439 0 ▶ my $sub_pack = (caller(1))[3] || '';
Condition0%0/2
(caller 1)[3] || ''
l!l
00
MC/DC0%0/1
(caller 1)[3] || ''
(caller 1)[3]
Truth table0%0/2
A
A= (caller 1)[3]
Aresult
11
00
1440 0 my( $pkg, $file, $line ) = caller( $frame );
1441 0 ▶ my $sub = ( caller( $frame + 1 ) )[3] // '';
Condition0%0/2
(caller $frame + 1)[3] // ""
l!l
00
MC/DC0%0/1
(caller $frame + 1)[3] // ""
(caller $frame + 1)[3]
Truth table0%0/2
A
A= (caller $frame + 1)[3]
Aresult
11
00
1442 0 my $sub2;
1443 0 ▶ if( CORE::length( $sub ) )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::length $sub) { } 0 0 0
1444 {
1445 0 $sub2 = substr( $sub, rindex( $sub, '::' ) + 2 );
1446 }
1447 else
1448 {
1449 0 $sub2 = 'main';
1450 }
1451  
1452 0 my $proc_info = " [PID: $$]";
1453 0 ▶ if( HAS_THREADS )
Branch: 1 branch
BranchTrueFalseTotal
if (&HAS_THREADS()) 0 0 0
1454 {
1455 0 my $tid = threads->tid;
1456 0 ▶ $proc_info .= ' -> [thread id ' . $tid . ']' if( $tid );
Branch: 1 branch
BranchTrueFalseTotal
if $tid 0 0 0
1457 }
1458  
1459 0 $msg =~ s/\n$//gs;
1460 0 my $long_msg = "## ${pkg}::${sub2}() [$line]${proc_info}: " . join( "\n## ", split( /\n/, $msg ) );
1461 0 my( $r, $s );
1462 0 ▶ if( $MOD_PERL )
Branch: 1 branch
BranchTrueFalseTotal
if ($Module::Generic::Global::MOD_PERL) { } 0 0 0
1463 {
1464 # try-catch
1465 0 local $@;
1466 eval
1467 0 {
1468 0 $r = Apache2::RequestUtil->request;
1469 };
1470 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1471 {
1472 0 warn( "Could not get the global Apache2::ApacheRec: $@" );
1473 }
1474  
1475 0 ▶ if( $r )
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 0 0 0
1476 {
1477 0 $r->log->debug( $msg );
1478 }
1479 else
1480 {
1481 0 $s = Apache2::ServerUtil->server;
1482 0 $s->log->debug( $msg );
1483 }
1484 }
1485 else
1486 {
1487 0 print( STDERR $long_msg, "\n" );
1488 }
1489 0 return(1);
1490 }
1491  
1492 sub _serialise
1493 359 ▶{
Subroutine _serialise: called CC=27 SCAR=53.4
1494 359 my $self = shift( @_ );
1495 359 my $data = shift( @_ );
1496 359 ▶ return( '' ) if( !CORE::defined( $data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 359 359
1497 359 ▶ return( '' ) if( Scalar::Util::blessed( $data ) && $data->isa( 'Module::Generic::Null' ) );
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($data) and $data->isa("Module::Generic::Null") 0 359 359
Condition66%2/3
builtin::blessed($data) and $data->isa("Module::Generic::Null")
!ll&&!rl&&r
742850
MC/DC0%0/2
builtin::blessed($data) and $data->isa("Module::Generic::Null")
builtin::blessed($data) $data->isa("Module::Generic::Null")
Truth table66%2/3
A and B
A= builtin::blessed($data)B= $data->isa("Module::Generic::Null")
ABresult
0X0
100
111
1498 359 ▶ return( '' ) if( !CORE::length( $data // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::length($data // "") 1 358 359
Condition50%1/2
$data // ""
l!l
3590
MC/DC0%0/1
$data // ""
$data
Truth table50%1/2
A
A= $data
Aresult
11
00
1499 358 ▶ my $serialiser = $self->{serialiser} || $DEFAULT_SERIALISER || 'Storable::Improved';
Condition40%2/5
$self->{'serialiser'} || $Module::Generic::Global::DEFAULT_SERIALISER || 'Storable::Improved'
l!l
3580
$self->{"serialiser"} or $Module::Generic::Global::DEFAULT_SERIALISER
l!l&&r!l&&!r
35800
MC/DC0%0/2
$self->{'serialiser'} || $Module::Generic::Global::DEFAULT_SERIALISER || 'Storable::Improved'
$self->{"serialiser"} $Module::Generic::Global::DEFAULT_SERIALISER
Truth table33%1/3
A or B
A= $self->{"serialiser"}B= $Module::Generic::Global::DEFAULT_SERIALISER
ABresult
1X1
011
000
1500 358 ▶ if( $serialiser eq 'CBOR' || $serialiser eq 'CBOR::XS' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq 'CBOR' or $serialiser eq 'CBOR::XS') { } 0 358 358
Condition33%1/3
$serialiser eq "CBOR" or $serialiser eq "CBOR::XS"
l!l&&r!l&&!r
00358
MC/DC0%0/2
$serialiser eq "CBOR" or $serialiser eq "CBOR::XS"
$serialiser eq "CBOR" $serialiser eq "CBOR::XS"
Truth table33%1/3
A or B
A= $serialiser eq "CBOR"B= $serialiser eq "CBOR::XS"
ABresult
1X1
011
000
1501 {
1502 0 eval( "require CBOR::XS;" );
1503 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1504 {
1505 0 return( $self->error( "Unable to load serialiser CBOR::XS: $@" ) );
1506 }
1507 }
1508 else
1509 {
1510 358 eval( "require $serialiser;" );
1511 358 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 358 358
1512 {
1513 0 return( $self->error( "Unable to load serialiser $serialiser: $@" ) );
1514 }
1515 358 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 0 358 358
1516 {
1517 0 eval( "require Sereal::Encoder;" );
1518 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1519 {
1520 0 return( $self->error( "Unable to load serialiser Sereal::Encoder: $@" ) );
1521 }
1522 }
1523 }
1524  
1525 # try-catch
1526 358 local $@;
1527 358 ▶ if( ref( $serialiser ) eq 'CODE' )
Branch: 5 branches
BranchTrueFalseTotal
if (ref $serialiser eq 'CODE') { } 0 358 358
elsif ($serialiser eq 'CBOR' or $serialiser eq 'CBOR::XS') { } 0 358 358
elsif ($serialiser eq 'CBOR::Free') { } 0 358 358
elsif ($serialiser eq 'Sereal') { } 0 358 358
elsif ($serialiser eq 'Storable::Improved' or $serialiser eq 'Storable') { } 358 0 358
1528 {
1529 my $serialised = eval
1530 0 {
1531 0 return( $serialiser->( $data, 'freeze' ) );
1532 };
1533 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1534 {
1535 0 return( $self->error( "Error trying to serialise data with user-provided callback: $@" ) );
1536 }
1537 0 return( $serialised );
1538 }
1539 ▶ elsif( $serialiser eq 'CBOR' || $serialiser eq 'CBOR::XS' )
Condition33%1/3
$serialiser eq "CBOR" or $serialiser eq "CBOR::XS"
l!l&&r!l&&!r
00358
MC/DC0%0/2
$serialiser eq "CBOR" or $serialiser eq "CBOR::XS"
$serialiser eq "CBOR" $serialiser eq "CBOR::XS"
Truth table33%1/3
A or B
A= $serialiser eq "CBOR"B= $serialiser eq "CBOR::XS"
ABresult
1X1
011
000
1540 {
1541 0 my $cbor = CBOR::XS->new;
1542 0 $cbor->allow_sharing(1);
1543 my $serialised = eval
1544 0 {
1545 0 $cbor->encode( $data );
1546 };
1547 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1548 {
1549 0 return( $self->error( "Error trying to serialise data with $serialiser: $@" ) );
1550 }
1551 0 return( $serialised );
1552 }
1553 elsif( $serialiser eq 'CBOR::Free' )
1554 {
1555 my $serialised = eval
1556 0 {
1557 0 CBOR::Free::encode( $data );
1558 };
1559 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1560 {
1561 0 return( $self->error( "Error trying to serialise data with $serialiser: $@" ) );
1562 }
1563 0 return( $serialised );
1564 }
1565 elsif( $serialiser eq 'Sereal' )
1566 {
1567 0 my $enc = Sereal::Encoder->new;
1568 my $serialised = eval
1569 0 {
1570 0 $enc->encode( $data );
1571 };
1572 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1573 {
1574 0 return( $self->error( "Error trying to serialise data with $serialiser: $@" ) );
1575 }
1576 0 return( $serialised );
1577 }
1578 ▶ elsif( $serialiser eq 'Storable::Improved' || $serialiser eq 'Storable' )
Condition33%1/3
$serialiser eq "Storable::Improved" or $serialiser eq "Storable"
l!l&&r!l&&!r
35800
MC/DC0%0/2
$serialiser eq "Storable::Improved" or $serialiser eq "Storable"
$serialiser eq "Storable::Improved" $serialiser eq "Storable"
Truth table33%1/3
A or B
A= $serialiser eq "Storable::Improved"B= $serialiser eq "Storable"
ABresult
1X1
011
000
1579 {
1580 my $serialised = eval
1581 358 {
1582 358 my $code = $serialiser->can( 'freeze' );
1583 358 ▶ if( !defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 358 358
1584 {
1585 0 die( "Class $serialiser has no method 'freeze' to serialise data." );
1586 }
1587 358 return( $code->( $data ) );
1588 };
1589 358 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 358 358
1590 {
1591 0 return( $self->error( "Error trying to serialise data with $serialiser: $@" ) );
1592 }
1593 358 return( $serialised );
1594 }
1595 else
1596 {
1597 0 return( $self->error( "Unsupporterd serialiser \"$serialiser\"." ) );
1598 }
1599 }
1600  
1601 sub _share_repo
1602 25326 ▶{
Subroutine _share_repo: called CC=25 SCAR=55.1
1603 25326 my $self = shift( @_ );
1604 25326 ▶ my $ns = shift( @_ ) || die( "No namespace is set." );
Condition50%1/2
shift @_ || die('No namespace is set.')
l!l
253260
MC/DC0%0/1
shift @_ || die('No namespace is set.')
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1605 # NOTE: Initialisation strategy
1606 # Our top-level globals ($REPO, $ORDER, $SIZES, $NS_LOCKS, $REFCOUNTS) are promoted
1607 # to :shared at BEGIN time when _NEED_SHARED is true, and stay :shared for the whole
1608 # process lifetime. Adding sub-entries to a :shared hash requires that the value
1609 # itself be :shared, otherwise modern threads::shared rejects the assignment with
1610 # "Invalid value for shared scalar" (and older releases silently corrupt memory and
1611 # SEGV at exit).
1612 # Conversely, creating a fresh :shared variable during the END phase or during global
1613 # destruction aborts the interpreter on older threads::shared releases (the 1.4
1614 # shipped with perl 5.16 in particular). So when we are in the shared world and in a
1615 # terminal phase, we have no safe action: we return without populating, and callers in
1616 # END/DESTRUCT must handle a missing namespace gracefully (typically by checking the
1617 # result of get()).
1618 # In the non-shared world (_NEED_SHARED is false), our globals are plain refs and we
1619 # can populate them with plain refs at any time without phase constraints.
1620 25326 ▶ if( _NEED_SHARED() )
Branch: 1 branch
BranchTrueFalseTotal
if (&_NEED_SHARED()) { } 0 25326 25326
1621 {
1622 0 ▶ if( !CORE::exists( $REPO->{ $ns } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Module::Generic::Global::REPO->{$ns}) 0 0 0
1623 {
1624 # Shared world: refuse to do anything during terminal phases.
1625 0 ▶ if( _in_end_phase() || _in_global_destruction() )
Branch: 1 branch
BranchTrueFalseTotal
if (&_in_end_phase() or &_in_global_destruction()) 0 0 0
Condition0%0/3
&_in_end_phase() or &_in_global_destruction()
l!l&&r!l&&!r
000
MC/DC0%0/2
&_in_end_phase() or &_in_global_destruction()
&_in_end_phase() &_in_global_destruction()
Truth table0%0/3
A or B
A= &_in_end_phase()B= &_in_global_destruction()
ABresult
1X1
011
000
1626 {
1627 0 return;
1628 }
1629 0 my %sub_repo :shared;
1630 0 $REPO->{ $ns } = \%sub_repo;
1631 }
1632 0 ▶ if( !CORE::exists( $ORDER->{ $ns } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Module::Generic::Global::ORDER->{$ns}) 0 0 0
1633 {
1634 # Shared world: refuse to do anything during terminal phases.
1635 0 ▶ if( _in_end_phase() || _in_global_destruction() )
Branch: 1 branch
BranchTrueFalseTotal
if (&_in_end_phase() or &_in_global_destruction()) 0 0 0
Condition0%0/3
&_in_end_phase() or &_in_global_destruction()
l!l&&r!l&&!r
000
MC/DC0%0/2
&_in_end_phase() or &_in_global_destruction()
&_in_end_phase() &_in_global_destruction()
Truth table0%0/3
A or B
A= &_in_end_phase()B= &_in_global_destruction()
ABresult
1X1
011
000
1636 {
1637 0 return;
1638 }
1639 0 my @sub_order :shared;
1640 0 $ORDER->{ $ns } = \@sub_order;
1641 }
1642 0 ▶ if( !CORE::exists( $SIZES->{ $ns } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Module::Generic::Global::SIZES->{$ns}) 0 0 0
1643 {
1644 # Shared world: refuse to do anything during terminal phases.
1645 0 ▶ if( _in_end_phase() || _in_global_destruction() )
Branch: 1 branch
BranchTrueFalseTotal
if (&_in_end_phase() or &_in_global_destruction()) 0 0 0
Condition0%0/3
&_in_end_phase() or &_in_global_destruction()
l!l&&r!l&&!r
000
MC/DC0%0/2
&_in_end_phase() or &_in_global_destruction()
&_in_end_phase() &_in_global_destruction()
Truth table0%0/3
A or B
A= &_in_end_phase()B= &_in_global_destruction()
ABresult
1X1
011
000
1646 {
1647 0 return;
1648 }
1649 0 my $sub_size :shared = 0;
1650 0 $SIZES->{ $ns } = \$sub_size;
1651 }
1652 0 ▶ if( !CORE::exists( $NS_LOCKS->{ $ns } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Module::Generic::Global::NS_LOCKS->{$ns}) 0 0 0
1653 {
1654 # Shared world: refuse to do anything during terminal phases.
1655 0 ▶ if( _in_end_phase() || _in_global_destruction() )
Branch: 1 branch
BranchTrueFalseTotal
if (&_in_end_phase() or &_in_global_destruction()) 0 0 0
Condition0%0/3
&_in_end_phase() or &_in_global_destruction()
l!l&&r!l&&!r
000
MC/DC0%0/2
&_in_end_phase() or &_in_global_destruction()
&_in_end_phase() &_in_global_destruction()
Truth table0%0/3
A or B
A= &_in_end_phase()B= &_in_global_destruction()
ABresult
1X1
011
000
1656 {
1657 0 return;
1658 }
1659 0 my $ns_lock :shared = 0;
1660 0 $NS_LOCKS->{ $ns } = \$ns_lock;
1661 }
1662 0 ▶ if( $self->{refcount} && !CORE::exists( $REFCOUNTS->{ $ns } ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"refcount"} and not exists $Module::Generic::Global::REFCOUNTS->{$ns}) 0 0 0
Condition0%0/3
$self->{"refcount"} and not exists $Module::Generic::Global::REFCOUNTS->{$ns}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"refcount"} and not exists $Module::Generic::Global::REFCOUNTS->{$ns}
$self->{"refcount"} not exists $Module::Generic::Global::REFCOUNTS->{$ns}
Truth table0%0/3
A and not(B)
A= $self->{"refcount"}B= not exists $Module::Generic::Global::REFCOUNTS->{$ns}
ABresult
0X0
100
111
1663 {
1664 # Shared world: refuse to do anything during terminal phases.
1665 0 ▶ if( _in_end_phase() || _in_global_destruction() )
Branch: 1 branch
BranchTrueFalseTotal
if (&_in_end_phase() or &_in_global_destruction()) 0 0 0
Condition0%0/3
&_in_end_phase() or &_in_global_destruction()
l!l&&r!l&&!r
000
MC/DC0%0/2
&_in_end_phase() or &_in_global_destruction()
&_in_end_phase() &_in_global_destruction()
Truth table0%0/3
A or B
A= &_in_end_phase()B= &_in_global_destruction()
ABresult
1X1
011
000
1666 {
1667 0 return;
1668 }
1669 0 my %refcounts :shared;
1670 0 $REFCOUNTS->{ $ns } = \%refcounts;
1671 }
1672 }
1673 else
1674 {
1675 # Non-shared world: plain refs everywhere, no phase constraints.
1676 25326 ▶ if( !CORE::exists( $REPO->{ $ns } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Module::Generic::Global::REPO->{$ns}) 175 25151 25326
1677 {
1678 175 $REPO->{ $ns } = {};
1679 }
1680 25326 ▶ if( !CORE::exists( $ORDER->{ $ns } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Module::Generic::Global::ORDER->{$ns}) 175 25151 25326
1681 {
1682 175 $ORDER->{ $ns } = [];
1683 }
1684 25326 ▶ if( !CORE::exists( $SIZES->{ $ns } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Module::Generic::Global::SIZES->{$ns}) 175 25151 25326
1685 {
1686 175 my $sub_size = 0;
1687 175 $SIZES->{ $ns } = \$sub_size;
1688 }
1689 25326 ▶ if( !CORE::exists( $NS_LOCKS->{ $ns } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Module::Generic::Global::NS_LOCKS->{$ns}) 175 25151 25326
1690 {
1691 175 my $ns_lock = 0;
1692 175 $NS_LOCKS->{ $ns } = \$ns_lock;
1693 }
1694 25326 ▶ if( $self->{refcount} && !CORE::exists( $REFCOUNTS->{ $ns } ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"refcount"} and not exists $Module::Generic::Global::REFCOUNTS->{$ns}) 0 25326 25326
Condition66%2/3
$self->{"refcount"} and not exists $Module::Generic::Global::REFCOUNTS->{$ns}
!ll&&!rl&&r
5353199730
MC/DC0%0/2
$self->{"refcount"} and not exists $Module::Generic::Global::REFCOUNTS->{$ns}
$self->{"refcount"} not exists $Module::Generic::Global::REFCOUNTS->{$ns}
Truth table66%2/3
A and not(B)
A= $self->{"refcount"}B= not exists $Module::Generic::Global::REFCOUNTS->{$ns}
ABresult
0X0
100
111
1695 {
1696 0 $REFCOUNTS->{ $ns } = {};
1697 }
1698 }
1699 25326 return(1);
1700 }
1701  
1702 sub _unlock
1703 23050 ▶{
Subroutine _unlock: called CC=2 SCAR=7.2
1704 23050 ▶ $MUTEX->unlock if( USE_MUTEX );
Branch: 1 branch
BranchTrueFalseTotal
if &USE_MUTEX() 0 23050 23050
1705 23050 return(1);
1706 }
1707  
1708 # NOTE: END
1709 END
1710 33 ▶{
Subroutine END: called CC=4 SCAR=16.1
1711 # On threaded Perls, clearing shared hashes while other threads may still be running
1712 # or in their own destruction phase causes a SEGV in threads::shared. We therefore
1713 # skip the cleanup when threads are active, and let Perl's own global destruction
1714 # handle the memory.
1715 33 ▶ if( _NEED_SHARED() && $INC{'threads.pm'} )
Branch: 1 branch
BranchTrueFalseTotal
if (&_NEED_SHARED() and $INC{"threads.pm"}) 0 33 33
Condition33%1/3
&_NEED_SHARED() and $INC{"threads.pm"}
!ll&&!rl&&r
3300
MC/DC0%0/2
&_NEED_SHARED() and $INC{"threads.pm"}
&_NEED_SHARED() $INC{"threads.pm"}
Truth table33%1/3
A and B
A= &_NEED_SHARED()B= $INC{"threads.pm"}
ABresult
0X0
100
111
1716 {
1717 0 my @running = grep{ $_->is_running } threads->list;
1718 0 ▶ return if( @running );
Branch: 1 branch
BranchTrueFalseTotal
if @running 0 0 0
1719 }
1720 33 %$REPO = ();
1721 33 %$ERRORS = ();
1722 33 %$LOCKS = ();
1723 33 %$STATS = ();
1724 33 %$ORDER = ();
1725 33 %$SIZES = ();
1726 33 %$CLEANUP = ();
1727 33 %$NS_LOCKS = ();
1728 33 %$REFCOUNTS = ();
1729 };
1730  
1731 {
1732 # NOTE: Module::Generic::Global::Guard
1733 package
1734 Module::Generic::Global::Guard;
1735 33 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1736 33 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1737 33 local $@;
1738 0 ▶ *_in_global_destruction = sub{ ${^GLOBAL_PHASE} eq 'DESTRUCT' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
1739 33 ▶ die( $@ ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 33 33
1740 33 our $VERSION = 'v0.1.0';
1741  
1742 sub new
1743 0 ▶ {
Subroutine new: not called CC=2 SCAR=17.9
1744 0 my $this = shift( @_ );
1745 0 my $mutex = shift( @_ );
1746 0 ▶ return( bless( { mutex => $mutex } => ( ref( $this ) || $this ) ) );
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
1747 }
1748  
1749 sub DESTROY
1750 0 ▶ {
Subroutine DESTROY: not called CC=5 SCAR=34.0
1751 # <https://perldoc.perl.org/perlobj#Destructors>
1752 0 CORE::local( $., $@, $!, $^E, $? );
1753 0 ▶ CORE::return if( &_in_global_destruction() );
Branch: 1 branch
BranchTrueFalseTotal
if &_in_global_destruction() 0 0 0
1754 0 my $self = CORE::shift( @_ );
1755 0 ▶ CORE::return if( !CORE::defined( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 0 0
1756 0 ▶ return(1) unless( $self->{mutex} && ref( $self->{mutex} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"mutex"} and ref $self->{"mutex"} 0 0 0
Condition0%0/3
$self->{"mutex"} and ref $self->{"mutex"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"mutex"} and ref $self->{"mutex"}
$self->{"mutex"} ref $self->{"mutex"}
Truth table0%0/3
A and B
A= $self->{"mutex"}B= ref $self->{"mutex"}
ABresult
0X0
100
111
1757 0 $self->{mutex}->unlock;
1758 0 return(1);
1759 };
1760 }
1761  
1762 {
1763 # NOTE: Module::Generic::Global::Scalar
1764 33 package
1765 Module::Generic::Global::Scalar;
1766 BEGIN
1767 33 ▶ {
Subroutine BEGIN: called CC=1 SCAR=0.0
1768 33 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1769 33 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1770 33 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
1771 33 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
1772 191 ▶ '""' => sub{ ${$_[0]} },
Subroutine __ANON__: called CC=1 SCAR=0.0
1773 0 ▶ bool => sub{1},
Subroutine __ANON__: not called CC=1 SCAR=6.9
1774 33 fallback => 1,
1775 33 );
1776 33 our $VERSION = 'v0.1.0';
1777 };
1778 33 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1779 33 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1780  
1781 sub new
1782 192 ▶ {
Subroutine new: called CC=6 SCAR=24.1
1783 192 my $this = shift( @_ );
1784 192 ▶ if( @_ != 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 1) 0 192 192
1785 {
1786 0 die( 'Bad usage: Module::Generic::Global::Scalar->new( \"Hello world" );' );
1787 }
1788 192 my $str;
1789 192 ▶ if( ref( $_[0] ) eq 'SCALAR' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'SCALAR') { } 192 0 192
elsif (not ref $_[0]) { } 0 0 0
1790 {
1791 192 $str = ${$_[0]};
1792 }
1793 elsif( !ref( $_[0] ) )
1794 {
1795 0 $str = $_[0];
1796 }
1797 else
1798 {
1799 0 ▶ die( "Unsupported value provided: ", overload::StrVal( $_[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
1800 }
1801 192 ▶ return( bless( \$str => ( ref( $this ) || $this ) ) );
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
01920
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
1802 }
1803  
1804 2808 ▶ sub as_string { return( ${$_[0]} ); }
Subroutine as_string: called CC=1 SCAR=0.0
1805  
1806 sub FREEZE
1807 191 ▶ {
Subroutine FREEZE: called CC=5 SCAR=22.3
1808 191 my $self = CORE::shift( @_ );
1809 191 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition50%1/2
shift @_ // ""
l!l
1910
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1810 191 ▶ my $class = CORE::ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
19100
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1811 # Return an array reference rather than a list so this works with Sereal and CBOR
1812 # On or before Sereal version 4.023, Sereal did not support multiple values returned
1813 191 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 0 191 191
1814 {
1815 0 require Sereal::Encoder;
1816 0 require version;
1817  
1818 0 ▶ if( version->parse( Sereal::Encoder->VERSION ) <= version->parse( '4.023' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ("version"->parse("Sereal::Encoder"->VERSION) <= "version"->parse("4.023")) 0 0 0
1819 {
1820 0 CORE::return( [$class, $$self] );
1821 }
1822 }
1823 # But Storable want a list with the first element being the serialised element
1824 191 CORE::return( $$self );
1825 }
1826  
1827 191 ▶ sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
1828  
1829 2808 ▶ sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: called CC=1 SCAR=0.0
1830  
1831 sub THAW
1832 2808 ▶ {
Subroutine THAW: called CC=5 SCAR=18.7
1833 2808 my( $self, undef, @args ) = @_;
1834 2808 my( $class, $str );
1835 2808 ▶ if( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args == 1 and ref $args[0] eq 'ARRAY') { } 0 2808 2808
Condition33%1/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
028080
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
1836 {
1837 0 ( $class, $str ) = @{$args[0]};
1838 }
1839 else
1840 {
1841 2808 ▶ $class = CORE::ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
280800
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1842 2808 $str = CORE::shift( @args );
1843 }
1844 2808 my $new;
1845 # Storable pattern requires to modify the object it created rather than returning a new one
1846 2808 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 2808 0 2808
1847 {
1848 2808 $$self = $str;
1849 2808 $new = $self;
1850 }
1851 else
1852 {
1853 0 $new = CORE::return( $class->new( $str ) );
1854 }
1855 2808 CORE::return( $new );
1856 }
1857  
1858 0 ▶ sub TO_JSON { CORE::return( ${$_[0]} ); }
Subroutine TO_JSON: not called CC=1 SCAR=6.9
1859 }
1860  
1861 {
1862 # NOTE: Module::Generic::Global::Exception
1863 33 package
1864 Module::Generic::Global::Exception;
1865 BEGIN
1866 33 ▶ {
Subroutine BEGIN: called CC=1 SCAR=0.0
1867 33 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1868 33 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1869 33 ▶ use vars qw( $VERSION $CALLER_LEVEL $CALLER_INTERNAL );
Subroutine BEGIN: called CC=1 SCAR=0.0
1870 33 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
1871 33 ▶ use Devel::StackTrace;
Subroutine BEGIN: called CC=1 SCAR=0.0
1872 33 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
1873 '""' => 'as_string',
1874 2 ▶ bool => sub{1},
Subroutine __ANON__: called CC=1 SCAR=0.0
1875 33 fallback => 1,
1876 33 );
1877 33 $CALLER_LEVEL = 0;
1878 33 $CALLER_INTERNAL->{'Module::Generic::Global'}++;
1879 33 $CALLER_INTERNAL->{'Module::Generic::Global::Exception'}++;
1880 33 our $VERSION = 'v0.1.0';
1881 };
1882 33 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1883 33 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1884  
1885 sub new
1886 4 ▶ {
Subroutine new: called CC=24 SCAR=51.5
1887 4 my $this = shift( @_ );
1888 4 ▶ my $class = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
1889 4 my $self = bless( {} => $class );
1890 4 my $args = {};
1891 4 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 0 4
1892 {
1893 4 ▶ if( Scalar::Util::blessed( $_[0] ) && $_[0]->isa( 'Module::Generic::Exception' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($_[0]) and $_[0]->isa('Module::Generic::Exception')) { } 0 4 4
elsif (ref $_[0] eq 'HASH') { } 4 0 4
Condition33%1/3
builtin::blessed($_[0]) and $_[0]->isa("Module::Generic::Exception")
!ll&&!rl&&r
400
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa("Module::Generic::Exception")
builtin::blessed($_[0]) $_[0]->isa("Module::Generic::Exception")
Truth table33%1/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("Module::Generic::Exception")
ABresult
0X0
100
111
1894 {
1895 0 $args->{object} = shift( @_ );
1896 }
1897 elsif( ref( $_[0] ) eq 'HASH' )
1898 {
1899 4 $args = shift( @_ );
1900 }
1901 else
1902 {
1903 0 ▶ $args->{message} = join( '', map( ref( $_ ) eq 'CODE' ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
1904 }
1905 }
1906  
1907 4 ▶ unless( length( $args->{skip_frames} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length $args->{"skip_frames"}) 0 4 4
1908 {
1909 # NOTE: Taken from Carp to find the right point in the stack to start from
1910 33 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1911 0 my $caller_func;
1912 0 ▶ $caller_func = \&{"CORE::GLOBAL::caller"} if( defined( &{"CORE::GLOBAL::caller"} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"CORE::GLOBAL::caller";} 0 0 0
1913 0 ▶ my $call_pack = $caller_func ? $caller_func->() : caller();
Branch: 1 branch
BranchTrueFalseTotal
$caller_func ? : 0 0 0
1914 # Check if this is an internal package or a package inheriting from us
1915 0 ▶ local $CALLER_LEVEL = ( $CALLER_INTERNAL->{ $call_pack } || bless( {} => $call_pack )->isa( 'Module::Generic::Exception' ) )
Branch: 1 branch
BranchTrueFalseTotal
$Module::Generic::Global::Exception::CALLER_INTERNAL->{$call_pack} || bless({}, $call_pack)->isa('Module::Generic::Exception') ? : 0 0 0
Condition0%0/3
$Module::Generic::Global::Exception::CALLER_INTERNAL->{$call_pack} or bless({}, $call_pack)->isa("Module::Generic::Exception")
l!l&&r!l&&!r
000
MC/DC0%0/2
$Module::Generic::Global::Exception::CALLER_INTERNAL->{$call_pack} or bless({}, $call_pack)->isa("Module::Generic::Exception")
$Module::Generic::Global::Exception::CALLER_INTERNAL->{$call_pack} bless({}, $call_pack)->isa("Module::Generic::Exception")
Truth table0%0/3
A or B
A= $Module::Generic::Global::Exception::CALLER_INTERNAL->{$call_pack}B= bless({}, $call_pack)->isa("Module::Generic::Exception")
ABresult
1X1
011
000
1916 ? $CALLER_LEVEL
1917 : $CALLER_LEVEL + 1;
1918 my $error_start_frame = sub
1919 0 ▶ {
Subroutine __ANON__: not called CC=7 SCAR=40.3
1920 0 my $i;
1921 0 my $lvl = $CALLER_LEVEL;
1922 {
1923 0 ++$i;
1924 0 ▶ my @caller = $caller_func ? $caller_func->( $i ) : caller( $i );
Branch: 1 branch
BranchTrueFalseTotal
$caller_func ? : 0 0 0
1925 0 my $pkg = $caller[0];
1926 0 ▶ unless( defined( $pkg ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pkg) 0 0 0
1927 {
1928 0 ▶ if( defined( $caller[2] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $caller[2]) { } 0 0 0
1929 {
1930 # this can happen when the stash has been deleted
1931 # in that case, just assume that it's a reasonable place to
1932 # stop (the file and line data will still be intact in any
1933 # case) - the only issue is that we can't detect if the
1934 # deleted package was internal (so don't do that then)
1935 # -doy
1936 0 ▶ redo unless( 0 > --$lvl );
Branch: 1 branch
BranchTrueFalseTotal
unless 0 > --$lvl 0 0 0
1937 0 last;
1938 }
1939 else
1940 {
1941 0 return(2);
1942 }
1943 }
1944 0 ▶ redo if( $CALLER_INTERNAL->{ $pkg } );
Branch: 1 branch
BranchTrueFalseTotal
if $Module::Generic::Global::Exception::CALLER_INTERNAL->{$pkg} 0 0 0
1945 0 ▶ redo unless( 0 > --$lvl );
Branch: 1 branch
BranchTrueFalseTotal
unless 0 > --$lvl 0 0 0
1946 }
1947 0 return( $i - 1 );
1948 0 };
1949  
1950 0 $args->{skip_frames} = $error_start_frame->();
1951 }
1952  
1953 4 ▶ my $skip_frame = $args->{skip_frames} || 0;
Condition50%1/2
$args->{'skip_frames'} || 0
l!l
40
MC/DC0%0/1
$args->{'skip_frames'} || 0
$args->{'skip_frames'}
Truth table50%1/2
A
A= $args->{'skip_frames'}
Aresult
11
00
1954 # Skip one frame to exclude us
1955 4 $skip_frame++;
1956  
1957 4 my $trace = Devel::StackTrace->new( skip_frames => $skip_frame, indent => 1 );
1958 4 my $frame = $trace->next_frame;
1959 4 my $frame2 = $trace->next_frame;
1960 4 $trace->reset_pointer;
1961 4 ▶ if( ref( $args->{object} ) && Scalar::Util::blessed( $args->{object} ) && ( $args->{object}->isa( 'Module::Generic::Exception' ) || $args->{object}->isa( 'Module::Generic::Global::Exception' ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args->{'object'} and builtin::blessed($args->{'object'}) and $args->{'object'}->isa('Module::Generic::Exception') || $args->{'object'}->isa('Module::Generic::Global::Exception')) { } 0 4 4
Condition22%2/9
ref $args->{"object"} and builtin::blessed($args->{"object"}) and $args->{"object"}->isa("Module::Generic::Exception") || $args->{"object"}->isa("Module::Generic::Global::Exception")
!ll&&!rl&&r
400
ref $args->{"object"} and builtin::blessed($args->{"object"})
!ll&&!rl&&r
400
$args->{"object"}->isa("Module::Generic::Exception") or $args->{"object"}->isa("Module::Generic::Global::Exception")
l!l&&r!l&&!r
000
MC/DC0%0/4
ref $args->{"object"} and builtin::blessed($args->{"object"}) and $args->{"object"}->isa("Module::Generic::Exception") || $args->{"object"}->isa("Module::Generic::Global::Exception")
ref $args->{"object"} builtin::blessed($args->{"object"}) $args->{"object"}->isa("Module::Generic::Exception") $args->{"object"}->isa("Module::Generic::Global::Exception")
Truth table20%1/5
A and B and C or D
A= ref $args->{"object"}B= builtin::blessed($args->{"object"})C= $args->{"object"}->isa("Module::Generic::Exception")D= $args->{"object"}->isa("Module::Generic::Global::Exception")
ABCDresult
0XXX0
10XX0
11000
111X1
11011
1962 {
1963 0 my $o = $args->{object};
1964 0 $self->{message} = $o->message;
1965 0 $self->{code} = $o->code;
1966 0 $self->{type} = $o->type;
1967 0 $self->{retry_after} = $o->retry_after;
1968 }
1969 else
1970 {
1971 # print( STDERR __PACKAGE__, "::init() Got here with args: ", Module::Generic->dump( $args ), "\n" );
1972 4 ▶ $self->{message} = $args->{message} || '';
Condition50%1/2
$args->{'message'} || ''
l!l
40
MC/DC0%0/1
$args->{'message'} || ''
$args->{'message'}
Truth table50%1/2
A
A= $args->{'message'}
Aresult
11
00
1973 4 ▶ $self->{code} = $args->{code} if( exists( $args->{code} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"code"} 4 0 4
1974 4 ▶ $self->{type} = $args->{type} if( exists( $args->{type} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"type"} 0 4 4
1975 4 ▶ $self->{retry_after} = $args->{retry_after} if( exists( $args->{retry_after} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"retry_after"} 0 4 4
1976 # I do not want to alter the original hash reference, which may adversely affect the calling code if they depend on its content for further execution for example.
1977 4 my $copy = {};
1978 4 %$copy = %$args;
1979 4 CORE::delete( @$copy{ qw( message code type retry_after skip_frames file line subroutine ) } );
1980 # print( STDERR __PACKAGE__, "::init() Following non-standard keys to set up: '", join( "', '", sort( keys( %$copy ) ) ), "'\n" );
1981 # Do we have some non-standard parameters?
1982 4 foreach my $p ( keys( %$copy ) )
1983 {
1984 0 my $p2 = $p;
1985 0 $p2 =~ tr/-/_/;
1986 0 $p2 =~ s/[^a-zA-Z0-9\_]+//g;
1987 0 $p2 =~ s/^\d+//g;
1988 # We do not want to trigger an error by calling non-existing subroutines
1989 0 ▶ if( my $subref = $self->can( $p2 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $subref = $self->can($p2)) 0 0 0
1990 {
1991 0 $self->{ $p2 } = $copy->{ $p };
1992 }
1993 }
1994 }
1995 4 $self->{file} = $frame->filename;
1996 4 $self->{line} = $frame->line;
1997 ## The caller sub routine ( caller( n ) )[3] returns the sub called by our caller instead of the sub that called our caller, so we go one frame back to get it
1998 4 ▶ $self->{subroutine} = $frame2->subroutine if( $frame2 );
Branch: 1 branch
BranchTrueFalseTotal
if $frame2 4 0 4
1999 4 $self->{package} = $frame->package;
2000 4 $self->{trace} = $trace;
2001 4 return( $self );
2002 }
2003  
2004 # This is important as stringification is called by die, so as per the manual page, we need to end with new line
2005 # And will add the stack trace
2006 sub as_string
2007 0 ▶ {
Subroutine as_string: not called CC=6 SCAR=31.8
2008 33 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
2009 0 my $self = shift( @_ );
2010 0 ▶ return( $self->{_cache} ) if( $self->{_cache} && !CORE::length( $self->{_reset} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_cache"} and not length $self->{"_reset"} 0 0 0
Condition0%0/3
$self->{"_cache"} and not length $self->{"_reset"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_cache"} and not length $self->{"_reset"}
$self->{"_cache"} not length $self->{"_reset"}
Truth table0%0/3
A and not(B)
A= $self->{"_cache"}B= not length $self->{"_reset"}
ABresult
0X0
100
111
2011 0 my $str = $self->message;
2012 0 ▶ if( defined( $str ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str and builtin::blessed($str) and overload::Method($str, "\"\"")) 0 0 0
Condition0%0/6
defined $str and builtin::blessed($str) and overload::Method($str, "\"\"")
!ll&&!rl&&r
000
defined $str and builtin::blessed($str)
!ll&&!rl&&r
000
MC/DC0%0/3
defined $str and builtin::blessed($str) and overload::Method($str, "\"\"")
defined $str builtin::blessed($str) overload::Method($str, "\"\"")
Truth table0%0/4
A and B and C
A= defined $strB= builtin::blessed($str)C= overload::Method($str, "\"\"")
ABCresult
0XX0
10X0
1100
1111
2013 Scalar::Util::blessed( $str ) &&
2014 overload::Method( $str => '""' ) )
2015 {
2016 33 ▶ use overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
2017 0 $str = "$str";
2018 }
2019 0 $str =~ s/\r?\n$//g;
2020 0 $str .= sprintf( " within package %s at line %d in file %s\n%s", $self->package, $self->line, $self->file, $self->trace->as_string );
2021 0 $self->{_cache} = $str;
2022 0 CORE::delete( $self->{_reset} );
2023 0 return( $str );
2024 }
2025  
2026 sub caught
2027 0 ▶ {
Subroutine caught: not called CC=4 SCAR=30.0
2028 0 my( $class, $e ) = @_;
2029 0 ▶ return if( ref( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
2030 0 ▶ return unless( Scalar::Util::blessed( $e ) && $e->isa( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($e) and $e->isa($class) 0 0 0
Condition0%0/3
builtin::blessed($e) and $e->isa($class)
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($e) and $e->isa($class)
builtin::blessed($e) $e->isa($class)
Truth table0%0/3
A and B
A= builtin::blessed($e)B= $e->isa($class)
ABresult
0X0
100
111
2031 0 return( $e );
2032 }
2033  
2034 0 ▶ sub cause { return( shift->{cause} ); }
Subroutine cause: not called CC=1 SCAR=6.9
2035  
2036 1 ▶ sub code { return( shift->{code} ); }
Subroutine code: called CC=1 SCAR=0.0
2037  
2038 0 ▶ sub file { return( shift->{file} ); }
Subroutine file: not called CC=1 SCAR=6.9
2039  
2040 0 ▶ sub lang { return( shift->{lang} ); }
Subroutine lang: not called CC=1 SCAR=6.9
2041  
2042 0 ▶ sub line { return( shift->{line} ); }
Subroutine line: not called CC=1 SCAR=6.9
2043  
2044 0 ▶ sub locale { return( shift->{locale} ); }
Subroutine locale: not called CC=1 SCAR=6.9
2045  
2046 4 ▶ sub message { return( shift->{message} ); }
Subroutine message: called CC=1 SCAR=0.0
2047  
2048 0 ▶ sub package { return( shift->{package} ); }
Subroutine package: not called CC=1 SCAR=6.9
2049  
2050 # From perlfunc docmentation on "die":
2051 # "If LIST was empty or made an empty string, and $@ contains an object reference that
2052 # has a "PROPAGATE" method, that method will be called with additional file and line
2053 # number parameters. The return value replaces the value in $@; i.e., as
2054 # if "$@ = eval { $@->PROPAGATE(__FILE__, __LINE__) };" were called."
2055 sub PROPAGATE
2056 0 ▶ {
Subroutine PROPAGATE: not called CC=3 SCAR=24.8
2057 0 my( $self, $file, $line ) = @_;
2058 0 ▶ if( defined( $file ) && defined( $line ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file and defined $line) 0 0 0
Condition0%0/3
defined $file and defined $line
!ll&&!rl&&r
000
MC/DC0%0/2
defined $file and defined $line
defined $file defined $line
Truth table0%0/3
A and B
A= defined $fileB= defined $line
ABresult
0X0
100
111
2059 {
2060 0 my $clone = $self->clone;
2061 0 $clone->file( $file );
2062 0 $clone->line( $line );
2063 0 return( $clone );
2064 }
2065 0 return( $self );
2066 }
2067  
2068 sub rethrow
2069 0 ▶ {
Subroutine rethrow: not called CC=2 SCAR=17.9
2070 0 my $self = shift( @_ );
2071 0 ▶ return if( !Scalar::Util::blessed( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self) 0 0 0
2072 0 die( $self );
2073 }
2074  
2075 0 ▶ sub retry_after { return( shift->{retry_after} ); }
Subroutine retry_after: not called CC=1 SCAR=6.9
2076  
2077 0 ▶ sub subroutine { return( shift->{subroutine} ); }
Subroutine subroutine: not called CC=1 SCAR=6.9
2078  
2079 sub trace
2080 0 ▶ {
Subroutine trace: not called CC=2 SCAR=17.9
2081 0 my $self = shift( @_ );
2082 0 ▶ $self->{trace} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
2083 0 return( $self->{trace} );
2084 }
2085  
2086 sub throw
2087 0 ▶ {
Subroutine throw: not called CC=2 SCAR=17.9
2088 0 my $self = shift( @_ );
2089 0 my $e;
2090 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
2091 {
2092 0 my $msg = shift( @_ );
2093 0 $e = $self->new({
2094 skip_frames => 1,
2095 message => $msg,
2096 });
2097 }
2098 else
2099 {
2100 0 $e = $self;
2101 }
2102 0 die( $e );
2103 }
2104  
2105 0 ▶ sub type { return( shift->{type} ); }
Subroutine type: not called CC=1 SCAR=6.9
2106 }
2107  
2108 33 1;
2109 # NOTE: POD
2110 __END__
« lib/Module/Generic/Number/Format.pm ↑ Summary lib/Module/Generic/SharedMemXS.pm »