blib/lib/Promise/Me.pm

filter: Statementstmt 52.5% 672 / 1280 Branchbran 29.9% 238 / 796 Conditioncond 23.7% 133 / 561 MC/DCmcdc 2.9% 9 / 305 Subroutinesub 66.9% 95 / 142 Podpod 92.4% 49 / 53 totaltotal 38.1% 1196 / 3137 CC 623 SCAR 51.4
CC
623
Cov
40%
_parse
1410.2
_share_vars
463.3
_set_shared_space
269.3
CRAP 170.8
↑ Summary
1 ##----------------------------------------------------------------------------
2 ## Promise - ~/lib/Promise/Me.pm
3 ## Version v0.6.1
4 ## Copyright(c) 2025 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/05/28
7 ## Modified 2026/09/25
8 ## All rights reserved
9 ## This program is free software; you can redistribute it and/or modify it
10 ## under the same terms as Perl itself.
11 ##----------------------------------------------------------------------------
12 package Promise::Me;
13 BEGIN
14 26 ▶{
Subroutine BEGIN: called CC=3 SCAR=11.0
15 26 ▶ use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 26 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 26 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 26 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 26 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 26 ▶ use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 $KIDS $DEBUG $FILTER_RE_FUNC_ARGS $FILTER_RE_SHARED_ATTRIBUTE
22 $RESULT_MEMORY_SIZE $SHARED_MEMORY_SIZE $SHARED $VERSION $SHARE_MEDIUM
23 $SHARE_FALLBACK $SHARE_AUTO_DESTROY $OBJECTS_REPO $EXCEPTION_CLASS $SERIALISER
24 $USE_THREADS_SHARED
25 26 );
26 26 ▶ use curry;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 26 ▶ use Clone;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 26 ▶ use Errno;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 26 ▶ use Filter::Util::Call ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30 26 ▶ use Module::Generic::File::Cache v0.2.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 26 ▶ use Module::Generic::File::Mmap v0.1.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 26 ▶ use Module::Generic::SharedMemXS v0.1.0 qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
33 26 ▶ use POSIX qw( WNOHANG WIFEXITED WEXITSTATUS WIFSIGNALED );
Subroutine BEGIN: called CC=1 SCAR=0.0
34 26 ▶ use PPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 26 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 26 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 26 our $KIDS = {};
38 26 our @EXPORT = qw( async await share unshare lock unlock );
39 26 our @EXPORT_OK = qw( share unshare lock unlock );
40 26 our %EXPORT_TAGS = (
41 all => [qw( share unshare lock unlock )],
42 lock => [qw( lock unlock )],
43 share => [qw( share unshare )],
44 );
45 26 Exporter::export_ok_tags( 'all', 'lock', 'share' );
46 26 our $DEBUG = 0;
47 # share( $this ):
48 # share( \$this );
49 # share ( ( \$this ), (( @that ) ), %plop );
50 # share
51 # ( ( \$this ), (( @that ) ), %plop );
52 26 our $FILTER_RE_FUNC_ARGS = qr{
53 (?<func>
54 \b(?:share|unshare|lock|unlock)\b
55 [[:blank:]\h\v]*
56 (?!\{)
57 )
58 (?<args>
59 (?:
60 (?:
61 [[:blank:]\h\v]
62 |
63 \(
64 )*
65 \\?[\$\@\%\*]\w+
66 (?:[[:blank:]\h\v]|\)|,)*
67 )+
68 )
69 }x;
70 # my $val : shared;
71 # our $val : shared = 'John';
72 # our( $plop, @truc ) : shared = ( '2', qw( Pierre Paul ) );
73 26 our $FILTER_RE_SHARED_ATTRIBUTE;
74 26 our $SHARED_MEMORY_SIZE = ( 64 * 1024 );
75 26 our $RESULT_MEMORY_SIZE = ( 512 * 1024 );
76 26 ▶ use constant SHARED_MEMORY_BLOCK => ( 64 * 1024 );
Subroutine BEGIN: called CC=1 SCAR=0.0
77 26 our $SHARED = {};
78 26 ▶ our $SHARE_MEDIUM = Module::Generic::SharedMemXS->supported
Branch: 2 branches
BranchTrueFalseTotal
'Module::Generic::SharedMemXS'->supported ? : 26 0 26
'Module::Generic::File::Mmap'->has_xs ? : 0 0 0
79 ? 'memory'
80 : Module::Generic::File::Mmap->has_xs
81 ? 'mmap'
82 : 'file';
83 # If shared memory block is not supported, should we fall back to cache file?
84 26 our $SHARE_FALLBACK = 1;
85 26 our $SHARE_AUTO_DESTROY = 1;
86 # By default, Promise::Me implementation of shared variable using the 'shared' attribute takes precedence over threads
87 26 our $USE_THREADS_SHARED = 0;
88 # A repository of objects that is used by END and DESTROY to remove the shared
89 # space only when no proces is using it, since the processes run asynchronously
90 26 our $OBJECTS_REPO = [];
91 26 our $EXCEPTION_CLASS = 'Module::Generic::Exception';
92 26 our $SERIALISER = 'storable';
93 26 our $VERSION = 'v0.6.1';
94 };
95  
96 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 26 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
98  
99 sub import
100 51 ▶{
Subroutine import: called CC=12 SCAR=31.1
101 51 my $class = shift( @_ );
102 51 my $hash = {};
103 51 ▶ for( my $i = 0; $i < scalar( @_ ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 50 51 101
104 {
105 50 ▶ if( $_[$i] eq 'debug' ||
Branch: 2 branches
BranchTrueFalseTotal
if ($_[$i] eq 'debug' or $_[$i] eq 'debug_code' or $_[$i] eq 'debug_file' or $_[$i] eq 'no_filter') { } 0 50 50
elsif ($_[$i] eq 'no_shared') { } 0 50 50
Condition33%3/9
$_[$i] eq "debug" or $_[$i] eq "debug_code" or $_[$i] eq "debug_file" or $_[$i] eq "no_filter"
l!l&&r!l&&!r
0050
$_[$i] eq "debug" or $_[$i] eq "debug_code" or $_[$i] eq "debug_file"
l!l&&r!l&&!r
0050
$_[$i] eq "debug" or $_[$i] eq "debug_code"
l!l&&r!l&&!r
0050
MC/DC0%0/4
$_[$i] eq "debug" or $_[$i] eq "debug_code" or $_[$i] eq "debug_file" or $_[$i] eq "no_filter"
$_[$i] eq "debug" $_[$i] eq "debug_code" $_[$i] eq "debug_file" $_[$i] eq "no_filter"
Truth table20%1/5
A or B or C or D
A= $_[$i] eq "debug"B= $_[$i] eq "debug_code"C= $_[$i] eq "debug_file"D= $_[$i] eq "no_filter"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
106 $_[$i] eq 'debug_code' ||
107 $_[$i] eq 'debug_file' ||
108 $_[$i] eq 'no_filter' )
109 {
110 0 $hash->{ $_[$i] } = $_[$i+1];
111 0 CORE::splice( @_, $i, 2 );
112 0 $i--;
113 }
114 # User does not want us to use Promise::Me shared variable using 'shared', but 'pshared' would still work though.
115 elsif( $_[$i] eq 'no_shared' )
116 {
117 0 $USE_THREADS_SHARED = 1;
118 }
119 }
120 51 ▶ $hash->{debug} = 0 if( !CORE::exists( $hash->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{"debug"} 51 0 51
121 51 ▶ $hash->{no_filter} = 0 if( !CORE::exists( $hash->{no_filter} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{"no_filter"} 51 0 51
122 51 ▶ $hash->{debug_code} = 0 if( !CORE::exists( $hash->{debug_code} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{"debug_code"} 51 0 51
123 51 ▶ Filter::Util::Call::filter_add( bless( $hash => ( ref( $class ) || $class ) ) );
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0510
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
124 51 my $caller = caller;
125 26 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
126 51 for( qw( ARRAY HASH SCALAR ) )
127 {
128 153 *{"${caller}\::MODIFY_${_}_ATTRIBUTES"} = sub
129 12 ▶ {
Subroutine __ANON__: called CC=7 SCAR=25.1
130 12 my( $pack, $ref, $attr ) = @_;
131 {
132 12 ▶ if( ( $attr // '' ) eq 'Promise_shared' )
Branch: 1 branch
BranchTrueFalseTotal
if (($attr // "") eq "Promise_shared") 12 0 12
Condition50%1/2
$attr // ""
l!l
120
MC/DC0%0/1
$attr // ""
$attr
Truth table50%1/2
A
A= $attr
Aresult
11
00
133 {
134 12 ▶ my $type = lc( ref( $ref // '' ) );
Condition50%1/2
$ref // ""
l!l
120
MC/DC0%0/1
$ref // ""
$ref
Truth table50%1/2
A
A= $ref
Aresult
11
00
135 12 ▶ if( $type !~ /^(array|hash|scalar)$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($type =~ /^(array|hash|scalar)$/) 0 12 12
136 {
137 0 ▶ warn( "Unsupported variable type '$type': '$ref'\n" ) if( warnings::enabled() || $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() or $Promise::Me::DEBUG 0 0 0
Condition0%0/3
warnings::enabled() or $Promise::Me::DEBUG
l!l&&r!l&&!r
000
MC/DC0%0/2
warnings::enabled() or $Promise::Me::DEBUG
warnings::enabled() $Promise::Me::DEBUG
Truth table0%0/3
A or B
A= warnings::enabled()B= $Promise::Me::DEBUG
ABresult
1X1
011
000
138 0 return;
139 }
140 12 &{"${class}\::share"}( $ref );
141 }
142 }
143 12 return;
144 153 };
145 }
146 51 $class->export_to_level( 1, @_ );
147 }
148  
149 sub filter
150 51 ▶{
Subroutine filter: called CC=22 SCAR=40.2
Pod documented
151 51 my( $self ) = @_ ;
152 51 my( $status, $last_line );
153 51 my $line = 0;
154 51 my $code = '';
155 51 ▶ if( $self->{no_filter} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"no_filter"}) 0 51 51
156 {
157 0 Filter::Util::Call::filter_del();
158 0 $status = 1;
159 0 return( $status );
160 }
161  
162 # If the user has opted to use threads 'shared' and threads indeed has been loaded (otherwise, this would not work at all).
163 51 ▶ if( $USE_THREADS_SHARED && ( CORE::exists( $INC{'threads.pm'} ) && $INC{'threads.pm'} && CORE::exists( $INC{'threads/shared.pm'} ) && $INC{'threads/shared.pm'} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($Promise::Me::USE_THREADS_SHARED and (exists $INC{'threads.pm'} and $INC{'threads.pm'} and exists $INC{'threads/shared.pm'} and $INC{'threads/shared.pm'})) { } 0 51 51
Condition8%1/12
$Promise::Me::USE_THREADS_SHARED and (exists $INC{"threads.pm"} and $INC{"threads.pm"} and exists $INC{"threads/shared.pm"} and $INC{"threads/shared.pm"})
!ll&&!rl&&r
5100
exists $INC{"threads.pm"} and $INC{"threads.pm"} and exists $INC{"threads/shared.pm"} and $INC{"threads/shared.pm"}
!ll&&!rl&&r
000
exists $INC{"threads.pm"} and $INC{"threads.pm"} and exists $INC{"threads/shared.pm"}
!ll&&!rl&&r
000
exists $INC{"threads.pm"} and $INC{"threads.pm"}
!ll&&!rl&&r
000
MC/DC0%0/5
$Promise::Me::USE_THREADS_SHARED and (exists $INC{"threads.pm"} and $INC{"threads.pm"} and exists $INC{"threads/shared.pm"} and $INC{"threads/shared.pm"})
$Promise::Me::USE_THREADS_SHARED exists $INC{"threads.pm"} $INC{"threads.pm"} exists $INC{"threads/shared.pm"} $INC{"threads/shared.pm"}
Truth table16%1/6
A and B and C and D and E
A= $Promise::Me::USE_THREADS_SHAREDB= exists $INC{"threads.pm"}C= $INC{"threads.pm"}D= exists $INC{"threads/shared.pm"}E= $INC{"threads/shared.pm"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
164 {
165 0 $FILTER_RE_SHARED_ATTRIBUTE = qr{
166 (
167 (?:my|our)
168 (
169 (?:
170 [[:blank:]\h\v]
171 |
172 \(
173 )*
174 \\?[\$\@\%\*]\w+
175 (?:[[:blank:]\h\v]|\)|,)*
176 )+
177 \:[[:blank:]\h\v]*
178 )
179 \b(?:pshared)\b
180 }x;
181 }
182 else
183 {
184 51 $FILTER_RE_SHARED_ATTRIBUTE = qr{
185 (
186 (?:my|our)
187 (
188 (?:
189 [[:blank:]\h\v]
190 |
191 \(
192 )*
193 \\?[\$\@\%\*]\w+
194 (?:[[:blank:]\h\v]|\)|,)*
195 )+
196 \:[[:blank:]\h\v]*
197 )
198 \b(?:pshared|shared)\b
199 }x;
200 }
201  
202 51 ▶ while( $status = Filter::Util::Call::filter_read() )
Branch: 1 branch
BranchTrueFalseTotal
if ($status = &Filter::Util::Call::filter_read()) 5493 0 5493
203 {
204 5493 ▶ return( $status ) if( $status < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $status < 0 0 5493 5493
205 5493 $line++;
206 5493 ▶ if( /^__(?:DATA|END)__/ )
Branch: 1 branch
BranchTrueFalseTotal
if (/^__(?:DATA|END)__/) 51 5442 5493
207 {
208 51 $last_line = $_;
209 51 last;
210 }
211  
212 s{
213 $FILTER_RE_FUNC_ARGS
214 }
215 {
216 25 my $func = $+{func};
217 25 my $args = $+{args};
218 # print( STDERR "Func is '$+{func}' and args are: '$+{args}'\n" );
219 25 $args =~ s,(?<!\\)([\$\@\%\*]\w+),\\$1,g;
220 25 "$func$args";
221 5442 }gexs;
222  
223 5442 s{
224 $FILTER_RE_SHARED_ATTRIBUTE
225 }
226 {
227 25 "${1}Promise_shared"
228 }gsex;
229  
230 5442 s#(\b(?:share|lock|unlock|unshare)\b[[:blank:]\h]*(?!{)\(?[[:blank:]\h]*)(?=[mo\$\@\%])#$1\\#gs;
231 5442 $code .= $_;
232 5442 $_ = '';
233 }
234 51 ▶ return( $line ) if( !$line );
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 51 51
235 51 ▶ unless( $status < 0 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($status < 0) 51 0 51
236 {
237 51 $code = ' ' . $code;
238 51 my $doc;
239 # No need to parse this if the keyword 'async' is not even used anywhere.
240 51 ▶ if( CORE::index( $code, 'async' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($code, "async") != -1) 0 51 51
241 {
242 0 ▶ $doc = PPI::Document->new( \$code, readonly => 1 ) || die( "Unable to parse: ", PPI::Document->errstr, "\n$code\n" );
Condition0%0/2
'PPI::Document'->new(\$code, 'readonly', 1) || die('Unable to parse: ', 'PPI::Document'->errstr, "\n$code\n")
l!l
00
MC/DC0%0/1
'PPI::Document'->new(\$code, 'readonly', 1) || die('Unable to parse: ', 'PPI::Document'->errstr, "\n$code\n")
'PPI::Document'->new(\$code, 'readonly', 1)
Truth table0%0/2
A
A= 'PPI::Document'->new(\$code, 'readonly', 1)
Aresult
11
00
243 }
244 51 ▶ if( defined( $doc ) && ( $doc = $self->_parse( $doc ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $doc and $doc = $self->_parse($doc)) { } 0 51 51
Condition33%1/3
defined $doc and $doc = $self->_parse($doc)
!ll&&!rl&&r
5100
MC/DC0%0/2
defined $doc and $doc = $self->_parse($doc)
defined $doc $doc = $self->_parse($doc)
Truth table33%1/3
A and B
A= defined $docB= $doc = $self->_parse($doc)
ABresult
0X0
100
111
245 {
246 0 $_ = $doc->serialize;
247 }
248 # Rollback
249 else
250 {
251 51 $_ = $code;
252 }
253 51 ▶ if( CORE::length( $last_line ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $last_line) 51 0 51
254 {
255 51 $_ .= $last_line;
256 }
257 }
258 51 ▶ unless( $status <= 0 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($status <= 0) 51 0 51
259 {
260 51 ▶ while( $status = Filter::Util::Call::filter_read() )
Branch: 1 branch
BranchTrueFalseTotal
if ($status = &Filter::Util::Call::filter_read()) 51 51 102
261 {
262 51 ▶ return( $status ) if( $status < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $status < 0 0 51 51
263 51 $line++;
264 }
265 }
266 51 ▶ if( $self->{debug_file} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug_file"}) 0 51 51
267 {
268 0 ▶ if( open( my $fh, ">$self->{debug_file}" ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, qq[>$self->{"debug_file"}]) 0 0 0
269 {
270 0 binmode( $fh, ':utf8' );
271 0 print( $fh $_ );
272 0 close( $fh );
273 }
274 }
275 51 return( $line );
276 }
277  
278 sub init
279 56 ▶{
Subroutine init: called CC=11 SCAR=25.6
Pod documented
280 56 my $self = shift( @_ );
281 56 my $name;
282 56 ▶ if( @_ >= 2 && !ref( $_[0] ) && ref( $_[1] ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ >= 2 and not ref $_[0] and ref $_[1] eq "CODE") 0 56 56
Condition33%2/6
@_ >= 2 and not ref $_[0] and ref $_[1] eq "CODE"
!ll&&!rl&&r
5600
@_ >= 2 and not ref $_[0]
!ll&&!rl&&r
0560
MC/DC0%0/3
@_ >= 2 and not ref $_[0] and ref $_[1] eq "CODE"
@_ >= 2 not ref $_[0] ref $_[1] eq "CODE"
Truth table25%1/4
A and not(B) and C
A= @_ >= 2B= not ref $_[0]C= ref $_[1] eq "CODE"
ABCresult
0XX0
10X0
1100
1111
283 {
284 0 $name = shift( @_ );
285 }
286 56 my $code = shift( @_ );
287 56 ▶ return( $self->error( "No code was provided to execute." ) ) if( !defined( $code ) || ref( $code ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $code or ref $code ne "CODE" 0 56 56
Condition33%1/3
not defined $code or ref $code ne "CODE"
l!l&&r!l&&!r
0056
MC/DC0%0/2
not defined $code or ref $code ne "CODE"
not defined $code ref $code ne "CODE"
Truth table33%1/3
not(A) or B
A= not defined $codeB= ref $code ne "CODE"
ABresult
1X1
011
000
288 56 $self->{args} = [];
289 56 $self->{exception_class} = $EXCEPTION_CLASS;
290 56 $self->{medium} = $SHARE_MEDIUM;
291 56 $self->{name} = $name;
292 56 $self->{result_shared_mem_size} = $RESULT_MEMORY_SIZE;
293 56 $self->{serialiser} = $SERIALISER;
294 56 $self->{shared_vars_mem_size} = $SHARED_MEMORY_SIZE;
295 56 $self->{tmpdir} = undef;
296 56 $self->{use_async} = 0;
297 # By default, should we use file cache to store shared data or memory?
298 56 ▶ $self->{use_cache_file} = ( $SHARE_MEDIUM eq 'file' ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$Promise::Me::SHARE_MEDIUM eq 'file' ? : 28 28 56
299 56 ▶ $self->{use_mmap} = ( $SHARE_MEDIUM eq 'mmap' ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$Promise::Me::SHARE_MEDIUM eq 'mmap' ? : 0 56 56
300 56 $self->{_init_strict_use_sub} = 1;
301 56 $self->SUPER::init( @_ );
302 # async sub my_subroutine { }
303 56 ▶ if( $self->{use_async} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'use_async'}) { } 0 56 56
304 {
305 # If it fails, it will trigger reject()
306 $self->{_code} = sub
307 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
308 0 ▶ $self->resolve( scalar( @{$self->{args}} ) ? $code->( @{$self->{args}} ) : $code->() );
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$self->{'args'};} ? : 0 0 0
309 0 };
310 }
311 # Promise::Me->new(sub{ my( $resolve, $reject ) = @_; });
312 else
313 {
314 # $self->{_code} = sub
315 # {
316 # $code->(
317 # sub{ $self->resolve( @_ ) },
318 # sub{ $self->reject( @_ ) },
319 # );
320 # };
321 56 $self->{_code} = $code;
322 }
323 56 ▶ if( $self->use_cache_file )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->use_cache_file) { } 36 20 56
elsif ($self->use_mmap) { } 0 20 20
324 {
325 36 $self->{medium} = 'file';
326 }
327 elsif( $self->use_mmap )
328 {
329 0 $self->{medium} = 'mmap';
330 }
331 56 $self->{_handlers} = [];
332 56 $self->{_no_more_chaining} = 0;
333 56 $self->{executed} = 0;
334 56 $self->{exit_bit} = '';
335 56 $self->{exit_signal} = '';
336 56 $self->{exit_status} = '';
337 56 $self->{has_coredump} = 0;
338 56 $self->{id} = Scalar::Util::refaddr( $self );
339 56 $self->{is_child} = 0;
340 56 $self->{pid} = $$;
341 56 $self->{share_auto_destroy} = 1;
342 # promise status; data space shared between child and parent through shared memory
343 56 $self->{shared} = {};
344 56 $self->{shared_key} = 'pm' . $$;
345 56 $self->{shared_space_destroy} = 1;
346 56 $self->{global} = {};
347 56 $self->{global_key} = 'gl' . $$;
348 # This will be set to true if the chain ends with a call to wait()
349 # Promise::Me->new(sub{})->then->catch->wait;
350 56 $self->{wait} = 0;
351 # Check if there are any variables to share
352 # Because this is stored in a global variable, we use the caller's package name as namespace
353 56 my $pack = caller(1);
354 # Resulting values from exec, or then when there are no more handler but there could be later
355 56 $self->{_saved_values} = [];
356 56 $self->{_shared_from} = $pack;
357 56 push( @$OBJECTS_REPO, $self );
358  
359 # unless( Wanted::want( 'OBJECT' ) )
360 # {
361 # $self->no_more_chaining(1);
362 # $self->exec;
363 # }
364 56 return( $self );
365 }
366  
367 sub add_final_handler
368 0 ▶{
Subroutine add_final_handler: not called CC=3 SCAR=24.8
Pod documented
369 0 my $self = shift( @_ );
370 0 ▶ my $code = shift( @_ ) || return( $self->error( "No code reference was provided to add a final handler." ) );
Condition0%0/2
shift @_ || (return $self->error('No code reference was provided to add a final handler.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No code reference was provided to add a final handler.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
371 0 ▶ return( $self->error( "Final handler provided is not a code reference." ) ) if( ref( $code ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $code ne "CODE" 0 0 0
372 0 push( @{$self->{_handlers}}, { type => 'finally', handler => $code });
373 0 return( $self );
374 }
375  
376 sub add_resolve_handler
377 64 ▶{
Subroutine add_resolve_handler: called CC=3 SCAR=11.2
Pod documented
378 64 my $self = shift( @_ );
379 64 ▶ my $code = shift( @_ ) || return( $self->error( "No code reference was provided to add a resolve handler." ) );
Condition50%1/2
shift @_ || (return $self->error('No code reference was provided to add a resolve handler.'))
l!l
640
MC/DC0%0/1
shift @_ || (return $self->error('No code reference was provided to add a resolve handler.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
380 64 ▶ return( $self->error( "Resolve handler provided is not a code reference." ) ) if( ref( $code ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $code ne "CODE" 0 64 64
381 64 push( @{$self->{_handlers}}, { type => 'then', handler => $code });
382 64 return( $self );
383 }
384  
385 sub add_reject_handler
386 36 ▶{
Subroutine add_reject_handler: called CC=3 SCAR=11.2
Pod documented
387 36 my $self = shift( @_ );
388 36 ▶ my $code = shift( @_ ) || return( $self->error( "No code reference was provided to add a reject handler." ) );
Condition50%1/2
shift @_ || (return $self->error('No code reference was provided to add a reject handler.'))
l!l
360
MC/DC0%0/1
shift @_ || (return $self->error('No code reference was provided to add a reject handler.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
389 36 ▶ return( $self->error( "Reject handler provided is not a code reference." ) ) if( ref( $code ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $code ne "CODE" 0 36 36
390 36 push( @{$self->{_handlers}}, { type => 'catch', handler => $code });
391 36 return( $self );
392 }
393  
394 sub all
395 0 ▶{
Subroutine all: not called CC=9 SCAR=45.0
Pod documented
396 0 my $this = shift( @_ );
397 0 ▶ return( __PACKAGE__->error( __PACKAGE__, "->all must be called as a class function such as: ", __PACKAGE__, "->all()" ) ) if( ref( $this ) || $this ne 'Promise::Me' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $this or $this ne "Promise::Me" 0 0 0
Condition0%0/3
ref $this or $this ne "Promise::Me"
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this or $this ne "Promise::Me"
ref $this $this ne "Promise::Me"
Truth table0%0/3
A or B
A= ref $thisB= $this ne "Promise::Me"
ABresult
1X1
011
000
398 0 my $opts = {};
399 0 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
400 0 ▶ $opts->{timeout} //= 0;
Condition0%0/2
$opts->{"timeout"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"timeout"} //= 0
$opts->{"timeout"}
Truth table0%0/2
A
A= $opts->{"timeout"}
Aresult
11
00
401 0 ▶ $opts->{race} //= 0;
Condition0%0/2
$opts->{"race"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"race"} //= 0
$opts->{"race"}
Truth table0%0/2
A
A= $opts->{"race"}
Aresult
11
00
402 0 ▶ my @proms = ( scalar( @_ ) == 1 && Scalar::Util::reftype( $_[0] ) eq 'ARRAY' ) ? @{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 && builtin::reftype($_[0]) eq 'ARRAY' ? : 0 0 0
Condition0%0/3
scalar @_ == 1 and builtin::reftype($_[0]) eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and builtin::reftype($_[0]) eq "ARRAY"
scalar @_ == 1 builtin::reftype($_[0]) eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @_ == 1B= builtin::reftype($_[0]) eq "ARRAY"
ABresult
0X0
100
111
403 # Make sure we are being provided with our objects
404 0 ▶ @proms = grep{ Scalar::Util::blessed( $_ ) && $_->isa( 'Promise::Me' ) } @proms;
Condition0%0/3
builtin::blessed($_) && $_->isa('Promise::Me')
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($_) && $_->isa('Promise::Me')
builtin::blessed($_) $_->isa('Promise::Me')
Truth table0%0/3
A && B
A= builtin::blessed($_)B= $_->isa('Promise::Me')
ABresult
0X0
100
111
405 return( $this->new(sub
406 0 ▶ {
Subroutine __ANON__: not called CC=12 SCAR=50.5
407 0 my( $resolve, $reject ) = @_;
408 # We make a copy that we can manipulate, remove, etc
409 0 my @promises = @proms;
410 0 my @results;
411 # Size the array
412 0 $#results = $#proms;
413 0 my $done = {};
414 0 my $keep_going = 1;
415 0 ▶ local $SIG{ALRM} = sub{ $keep_going = 0 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
416 0 ▶ alarm( $opts->{timeout} ) if( $opts->{timeout} =~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"timeout"} =~ /^\d+$/ 0 0 0
417 0 ▶ COLLECT: while($keep_going)
Branch: 1 branch
BranchTrueFalseTotal
if ($keep_going) 0 0 0
418 {
419 0 ▶ for( my $i = 0; $i < scalar( @promises ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @promises) 0 0 0
420 {
421 0 ▶ next if( CORE::exists( $done->{ $i } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $done->{$i} 0 0 0
422 0 my $p = $promises[$i];
423 0 ▶ if( $p->rejected )
Branch: 2 branches
BranchTrueFalseTotal
if ($p->rejected) { } 0 0 0
elsif ($p->resolved) { } 0 0 0
424 {
425 0 $done->{ $i } = 0;
426 0 $reject->( $p->result );
427 0 last COLLECT;
428 }
429 elsif( $p->resolved )
430 {
431 0 $done->{ $i } = 1;
432 0 ▶ if( $opts->{race} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'race'}) { } 0 0 0
433 {
434 0 @results = $p->result;
435 0 $resolve->( @results );
436 0 last COLLECT;
437 }
438 else
439 {
440 0 $results[$i] = $p->result;
441 0 CORE::splice( @promises, $i, 1 );
442 0 $i--;
443 }
444 }
445 }
446 0 ▶ last COLLECT if( !scalar( @promises ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @promises 0 0 0
447 }
448 0 alarm(0);
449 0 ▶ if( $opts->{race} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'race'}) { } 0 0 0
450 {
451 0 ▶ scalar( @results ) > 1 ? @results : $results[0];
Branch: 1 branch
BranchTrueFalseTotal
scalar @results > 1 ? : 0 0 0
452 }
453 else
454 {
455 0 ▶ if( !$keep_going )
Branch: 1 branch
BranchTrueFalseTotal
if (not $keep_going) { } 0 0 0
456 {
457 0 $reject->( Promise::Me::Exception->new( 'timeout' ) );
458 }
459 else
460 {
461 0 $resolve->( \@results );
462 }
463 }
464 0 }) );
465 }
466  
467 16 ▶sub args { return( shift->_set_get_array_as_object( 'args', @_ ) ); }
Subroutine args: called CC=1 SCAR=0.0
Pod documented
468  
469 0 ▶sub async { return( Promise::Me->new( @_ ) ); }
Subroutine async: not called CC=1 SCAR=6.9
Pod documented
470  
471 # Called as a function. Takes promise objects as arguments, possibly with an hash
472 # reference of options at the end
473 # away( $p1, $p2 );
474 # away( $p1, $p2, { timeout => 2 });
475 sub await
476 4 ▶{
Subroutine await: called CC=24 SCAR=41.5
Pod documented
477 4 my $opts = {};
478 4 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 4 4
479 4 my @promises = @_;
480 4 ▶ return if( !scalar( @promises ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @promises 0 4 4
481 4 ▶ @promises = grep{ Scalar::Util::blessed( $_ ) && $_->isa( 'Promise::Me' ) } @promises;
Condition33%1/3
builtin::blessed($_) && $_->isa('Promise::Me')
!ll&&!rl&&r
008
MC/DC0%0/2
builtin::blessed($_) && $_->isa('Promise::Me')
builtin::blessed($_) $_->isa('Promise::Me')
Truth table33%1/3
A && B
A= builtin::blessed($_)B= $_->isa('Promise::Me')
ABresult
0X0
100
111
482 4 ▶ if( !scalar( @promises ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @promises) 0 4 4
483 {
484 0 ▶ warn( "No promise object was provided to await()!\n" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
485 0 return;
486 }
487 4 my @results;
488 # Pre-size the array
489 4 $#results = $#promises;
490 4 my $timeout = 0;
491 4 ▶ $opts->{timeout} //= 3;
Condition50%1/2
$opts->{"timeout"} //= 3
l!l
04
MC/DC0%0/1
$opts->{"timeout"} //= 3
$opts->{"timeout"}
Truth table50%1/2
A
A= $opts->{"timeout"}
Aresult
11
00
492 local $SIG{ALRM} = sub
493 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
494 0 $timeout++;
495 0 ▶ print( STDERR __PACKAGE__, "::await: Reached timeout of $opts->{timeout} seconds.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG 0 0 0
496 4 };
497 4 CORE::alarm( $opts->{timeout} );
498 4 ▶ printf( STDERR "%s::await: %d promise(s) to process.\n", __PACKAGE__, scalar( @promises ) ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 4 4
499 4 ▶ CHECK_KIDS: while( !$timeout )
Branch: 1 branch
BranchTrueFalseTotal
unless ($timeout) 6870 0 6870
500 {
501 6870 ▶ for( my $i = 0; $i <= $#promises; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#promises) 11886 6870 18756
502 {
503 11886 my $prom = $promises[$i];
504 11886 my $pid = $prom->child;
505 11886 ▶ my $prefix = '[' . ( $prom->is_child ? 'child' : 'parent' ) . ']';
Branch: 1 branch
BranchTrueFalseTotal
$prom->is_child ? : 0 11886 11886
506 # Already removed
507 11886 ▶ if( !CORE::defined( $pid ) || !CORE::exists( $KIDS->{ $pid } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pid and exists $Promise::Me::KIDS->{$pid}) 8 11878 11886
Condition66%2/3
defined $pid and exists $Promise::Me::KIDS->{$pid}
!ll&&!rl&&r
0811878
MC/DC50%1/2
defined $pid and exists $Promise::Me::KIDS->{$pid}
defined $pid exists $Promise::Me::KIDS->{$pid}
Truth table66%2/3
A and B
A= defined $pidB= exists $Promise::Me::KIDS->{$pid}
ABresult
0X0
100
111
508 {
509 8 splice( @promises, $i, 1 );
510 8 $i--;
511 8 next;
512 }
513  
514 11878 my $rv = waitpid( $pid, POSIX::WNOHANG );
515 11878 ▶ if( $rv == 0 )
Branch: 3 branches
BranchTrueFalseTotal
if ($rv == 0) { } 11870 8 11878
elsif ($rv > 0) { } 8 0 8
elsif ($rv == -1) { } 0 0 0
516 {
517 # Child pid is still running, waiting for it.
518 }
519 elsif( $rv > 0 )
520 {
521 8 CORE::delete( $KIDS->{ $pid } );
522 8 $prom->_set_exit_values( $? );
523 8 ▶ if( !$prom->resolved && !$prom->rejected )
Branch: 1 branch
BranchTrueFalseTotal
unless ($prom->resolved or $prom->rejected) 0 8 8
Condition33%1/3
$prom->resolved or $prom->rejected
l!l&&r!l&&!r
800
MC/DC0%0/2
$prom->resolved or $prom->rejected
$prom->resolved $prom->rejected
Truth table33%1/3
A or B
A= $prom->resolvedB= $prom->rejected
ABresult
1X1
011
000
524 {
525 # exit with value > 0 meaning an error occurred
526 0 ▶ if( $prom->exit_status )
Branch: 1 branch
BranchTrueFalseTotal
if ($prom->exit_status) { } 0 0 0
527 {
528 0 my $err = '';
529 0 ▶ if( $prom->exit_signal )
Branch: 2 branches
BranchTrueFalseTotal
if ($prom->exit_signal) { } 0 0 0
elsif ($prom->exit_status) { } 0 0 0
530 {
531 0 $err = 'Asynchronous process killed by signal.';
532 }
533 elsif( $prom->exit_status )
534 {
535 0 $err = 'Asynchronous process exited due to an error.';
536 }
537 0 $prom->reject( Promise::Me::Exception->new( $err ) );
538 }
539 else
540 {
541 0 $prom->resolve;
542 }
543 }
544 8 $results[$i] = $prom->result;
545 }
546 # Child process has already exited
547 elsif( $rv == -1 )
548 {
549 0 CORE::delete( $KIDS->{ $pid } );
550 0 next CHECK_KIDS;
551 }
552 }
553 6870 ▶ last if( !scalar( @promises ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @promises 4 6866 6870
554 # Mixing alarm and sleep yield weird results, so we temporarily back it up
555 # and deactivate it
556 6866 my $alarm = CORE::alarm(0);
557 6866 sleep(0.5);
558 6866 CORE::alarm( $alarm );
559 }
560 4 CORE::alarm(0);
561 4 ▶ print( STDERR __PACKAGE__, "::await: Finished awaiting for the processes\n" ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 4 4
562 4 ▶ return( scalar( @results ) > 1 ? @results : $results[0] );
Branch: 1 branch
BranchTrueFalseTotal
scalar @results > 1 ? : 4 0 4
563 }
564  
565 sub catch
566 36 ▶{
Subroutine catch: called CC=7 SCAR=21.3
Pod documented
567 36 my $self = shift( @_ );
568 36 ▶ @_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and not defined $_[0] 0 36 36
Condition33%1/3
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
0360
MC/DC0%0/2
scalar @_ == 1 and not defined $_[0]
scalar @_ == 1 not defined $_[0]
Truth table33%1/3
A and not(B)
A= scalar @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
569 36 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 36 0 36
570 {
571 36 my $code = shift( @_ );
572 36 ▶ return( $self->error( "catch() only accepts a code references. Value provided was '$code'." ) ) if( ref( $code ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $code ne "CODE" 0 36 36
573 36 $self->add_reject_handler( $code );
574 }
575  
576 # Is there more chaining, or is this the end of the chain?
577 # If the latter, we then start executing our codes
578 36 ▶ unless( Wanted::want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (Wanted::want("OBJECT")) 36 0 36
579 {
580 36 $self->no_more_chaining(1);
581 36 ▶ $self->exec || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->exec or return $self->pass_error 24 0 24
582 }
583 24 return( $self );
584 }
585  
586 11926 ▶sub child { return( shift->_set_get_scalar( 'child', @_ ) ); }
Subroutine child: called CC=1 SCAR=0.0
Pod undocumented
587  
588 16 ▶sub exception_class { return( shift->_set_get_scalar( 'exception_class', @_ ) ); }
Subroutine exception_class: called CC=1 SCAR=0.0
Pod documented
589  
590 sub exec
591 56 ▶{
Subroutine exec: called CC=27 SCAR=45.4
Pod documented
592 56 my $self = shift( @_ );
593 # Block signal for fork
594 56 my $sigset = POSIX::SigSet->new( POSIX::SIGINT );
595 56 ▶ POSIX::sigprocmask( POSIX::SIG_BLOCK, $sigset ) ||
Branch: 1 branch
BranchTrueFalseTotal
POSIX::sigprocmask(0, $sigset) or return $self->error("Cannot block SIGINT for fork: $!") 56 0 56
596 return( $self->error( "Cannot block SIGINT for fork: $!" ) );
597 56 select((select(STDOUT), $|=1)[0]);
598 56 select((select(STDERR), $|=1)[0]);
599 56 $self->executed(1);
600  
601 56 my $pid = fork();
602 # Parent
603 56 ▶ if( $pid )
Branch: 2 branches
BranchTrueFalseTotal
if ($pid) { } 40 16 56
elsif ($pid == 0) { } 16 0 16
604 {
605 # $self->kids->push( $pid );
606 40 $KIDS->{ $pid } = { me => $self };
607 40 $self->child( $pid );
608 40 ▶ POSIX::sigprocmask( POSIX::SIG_UNBLOCK, $sigset ) ||
Branch: 1 branch
BranchTrueFalseTotal
POSIX::sigprocmask(1, $sigset) or return $self->error("Cannot unblock SIGINT for fork: $!") 40 0 40
609 return( $self->error( "Cannot unblock SIGINT for fork: $!" ) );
610 40 ▶ my $shm = $self->_set_shared_space() || return( $self->pass_error );
Condition50%1/2
$self->_set_shared_space || (return $self->pass_error)
l!l
400
MC/DC0%0/1
$self->_set_shared_space || (return $self->pass_error)
$self->_set_shared_space
Truth table50%1/2
A
A= $self->_set_shared_space
Aresult
11
00
611 # Locking is done inside 'write'
612 # $shm->lock( LOCK_EX );
613 40 $shm->write( $self->{shared} );
614 # $shm->unlock;
615 # If we are to wait for the child to exit, there is no CHLD signal handler
616 40 ▶ if( $self->{wait} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'wait'}) { } 0 40 40
617 {
618 # Is the child still there?
619 0 ▶ if( kill( 0 => $pid ) || $!{EPERM} )
Branch: 1 branch
BranchTrueFalseTotal
if (kill 0, $pid or $!{'EPERM'}) { } 0 0 0
Condition0%0/3
kill 0, $pid or $!{"EPERM"}
l!l&&r!l&&!r
000
MC/DC0%0/2
kill 0, $pid or $!{"EPERM"}
kill 0, $pid $!{"EPERM"}
Truth table0%0/3
A or B
A= kill 0, $pidB= $!{"EPERM"}
ABresult
1X1
011
000
620 {
621 # Blocking wait
622 0 waitpid( $pid, 0 );
623 0 $self->_set_exit_values( $? );
624 0 ▶ if( WIFEXITED($?) )
Branch: 1 branch
BranchTrueFalseTotal
if (WIFEXITED($?)) { } 0 0 0
625 {
626 # Child exited normally
627 }
628 else
629 {
630 # Child exited with non-zero
631 }
632 }
633 else
634 {
635 # Child has already exited
636 }
637 }
638 else
639 {
640 # We let perl handle itself the reaping of the child process
641 40 local $SIG{CHLD} = 'IGNORE';
642 }
643 40 return( $self );
644 }
645 # Child
646 elsif( $pid == 0 )
647 {
648 16 $self->is_child(1);
649 16 $self->pid( $$ );
650 16 ▶ $self->_set_shared_space() || return( $self->reject( $self->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_set_shared_space or return $self->reject($self->error) 16 0 16
651 16 my $exception_class = $self->exception_class;
652  
653 16 my $args = $self->args;
654 16 my @rv;
655 # try-catch
656 16 local $@;
657 eval
658 16 {
659 # Possibly any arguments passed in the 'async sub some_routine'; or
660 # Promise::Me->new( args => [@args] );
661 16 local $_ = [ $self->curry::resolve, $self->curry::reject ];
662 16 my $code = $self->{_code};
663 16 ▶ @rv = @$args ? $code->( @$args ) : $code->();
Branch: 1 branch
BranchTrueFalseTotal
@$args ? : 0 16 16
664 };
665 16 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 4 12 16
666 {
667 4 my $e = "$@";
668 4 $e =~ s/\r?\n$//gs;
669 4 ▶ if( Scalar::Util::blessed( $@ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($@)) { } 0 4 4
670 {
671 0 $self->reject( $@ );
672 }
673 else
674 {
675 4 $self->reject( Promise::Me::Exception->new( $e ) );
676 }
677 }
678 else
679 {
680 # The code executed, returned a promise, so we use it and call the next 'then'
681 # in the chain with it.
682 12 ▶ if( scalar( @rv ) &&
Branch: 5 branches
BranchTrueFalseTotal
if (scalar @rv and builtin::blessed($rv[0]) and $rv[0]->isa('Promise::Me')) { } 0 12 12
elsif (scalar @rv and builtin::blessed($rv[0]) and $exception_class and $rv[0]->isa($exception_class)) { } 0 12 12
elsif (scalar @rv) { } 12 0 12
elsif ($self->resolved) { } 0 0 0
elsif ($self->rejected) { } 0 0 0
Condition66%4/6
scalar @rv and builtin::blessed($rv[0]) and $rv[0]->isa("Promise::Me")
!ll&&!rl&&r
480
scalar @rv and builtin::blessed($rv[0])
!ll&&!rl&&r
048
MC/DC0%0/3
scalar @rv and builtin::blessed($rv[0]) and $rv[0]->isa("Promise::Me")
scalar @rv builtin::blessed($rv[0]) $rv[0]->isa("Promise::Me")
Truth table50%2/4
A and B and C
A= scalar @rvB= builtin::blessed($rv[0])C= $rv[0]->isa("Promise::Me")
ABCresult
0XX0
10X0
1100
1111
683 Scalar::Util::blessed( $rv[0] ) &&
684 $rv[0]->isa( 'Promise::Me' ) )
685 {
686 # shift( @rv )->resolve( @rv );
687 0 my $other = shift( @rv );
688 0 ▶ if( $self->id eq $other->id )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->id eq $other->id) { } 0 0 0
689 {
690 0 $other->resolve( @rv );
691 }
692 else
693 {
694 # Received a promise object ($other), which is not one of ours. Discarding it.
695 }
696 }
697 ▶ elsif( scalar( @rv ) &&
Condition66%6/9
scalar @rv and builtin::blessed($rv[0]) and $exception_class and $rv[0]->isa($exception_class)
!ll&&!rl&&r
480
scalar @rv and builtin::blessed($rv[0]) and $exception_class
!ll&&!rl&&r
408
scalar @rv and builtin::blessed($rv[0])
!ll&&!rl&&r
048
MC/DC0%0/4
scalar @rv and builtin::blessed($rv[0]) and $exception_class and $rv[0]->isa($exception_class)
scalar @rv builtin::blessed($rv[0]) $exception_class $rv[0]->isa($exception_class)
Truth table40%2/5
A and B and C and D
A= scalar @rvB= builtin::blessed($rv[0])C= $exception_classD= $rv[0]->isa($exception_class)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
698 Scalar::Util::blessed( $rv[0] ) &&
699 $exception_class &&
700 $rv[0]->isa( $exception_class ) )
701 {
702 0 $self->reject( shift( @rv ) );
703 }
704 elsif( scalar( @rv ) )
705 {
706 12 $self->resolve( @rv );
707 }
708 # If the callback has used the $_->[0] to resolve the promise, we pass on to then
709 elsif( $self->resolved )
710 {
711 # $self->resolve;
712 # The user already called resolve, so we do nothing.
713 }
714 # If the callback has used the $_->[1] to reject the promise, we pass on to catch
715 elsif( $self->rejected )
716 {
717 # $self->reject;
718 # The user already called reject, so we do nothing.
719 }
720 }
721 16 exit(0);
722 }
723 else
724 {
725 0 my $err;
726 0 ▶ if( $! == POSIX::EAGAIN() )
Branch: 2 branches
BranchTrueFalseTotal
if ($! == 11) { } 0 0 0
elsif ($! == 12) { } 0 0 0
727 {
728 0 $err = "fork cannot allocate sufficient memory to copy the parent's page tables and allocate a task structure for the child.";
729 }
730 elsif( $! == POSIX::ENOMEM() )
731 {
732 0 $err = "fork failed to allocate the necessary kernel structures because memory is tight.";
733 }
734 else
735 {
736 0 $err = "Unable to fork a new process to execute promised code: $!";
737 }
738 0 return( $self->reject( Module::Promise::Exception->new( $err ) ) );
739 }
740 0 return( $self );
741 }
742  
743 148 ▶sub executed { return( shift->_set_get_boolean( 'executed', @_ ) ); }
Subroutine executed: called CC=1 SCAR=0.0
Pod undocumented
744  
745 8 ▶sub exit_bit { return( shift->_set_get_scalar( 'exit_bit', @_ ) ); }
Subroutine exit_bit: called CC=1 SCAR=0.0
Pod documented
746  
747 8 ▶sub exit_signal { return( shift->_set_get_scalar( 'exit_signal', @_ ) ); }
Subroutine exit_signal: called CC=1 SCAR=0.0
Pod documented
748  
749 8 ▶sub exit_status { return( shift->_set_get_scalar( 'exit_status', @_ ) ); }
Subroutine exit_status: called CC=1 SCAR=0.0
Pod documented
750  
751 sub get_next_by_type
752 36 ▶{
Subroutine get_next_by_type: called CC=5 SCAR=16.1
Pod documented
753 36 my $self = shift( @_ );
754 36 ▶ my $type = shift( @_ ) ||
Condition50%1/2
shift @_ || (return $self->error('No type provided to get its next handler.'))
l!l
360
MC/DC0%0/1
shift @_ || (return $self->error('No type provided to get its next handler.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
755 return( $self->error( "No type provided to get its next handler." ) );
756 36 my $h = $self->{_handlers};
757 36 my( $code, $pos );
758 36 ▶ for( my $i = 0; $i < scalar( @$h ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$h) 32 16 48
759 {
760 32 ▶ if( $h->[$i]->{type} eq $type )
Branch: 1 branch
BranchTrueFalseTotal
if ($h->[$i]{"type"} eq $type) 20 12 32
761 {
762 20 $code = $h->[$i]->{handler};
763 20 $pos = $i;
764 20 last;
765 }
766 }
767 36 ▶ return if( !defined( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code 16 20 36
768 20 splice( @$h, 0, $pos + 1 );
769 20 return( $code );
770 }
771  
772 0 ▶sub get_finally_handler { return( shift->get_next_by_type( 'finally' ) ); }
Subroutine get_finally_handler: not called CC=1 SCAR=6.9
Pod documented
773  
774 4 ▶sub get_next_reject_handler { return( shift->get_next_by_type( 'catch' ) ); }
Subroutine get_next_reject_handler: called CC=1 SCAR=0.0
Pod documented
775  
776 32 ▶sub get_next_resolve_handler { return( shift->get_next_by_type( 'then' ) ); }
Subroutine get_next_resolve_handler: called CC=1 SCAR=0.0
Pod documented
777  
778 8 ▶sub has_coredump { return( shift->_set_get_boolean( 'has_coredump', @_ ) ); }
Subroutine has_coredump: called CC=1 SCAR=0.0
Pod documented
779  
780 0 ▶sub id { return( shift->{id} ); }
Subroutine id: not called CC=1 SCAR=6.9
Pod undocumented
781  
782 11998 ▶sub is_child { return( shift->_set_get_boolean( 'is_child', @_ ) ); }
Subroutine is_child: called CC=1 SCAR=0.0
Pod documented
783  
784 56 ▶sub is_parent { return( !shift->is_child ); }
Subroutine is_parent: called CC=1 SCAR=0.0
Pod documented
785  
786 sub lock
787 0 ▶{
Subroutine lock: not called CC=13 SCAR=52.0
Pod documented
788 0 my $self;
789 0 ▶ $self = shift( @_ ) if( scalar( @_ ) && Scalar::Util::blessed( $_[0] ) && $_[0]->isa( 'Promise::Me' ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ and builtin::blessed($_[0]) and $_[0]->isa("Promise::Me") 0 0 0
Condition0%0/6
scalar @_ and builtin::blessed($_[0]) and $_[0]->isa("Promise::Me")
!ll&&!rl&&r
000
scalar @_ and builtin::blessed($_[0])
!ll&&!rl&&r
000
MC/DC0%0/3
scalar @_ and builtin::blessed($_[0]) and $_[0]->isa("Promise::Me")
scalar @_ builtin::blessed($_[0]) $_[0]->isa("Promise::Me")
Truth table0%0/4
A and B and C
A= scalar @_B= builtin::blessed($_[0])C= $_[0]->isa("Promise::Me")
ABCresult
0XX0
10X0
1100
1111
790 0 my $type;
791 0 ▶ $type = pop( @_ ) if( !ref( $_[-1] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[-1] 0 0 0
792 0 foreach my $ref ( @_ )
793 {
794 0 my $tied = tied( $ref );
795 0 ▶ if( defined( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self) { } 0 0 0
796 {
797 }
798 else
799 {
800 0 ▶ print( STDERR __PACKAGE__, "::lock: Checking if variable '$ref' is tied -> ", ( Scalar::Util::blessed( $tied ) ? 'Yes' : 'No' ), "\n" ) if( $DEBUG >= 4 );
Branch: 2 branches
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 0 0
builtin::blessed($tied) ? : 0 0 0
801 }
802 0 ▶ if( Scalar::Util::blessed( $tied ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($tied) and $tied->isa("Promise::Me::Share")) 0 0 0
Condition0%0/3
builtin::blessed($tied) and $tied->isa("Promise::Me::Share")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($tied) and $tied->isa("Promise::Me::Share")
builtin::blessed($tied) $tied->isa("Promise::Me::Share")
Truth table0%0/3
A and B
A= builtin::blessed($tied)B= $tied->isa("Promise::Me::Share")
ABresult
0X0
100
111
803 $tied->isa( 'Promise::Me::Share' ) )
804 {
805 0 ▶ defined( $type ) ? $tied->lock( $type ) : $tied->lock;
Branch: 1 branch
BranchTrueFalseTotal
defined $type ? : 0 0 0
806 }
807 }
808 0 ▶ return( $self ) if( $self );
Branch: 1 branch
BranchTrueFalseTotal
if $self 0 0 0
809 }
810  
811 20 ▶sub medium { return( shift->_set_get_scalar( 'medium', @_ ) ); }
Subroutine medium: called CC=1 SCAR=0.0
Pod documented
812  
813 56 ▶sub no_more_chaining { return( shift->_set_get_boolean( '_no_more_chaining', @_ ) ); }
Subroutine no_more_chaining: called CC=1 SCAR=0.0
Pod documented
814  
815 52 ▶sub pid { return( shift->_set_get_scalar( 'pid', @_ ) ); }
Subroutine pid: called CC=1 SCAR=0.0
Pod documented
816  
817 sub race
818 0 ▶{
Subroutine race: not called CC=4 SCAR=30.0
Pod documented
819 0 my $this = shift( @_ );
820 0 ▶ return( __PACKAGE__->error( __PACKAGE__, "->race must be called as a class function such as: ", __PACKAGE__, "->race()" ) ) if( ref( $this ) || $this ne 'Promise::Me' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $this or $this ne "Promise::Me" 0 0 0
Condition0%0/3
ref $this or $this ne "Promise::Me"
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this or $this ne "Promise::Me"
ref $this $this ne "Promise::Me"
Truth table0%0/3
A or B
A= ref $thisB= $this ne "Promise::Me"
ABresult
1X1
011
000
821 0 my $opts = {};
822 0 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
823 0 $opts->{race} = 1;
824 0 return( $this->all( @_, $opts ) );
825 }
826  
827 sub reject
828 4 ▶{
Subroutine reject: called CC=9 SCAR=29.5
Pod documented
829 4 my $self = shift( @_ );
830 4 my $vals = [@_];
831 4 $self->rejected(1);
832 # Maybe there is no more reject handler, like when we are at the end of the chain.
833 4 my $code = $self->get_next_reject_handler();
834 4 ▶ if( !defined( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 4 4
835 {
836 0 $self->{_saved_values} = $vals;
837 0 return( $self );
838 }
839  
840 4 my @rv;
841 # try-catch
842 4 local $@;
843 eval
844 4 {
845 4 local $_ = [ $self->curry::resolve, $self->curry::reject ];
846 4 ▶ @rv = @$vals ? $code->( @$vals ) : $code->();
Branch: 1 branch
BranchTrueFalseTotal
@$vals ? : 4 0 4
847 };
848 4 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 4 4
849 {
850 0 ▶ if( Scalar::Util::blessed( $@ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($@)) { } 0 0 0
851 {
852 0 return( $self->reject( $@ ) );
853 }
854 else
855 {
856 0 my $e = "$@";
857 0 $e =~ s/\r?\n$//gs;
858 0 return( $self->reject( Promise::Me::Exception->new( $e ) ) );
859 }
860 }
861 else
862 {
863 # The code returned another promise
864 4 ▶ if( scalar( @rv ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @rv and builtin::blessed($rv[0]) and $rv[0]->isa('Promise::Me')) { } 0 4 4
elsif (scalar @rv) { } 4 0 4
Condition33%2/6
scalar @rv and builtin::blessed($rv[0]) and $rv[0]->isa("Promise::Me")
!ll&&!rl&&r
400
scalar @rv and builtin::blessed($rv[0])
!ll&&!rl&&r
040
MC/DC0%0/3
scalar @rv and builtin::blessed($rv[0]) and $rv[0]->isa("Promise::Me")
scalar @rv builtin::blessed($rv[0]) $rv[0]->isa("Promise::Me")
Truth table25%1/4
A and B and C
A= scalar @rvB= builtin::blessed($rv[0])C= $rv[0]->isa("Promise::Me")
ABCresult
0XX0
10X0
1100
1111
865 Scalar::Util::blessed( $rv[0] ) &&
866 $rv[0]->isa( 'Promise::Me' ) )
867 {
868 0 return( shift( @rv )->resolve( @rv ) );
869 }
870 # We call our next 'then' by resolving this with the arguments received
871 elsif( scalar( @rv ) )
872 {
873 4 return( $self->resolve( @rv ) );
874 }
875 # Called in void
876 else
877 {
878 0 return( $self );
879 }
880 }
881 }
882  
883 4 ▶sub rejected { return( shift->_reject_resolve( 'rejected', @_ ) ); }
Subroutine rejected: called CC=1 SCAR=0.0
Pod documented
884  
885 sub resolve
886 32 ▶{
Subroutine resolve: called CC=13 SCAR=32.7
Pod documented
887 32 my $self = shift( @_ );
888 32 my $vals = [@_];
889 # Maybe there is no more resolve handler, like when we are at the end of the chain.
890 32 my $code = $self->get_next_resolve_handler();
891 # No more resolve handler. We are at the end of the chain. Mark this as resolved
892 # No actually, mark this resolved right now, and if next iteration is a fail,
893 # then it will be marked differently
894 32 $self->resolved(1);
895 32 ▶ if( !defined( $code ) || !ref( $code ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code and ref $code) 16 16 32
Condition66%2/3
defined $code and ref $code
!ll&&!rl&&r
16016
MC/DC50%1/2
defined $code and ref $code
defined $code ref $code
Truth table66%2/3
A and B
A= defined $codeB= ref $code
ABresult
0X0
100
111
896 {
897 16 $self->{_saved_values} = $vals;
898 16 return( $self );
899 }
900  
901 16 my @rv;
902 # try-catch
903 16 local $@;
904 eval
905 16 {
906 16 local $_ = [ $self->curry::resolve, $self->curry::reject ];
907 16 ▶ @rv = @$vals ? $code->( @$vals ) : $code->();
Branch: 1 branch
BranchTrueFalseTotal
@$vals ? : 16 0 16
908 };
909 16 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 16 16
910 {
911 0 my $ex;
912 0 ▶ if( Scalar::Util::blessed( $@ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($@)) { } 0 0 0
913 {
914 0 $ex = $@;
915 }
916 else
917 {
918 0 my $e = "$@";
919 0 $e =~ s/\r?\n$//gs;
920 0 $ex = Promise::Me::Exception->new( $e );
921 }
922 0 $self->result( $ex );
923 0 return( $self->reject( $ex ) );
924 }
925 else
926 {
927 # It seems the user used the resolve or reject callbacks and returned, such as return( $resolve->() )
928 # In which case, we do not save our promise object, because it would not make sense obviously.
929 16 ▶ if( scalar( @rv ) && $self->_is_a( $rv[0] => 'Promise::Me' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @rv and $self->_is_a($rv[0], 'Promise::Me')) { } 0 16 16
Condition33%1/3
scalar @rv and $self->_is_a($rv[0], "Promise::Me")
!ll&&!rl&&r
0160
MC/DC0%0/2
scalar @rv and $self->_is_a($rv[0], "Promise::Me")
scalar @rv $self->_is_a($rv[0], "Promise::Me")
Truth table33%1/3
A and B
A= scalar @rvB= $self->_is_a($rv[0], "Promise::Me")
ABresult
0X0
100
111
930 {
931 0 return( $self );
932 }
933 # User returned some other values from its then() method, so we save it and resolve it
934 else
935 {
936 16 ▶ $self->result( @rv ) || return( $self->reject( Promise::Me::Exception->new( $self->error ) ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->result(@rv) or return $self->reject("Promise::Me::Exception"->new($self->error)) 16 0 16
937 }
938 # The code returned another promise
939 16 ▶ if( scalar( @rv ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @rv and builtin::blessed($rv[0]) and $rv[0]->isa('Promise::Me')) { } 0 16 16
elsif (scalar @rv) { } 16 0 16
Condition66%4/6
scalar @rv and builtin::blessed($rv[0]) and $rv[0]->isa("Promise::Me")
!ll&&!rl&&r
4120
scalar @rv and builtin::blessed($rv[0])
!ll&&!rl&&r
0412
MC/DC0%0/3
scalar @rv and builtin::blessed($rv[0]) and $rv[0]->isa("Promise::Me")
scalar @rv builtin::blessed($rv[0]) $rv[0]->isa("Promise::Me")
Truth table50%2/4
A and B and C
A= scalar @rvB= builtin::blessed($rv[0])C= $rv[0]->isa("Promise::Me")
ABCresult
0XX0
10X0
1100
1111
940 Scalar::Util::blessed( $rv[0] ) &&
941 $rv[0]->isa( 'Promise::Me' ) )
942 {
943 0 return( shift( @rv )->resolve( @rv ) );
944 }
945 # We call our next 'then' by resolving this with the arguments received
946 elsif( scalar( @rv ) )
947 {
948 16 return( $self->resolve( @rv ) );
949 }
950 # Called in void
951 else
952 {
953 0 return( $self );
954 }
955 }
956 }
957  
958 40 ▶sub resolved { return( shift->_reject_resolve( 'resolved', @_ ) ); }
Subroutine resolved: called CC=1 SCAR=0.0
Pod documented
959  
960 sub result
961 24 ▶{
Subroutine result: called CC=12 SCAR=29.2
Pod documented
962 24 my $self = shift( @_ );
963 24 my $shm = $self->shared_mem;
964 24 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 16 8 24
965 {
966 # We need to save the result provided as a 1 reference variable
967 16 ▶ my $val = ( @_ == 1 && ref( $_[0] ) ) ? shift( @_ ) : [@_];
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] ? : 12 4 16
Condition66%2/3
@_ == 1 and ref $_[0]
!ll&&!rl&&r
0412
MC/DC50%1/2
@_ == 1 and ref $_[0]
@_ == 1 ref $_[0]
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0]
ABresult
0X0
100
111
968 16 ▶ if( $shm )
Branch: 1 branch
BranchTrueFalseTotal
if ($shm) { } 16 0 16
969 {
970 16 my $hash = $shm->read;
971 16 ▶ $hash = {} if( ref( $hash ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $hash ne "HASH" 0 16 16
972 16 $hash->{result} = $val;
973 # $shm->lock( LOCK_EX );
974 # locking is done inside the method 'write'
975 16 ▶ $shm->write( $hash ) || return( $self->pass_error( $shm->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$shm->write($hash) or return $self->pass_error($shm->error) 16 0 16
976 # $shm->unlock;
977 16 return( $hash );
978 }
979 else
980 {
981 0 ▶ warn( "Shared space object not set or lost!\n" ) if( $self->_is_warnings_enabled || $self->debug );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled or $self->debug 0 0 0
Condition0%0/3
$self->_is_warnings_enabled or $self->debug
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_is_warnings_enabled or $self->debug
$self->_is_warnings_enabled $self->debug
Truth table0%0/3
A or B
A= $self->_is_warnings_enabledB= $self->debug
ABresult
1X1
011
000
982 }
983 }
984 else
985 {
986 8 ▶ if( !$self->executed )
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->executed) { } 0 8 8
elsif (not $shm) { } 0 8 8
987 {
988 0 return( $self->error( "The promise has not yet been executed, because you have called result() without first calling then() or wait() (in void context)." ) );
989 }
990 elsif( !$shm )
991 {
992 0 return( $self->error( "Shared space object not set or lost!" ) );
993 }
994 8 my $hash = $shm->read;
995 8 ▶ $hash = {} if( ref( $hash ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $hash ne "HASH" 0 8 8
996 8 $self->{shared} = $hash;
997 8 return( $hash->{result} );
998 }
999 }
1000  
1001 56 ▶sub result_shared_mem_size { return( shift->_set_get_mem_size( 'result_shared_mem_size', @_ ) ); }
Subroutine result_shared_mem_size: called CC=1 SCAR=0.0
Pod documented
1002  
1003 112 ▶sub serialiser { return( shift->_set_get_scalar( 'serialiser', @_ ) ); }
Subroutine serialiser: called CC=1 SCAR=0.0
Pod documented
1004  
1005 # We merely register the variables the user wants to share
1006 # Next time we will fork, we will share those registered variables
1007 sub share
1008 24 ▶{
Subroutine share: called CC=11 SCAR=32.6
Pod documented
1009 24 my $self;
1010 24 ▶ $self = shift( @_ ) if( scalar( @_ ) && Scalar::Util::blessed( $_[0] ) && $_[0]->isa( 'Promise::Me' ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ and builtin::blessed($_[0]) and $_[0]->isa("Promise::Me") 0 24 24
Condition33%2/6
scalar @_ and builtin::blessed($_[0]) and $_[0]->isa("Promise::Me")
!ll&&!rl&&r
2400
scalar @_ and builtin::blessed($_[0])
!ll&&!rl&&r
0240
MC/DC0%0/3
scalar @_ and builtin::blessed($_[0]) and $_[0]->isa("Promise::Me")
scalar @_ builtin::blessed($_[0]) $_[0]->isa("Promise::Me")
Truth table25%1/4
A and B and C
A= scalar @_B= builtin::blessed($_[0])C= $_[0]->isa("Promise::Me")
ABCresult
0XX0
10X0
1100
1111
1011 # Sanity check
1012 24 foreach my $ref ( @_ )
1013 {
1014 48 my $type = lc( ref( $ref ) );
1015 48 ▶ print( STDERR __PACKAGE__, "::share: Checking variable '$ref'.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG 0 48 48
1016 48 ▶ if( $type !~ /^(array|hash|scalar)$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($type =~ /^(array|hash|scalar)$/) 0 48 48
1017 {
1018 0 ▶ warnings::warn( "Unsupported variable type '$type': '$ref'\n" ) if( warnings::enabled() || $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() or $Promise::Me::DEBUG 0 0 0
Condition0%0/3
warnings::enabled() or $Promise::Me::DEBUG
l!l&&r!l&&!r
000
MC/DC0%0/2
warnings::enabled() or $Promise::Me::DEBUG
warnings::enabled() $Promise::Me::DEBUG
Truth table0%0/3
A or B
A= warnings::enabled()B= $Promise::Me::DEBUG
ABresult
1X1
011
000
1019 0 next;
1020 }
1021 }
1022 24 ▶ printf( STDERR "%s::share: Calling _share_vars() for %d variables.\n", __PACKAGE__, scalar( @_ ) ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 24 24
1023 24 ▶ &_share_vars( [@_] ) || return;
Branch: 1 branch
BranchTrueFalseTotal
&_share_vars([@_]) or return 24 0 24
1024 24 return(1);
1025 }
1026  
1027 16 ▶sub share_auto_destroy { return( shift->_set_get_boolean( 'share_auto_destroy', @_ ) ); }
Subroutine share_auto_destroy: called CC=1 SCAR=0.0
Pod documented
1028  
1029 144 ▶sub shared_mem { return( shift->_set_get_object_without_init( 'shared_mem', [qw( Module::Generic::SharedMem Module::Generic::SharedMemXS Module::Generic::File::Cache Module::Generic::File::Mmap )], @_ ) ); }
Subroutine shared_mem: called CC=1 SCAR=0.0
Pod documented
1030  
1031 0 ▶sub shared_mem_global { return( shift->_set_get_object( 'shared_mem_global',[qw( Module::Generic::SharedMem Module::Generic::SharedMemXS Module::Generic::File::Cache Module::Generic::File::Mmap )], @_ ) ); }
Subroutine shared_mem_global: not called CC=1 SCAR=6.9
Pod undocumented
1032  
1033 12 ▶sub shared_space_destroy { return( shift->_set_get_boolean( 'shared_space_destroy', @_ ) ); }
Subroutine shared_space_destroy: called CC=1 SCAR=0.0
Pod documented
1034  
1035 0 ▶sub shared_vars_mem_size { return( shift->_set_get_mem_size( 'shared_vars_mem_size', @_ ) ); }
Subroutine shared_vars_mem_size: not called CC=1 SCAR=6.9
Pod documented
1036  
1037 92 ▶sub tmpdir { return( shift->_set_get_file( 'tmpdir', @_ ) ); }
Subroutine tmpdir: called CC=1 SCAR=0.0
Pod documented
1038  
1039 # $d->then(sub{ do_something() })->catch()->finally();
1040 sub then
1041 64 ▶{
Subroutine then: called CC=15 SCAR=33.7
Pod documented
1042 64 my $self = shift( @_ );
1043 64 ▶ @_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and not defined $_[0] 0 64 64
Condition33%1/3
scalar @_ == 1 and not defined $_[0]
!ll&&!rl&&r
0640
MC/DC0%0/2
scalar @_ == 1 and not defined $_[0]
scalar @_ == 1 not defined $_[0]
Truth table33%1/3
A and not(B)
A= scalar @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
1044 64 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 64 0 64
1045 {
1046 64 my( $pass, $fail ) = @_;
1047 64 ▶ return( $self->error( "then() only accepts one or two code references. Value provided for resolve was '$pass'." ) ) if( ref( $pass ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $pass ne "CODE" 0 64 64
1048 64 ▶ return( $self->error( "then() only accepts one or two code references. Value provided for reject was '$fail'." ) ) if( defined( $fail ) && ref( $fail ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if defined $fail and ref $fail ne "CODE" 0 64 64
Condition33%1/3
defined $fail and ref $fail ne "CODE"
!ll&&!rl&&r
6400
MC/DC0%0/2
defined $fail and ref $fail ne "CODE"
defined $fail ref $fail ne "CODE"
Truth table33%1/3
A and B
A= defined $failB= ref $fail ne "CODE"
ABresult
0X0
100
111
1049 64 $self->add_resolve_handler( $pass );
1050 64 ▶ $self->add_reject_handler( $fail ) if( defined( $fail ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $fail 0 64 64
1051 64 ▶ my $vals = $self->{_saved_values} || [];
Condition50%1/2
$self->{'_saved_values'} || []
l!l
640
MC/DC0%0/1
$self->{'_saved_values'} || []
$self->{'_saved_values'}
Truth table50%1/2
A
A= $self->{'_saved_values'}
Aresult
11
00
1052 # Now that we have a new handler, call resolve to process the saved values
1053 64 ▶ if( $self->executed && scalar( @$vals ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->executed and scalar @$vals) 0 64 64
Condition50%1/2
$self->executed and scalar @$vals
!ll
640
MC/DC0%0/1
$self->executed and scalar @$vals
$self->executed
Truth table50%1/2
A
A= $self->executed
Aresult
00
11
1054 {
1055 0 ▶ if( $self->rejected )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->rejected) { } 0 0 0
1056 {
1057 0 return( $self->reject( @$vals ) );
1058 }
1059 else
1060 {
1061 0 return( $self->resolve( @$vals ) );
1062 }
1063 }
1064 }
1065  
1066 # Is there more chaining, or is this the end of the chain?
1067 # If the latter, we then start executing our codes
1068 64 ▶ unless( Wanted::want( 'OBJECT' ) || $self->executed )
Branch: 1 branch
BranchTrueFalseTotal
unless (Wanted::want("OBJECT") or $self->executed) 20 44 64
Condition66%2/3
Wanted::want("OBJECT") or $self->executed
l!l&&r!l&&!r
44020
MC/DC50%1/2
Wanted::want("OBJECT") or $self->executed
Wanted::want("OBJECT") $self->executed
Truth table66%2/3
A or B
A= Wanted::want("OBJECT")B= $self->executed
ABresult
1X1
011
000
1069 {
1070 20 $self->no_more_chaining(1);
1071 20 ▶ $self->exec || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->exec or return $self->pass_error 16 0 16
1072 }
1073 60 return( $self );
1074 }
1075  
1076 8 ▶sub timeout { return( shift->_set_get_scalar( 'timeout', @_ ) ); }
Subroutine timeout: called CC=1 SCAR=0.0
Pod documented
1077  
1078 sub unlock
1079 0 ▶{
Subroutine unlock: not called CC=13 SCAR=52.0
Pod documented
1080 0 my $self;
1081 0 ▶ $self = shift( @_ ) if( scalar( @_ ) && Scalar::Util::blessed( $_[0] ) && $_[0]->isa( 'Promise::Me' ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ and builtin::blessed($_[0]) and $_[0]->isa("Promise::Me") 0 0 0
Condition0%0/6
scalar @_ and builtin::blessed($_[0]) and $_[0]->isa("Promise::Me")
!ll&&!rl&&r
000
scalar @_ and builtin::blessed($_[0])
!ll&&!rl&&r
000
MC/DC0%0/3
scalar @_ and builtin::blessed($_[0]) and $_[0]->isa("Promise::Me")
scalar @_ builtin::blessed($_[0]) $_[0]->isa("Promise::Me")
Truth table0%0/4
A and B and C
A= scalar @_B= builtin::blessed($_[0])C= $_[0]->isa("Promise::Me")
ABCresult
0XX0
10X0
1100
1111
1082 0 my $type;
1083 0 ▶ $type = pop( @_ ) if( !ref( $_[-1] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[-1] 0 0 0
1084 0 foreach my $ref ( @_ )
1085 {
1086 0 my $tied = tied( $ref );
1087 0 ▶ if( defined( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self) { } 0 0 0
1088 {
1089 }
1090 else
1091 {
1092 0 ▶ print( STDERR __PACKAGE__, "::unlock: Checking if variable '$ref' is tied -> ", ( Scalar::Util::blessed( $tied ) ? 'Yes' : 'No' ), "\n" ) if( $DEBUG >= 4 );
Branch: 2 branches
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 0 0
builtin::blessed($tied) ? : 0 0 0
1093 }
1094 0 ▶ if( Scalar::Util::blessed( $tied ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($tied) and $tied->isa("Promise::Me::Share")) 0 0 0
Condition0%0/3
builtin::blessed($tied) and $tied->isa("Promise::Me::Share")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($tied) and $tied->isa("Promise::Me::Share")
builtin::blessed($tied) $tied->isa("Promise::Me::Share")
Truth table0%0/3
A and B
A= builtin::blessed($tied)B= $tied->isa("Promise::Me::Share")
ABresult
0X0
100
111
1095 $tied->isa( 'Promise::Me::Share' ) )
1096 {
1097 0 ▶ defined( $type ) ? $tied->unlock( $type ) : $tied->unlock;
Branch: 1 branch
BranchTrueFalseTotal
defined $type ? : 0 0 0
1098 }
1099 }
1100 0 ▶ return( $self ) if( $self );
Branch: 1 branch
BranchTrueFalseTotal
if $self 0 0 0
1101 }
1102  
1103 sub unshare
1104 0 ▶{
Subroutine unshare: not called CC=10 SCAR=47.0
Pod documented
1105 0 my $self;
1106 0 ▶ $self = shift( @_ ) if( scalar( @_ ) && Scalar::Util::blessed( $_[0] ) && $_[0]->isa( 'Promise::Me' ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ and builtin::blessed($_[0]) and $_[0]->isa("Promise::Me") 0 0 0
Condition0%0/6
scalar @_ and builtin::blessed($_[0]) and $_[0]->isa("Promise::Me")
!ll&&!rl&&r
000
scalar @_ and builtin::blessed($_[0])
!ll&&!rl&&r
000
MC/DC0%0/3
scalar @_ and builtin::blessed($_[0]) and $_[0]->isa("Promise::Me")
scalar @_ builtin::blessed($_[0]) $_[0]->isa("Promise::Me")
Truth table0%0/4
A and B and C
A= scalar @_B= builtin::blessed($_[0])C= $_[0]->isa("Promise::Me")
ABCresult
0XX0
10X0
1100
1111
1107 0 my $pack = caller;
1108 0 ▶ $SHARED->{ $pack } = {} if( !CORE::exists( $SHARED->{ $pack } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Promise::Me::SHARED->{$pack} 0 0 0
1109 0 my @removed = ();
1110 0 ▶ printf( STDERR "%s::unshare: Unsharing %d variables called from package '$pack'.\n", __PACKAGE__, scalar( @_ ) ) if( $DEBUG >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 3 0 0 0
1111 0 foreach my $ref ( @_ )
1112 {
1113 0 my $addr = Scalar::Util::refaddr( $ref );
1114 0 my $type = lc( ref( $ref ) );
1115 0 ▶ if( CORE::exists( $SHARED->{ $pack }->{ $addr } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Promise::Me::SHARED->{$pack}{$addr}) { } 0 0 0
1116 {
1117 0 push( @removed, CORE::delete( $SHARED->{ $pack }->{ $addr } ) );
1118 0 next;
1119 }
1120 else
1121 {
1122 0 ▶ print( STDERR __PACKAGE__, "::unshare: Variable '$ref' of type '$type' could not be found in our registry.\n" ) if( $DEBUG >= 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 3 0 0 0
1123 }
1124 }
1125 0 ▶ return( scalar( @removed ) > 1 ? @removed : $removed[0] );
Branch: 1 branch
BranchTrueFalseTotal
scalar @removed > 1 ? : 0 0 0
1126 }
1127  
1128 0 ▶sub use_async { return( shift->_set_get_boolean( 'use_async', @_ ) ); }
Subroutine use_async: not called CC=1 SCAR=6.9
Pod documented
1129  
1130 72 ▶sub use_cache_file { return( shift->_set_get_boolean( 'use_cache_file', @_ ) ); }
Subroutine use_cache_file: called CC=1 SCAR=0.0
Pod documented
1131  
1132 20 ▶sub use_mmap { return( shift->_set_get_boolean( 'use_mmap', @_ ) ); }
Subroutine use_mmap: called CC=1 SCAR=0.0
Pod documented
1133  
1134 sub wait
1135 0 ▶{
Subroutine wait: not called CC=6 SCAR=37.4
Pod documented
1136 0 my $self = shift( @_ );
1137 0 my @callinfo = caller;
1138  
1139 # $prom->wait(1)
1140 # $prom->wait(0)
1141 0 ▶ if( @_ )
Branch: 3 branches
BranchTrueFalseTotal
if (@_) { } 0 0 0
elsif (Wanted::want('OBJECT')) { } 0 0 0
elsif (Wanted::want('VOID') or Wanted::want('SCALAR')) { } 0 0 0
1142 {
1143 0 $self->_set_get_boolean( 'wait', @_ );
1144 }
1145 # In chaining, without argument, we set this implicitly to true
1146 # $prom->then(sub{})->wait->catch(sub{})
1147 elsif( Wanted::want( 'OBJECT' ) )
1148 {
1149 0 $self->_set_get_boolean( 'wait', 1 );
1150 }
1151 ▶ elsif( Wanted::want( 'VOID' ) || Wanted::want( 'SCALAR' ) )
Condition0%0/3
Wanted::want("VOID") or Wanted::want("SCALAR")
l!l&&r!l&&!r
000
MC/DC0%0/2
Wanted::want("VOID") or Wanted::want("SCALAR")
Wanted::want("VOID") Wanted::want("SCALAR")
Truth table0%0/3
A or B
A= Wanted::want("VOID")B= Wanted::want("SCALAR")
ABresult
1X1
011
000
1152 {
1153 0 $self->_set_get_boolean( 'wait', 1 );
1154 0 $self->no_more_chaining(1);
1155 0 ▶ $self->exec || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->exec or return $self->pass_error 0 0 0
1156 }
1157 else
1158 {
1159 0 return( $self->_set_get_boolean( 'wait' ) );
1160 }
1161 0 return( $self );
1162 }
1163  
1164 sub _browse
1165 0 ▶{
Subroutine _browse: not called CC=7 SCAR=40.3
1166 0 my $self = shift( @_ );
1167 0 my $elem = shift( @_ );
1168 0 ▶ my $level = shift( @_ ) || 0;
Condition0%0/2
shift @_ || 0
l!l
00
MC/DC0%0/1
shift @_ || 0
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1169 0 ▶ return if( !$elem->children );
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->children 0 0 0
1170 0 foreach my $e ( $elem->elements )
1171 {
1172 0 ▶ printf( STDERR "%sElement: [%d] class %s, value '%s'\n", ( '.' x $level ), $e->line_number, $e->class, $e->content ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 0 0
1173 0 ▶ if( $e->can('children') && $e->children )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->can("children") and $e->children) 0 0 0
Condition0%0/3
$e->can("children") and $e->children
!ll&&!rl&&r
000
MC/DC0%0/2
$e->can("children") and $e->children
$e->can("children") $e->children
Truth table0%0/3
A and B
A= $e->can("children")B= $e->children
ABresult
0X0
100
111
1174 {
1175 0 $self->_browse( $e, $level + 1 );
1176 }
1177 }
1178 }
1179  
1180 sub _parse
1181 0 ▶{
Subroutine _parse: not called CC=38 SCAR=72.5
1182 0 my $self = shift( @_ );
1183 0 my $elem = shift( @_ );
1184 0 ▶ $self->_browse( $elem ) if( $self->debug >= 6 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug >= 6 0 0 0
1185  
1186 26 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1187 0 ▶ if( !Scalar::Util::blessed( $elem ) || !$elem->isa( 'PPI::Node' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($elem) and $elem->isa("PPI::Node")) 0 0 0
Condition0%0/3
builtin::blessed($elem) and $elem->isa("PPI::Node")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($elem) and $elem->isa("PPI::Node")
builtin::blessed($elem) $elem->isa("PPI::Node")
Truth table0%0/3
A and B
A= builtin::blessed($elem)B= $elem->isa("PPI::Node")
ABresult
0X0
100
111
1188 {
1189 0 return( $self->_error( "Element provided to parse is not a PPI::Node object" ) );
1190 }
1191  
1192 # Check for PPI statements that would have caught some unrelated statements before
1193 my $sts = $elem->find(sub
1194 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1195 0 my( $top, $this ) = @_;
1196 0 ▶ if( $this->class eq 'PPI::Statement' && substr( $this->content, 0, 5 ) ne 'async' )
Branch: 1 branch
BranchTrueFalseTotal
if ($this->class eq "PPI::Statement" and substr($this->content, 0, 5) ne "async") 0 0 0
Condition0%0/3
$this->class eq "PPI::Statement" and substr($this->content, 0, 5) ne "async"
!ll&&!rl&&r
000
MC/DC0%0/2
$this->class eq "PPI::Statement" and substr($this->content, 0, 5) ne "async"
$this->class eq "PPI::Statement" substr($this->content, 0, 5) ne "async"
Truth table0%0/3
A and B
A= $this->class eq "PPI::Statement"B= substr($this->content, 0, 5) ne "async"
ABresult
0X0
100
111
1197 {
1198 my $found_async = $this->find_first(sub
1199 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1200 0 my( $orig, $that ) = @_;
1201 0 ▶ return( $that->class eq 'PPI::Token::Word' && $that->content eq 'async' );
Condition0%0/3
$that->class eq 'PPI::Token::Word' && $that->content eq 'async'
!ll&&!rl&&r
000
MC/DC0%0/2
$that->class eq 'PPI::Token::Word' && $that->content eq 'async'
$that->class eq 'PPI::Token::Word' $that->content eq 'async'
Truth table0%0/3
A && B
A= $that->class eq 'PPI::Token::Word'B= $that->content eq 'async'
ABresult
0X0
100
111
1202 0 });
1203 }
1204 0 });
1205 0 ▶ $sts ||= [];
Condition0%0/2
$sts ||= []
l!l
00
MC/DC0%0/1
$sts ||= []
$sts
Truth table0%0/2
A
A= $sts
Aresult
11
00
1206 0 ▶ if( scalar( @$sts ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$sts) 0 0 0
1207 {
1208 # We take everything from the 'async sub' up until the end of this statements and we move it to its own separate statement
1209 0 STATEMENT: foreach my $st ( @$sts )
1210 {
1211 0 my $temps = [];
1212 0 my $kids = [$st->children];
1213 0 ▶ for( my $i = 0; $i < scalar( @$kids ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$kids) 0 0 0
1214 {
1215 0 my $e = $kids->[$i];
1216 0 ▶ if( $e->class eq 'PPI::Token::Word' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($e->class eq "PPI::Token::Word" and $e->content eq "async") 0 0 0
Condition0%0/3
$e->class eq "PPI::Token::Word" and $e->content eq "async"
!ll&&!rl&&r
000
MC/DC0%0/2
$e->class eq "PPI::Token::Word" and $e->content eq "async"
$e->class eq "PPI::Token::Word" $e->content eq "async"
Truth table0%0/3
A and B
A= $e->class eq "PPI::Token::Word"B= $e->content eq "async"
ABresult
0X0
100
111
1217 $e->content eq 'async' )
1218 {
1219 0 ▶ if( $e->snext_sibling &&
Branch: 1 branch
BranchTrueFalseTotal
if ($e->snext_sibling and $e->snext_sibling->class eq 'PPI::Token::Word' and $e->snext_sibling->content eq 'sub') { } 0 0 0
Condition0%0/6
$e->snext_sibling and $e->snext_sibling->class eq "PPI::Token::Word" and $e->snext_sibling->content eq "sub"
!ll&&!rl&&r
000
$e->snext_sibling and $e->snext_sibling->class eq "PPI::Token::Word"
!ll&&!rl&&r
000
MC/DC0%0/3
$e->snext_sibling and $e->snext_sibling->class eq "PPI::Token::Word" and $e->snext_sibling->content eq "sub"
$e->snext_sibling $e->snext_sibling->class eq "PPI::Token::Word" $e->snext_sibling->content eq "sub"
Truth table0%0/4
A and B and C
A= $e->snext_siblingB= $e->snext_sibling->class eq "PPI::Token::Word"C= $e->snext_sibling->content eq "sub"
ABCresult
0XX0
10X0
1100
1111
1220 $e->snext_sibling->class eq 'PPI::Token::Word' &&
1221 $e->snext_sibling->content eq 'sub' )
1222 {
1223 0 push( @$temps, splice( @$kids, $i ) );
1224 0 last;
1225 }
1226 else
1227 {
1228 0 require Carp;
1229 0 Carp::croak( "You can only use async on a subroutine (including method) at line ", $e->line_number, "." );
1230 }
1231 }
1232 }
1233 0 my $code = join( '', map( $_->content, @$temps ) );
1234 0 ▶ my $tmp = PPI::Document->new( \$code, readonly => 1 ) || die( "Unable to parse: ", PPI::Document->errstr, "\n$code\n" );
Condition0%0/2
'PPI::Document'->new(\$code, 'readonly', 1) || die('Unable to parse: ', 'PPI::Document'->errstr, "\n$code\n")
l!l
00
MC/DC0%0/1
'PPI::Document'->new(\$code, 'readonly', 1) || die('Unable to parse: ', 'PPI::Document'->errstr, "\n$code\n")
'PPI::Document'->new(\$code, 'readonly', 1)
Truth table0%0/2
A
A= 'PPI::Document'->new(\$code, 'readonly', 1)
Aresult
11
00
1235 # PPI::Statement
1236 0 my $new = [$tmp->children]->[0];
1237 # Detach it from its current parent
1238 0 $new->remove;
1239 0 $_->delete for( @$temps );
1240 0 ▶ $st->__insert_after( $new ) || die( "Could not insert element of class '", $new->class, "' after former element of class '", $st->class, "'\n" );
Branch: 1 branch
BranchTrueFalseTotal
$st->__insert_after($new) or die "Could not insert element of class '", $new->class, "' after former element of class '", $st->class, "'\n" 0 0 0
1241 }
1242 }
1243  
1244 my $ref = $elem->find(sub
1245 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1246 0 my( $top, $this ) = @_;
1247 0 ▶ return( $this->class eq 'PPI::Statement' && substr( $this->content, 0, 5 ) eq 'async' );
Condition0%0/3
$this->class eq 'PPI::Statement' && substr($this->content, 0, 5) eq 'async'
!ll&&!rl&&r
000
MC/DC0%0/2
$this->class eq 'PPI::Statement' && substr($this->content, 0, 5) eq 'async'
$this->class eq 'PPI::Statement' substr($this->content, 0, 5) eq 'async'
Truth table0%0/3
A && B
A= $this->class eq 'PPI::Statement'B= substr($this->content, 0, 5) eq 'async'
ABresult
0X0
100
111
1248 0 });
1249 0 ▶ $ref ||= [];
Condition0%0/2
$ref ||= []
l!l
00
MC/DC0%0/1
$ref ||= []
$ref
Truth table0%0/2
A
A= $ref
Aresult
11
00
1250 0 ▶ return( $self->_error( "Failed to find any async subroutines: $@" ) ) if( !defined( $ref ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ref 0 0 0
1251 0 ▶ return if( !scalar( @$ref ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$ref 0 0 0
1252  
1253 0 my $asyncs = [];
1254 0 foreach my $e ( @$ref )
1255 {
1256 0 ▶ if( $e->content !~ /^async[[:blank:]\h\v]+sub[[:blank:]\h\v]+/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($e->content =~ /^async[[:blank:]\h\v]+sub[[:blank:]\h\v]+/) 0 0 0
1257 {
1258 0 require Carp;
1259 0 Carp::croak( "You can only use async on a subroutine (including method) at line ", $e->line_number, "." );
1260 }
1261 # Now, check if we do not have two consecutive async sub ... statements
1262 # $tmp_nodes will contains all the nodes from the start of the async to the end
1263 # of the subroutine block.
1264 0 my $tmp_nodes = [];
1265 # We already know the first item is a valid async statement, so we state we are
1266 # inside it and continue until we find a first block
1267 0 my $block_kids = [$e->children];
1268 0 my $prev_sib = $block_kids->[0];
1269 0 push( @$tmp_nodes, $prev_sib );
1270 0 my $to_remove = [];
1271 # The last element after which we insert the others
1272 0 my $last = $e;
1273 0 my $sib;
1274 # while( ( $sib = $prev_sib->next_sibling ) )
1275 # foreach my $sib ( @$block_kids )
1276 0 ▶ for( my $i = 1; $i < scalar( @$block_kids ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$block_kids) 0 0 0
1277 {
1278 0 my $sib = $block_kids->[$i];
1279 0 ▶ if( scalar( @$tmp_nodes ) && $sib->class eq 'PPI::Structure::Block' )
Branch: 3 branches
BranchTrueFalseTotal
if (scalar @$tmp_nodes and $sib->class eq 'PPI::Structure::Block') { } 0 0 0
elsif (not scalar @$tmp_nodes and $sib->class eq 'PPI::Token::Word' and $sib->content eq 'async') { } 0 0 0
elsif (scalar @$tmp_nodes) { } 0 0 0
Condition0%0/3
scalar @$tmp_nodes and $sib->class eq "PPI::Structure::Block"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tmp_nodes and $sib->class eq "PPI::Structure::Block"
scalar @$tmp_nodes $sib->class eq "PPI::Structure::Block"
Truth table0%0/3
A and B
A= scalar @$tmp_nodesB= $sib->class eq "PPI::Structure::Block"
ABresult
0X0
100
111
1280 {
1281 0 push( @$tmp_nodes, $sib );
1282 0 my $code = join( '', map( $_->content, @$tmp_nodes ) );
1283 0 ▶ my $tmp = PPI::Document->new( \$code, readonly => 1 ) || die( "Unable to parse: ", PPI::Document->errstr, "\n$code\n" );
Condition0%0/2
'PPI::Document'->new(\$code, 'readonly', 1) || die('Unable to parse: ', 'PPI::Document'->errstr, "\n$code\n")
l!l
00
MC/DC0%0/1
'PPI::Document'->new(\$code, 'readonly', 1) || die('Unable to parse: ', 'PPI::Document'->errstr, "\n$code\n")
'PPI::Document'->new(\$code, 'readonly', 1)
Truth table0%0/2
A
A= 'PPI::Document'->new(\$code, 'readonly', 1)
Aresult
11
00
1284 # PPI::Statement
1285 0 my $new = [$tmp->children]->[0];
1286 # Detach it from its current parent
1287 0 $new->remove;
1288 # Can insert another structure or another token
1289 0 ▶ $last->__insert_after( $new ) || die( "Could not insert element of class '", $new->class, "' after former element of class '", $sib->class, "'\n" );
Branch: 1 branch
BranchTrueFalseTotal
$last->__insert_after($new) or die "Could not insert element of class '", $new->class, "' after former element of class '", $sib->class, "'\n" 0 0 0
1290 0 push( @$to_remove, @$tmp_nodes );
1291 # $prev_sib = $sib;
1292 0 $last = $new;
1293 0 push( @$asyncs, $new );
1294 0 $tmp_nodes = [];
1295 # next;
1296 }
1297 ▶ elsif( !scalar( @$tmp_nodes ) &&
Condition0%0/6
not scalar @$tmp_nodes and $sib->class eq "PPI::Token::Word" and $sib->content eq "async"
!ll&&!rl&&r
000
not scalar @$tmp_nodes and $sib->class eq "PPI::Token::Word"
!ll&&!rl&&r
000
MC/DC0%0/3
not scalar @$tmp_nodes and $sib->class eq "PPI::Token::Word" and $sib->content eq "async"
not scalar @$tmp_nodes $sib->class eq "PPI::Token::Word" $sib->content eq "async"
Truth table0%0/4
not(A) and B and C
A= not scalar @$tmp_nodesB= $sib->class eq "PPI::Token::Word"C= $sib->content eq "async"
ABCresult
0XX0
10X0
1100
1111
1298 $sib->class eq 'PPI::Token::Word' &&
1299 $sib->content eq 'async' )
1300 {
1301 0 ▶ if( $sib->snext_sibling &&
Branch: 1 branch
BranchTrueFalseTotal
if ($sib->snext_sibling and $sib->snext_sibling->class eq 'PPI::Token::Word' and $sib->snext_sibling->content eq 'sub') { } 0 0 0
Condition0%0/6
$sib->snext_sibling and $sib->snext_sibling->class eq "PPI::Token::Word" and $sib->snext_sibling->content eq "sub"
!ll&&!rl&&r
000
$sib->snext_sibling and $sib->snext_sibling->class eq "PPI::Token::Word"
!ll&&!rl&&r
000
MC/DC0%0/3
$sib->snext_sibling and $sib->snext_sibling->class eq "PPI::Token::Word" and $sib->snext_sibling->content eq "sub"
$sib->snext_sibling $sib->snext_sibling->class eq "PPI::Token::Word" $sib->snext_sibling->content eq "sub"
Truth table0%0/4
A and B and C
A= $sib->snext_siblingB= $sib->snext_sibling->class eq "PPI::Token::Word"C= $sib->snext_sibling->content eq "sub"
ABCresult
0XX0
10X0
1100
1111
1302 $sib->snext_sibling->class eq 'PPI::Token::Word' &&
1303 $sib->snext_sibling->content eq 'sub' )
1304 {
1305 0 push( @$tmp_nodes, $sib );
1306 }
1307 else
1308 {
1309 0 require Carp;
1310 0 Carp::croak( "You can only use async on a subroutine (including method) at line ", $sib->line_number, "." );
1311 }
1312 }
1313 elsif( scalar( @$tmp_nodes ) )
1314 {
1315 0 push( @$tmp_nodes, $sib );
1316 }
1317 else
1318 {
1319 0 $sib->remove;
1320 0 $last->__insert_after( $sib );
1321 0 $last = $sib;
1322 }
1323 0 $prev_sib = $sib;
1324 }
1325 # Remove what needs to be removed
1326 0 $_->delete for( @$to_remove );
1327 }
1328 0 foreach my $e ( @$asyncs )
1329 {
1330 0 my @kids = $e->children;
1331 0 my $async = $kids[0];
1332 0 my $sub = $async->snext_sibling;
1333 0 my $name = $sub->snext_sibling;
1334 0 my $block = $e->find_first( 'PPI::Structure::Block' );
1335 0 my $nl_braces = {};
1336 0 my $this = $block;
1337 0 my $before = '';
1338 0 ▶ while( ( $this = $this->previous_sibling ) && $this->class eq 'PPI::Token::Whitespace' )
Branch: 1 branch
BranchTrueFalseTotal
if ($this = $this->previous_sibling and $this->class eq "PPI::Token::Whitespace") 0 0 0
Condition0%0/3
$this = $this->previous_sibling and $this->class eq "PPI::Token::Whitespace"
!ll&&!rl&&r
000
MC/DC0%0/2
$this = $this->previous_sibling and $this->class eq "PPI::Token::Whitespace"
$this = $this->previous_sibling $this->class eq "PPI::Token::Whitespace"
Truth table0%0/3
A and B
A= $this = $this->previous_siblingB= $this->class eq "PPI::Token::Whitespace"
ABresult
0X0
100
111
1339 {
1340 0 $before .= $this->content;
1341 }
1342 # We do not care about spaces after the block, because our element $e being
1343 # processed only contains elements up to the closing brace. So whatever there is
1344 # after is not our concern.
1345 0 $nl_braces->{open_before} = () = $before =~ /(\v)/g;
1346 0 my $open_spacer = ( "\n" x $nl_braces->{open_before} );
1347  
1348 0 my $code = qq{sub $name ${open_spacer}{ Promise::Me::async($name => sub $block, args => [\@_], use_async => 1); }};
1349 0 ▶ my $doc = PPI::Document->new( \$code, readonly => 1 ) || die( "Unable to parse: ", PPI::Document->errstr, "\n$code\n" );
Condition0%0/2
'PPI::Document'->new(\$code, 'readonly', 1) || die('Unable to parse: ', 'PPI::Document'->errstr, "\n$code\n")
l!l
00
MC/DC0%0/1
'PPI::Document'->new(\$code, 'readonly', 1) || die('Unable to parse: ', 'PPI::Document'->errstr, "\n$code\n")
'PPI::Document'->new(\$code, 'readonly', 1)
Truth table0%0/2
A
A= 'PPI::Document'->new(\$code, 'readonly', 1)
Aresult
11
00
1350 0 my $new = [$doc->children]->[0];
1351 # Need to detach it first from its current parent before we can re-allocate it
1352 0 $new->remove;
1353 0 $e->replace( $new );
1354 }
1355 0 return( $elem );
1356 }
1357  
1358 sub _reject_resolve
1359 44 ▶{
Subroutine _reject_resolve: called CC=9 SCAR=24.3
1360 44 my $self = shift( @_ );
1361 44 my $what = shift( @_ );
1362 44 my $shm = $self->shared_mem;
1363 44 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 36 8 44
1364 {
1365 36 my $val = shift( @_ );
1366 36 ▶ if( $shm )
Branch: 1 branch
BranchTrueFalseTotal
if ($shm) { } 36 0 36
1367 {
1368 36 my $hash = $shm->read;
1369 36 ▶ $hash = {} if( ref( $hash ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $hash ne "HASH" 1 35 36
1370 36 $hash->{ $what } = $val;
1371 # Locking is done inside 'write'
1372 # $shm->lock( LOCK_EX );
1373 36 my $rv = $shm->write( $hash );
1374 36 ▶ if( !defined( $rv ) && $shm->error )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rv and $shm->error) 0 36 36
Condition33%1/3
not defined $rv and $shm->error
!ll&&!rl&&r
3600
MC/DC0%0/2
not defined $rv and $shm->error
not defined $rv $shm->error
Truth table33%1/3
not(A) and B
A= not defined $rvB= $shm->error
ABresult
0X0
100
111
1375 {
1376 # $shm->unlock;
1377 0 ▶ return( $self->error( "Unable to write data to shared space with serialiser '", ( $self->{serialiser} // '' ), "' using object (", overload::StrVal( $shm ), "): ", $shm->error ) );
Condition0%0/2
$self->{"serialiser"} // ""
l!l
00
MC/DC0%0/1
$self->{"serialiser"} // ""
$self->{"serialiser"}
Truth table0%0/2
A
A= $self->{"serialiser"}
Aresult
11
00
1378 }
1379 # $shm->unlock;
1380 }
1381 else
1382 {
1383 0 ▶ warn( "Shared space object not set or lost!" ) if( $self->_is_warnings_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled 0 0 0
1384 }
1385 36 $self->_set_get_boolean( $what, $val );
1386 }
1387 else
1388 {
1389 8 my $hash = $shm->read;
1390 8 ▶ return( $hash ) unless( ref( $hash ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $hash 0 8 8
1391 8 $self->{shared} = $hash;
1392 8 return( $hash->{ $what } );
1393 }
1394 36 return( $self->_set_get_boolean( $what ) );
1395 }
1396  
1397 sub _set_exit_values
1398 8 ▶{
Subroutine _set_exit_values: called CC=1 SCAR=0.0
1399 8 my $self = shift( @_ );
1400 8 my $bit = shift( @_ );
1401 8 $self->exit_status( ( $bit >> 8 ) );
1402 8 $self->exit_bit( $bit );
1403 8 $self->exit_signal( ( $bit & 127 ) );
1404 8 $self->has_coredump( ( $bit & 128 ) );
1405 8 return( $self );
1406 }
1407  
1408 sub _set_get_mem_size
1409 56 ▶{
Subroutine _set_get_mem_size: called CC=5 SCAR=27.1
1410 56 my $self = shift( @_ );
1411 56 my $field = shift( @_ );
1412 56 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 56 56
1413 {
1414 0 my $val = shift( @_ );
1415 0 ▶ if( CORE::defined( $val ) && CORE::length( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and length $val) 0 0 0
Condition0%0/3
defined $val and length $val
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and length $val
defined $val length $val
Truth table0%0/3
A and B
A= defined $valB= length $val
ABresult
0X0
100
111
1416 {
1417 0 my $map =
1418 {
1419 K => 1024,
1420 M => ( 1024 ** 2 ),
1421 G => ( 1024 ** 3 ),
1422 T => ( 1024 ** 4 ),
1423 };
1424 0 ▶ if( CORE::exists( $map->{ substr( $val, -1, 1 ) } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$map{substr $val, -1, 1}) 0 0 0
1425 {
1426 0 $val = substr( $val, 0, length( $val ) - 1 ) * $map->{ substr( $val, -1, 1 ) };
1427 }
1428 }
1429 0 $self->_set_get_scalar( $field, int( $val ) );
1430 }
1431 56 return( $self->_set_get_scalar( $field, @_ ) );
1432 }
1433  
1434 sub _share_vars
1435 24 ▶{
Subroutine _share_vars: called CC=69 SCAR=61.4
1436 24 my $vars = shift( @_ );
1437 24 my $opts = {};
1438 24 ▶ $opts = pop( @_ ) if( scalar( @_ ) && ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ and ref $_[-1] eq "HASH" 0 24 24
Condition33%1/3
scalar @_ and ref $_[-1] eq "HASH"
!ll&&!rl&&r
2400
MC/DC0%0/2
scalar @_ and ref $_[-1] eq "HASH"
scalar @_ ref $_[-1] eq "HASH"
Truth table33%1/3
A and B
A= scalar @_B= ref $_[-1] eq "HASH"
ABresult
0X0
100
111
1439 # Nothing to do
1440 24 ▶ return if( !scalar( @$vars ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$vars 0 24 24
1441 24 ▶ $opts->{medium} //= $SHARE_MEDIUM;
Condition33%1/3
$opts->{"medium"} //= $Promise::Me::SHARE_MEDIUM
l!l&&r!l&&!r
0240
MC/DC0%0/2
$opts->{"medium"} //= $Promise::Me::SHARE_MEDIUM
$opts->{"medium"} $Promise::Me::SHARE_MEDIUM
Truth table33%1/3
A //= B
A= $opts->{"medium"}B= $Promise::Me::SHARE_MEDIUM
ABresult
1X1
011
000
1442 24 ▶ $opts->{use_cache_file} //= ( $opts->{medium} eq 'file' ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'medium'} eq 'file' ? : 12 12 24
Condition50%1/2
$opts->{"use_cache_file"} //= $opts->{"medium"} eq "file" ? 1 : 0
l!l
024
MC/DC0%0/1
$opts->{"use_cache_file"} //= $opts->{"medium"} eq "file" ? 1 : 0
$opts->{"use_cache_file"}
Truth table50%1/2
A
A= $opts->{"use_cache_file"}
Aresult
11
00
1443 24 ▶ $opts->{use_mmap} //= ( $opts->{medium} eq 'mmap' ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'medium'} eq 'mmap' ? : 0 24 24
Condition50%1/2
$opts->{"use_mmap"} //= $opts->{"medium"} eq "mmap" ? 1 : 0
l!l
024
MC/DC0%0/1
$opts->{"use_mmap"} //= $opts->{"medium"} eq "mmap" ? 1 : 0
$opts->{"use_mmap"}
Truth table50%1/2
A
A= $opts->{"use_mmap"}
Aresult
11
00
1444 24 ▶ $opts->{fallback} = $SHARE_FALLBACK if( !CORE::exists( $opts->{fallback} ) || !CORE::length( $opts->{fallback} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"fallback"} and length $opts->{"fallback"} 24 0 24
Condition33%1/3
exists $opts->{"fallback"} and length $opts->{"fallback"}
!ll&&!rl&&r
2400
MC/DC0%0/2
exists $opts->{"fallback"} and length $opts->{"fallback"}
exists $opts->{"fallback"} length $opts->{"fallback"}
Truth table33%1/3
A and B
A= exists $opts->{"fallback"}B= length $opts->{"fallback"}
ABresult
0X0
100
111
1445  
1446 24 ▶ print( STDERR __PACKAGE__, "::_share_vars: Using medium '", ( $opts->{medium} // 'undef' ), "', and serialiser '", ( $SERIALISER // 'undef' ), "'.\n" ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 24 24
Condition0%0/4
$opts->{"medium"} // "undef"
l!l
00
$Promise::Me::SERIALISER // "undef"
l!l
00
MC/DC0%0/1
$opts->{"medium"} // "undef"
$opts->{"medium"}
MC/DC0%0/1
$Promise::Me::SERIALISER // "undef"
$Promise::Me::SERIALISER
Truth table0%0/2
A
A= $opts->{"medium"}
Aresult
11
00
Truth table0%0/2
A
A= $Promise::Me::SERIALISER
Aresult
11
00
1447  
1448 24 my( $shm, $data );
1449 # By process id
1450 24 my $index = $$;
1451 24 ▶ unless( ref( $SHARED->{ $index } ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $Promise::Me::SHARED->{$index} eq "HASH") 12 12 24
1452 {
1453 12 $SHARED->{ $index } = {};
1454 }
1455  
1456 24 ▶ if( scalar( keys( %{$SHARED->{ $index }} ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$$Promise::Me::SHARED{$index};}) { } 12 12 24
1457 {
1458 12 ▶ print( STDERR __PACKAGE__, "::_share_vars: Re-using already shared variables.\n" ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 12 12
1459 12 my $first = [keys( %{$SHARED->{ $index }} )]->[0];
1460 12 my $ref = $SHARED->{ $index }->{ $first };
1461 12 my $type = lc( ref( $ref ) );
1462 12 ▶ my $tied = tied( $type eq 'array' ? @$ref : $type eq 'hash' ? %$ref : $$ref );
Branch: 2 branches
BranchTrueFalseTotal
$type eq 'array' ? : 0 12 12
$type eq 'hash' ? : 0 12 12
1463 12 ▶ unless( Scalar::Util::blessed( $tied ) && $tied->isa( 'Promise::Me::Share' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($tied) and $tied->isa("Promise::Me::Share")) 0 12 12
Condition33%1/3
builtin::blessed($tied) and $tied->isa("Promise::Me::Share")
!ll&&!rl&&r
0012
MC/DC0%0/2
builtin::blessed($tied) and $tied->isa("Promise::Me::Share")
builtin::blessed($tied) $tied->isa("Promise::Me::Share")
Truth table33%1/3
A and B
A= builtin::blessed($tied)B= $tied->isa("Promise::Me::Share")
ABresult
0X0
100
111
1464 {
1465 0 die( "Weirdly enough, the tied object found for an already shared variable ($ref) seems to be gone!\n" );
1466 }
1467 12 $shm = $tied->shared;
1468 12 $data = $shm->read;
1469 12 ▶ $data = {} if( ref( $data ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $data ne "HASH" 0 12 12
1470 }
1471 else
1472 {
1473 12 my $key = 'gl' . $$;
1474 12 ▶ print( STDERR __PACKAGE__, "::_share_vars: Initiating shared memory with key '$key'.\n" ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 12 12
1475 12 my $p =
1476 {
1477 create => 1,
1478 # destroy => $SHARE_AUTO_DESTROY,
1479 # Actually, we need to control when to remove the shared memory space, and
1480 # this needs to happen when this module ends
1481 destroy => 0,
1482 key => $key,
1483 mode => 0666,
1484 # storable => 1,
1485 # base64 => 1,
1486 };
1487 12 my $serialiser = $SERIALISER;
1488 12 ▶ $serialiser = lc( $serialiser ) if( defined( $serialiser ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $serialiser 12 0 12
1489 12 ▶ if( defined( $serialiser ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $serialiser and $serialiser eq 'sereal' || $serialiser eq 'storable' || $serialiser eq 'cbor') { } 12 0 12
Condition44%4/9
defined $serialiser and $serialiser eq "sereal" || $serialiser eq "storable" || $serialiser eq "cbor"
!ll&&!rl&&r
0012
$serialiser eq "sereal" or $serialiser eq "storable" or $serialiser eq "cbor"
l!l&&r!l&&!r
1200
$serialiser eq "sereal" or $serialiser eq "storable"
l!l&&r!l&&!r
660
MC/DC0%0/4
defined $serialiser and $serialiser eq "sereal" || $serialiser eq "storable" || $serialiser eq "cbor"
defined $serialiser $serialiser eq "sereal" $serialiser eq "storable" $serialiser eq "cbor"
Truth table40%2/5
A and B or C or D
A= defined $serialiserB= $serialiser eq "sereal"C= $serialiser eq "storable"D= $serialiser eq "cbor"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
1490 ( $serialiser eq 'sereal' || $serialiser eq 'storable' || $serialiser eq 'cbor' ) )
1491 {
1492 # $p->{ $serialiser } = 1;
1493 12 $p->{serialiser} = $serialiser;
1494 }
1495 # Default to Sereal, because it has better hook design to handle properly globs
1496 else
1497 {
1498 # $p->{sereal} = 1;
1499 0 $p->{serialiser} = 'sereal';
1500 }
1501  
1502 12 my $size = $SHARED_MEMORY_SIZE;
1503 12 ▶ $p->{size} = $size if( defined( $size ) && CORE::length( $size ) && int( $size ) > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if defined $size and length $size and int $size > 0 12 0 12
Condition33%2/6
defined $size and length $size and int $size > 0
!ll&&!rl&&r
0012
defined $size and length $size
!ll&&!rl&&r
0012
MC/DC0%0/3
defined $size and length $size and int $size > 0
defined $size length $size int $size > 0
Truth table25%1/4
A and B and C
A= defined $sizeB= length $sizeC= int $size > 0
ABCresult
0XX0
10X0
1100
1111
1504 12 ▶ if( $opts->{use_mmap} ||
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'use_mmap'} or $opts->{'medium'} eq 'mmap') { } 0 12 12
elsif ('Module::Generic::SharedMemXS'->supported and not $opts->{'use_cache_file'} or $opts->{'medium'} eq 'memory') { } 6 6 12
Condition33%1/3
$opts->{"use_mmap"} or $opts->{"medium"} eq "mmap"
l!l&&r!l&&!r
0012
MC/DC0%0/2
$opts->{"use_mmap"} or $opts->{"medium"} eq "mmap"
$opts->{"use_mmap"} $opts->{"medium"} eq "mmap"
Truth table33%1/3
A or B
A= $opts->{"use_mmap"}B= $opts->{"medium"} eq "mmap"
ABresult
1X1
011
000
1505 $opts->{medium} eq 'mmap' )
1506 {
1507 0 ▶ print( STDERR __PACKAGE__, "::_share_vars: Using Mmap as medium.\n" ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 0 0
1508 0 ▶ my $s = Module::Generic::File::Mmap->new( %$p ) ||
Condition0%0/2
'Module::Generic::File::Mmap'->new(%$p) || (return __PACKAGE__->pass_error('Module::Generic::File::Mmap'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::File::Mmap'->new(%$p) || (return __PACKAGE__->pass_error('Module::Generic::File::Mmap'->error))
'Module::Generic::File::Mmap'->new(%$p)
Truth table0%0/2
A
A= 'Module::Generic::File::Mmap'->new(%$p)
Aresult
11
00
1509 return( __PACKAGE__->pass_error( Module::Generic::File::Mmap->error ) );
1510 0 ▶ $shm = $s->open || return( __PACKAGE__->pass_error( $s->error ) );
Condition0%0/2
$s->open || (return __PACKAGE__->pass_error($s->error))
l!l
00
MC/DC0%0/1
$s->open || (return __PACKAGE__->pass_error($s->error))
$s->open
Truth table0%0/2
A
A= $s->open
Aresult
11
00
1511 }
1512 ▶ elsif( ( Module::Generic::SharedMemXS->supported && !$opts->{use_cache_file} ) ||
Condition66%4/6
"Module::Generic::SharedMemXS"->supported and not $opts->{"use_cache_file"} or $opts->{"medium"} eq "memory"
l!l&&r!l&&!r
606
"Module::Generic::SharedMemXS"->supported and not $opts->{"use_cache_file"}
!ll&&!rl&&r
066
MC/DC33%1/3
"Module::Generic::SharedMemXS"->supported and not $opts->{"use_cache_file"} or $opts->{"medium"} eq "memory"
"Module::Generic::SharedMemXS"->supported not $opts->{"use_cache_file"} $opts->{"medium"} eq "memory"
Truth table40%2/5
A and not(B) or C
A= "Module::Generic::SharedMemXS"->supportedB= not $opts->{"use_cache_file"}C= $opts->{"medium"} eq "memory"
ABCresult
11X1
0X11
1011
0X00
1000
1513 $opts->{medium} eq 'memory' )
1514 {
1515 6 ▶ print( STDERR __PACKAGE__, "::_share_vars: Using memory as medium.\n" ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 6 6
1516 6 ▶ my $s = Module::Generic::SharedMemXS->new( %$p ) || return( __PACKAGE__->error( "Unable to create shared memory object: ", Module::Generic::SharedMemXS->error ) );
Condition50%1/2
'Module::Generic::SharedMemXS'->new(%$p) || (return __PACKAGE__->error('Unable to create shared memory object: ', 'Module::Generic::SharedMemXS'->error))
l!l
60
MC/DC0%0/1
'Module::Generic::SharedMemXS'->new(%$p) || (return __PACKAGE__->error('Unable to create shared memory object: ', 'Module::Generic::SharedMemXS'->error))
'Module::Generic::SharedMemXS'->new(%$p)
Truth table50%1/2
A
A= 'Module::Generic::SharedMemXS'->new(%$p)
Aresult
11
00
1517 6 $shm = $s->open;
1518 6 ▶ if( !$shm )
Branch: 1 branch
BranchTrueFalseTotal
if (not $shm) { } 0 6 6
1519 {
1520 0 ▶ if( $opts->{fallback} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'fallback'}) { } 0 0 0
1521 {
1522 0 ▶ print( STDERR __PACKAGE__, "::_share_vars: Failed to open shared memory segment: ", $s->error, "\nFalling back to cache file.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG 0 0 0
1523 0 ▶ my $c = Module::Generic::File::Cache->new( %$p ) ||
Condition0%0/2
'Module::Generic::File::Cache'->new(%$p) || (return __PACKAGE__->error('Unable to create a shared cache file or a shared memory: ', 'Module::Generic::File::Cache'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::File::Cache'->new(%$p) || (return __PACKAGE__->error('Unable to create a shared cache file or a shared memory: ', 'Module::Generic::File::Cache'->error))
'Module::Generic::File::Cache'->new(%$p)
Truth table0%0/2
A
A= 'Module::Generic::File::Cache'->new(%$p)
Aresult
11
00
1524 return( __PACKAGE__->error( "Unable to create a shared cache file or a shared memory: ", Module::Generic::File::Cache->error ) );
1525 0 ▶ $shm = $c->open || return( __PACKAGE__->error( "Unable to create a shared cache file: ", $c->error ) );
Condition0%0/2
$c->open || (return __PACKAGE__->error('Unable to create a shared cache file: ', $c->error))
l!l
00
MC/DC0%0/1
$c->open || (return __PACKAGE__->error('Unable to create a shared cache file: ', $c->error))
$c->open
Truth table0%0/2
A
A= $c->open
Aresult
11
00
1526 }
1527 else
1528 {
1529 0 ▶ print( STDERR __PACKAGE__, "::_share_vars: Failed to open shared memory segment. Fallback is not permitted. Failing now.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG 0 0 0
1530 0 return( __PACKAGE__->error( "Unable to open shared memory object: ", $s->error ) );
1531 }
1532 }
1533 else
1534 {
1535 6 $shm->attach;
1536 }
1537 }
1538 # Fallback to cache file
1539 else
1540 {
1541 6 ▶ print( STDERR __PACKAGE__, "::_share_vars: No medium specified. Falling back to cache file.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG 0 6 6
1542 6 ▶ my $c = Module::Generic::File::Cache->new( %$p ) ||
Condition50%1/2
'Module::Generic::File::Cache'->new(%$p) || (return __PACKAGE__->error('Unable to create a shared cache file: ', 'Module::Generic::File::Cache'->error))
l!l
60
MC/DC0%0/1
'Module::Generic::File::Cache'->new(%$p) || (return __PACKAGE__->error('Unable to create a shared cache file: ', 'Module::Generic::File::Cache'->error))
'Module::Generic::File::Cache'->new(%$p)
Truth table50%1/2
A
A= 'Module::Generic::File::Cache'->new(%$p)
Aresult
11
00
1543 return( __PACKAGE__->error( "Unable to create a shared cache file: ", Module::Generic::File::Cache->error ) );
1544 6 ▶ $shm = $c->open || return( __PACKAGE__->error( "Unable to create a shared cache file: ", $c->error ) );
Condition50%1/2
$c->open || (return __PACKAGE__->error('Unable to create a shared cache file: ', $c->error))
l!l
60
MC/DC0%0/1
$c->open || (return __PACKAGE__->error('Unable to create a shared cache file: ', $c->error))
$c->open
Truth table50%1/2
A
A= $c->open
Aresult
11
00
1545 }
1546 12 $data = {};
1547 }
1548 24 ▶ print( STDERR __PACKAGE__, "::_share_vars: Shared object is '$shm' and id is '", $shm->id, "'.\n" ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 24 24
1549  
1550 24 ▶ printf( STDERR "%s::_share_vars: Processing %d variables.\n", __PACKAGE__, scalar( @$vars ) ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 24 24
1551 24 my @objects = ();
1552 24 my @clones = ();
1553 24 foreach my $ref ( @$vars )
1554 {
1555 48 my $type = lc( ref( $ref ) );
1556 48 ▶ if( $type !~ /^(array|hash|scalar)$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($type =~ /^(array|hash|scalar)$/) 0 48 48
1557 {
1558 0 ▶ warn( "Unsupported variable type '$type': '$ref'" ) if( warnings::enabled() || $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() or $Promise::Me::DEBUG 0 0 0
Condition0%0/3
warnings::enabled() or $Promise::Me::DEBUG
l!l&&r!l&&!r
000
MC/DC0%0/2
warnings::enabled() or $Promise::Me::DEBUG
warnings::enabled() $Promise::Me::DEBUG
Truth table0%0/3
A or B
A= warnings::enabled()B= $Promise::Me::DEBUG
ABresult
1X1
011
000
1559 0 next;
1560 }
1561 48 my $addr = Scalar::Util::refaddr( $ref );
1562 48 ▶ print( STDERR __PACKAGE__, "::_share_vars: Processing variable '$ref' of type '$type' with address '$addr'\n" ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 48 48
1563 48 my $pref =
1564 {
1565 addr => $addr,
1566 # debug => $self->debug,
1567 debug => 7,
1568 shm => $shm,
1569 # value => $ref,
1570 };
1571  
1572 48 my $clone = Clone::clone( $ref );
1573 # Keep clone alive; prevent destruction
1574 48 CORE::push( @clones, $clone );
1575 48 my $tied;
1576 48 ▶ if( $type eq 'array' )
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'array') { } 12 36 48
elsif ($type eq 'hash') { } 12 24 36
elsif ($type eq 'scalar') { } 24 0 24
1577 {
1578 12 $tied = tie( @$ref, 'Promise::Me::Share', $pref );
1579 }
1580 elsif( $type eq 'hash' )
1581 {
1582 12 $tied = tie( %$ref, 'Promise::Me::Share', $pref );
1583 }
1584 elsif( $type eq 'scalar' )
1585 {
1586 24 $tied = tie( $$ref, 'Promise::Me::Share', $pref );
1587 }
1588  
1589 48 ▶ print( STDERR __PACKAGE__, "::_share_vars: tied object is '", ( $tied // 'undef' ), "'\n" ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 48 48
Condition0%0/2
$tied // "undef"
l!l
00
MC/DC0%0/1
$tied // "undef"
$tied
Truth table0%0/2
A
A= $tied
Aresult
11
00
1590 48 ▶ if( !CORE::defined( $tied ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tied) 0 48 48
1591 {
1592 0 ▶ warn( "Unable to tie reference variable '$ref': $!" ) if( warnings::enabled() || $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() or $Promise::Me::DEBUG 0 0 0
Condition0%0/3
warnings::enabled() or $Promise::Me::DEBUG
l!l&&r!l&&!r
000
MC/DC0%0/2
warnings::enabled() or $Promise::Me::DEBUG
warnings::enabled() $Promise::Me::DEBUG
Truth table0%0/3
A or B
A= warnings::enabled()B= $Promise::Me::DEBUG
ABresult
1X1
011
000
1593 0 next;
1594 }
1595 48 $data->{ $addr } = $clone;
1596 48 push( @objects, $tied );
1597 48 $SHARED->{ $index }->{ $addr } = $ref;
1598 }
1599 24 ▶ print( STDERR __PACKAGE__, "::_share_vars: Saving data to shared memory.\n" ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 24 24
1600 # Locking is done inside 'write'
1601 # $shm->lock( LOCK_EX );
1602 24 ▶ if( !$shm->write( $data ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($shm->write($data)) 0 24 24
1603 {
1604 # $shm->unlock;
1605 0 return( __PACKAGE__->pass_error( $shm->error ) );
1606 }
1607 # $shm->unlock;
1608 24 ▶ print( STDERR __PACKAGE__, "::_share_vars: Done.\n" ) if( $DEBUG >= 4 );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 24 24
1609 24 ▶ return( scalar( @objects ) > 1 ? @objects : $objects[0] );
Branch: 1 branch
BranchTrueFalseTotal
scalar @objects > 1 ? : 12 12 24
1610 }
1611  
1612 # Used to create a shared space for processes to share result
1613 sub _set_shared_space
1614 56 ▶{
Subroutine _set_shared_space: called CC=43 SCAR=56.0
1615 56 my $self = shift( @_ );
1616 my $key = $self->{shared_key} ||
1617 56 ▶ return( $self->error( "No shared key found!" ) );
Condition50%1/2
$self->{'shared_key'} || (return $self->error('No shared key found!'))
l!l
560
MC/DC0%0/1
$self->{'shared_key'} || (return $self->error('No shared key found!'))
$self->{'shared_key'}
Truth table50%1/2
A
A= $self->{'shared_key'}
Aresult
11
00
1618 my $p =
1619 {
1620 create => 1,
1621 # The user ID $> will be used by Module::Generic::SharedMemXS to derive the user home path, which serves as a key parameter to IPC::SysV::ftok()
1622 56 ▶ key => ( ( defined( $self->{medium} ) && $self->{medium} eq 'memory' ) ? [$key, $>] : $key ),
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'medium'} && $self->{'medium'} eq 'memory' ? : 20 36 56
Condition66%2/3
defined $self->{"medium"} and $self->{"medium"} eq "memory"
!ll&&!rl&&r
03620
MC/DC50%1/2
defined $self->{"medium"} and $self->{"medium"} eq "memory"
defined $self->{"medium"} $self->{"medium"} eq "memory"
Truth table66%2/3
A and B
A= defined $self->{"medium"}B= $self->{"medium"} eq "memory"
ABresult
0X0
100
111
1623 # key => [$key, $>],
1624 mode => 0666,
1625 debug => $self->debug,
1626 # storable => 1,
1627 # base64 => 1,
1628 };
1629 56 my $serialiser = $self->serialiser;
1630 56 ▶ $serialiser = lc( $serialiser ) if( defined( $serialiser ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $serialiser 56 0 56
1631 56 ▶ if( defined( $serialiser ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $serialiser and $serialiser eq 'sereal' || $serialiser eq 'storable' || $serialiser eq 'cbor') { } 56 0 56
Condition44%4/9
defined $serialiser and $serialiser eq "sereal" || $serialiser eq "storable" || $serialiser eq "cbor"
!ll&&!rl&&r
0056
$serialiser eq "sereal" or $serialiser eq "storable" or $serialiser eq "cbor"
l!l&&r!l&&!r
5600
$serialiser eq "sereal" or $serialiser eq "storable"
l!l&&r!l&&!r
28280
MC/DC0%0/4
defined $serialiser and $serialiser eq "sereal" || $serialiser eq "storable" || $serialiser eq "cbor"
defined $serialiser $serialiser eq "sereal" $serialiser eq "storable" $serialiser eq "cbor"
Truth table40%2/5
A and B or C or D
A= defined $serialiserB= $serialiser eq "sereal"C= $serialiser eq "storable"D= $serialiser eq "cbor"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
1632 ( $serialiser eq 'sereal' || $serialiser eq 'storable' || $serialiser eq 'cbor' ) )
1633 {
1634 # $p->{ $serialiser } = 1;
1635 56 $p->{serialiser} = $serialiser;
1636 }
1637 # Default to Sereal, because it has better hook design to handle properly globs
1638 else
1639 {
1640 # $p->{sereal} = 1;
1641 0 $p->{serialiser} = 'sereal';
1642 }
1643  
1644 56 my $size = $self->result_shared_mem_size;
1645 56 ▶ $p->{size} = $size if( defined( $size ) && CORE::length( $size ) && int( $size ) > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if defined $size and length $size and int $size > 0 56 0 56
Condition33%2/6
defined $size and length $size and int $size > 0
!ll&&!rl&&r
0056
defined $size and length $size
!ll&&!rl&&r
0056
MC/DC0%0/3
defined $size and length $size and int $size > 0
defined $size length $size int $size > 0
Truth table25%1/4
A and B and C
A= defined $sizeB= length $sizeC= int $size > 0
ABCresult
0XX0
10X0
1100
1111
1646 # If we are the child we do not destroy the shared memory, otherwise our parent
1647 # would not have time to access the data we will have stored there. We just remove
1648 # our semaphore
1649 56 ▶ if( ( ( defined( $self->{medium} ) && $self->{medium} eq 'memory' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"medium"} && $self->{"medium"} eq "memory" || !($self->{"use_cache_file"} || $self->{"use_mmap"}) && $self->{"medium"} ne "file" && $self->{"medium"} ne "mmap" and $self->is_child) 6 50 56
Condition55%10/18
defined $self->{"medium"} && $self->{"medium"} eq "memory" || !($self->{"use_cache_file"} || $self->{"use_mmap"}) && $self->{"medium"} ne "file" && $self->{"medium"} ne "mmap" and $self->is_child
!ll&&!rl&&r
36146
defined $self->{"medium"} and $self->{"medium"} eq "memory" or not $self->{"use_cache_file"} || $self->{"use_mmap"} and $self->{"medium"} ne "file" and $self->{"medium"} ne "mmap"
l!l&&r!l&&!r
20036
defined $self->{"medium"} and $self->{"medium"} eq "memory"
!ll&&!rl&&r
03620
not $self->{"use_cache_file"} || $self->{"use_mmap"} and $self->{"medium"} ne "file" and $self->{"medium"} ne "mmap"
!ll&&!rl&&r
3600
not $self->{"use_cache_file"} || $self->{"use_mmap"} and $self->{"medium"} ne "file"
!ll&&!rl&&r
3600
$self->{'use_cache_file'} || $self->{'use_mmap'}
l!l&&r!l&&!r
3600
MC/DC28%2/7
defined $self->{"medium"} && $self->{"medium"} eq "memory" || !($self->{"use_cache_file"} || $self->{"use_mmap"}) && $self->{"medium"} ne "file" && $self->{"medium"} ne "mmap" and $self->is_child
defined $self->{"medium"} $self->{"medium"} eq "memory" $self->{'use_cache_file'} $self->{'use_mmap'} $self->{"medium"} ne "file" $self->{"medium"} ne "mmap" $self->is_child
Truth table21%3/14
A and B or not(C || D) and E and F and G
A= defined $self->{"medium"}B= $self->{"medium"} eq "memory"C= $self->{'use_cache_file'}D= $self->{'use_mmap'}E= $self->{"medium"} ne "file"F= $self->{"medium"} ne "mmap"G= $self->is_child
ABCDEFGresult
0X1XXXX0
0X01XXX0
0X000XX0
0X0010X0
101XXXX0
1001XXX0
10000XX0
100010X0
11XXXX00
0X001100
10001100
11XXXX11
0X001111
10001111
1650 ( !$self->{use_cache_file} &&
1651 !$self->{use_mmap} &&
1652 $self->{medium} ne 'file' &&
1653 $self->{medium} ne 'mmap' )
1654 ) && $self->is_child )
1655 {
1656 6 $p->{destroy_semaphore} = 0;
1657 }
1658  
1659 56 my $shm;
1660 56 ▶ if( $self->{use_mmap} || $self->{medium} eq 'mmap' )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'use_mmap'} or $self->{'medium'} eq 'mmap') { } 0 56 56
elsif ('Module::Generic::SharedMemXS'->supported and not $self->{'use_cache_file'} and $self->{'medium'} ne 'file' or $self->{'medium'} eq 'memory') { } 20 36 56
Condition33%1/3
$self->{"use_mmap"} or $self->{"medium"} eq "mmap"
l!l&&r!l&&!r
0056
MC/DC0%0/2
$self->{"use_mmap"} or $self->{"medium"} eq "mmap"
$self->{"use_mmap"} $self->{"medium"} eq "mmap"
Truth table33%1/3
A or B
A= $self->{"use_mmap"}B= $self->{"medium"} eq "mmap"
ABresult
1X1
011
000
1661 {
1662 0 ▶ my $s = Module::Generic::File::Mmap->new( %$p ) ||
Condition0%0/2
'Module::Generic::File::Mmap'->new(%$p) || (return $self->pass_error('Module::Generic::File::Mmap'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::File::Mmap'->new(%$p) || (return $self->pass_error('Module::Generic::File::Mmap'->error))
'Module::Generic::File::Mmap'->new(%$p)
Truth table0%0/2
A
A= 'Module::Generic::File::Mmap'->new(%$p)
Aresult
11
00
1663 return( $self->pass_error( Module::Generic::File::Mmap->error ) );
1664 0 ▶ $shm = $s->open || return( $self->pass_error( $s->error ) );
Condition0%0/2
$s->open || (return $self->pass_error($s->error))
l!l
00
MC/DC0%0/1
$s->open || (return $self->pass_error($s->error))
$s->open
Truth table0%0/2
A
A= $s->open
Aresult
11
00
1665 }
1666 ▶ elsif( ( Module::Generic::SharedMemXS->supported && !$self->{use_cache_file} && $self->{medium} ne 'file' ) ||
Condition66%6/9
"Module::Generic::SharedMemXS"->supported and not $self->{"use_cache_file"} and $self->{"medium"} ne "file" or $self->{"medium"} eq "memory"
l!l&&r!l&&!r
20036
"Module::Generic::SharedMemXS"->supported and not $self->{"use_cache_file"} and $self->{"medium"} ne "file"
!ll&&!rl&&r
36020
"Module::Generic::SharedMemXS"->supported and not $self->{"use_cache_file"}
!ll&&!rl&&r
03620
MC/DC25%1/4
"Module::Generic::SharedMemXS"->supported and not $self->{"use_cache_file"} and $self->{"medium"} ne "file" or $self->{"medium"} eq "memory"
"Module::Generic::SharedMemXS"->supported not $self->{"use_cache_file"} $self->{"medium"} ne "file" $self->{"medium"} eq "memory"
Truth table28%2/7
A and not(B) and C or D
A= "Module::Generic::SharedMemXS"->supportedB= not $self->{"use_cache_file"}C= $self->{"medium"} ne "file"D= $self->{"medium"} eq "memory"
ABCDresult
111X1
0XX11
10X11
11011
0XX00
10X00
11000
1667 $self->{medium} eq 'memory' )
1668 {
1669 20 ▶ my $s = Module::Generic::SharedMemXS->new( %$p ) || return( $self->error( "Unable to create shared memory object: ", Module::Generic::SharedMemXS->error ) );
Condition50%1/2
'Module::Generic::SharedMemXS'->new(%$p) || (return $self->error('Unable to create shared memory object: ', 'Module::Generic::SharedMemXS'->error))
l!l
200
MC/DC0%0/1
'Module::Generic::SharedMemXS'->new(%$p) || (return $self->error('Unable to create shared memory object: ', 'Module::Generic::SharedMemXS'->error))
'Module::Generic::SharedMemXS'->new(%$p)
Truth table50%1/2
A
A= 'Module::Generic::SharedMemXS'->new(%$p)
Aresult
11
00
1670 20 $shm = $s->open;
1671  
1672 20 ▶ if( !$shm )
Branch: 1 branch
BranchTrueFalseTotal
if (not $shm) { } 0 20 20
1673 {
1674 0 ▶ if( $s->error->message =~ /No[[:blank:]\h]+space[[:blank:]\h]+left/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($s->error->message =~ /No[[:blank:]\h]+space[[:blank:]\h]+left/i) { } 0 0 0
1675 {
1676 0 my $tmpdir = $self->tmpdir;
1677 0 ▶ if( defined( $tmpdir ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmpdir and length $tmpdir and -e $tmpdir and -d $tmpdir) 0 0 0
Condition0%0/9
defined $tmpdir and length $tmpdir and -e $tmpdir and -d $tmpdir
!ll&&!rl&&r
000
defined $tmpdir and length $tmpdir and -e $tmpdir
!ll&&!rl&&r
000
defined $tmpdir and length $tmpdir
!ll&&!rl&&r
000
MC/DC0%0/4
defined $tmpdir and length $tmpdir and -e $tmpdir and -d $tmpdir
defined $tmpdir length $tmpdir -e $tmpdir -d $tmpdir
Truth table0%0/5
A and B and C and D
A= defined $tmpdirB= length $tmpdirC= -e $tmpdirD= -d $tmpdir
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1678 length( $tmpdir ) &&
1679 -e( $tmpdir ) &&
1680 -d( $tmpdir ) )
1681 {
1682 0 $p->{tmpdir} = $tmpdir;
1683 }
1684 0 ▶ my $s = Module::Generic::File::Cache->new( %$p ) || return( $self->error( "Unable to create shared cache file object: ", Module::Generic::File::Cache->error ) );
Condition0%0/2
'Module::Generic::File::Cache'->new(%$p) || (return $self->error('Unable to create shared cache file object: ', 'Module::Generic::File::Cache'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::File::Cache'->new(%$p) || (return $self->error('Unable to create shared cache file object: ', 'Module::Generic::File::Cache'->error))
'Module::Generic::File::Cache'->new(%$p)
Truth table0%0/2
A
A= 'Module::Generic::File::Cache'->new(%$p)
Aresult
11
00
1685 0 ▶ $shm = $s->open ||
Condition0%0/2
$s->open || (return $self->error('Unable to open shared cache file object: ', $s->error))
l!l
00
MC/DC0%0/1
$s->open || (return $self->error('Unable to open shared cache file object: ', $s->error))
$s->open
Truth table0%0/2
A
A= $s->open
Aresult
11
00
1686 return( $self->error( "Unable to open shared cache file object: ", $s->error ) );
1687 }
1688 else
1689 {
1690 0 return( $self->error( "Unable to open shared memory object: ", $s->error ) );
1691 }
1692 }
1693 else
1694 {
1695 20 $shm->attach;
1696 }
1697 }
1698 # File Cache
1699 else
1700 {
1701 36 my $tmpdir = $self->tmpdir;
1702 36 ▶ if( defined( $tmpdir ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmpdir and length "$tmpdir" and -e "$tmpdir" and -d "$tmpdir") 36 0 36
Condition33%3/9
defined $tmpdir and length "$tmpdir" and -e "$tmpdir" and -d "$tmpdir"
!ll&&!rl&&r
0036
defined $tmpdir and length "$tmpdir" and -e "$tmpdir"
!ll&&!rl&&r
0036
defined $tmpdir and length "$tmpdir"
!ll&&!rl&&r
0036
MC/DC0%0/4
defined $tmpdir and length "$tmpdir" and -e "$tmpdir" and -d "$tmpdir"
defined $tmpdir length "$tmpdir" -e "$tmpdir" -d "$tmpdir"
Truth table20%1/5
A and B and C and D
A= defined $tmpdirB= length "$tmpdir"C= -e "$tmpdir"D= -d "$tmpdir"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1703 length( "$tmpdir" ) &&
1704 -e( "$tmpdir" ) &&
1705 -d( "$tmpdir" ) )
1706 {
1707 36 $p->{tmpdir} = $tmpdir;
1708 }
1709 36 ▶ my $s = Module::Generic::File::Cache->new( %$p ) || return( $self->error( "Unable to create shared cache file object: ", Module::Generic::File::Cache->error ) );
Condition50%1/2
'Module::Generic::File::Cache'->new(%$p) || (return $self->error('Unable to create shared cache file object: ', 'Module::Generic::File::Cache'->error))
l!l
360
MC/DC0%0/1
'Module::Generic::File::Cache'->new(%$p) || (return $self->error('Unable to create shared cache file object: ', 'Module::Generic::File::Cache'->error))
'Module::Generic::File::Cache'->new(%$p)
Truth table50%1/2
A
A= 'Module::Generic::File::Cache'->new(%$p)
Aresult
11
00
1710 36 ▶ if( !( $shm = $s->open ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($shm = $s->open) 0 36 36
1711 {
1712 0 return( $self->error( "Unable to open shared cache file object: ", $s->error ) );
1713 }
1714 }
1715 56 $self->shared_mem( $shm );
1716  
1717 56 ▶ if( $self->is_parent )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_parent) 40 16 56
1718 {
1719 40 $shm->reset( {} );
1720 }
1721 56 return( $shm );
1722 }
1723  
1724 sub DESTROY
1725 0 ▶{
Subroutine DESTROY: not called CC=10 SCAR=47.0
1726 0 my $self = shift( @_ );
1727 0 my $child = $self->child;
1728 0 my $status = $self->exit_status;
1729 0 my $shm = $self->shared_mem;
1730 0 my $destroy = $self->shared_space_destroy;
1731 # If there is a child associated and it has exited and we still have a shared space
1732 # object, then remove that shared space
1733 0 ▶ if( $destroy && $child && CORE::length( $status ) && $shm )
Branch: 1 branch
BranchTrueFalseTotal
if ($destroy and $child and length $status and $shm) 0 0 0
Condition0%0/9
$destroy and $child and length $status and $shm
!ll&&!rl&&r
000
$destroy and $child and length $status
!ll&&!rl&&r
000
$destroy and $child
!ll&&!rl&&r
000
MC/DC0%0/4
$destroy and $child and length $status and $shm
$destroy $child length $status $shm
Truth table0%0/5
A and B and C and D
A= $destroyB= $childC= length $statusD= $shm
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1734 {
1735 # We only do this for shared memory, but not for cache file or mmap file
1736 0 ▶ if( $shm->isa( 'Module::Generic::SharedMem' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($shm->isa("Module::Generic::SharedMem") or $shm->isa("Module::Generic::SharedMemXS")) 0 0 0
Condition0%0/3
$shm->isa("Module::Generic::SharedMem") or $shm->isa("Module::Generic::SharedMemXS")
l!l&&r!l&&!r
000
MC/DC0%0/2
$shm->isa("Module::Generic::SharedMem") or $shm->isa("Module::Generic::SharedMemXS")
$shm->isa("Module::Generic::SharedMem") $shm->isa("Module::Generic::SharedMemXS")
Truth table0%0/3
A or B
A= $shm->isa("Module::Generic::SharedMem")B= $shm->isa("Module::Generic::SharedMemXS")
ABresult
1X1
011
000
1737 $shm->isa( 'Module::Generic::SharedMemXS' ) )
1738 {
1739 0 $shm->remove;
1740 }
1741 0 my $addr = Scalar::Util::refaddr( $self );
1742 0 ▶ for( my $i = 0; $i < $#$OBJECTS_REPO; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $Promise::Me::OBJECTS_REPO->$#*) 0 0 0
1743 {
1744 0 ▶ if( !defined( $OBJECTS_REPO->[$i] ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $Promise::Me::OBJECTS_REPO->[$i]) { } 0 0 0
elsif (builtin::refaddr($Promise::Me::OBJECTS_REPO->[$i]) eq $addr) { } 0 0 0
1745 {
1746 0 CORE::splice( @$OBJECTS_REPO, $i, 1 );
1747 0 $i--;
1748 0 next;
1749 }
1750 elsif( Scalar::Util::refaddr( $OBJECTS_REPO->[$i] ) eq $addr )
1751 {
1752 0 CORE::splice( @$OBJECTS_REPO, $i, 1 );
1753 0 last;
1754 }
1755 }
1756 }
1757 };
1758  
1759 # NOTE: END
1760 END
1761 26 ▶{
Subroutine END: called CC=19 SCAR=33.3
1762 # Only the objects, which are initiated in the parent process are in here.
1763 26 ▶ for( my $i = 0; $i < $#$OBJECTS_REPO; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $Promise::Me::OBJECTS_REPO->$#*) 36 26 62
1764 {
1765 36 my $o = $OBJECTS_REPO->[$i];
1766 36 ▶ next unless( defined( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 36 36
1767 # END block called by child process typically
1768 36 my $pid = $o->pid;
1769 36 ▶ next if( $pid ne $$ );
Branch: 1 branch
BranchTrueFalseTotal
if $pid ne $$ 24 12 36
1770 12 my $shm;
1771 12 ▶ if( (
Branch: 1 branch
BranchTrueFalseTotal
if ($o->shared_space_destroy and defined($shm = $o->shared_mem) and $shm->isa("Module::Generic::SharedMem") || $shm->isa("Module::Generic::SharedMemXS") or defined($shm = $o->shared_mem) and $shm->isa("Module::Generic::File::Cache") || $shm->isa("Module::Generic::File::Mmap")) 12 0 12
Condition50%9/18
$o->shared_space_destroy and defined($shm = $o->shared_mem) and $shm->isa("Module::Generic::SharedMem") || $shm->isa("Module::Generic::SharedMemXS") or defined($shm = $o->shared_mem) and $shm->isa("Module::Generic::File::Cache") || $shm->isa("Module::Generic::File::Mmap")
l!l&&r!l&&!r
480
$o->shared_space_destroy and defined($shm = $o->shared_mem) and $shm->isa("Module::Generic::SharedMem") || $shm->isa("Module::Generic::SharedMemXS")
!ll&&!rl&&r
084
$o->shared_space_destroy and defined($shm = $o->shared_mem)
!ll&&!rl&&r
0012
$shm->isa("Module::Generic::SharedMem") or $shm->isa("Module::Generic::SharedMemXS")
l!l&&r!l&&!r
048
defined($shm = $o->shared_mem) and $shm->isa("Module::Generic::File::Cache") || $shm->isa("Module::Generic::File::Mmap")
!ll&&!rl&&r
008
$shm->isa("Module::Generic::File::Cache") or $shm->isa("Module::Generic::File::Mmap")
l!l&&r!l&&!r
800
MC/DC0%0/7
$o->shared_space_destroy and defined($shm = $o->shared_mem) and $shm->isa("Module::Generic::SharedMem") || $shm->isa("Module::Generic::SharedMemXS") or defined($shm = $o->shared_mem) and $shm->isa("Module::Generic::File::Cache") || $shm->isa("Module::Generic::File::Mmap")
$o->shared_space_destroy defined($shm = $o->shared_mem) $shm->isa("Module::Generic::SharedMem") $shm->isa("Module::Generic::SharedMemXS") defined($shm = $o->shared_mem) $shm->isa("Module::Generic::File::Cache") $shm->isa("Module::Generic::File::Mmap")
Truth table14%2/14
A and B and C or D or E and F or G
A= $o->shared_space_destroyB= defined($shm = $o->shared_mem)C= $shm->isa("Module::Generic::SharedMem")D= $shm->isa("Module::Generic::SharedMemXS")E= defined($shm = $o->shared_mem)F= $shm->isa("Module::Generic::File::Cache")G= $shm->isa("Module::Generic::File::Mmap")
ABCDEFGresult
111XXXX1
1101XXX1
0XXX11X1
0XXX1011
10XX11X1
10XX1011
110011X1
11001011
0XXX0XX0
0XXX1000
10XX0XX0
10XX1000
11000XX0
11001000
1772 $o->shared_space_destroy &&
1773 defined( $shm = $o->shared_mem ) &&
1774 (
1775 $shm->isa( 'Module::Generic::SharedMem' ) ||
1776 $shm->isa( 'Module::Generic::SharedMemXS' )
1777 )
1778 ) ||
1779 (
1780 defined( $shm = $o->shared_mem ) &&
1781 (
1782 $shm->isa( 'Module::Generic::File::Cache' ) ||
1783 $shm->isa( 'Module::Generic::File::Mmap' ) )
1784 )
1785 )
1786 {
1787 12 $shm->remove;
1788 }
1789 12 ▶ next if( !CORE::exists( $SHARED->{ $pid } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Promise::Me::SHARED->{$pid} 8 4 12
1790 4 my $rv = kill( $pid, 0 );
1791 4 ▶ print( STDERR __PACKAGE__, "::END: [$$] Checking pid $pid -> ", ( $rv ? 'alive' : 'exited' ), "\n" ) if( $DEBUG >= 4 );
Branch: 2 branches
BranchTrueFalseTotal
if $Promise::Me::DEBUG >= 4 0 4 4
$rv ? : 0 0 0
1792 4 my $first = [keys( %{$SHARED->{ $pid }} )]->[0];
1793 4 my $ref = $SHARED->{ $pid }->{ $first };
1794 4 my $type = lc( ref( $ref ) );
1795 4 ▶ my $tied = tied( $type eq 'array' ? @$ref : $type eq 'hash' ? %$ref : $$ref );
Branch: 2 branches
BranchTrueFalseTotal
$type eq 'array' ? : 1 3 4
$type eq 'hash' ? : 1 2 3
1796 4 ▶ unless( Scalar::Util::blessed( $tied ) && $tied->isa( 'Promise::Me::Share' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($tied) and $tied->isa("Promise::Me::Share")) 0 4 4
Condition33%1/3
builtin::blessed($tied) and $tied->isa("Promise::Me::Share")
!ll&&!rl&&r
004
MC/DC0%0/2
builtin::blessed($tied) and $tied->isa("Promise::Me::Share")
builtin::blessed($tied) $tied->isa("Promise::Me::Share")
Truth table33%1/3
A and B
A= builtin::blessed($tied)B= $tied->isa("Promise::Me::Share")
ABresult
0X0
100
111
1797 {
1798 0 next;
1799 }
1800 4 $shm = $tied->shared;
1801 4 ▶ next if( !$shm );
Branch: 1 branch
BranchTrueFalseTotal
unless $shm 0 4 4
1802 4 $shm->remove;
1803 4 CORE::delete( $SHARED->{ $pid } );
1804 }
1805 };
1806  
1807 # NOTE: PPI::Element class, modifying PPI::Element::replace to be more permissive
1808 {
1809 package
1810 PPI::Element;
1811  
1812 26 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
1813 0 ▶ sub replace {
Subroutine replace: not called CC=2 SCAR=17.9
Pod documented
1814 0 ▶ my $self = ref $_[0] ? shift : return undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
1815 # If our object and the other are not of the same class, PPI refuses to replace
1816 # to avoid damages to perl code
1817 # my $other = _INSTANCE(shift, ref $self) or return undef;
1818 0 my $other = shift;
1819 # die "The ->replace method has not yet been implemented";
1820 0 $self->parent->__replace_child( $self, $other );
1821 0 1;
1822 }
1823 }
1824  
1825 # NOTE: Promise::Me::Exception
1826 package
1827 26 Promise::Me::Exception;
1828 BEGIN
1829 26 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
1830 26 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1831 26 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1832 26 ▶ use parent qw( Module::Generic::Exception );
Subroutine BEGIN: called CC=1 SCAR=0.0
1833 26 our $VERSION = 'v0.1.0';
1834 };
1835  
1836 # NOTE: Promise::Me::Share class
1837 package
1838 Promise::Me::Share;
1839 BEGIN
1840 26 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
1841 26 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1842 26 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1843 26 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
1844 26 warnings::register_categories( 'Promise::Me' );
1845 26 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
1846 26 ▶ use vars qw( $DEBUG $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
1847 26 ▶ use Module::Generic::SharedMemXS qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
1848 26 ▶ use constant SHMEM_SIZE => 65536;
Subroutine BEGIN: called CC=1 SCAR=0.0
1849 26 our $DEBUG = $Promise::Me::DEBUG;
1850 26 ▶ our $VERSION = 'v0.1.0';
Subroutine BEGIN: not called CC=1 SCAR=0.0
1851 };
1852  
1853 sub TIEARRAY
1854 12 ▶{
Subroutine TIEARRAY: called CC=3 SCAR=13.1
1855 12 my $class = shift( @_ );
1856 12 my $opts = $class->_get_args_as_hash( @_ );
1857 12 $opts->{type} = 'array';
1858 12 my $self = $class->_tie( $opts );
1859 12 my $prefix = __PACKAGE__ . "::TIEARRAY [pid $$]";
1860 12 ▶ if( !$self )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self) 0 12 12
1861 {
1862 0 ▶ print( STDERR "$prefix: Failed to create object with given options.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
1863 0 warn( "Failed to create object with given options." );
1864 0 return;
1865 }
1866 12 return( $self );
1867 }
1868  
1869 sub TIEHASH
1870 12 ▶{
Subroutine TIEHASH: called CC=3 SCAR=13.1
1871 12 my $class = shift( @_ );
1872 12 my $opts = $class->_get_args_as_hash( @_ );
1873 12 $opts->{type} = 'hash';
1874 12 my $self = $class->_tie( $opts );
1875 12 my $prefix = __PACKAGE__ . "::TIEHASH [pid $$]";
1876 12 ▶ if( !$self )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self) 0 12 12
1877 {
1878 0 ▶ print( STDERR "$prefix: Failed to create object with given options.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
1879 0 warn( "Failed to create object with given options." );
1880 0 return;
1881 }
1882 12 return( $self );
1883 }
1884  
1885 sub TIESCALAR
1886 24 ▶{
Subroutine TIESCALAR: called CC=3 SCAR=13.1
1887 24 my $class = shift( @_ );
1888 24 my $opts = $class->_get_args_as_hash( @_ );
1889 24 $opts->{type} = 'scalar';
1890 24 my $self = $class->_tie( $opts );
1891 24 my $prefix = __PACKAGE__ . "::TIESCALAR [pid $$]";
1892 24 ▶ if( !$self )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self) 0 24 24
1893 {
1894 0 ▶ print( STDERR "$prefix: Failed to create object with given options.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
1895 0 warn( "Failed to create object with given options." );
1896 0 return;
1897 }
1898 24 return( $self );
1899 }
1900  
1901 sub CLEAR
1902 0 ▶{
Subroutine CLEAR: not called CC=8 SCAR=42.8
1903 0 my $self = shift( @_ );
1904 0 my $prefix = ref( $self ) . "::CLEAR [pid $$]";
1905 0 ▶ print( STDERR "$prefix: clearing tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
1906 0 my $locked = $self->locked;
1907 0 ▶ if( $self->{type} eq 'array' )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'type'} eq 'array') { } 0 0 0
elsif ($self->{'type'} eq 'hash') { } 0 0 0
elsif ($self->{'type'} eq 'scalar') { } 0 0 0
1908 {
1909 0 $self->{data} = [];
1910 }
1911 elsif( $self->{type} eq 'hash' )
1912 {
1913 0 $self->{data} = {};
1914 }
1915 elsif( $self->{type} eq 'scalar' )
1916 {
1917 0 $$self->{data} = \'';
1918 }
1919  
1920 0 ▶ if( $locked & LOCK_EX )
Branch: 1 branch
BranchTrueFalseTotal
if ($locked & 2) { } 0 0 0
1921 {
1922 0 $self->{_changed}++;
1923 }
1924 else
1925 {
1926 0 ▶ print( STDERR "$prefix: unloading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
1927 0 ▶ $self->unload( $self->{data} ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->unload($self->{"data"}) or return $self->pass_error 0 0 0
1928 }
1929 0 return(1);
1930 }
1931  
1932 sub DELETE
1933 0 ▶{
Subroutine DELETE: not called CC=9 SCAR=45.0
1934 0 my $self = shift( @_ );
1935 0 my $key = shift( @_ );
1936 0 my $prefix = ref( $self ) . "::DELETE [pid $$]";
1937 0 ▶ print( STDERR "$prefix: deleting key '$key' from tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
1938 0 my $locked = $self->locked;
1939 0 ▶ unless( $locked )
Branch: 1 branch
BranchTrueFalseTotal
unless ($locked) 0 0 0
1940 {
1941 0 ▶ $self->{data} = $self->load || return( $self->pass_error );
Condition0%0/2
$self->load || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->load || (return $self->pass_error)
$self->load
Truth table0%0/2
A
A= $self->load
Aresult
11
00
1942 }
1943 0 my $val;
1944 0 ▶ if( $self->{type} eq 'array' )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'type'} eq 'array') { } 0 0 0
elsif ($self->{'type'} eq 'hash') { } 0 0 0
1945 {
1946 0 $val = CORE::delete( $self->{data}->[ $key ] );
1947 }
1948 elsif( $self->{type} eq 'hash' )
1949 {
1950 0 $val = CORE::delete( $self->{data}->{ $key } );
1951 }
1952  
1953 0 ▶ if( $locked & LOCK_EX )
Branch: 1 branch
BranchTrueFalseTotal
if ($locked & 2) { } 0 0 0
1954 {
1955 0 $self->{_changed}++;
1956 }
1957 else
1958 {
1959 0 ▶ print( STDERR "$prefix: unloading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
1960 0 ▶ $self->unload( $self->{data} ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->unload($self->{"data"}) or return $self->pass_error 0 0 0
1961 }
1962 0 return( $val );
1963 }
1964  
1965 sub EXISTS
1966 0 ▶{
Subroutine EXISTS: not called CC=6 SCAR=37.4
1967 0 my $self = shift( @_ );
1968 0 my $key = shift( @_ );
1969 0 my $prefix = ref( $self ) . "::EXISTS [pid $$]";
1970 0 ▶ print( STDERR "$prefix: checking if key '$key' exists in tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
1971 0 my $locked = $self->locked;
1972 0 ▶ unless( $locked )
Branch: 1 branch
BranchTrueFalseTotal
unless ($locked) 0 0 0
1973 {
1974 0 ▶ $self->{data} = $self->load || return( $self->pass_error );
Condition0%0/2
$self->load || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->load || (return $self->pass_error)
$self->load
Truth table0%0/2
A
A= $self->load
Aresult
11
00
1975 }
1976 0 ▶ if( $self->{type} eq 'array' )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'type'} eq 'array') { } 0 0 0
elsif ($self->{'type'} eq 'hash') { } 0 0 0
1977 {
1978 0 return( CORE::exists( $self->{data}->[ $key ] ) );
1979 }
1980 elsif( $self->{type} eq 'hash' )
1981 {
1982 0 return( CORE::exists( $self->{data}->{ $key } ) );
1983 }
1984 }
1985  
1986 0 ▶sub EXTEND {}
Subroutine EXTEND: not called CC=1 SCAR=0.0
1987  
1988 sub FETCH
1989 12 ▶{
Subroutine FETCH: called CC=10 SCAR=29.1
1990 12 my $self = shift( @_ );
1991 12 ▶ if( caller eq __PACKAGE__ )
Branch: 1 branch
BranchTrueFalseTotal
if (caller eq __PACKAGE__) 0 12 12
1992 {
1993 0 die( "I am called from within my own package\n" );
1994 }
1995 12 my $prefix = ref( $self ) . "::FETCH [pid $$]";
1996 12 ▶ print( STDERR "$prefix: fetching the value of tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 12 12
1997 12 my $locked = $self->locked;
1998 12 my $data;
1999 12 ▶ if( $locked || $self->{_iterating} )
Branch: 1 branch
BranchTrueFalseTotal
if ($locked or $self->{'_iterating'}) { } 0 12 12
Condition33%1/3
$locked or $self->{"_iterating"}
l!l&&r!l&&!r
0012
MC/DC0%0/2
$locked or $self->{"_iterating"}
$locked $self->{"_iterating"}
Truth table33%1/3
A or B
A= $lockedB= $self->{"_iterating"}
ABresult
1X1
011
000
2000 {
2001 0 $data = $self->{data};
2002 0 $self->{_iterating} = '';
2003 }
2004 else
2005 {
2006 12 ▶ print( STDERR "$prefix: loading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 12 12
2007 12 ▶ $data = $self->load || return( $self->pass_error );
Condition50%1/2
$self->load || (return $self->pass_error)
l!l
120
MC/DC0%0/1
$self->load || (return $self->pass_error)
$self->load
Truth table50%1/2
A
A= $self->load
Aresult
11
00
2008 }
2009  
2010 12 my $val;
2011 12 ▶ if( $self->{type} eq 'array' )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'type'} eq 'array') { } 0 12 12
elsif ($self->{'type'} eq 'hash') { } 0 12 12
elsif ($self->{'type'} eq 'scalar') { } 12 0 12
2012 {
2013 0 my $key = shift( @_ );
2014 0 $val = $data->[$key];
2015 }
2016 elsif( $self->{type} eq 'hash' )
2017 {
2018 0 my $key = shift( @_ );
2019 0 $val = $data->{ $key };
2020 }
2021 elsif( $self->{type} eq 'scalar' )
2022 {
2023 12 $val = $$data;
2024 }
2025 12 return( $val );
2026 }
2027  
2028 sub FETCHSIZE
2029 0 ▶{
Subroutine FETCHSIZE: not called CC=8 SCAR=42.8
2030 0 my $self = shift( @_ );
2031 0 my $prefix = ref( $self ) . "::FETCHSIZE [pid $$]";
2032 0 ▶ print( STDERR "$prefix: fetching the size for the tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2033 0 my $locked = $self->locked;
2034 0 ▶ unless( $locked )
Branch: 1 branch
BranchTrueFalseTotal
unless ($locked) 0 0 0
2035 {
2036 0 ▶ print( STDERR "$prefix: loading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2037 0 ▶ $self->{data} = $self->load || return( $self->pass_error );
Condition0%0/2
$self->load || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->load || (return $self->pass_error)
$self->load
Truth table0%0/2
A
A= $self->load
Aresult
11
00
2038 }
2039 0 ▶ if( $self->{type} eq 'array' )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'type'} eq 'array') { } 0 0 0
elsif ($self->{'type'} eq 'hash') { } 0 0 0
elsif ($self->{'type'} eq 'scalar') { } 0 0 0
2040 {
2041 0 return( scalar( @{$self->{data}} ) );
2042 }
2043 elsif( $self->{type} eq 'hash' )
2044 {
2045 0 return( scalar( keys( %{$self->{data}} ) ) );
2046 }
2047 elsif( $self->{type} eq 'scalar' )
2048 {
2049 0 return( length( ${$self->{data}} ) );
2050 }
2051 }
2052  
2053 sub FIRSTKEY
2054 0 ▶{
Subroutine FIRSTKEY: not called CC=5 SCAR=34.0
2055 0 my $self = shift( @_ );
2056 0 my $prefix = ref( $self ) . "::FIRSTKEY [pid $$]";
2057 0 ▶ print( STDERR "$prefix: fetching the first key for the tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2058 0 my $locked = $self->locked;
2059 0 ▶ unless( $locked )
Branch: 1 branch
BranchTrueFalseTotal
unless ($locked) 0 0 0
2060 {
2061 0 ▶ print( STDERR "$prefix: loading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2062 0 ▶ $self->{data} = $self->load || return( $self->pass_error );
Condition0%0/2
$self->load || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->load || (return $self->pass_error)
$self->load
Truth table0%0/2
A
A= $self->load
Aresult
11
00
2063 }
2064 0 my $reset = keys( %{$self->{data}} );
2065 0 my $first = each( %{$self->{data}} );
2066 0 $self->{_iterating} = 1;
2067 0 return( $first );
2068 }
2069  
2070 sub NEXTKEY
2071 0 ▶{
Subroutine NEXTKEY: not called CC=3 SCAR=24.8
2072 0 my $self = shift( @_ );
2073 0 my $prefix = ref( $self ) . "::NEXTKEY [pid $$]";
2074 0 ▶ print( STDERR "$prefix: fetching the next key for the tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2075 0 my $next = each( %{$self->{data}} );
2076 0 ▶ if( !defined( $next ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $next) { } 0 0 0
2077 {
2078 0 $self->{_iterating} = 0;
2079 0 return;
2080 }
2081 else
2082 {
2083 0 $self->{_iterating} = 1;
2084 0 return( $next );
2085 }
2086 }
2087  
2088 sub POP
2089 0 ▶{
Subroutine POP: not called CC=8 SCAR=42.8
2090 0 my $self = shift( @_ );
2091 0 my $prefix = ref( $self ) . "::POP [pid $$]";
2092 0 ▶ print( STDERR "$prefix: removing the last entry from the tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2093 0 my $locked = $self->locked;
2094 0 ▶ unless( $locked )
Branch: 1 branch
BranchTrueFalseTotal
unless ($locked) 0 0 0
2095 {
2096 0 ▶ print( STDERR "$prefix: loading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2097 0 ▶ $self->{data} = $self->load || return( $self->pass_error );
Condition0%0/2
$self->load || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->load || (return $self->pass_error)
$self->load
Truth table0%0/2
A
A= $self->load
Aresult
11
00
2098 }
2099 0 my $val = pop( @{$self->{data}} );
2100 0 ▶ if( $locked & LOCK_EX )
Branch: 1 branch
BranchTrueFalseTotal
if ($locked & 2) { } 0 0 0
2101 {
2102 0 $self->{_changed}++;
2103 }
2104 else
2105 {
2106 0 ▶ print( STDERR "$prefix: unloading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2107 0 ▶ $self->unload( $self->{data} ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->unload($self->{"data"}) or return $self->pass_error 0 0 0
2108 }
2109 0 return( $val );
2110 }
2111  
2112 sub PUSH
2113 0 ▶{
Subroutine PUSH: not called CC=8 SCAR=42.8
2114 0 my $self = shift( @_ );
2115 0 my $prefix = ref( $self ) . "::PUSH [pid $$]";
2116 0 ▶ print( STDERR "$prefix: adding a new value to the tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2117 0 my $locked = $self->locked;
2118 0 ▶ unless( $locked )
Branch: 1 branch
BranchTrueFalseTotal
unless ($locked) 0 0 0
2119 {
2120 0 ▶ print( STDERR "$prefix: loading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2121 0 ▶ $self->{data} = $self->load || return( $self->pass_error );
Condition0%0/2
$self->load || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->load || (return $self->pass_error)
$self->load
Truth table0%0/2
A
A= $self->load
Aresult
11
00
2122 }
2123 0 push( @{$self->{data}}, @_ );
2124 0 ▶ if( $locked & LOCK_EX )
Branch: 1 branch
BranchTrueFalseTotal
if ($locked & 2) { } 0 0 0
2125 {
2126 0 $self->{_changed}++;
2127 }
2128 else
2129 {
2130 0 ▶ print( STDERR "$prefix: unloading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2131 0 ▶ $self->unload( $self->{data} ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->unload($self->{"data"}) or return $self->pass_error 0 0 0
2132 }
2133 }
2134  
2135 sub SCALAR
2136 0 ▶{
Subroutine SCALAR: not called CC=6 SCAR=37.4
2137 0 my $self = shift( @_ );
2138 0 my $prefix = ref( $self ) . "::SCALAR [pid $$]";
2139 0 ▶ print( STDERR "$prefix: called for the tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2140 0 my $locked = $self->locked;
2141 0 ▶ unless( $locked )
Branch: 1 branch
BranchTrueFalseTotal
unless ($locked) 0 0 0
2142 {
2143 0 ▶ print( STDERR "$prefix: loading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2144 0 ▶ $self->{data} = $self->load || return( $self->pass_error );
Condition0%0/2
$self->load || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->load || (return $self->pass_error)
$self->load
Truth table0%0/2
A
A= $self->load
Aresult
11
00
2145 }
2146 0 ▶ if( $self->{type} eq 'hash' )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"type"} eq "hash") 0 0 0
2147 {
2148 0 return( scalar( keys( %{$self->{data}} ) ) );
2149 }
2150 }
2151  
2152 sub SHIFT
2153 0 ▶{
Subroutine SHIFT: not called CC=7 SCAR=40.3
2154 0 my $self = shift( @_ );
2155 0 my $prefix = ref( $self ) . "::SHIFT [pid $$]";
2156 0 ▶ print( STDERR "$prefix: removing the top value from the tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2157 0 my $locked = $self->locked;
2158 0 ▶ unless( $locked )
Branch: 1 branch
BranchTrueFalseTotal
unless ($locked) 0 0 0
2159 {
2160 0 ▶ print( STDERR "$prefix: loading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2161 0 ▶ $self->{data} = $self->load || return( $self->pass_error );
Condition0%0/2
$self->load || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->load || (return $self->pass_error)
$self->load
Truth table0%0/2
A
A= $self->load
Aresult
11
00
2162 }
2163 0 my $val = shift( @{$self->{data}} );
2164 0 ▶ if( $locked & LOCK_EX )
Branch: 1 branch
BranchTrueFalseTotal
if ($locked & 2) { } 0 0 0
2165 {
2166 0 $self->{_changed}++;
2167 }
2168 else
2169 {
2170 0 ▶ $self->unload( $self->{data} ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->unload($self->{"data"}) or return $self->pass_error 0 0 0
2171 }
2172 0 return( $val );
2173 }
2174  
2175 sub SPLICE
2176 0 ▶{
Subroutine SPLICE: not called CC=8 SCAR=42.8
2177 0 my $self = shift( @_ );
2178 0 my $prefix = ref( $self ) . "::SPLICE [pid $$]";
2179 0 ▶ print( STDERR "$prefix: called for the tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2180 0 my( $offset, $length, @vals ) = @_;
2181 0 my $locked = $self->locked;
2182 0 ▶ unless( $locked )
Branch: 1 branch
BranchTrueFalseTotal
unless ($locked) 0 0 0
2183 {
2184 0 ▶ print( STDERR "$prefix: loading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2185 0 ▶ $self->{data} = $self->load || return( $self->pass_error );
Condition0%0/2
$self->load || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->load || (return $self->pass_error)
$self->load
Truth table0%0/2
A
A= $self->load
Aresult
11
00
2186 }
2187 0 my @values = splice( @{$self->{data}}, $offset, $length, @vals );
2188 0 ▶ if( $locked & LOCK_EX )
Branch: 1 branch
BranchTrueFalseTotal
if ($locked & 2) { } 0 0 0
2189 {
2190 0 $self->{_changed}++;
2191 }
2192 else
2193 {
2194 0 ▶ print( STDERR "$prefix: unloading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2195 0 ▶ $self->unload( $self->{data} ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->unload($self->{"data"}) or return $self->pass_error 0 0 0
2196 }
2197 0 return( @values );
2198 }
2199  
2200 sub STORE
2201 20 ▶{
Subroutine STORE: called CC=11 SCAR=28.8
2202 20 my $self = shift( @_ );
2203 20 my $prefix = ref( $self ) . "::STORE [pid $$]";
2204 20 ▶ print( STDERR "$prefix: saving a value for the tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 20 20
2205 20 my $locked = $self->locked;
2206 20 ▶ unless( $locked )
Branch: 1 branch
BranchTrueFalseTotal
unless ($locked) 20 0 20
2207 {
2208 20 ▶ print( STDERR "$prefix: loading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 20 20
2209 20 ▶ $self->{data} = $self->load || return( $self->pass_error );
Condition50%1/2
$self->load || (return $self->pass_error)
l!l
200
MC/DC0%0/1
$self->load || (return $self->pass_error)
$self->load
Truth table50%1/2
A
A= $self->load
Aresult
11
00
2210 }
2211  
2212 20 ▶ if( $self->{type} eq 'array' )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'type'} eq 'array') { } 0 20 20
elsif ($self->{'type'} eq 'hash') { } 0 20 20
elsif ($self->{'type'} eq 'scalar') { } 20 0 20
2213 {
2214 0 my( $key, $val ) = @_;
2215 0 $self->{data}->[$key] = $val;
2216 }
2217 elsif( $self->{type} eq 'hash' )
2218 {
2219 0 my( $key, $val ) = @_;
2220 0 $self->{data}->{ $key } = $val;
2221 }
2222 elsif( $self->{type} eq 'scalar' )
2223 {
2224 20 my $val = shift( @_ );
2225 20 $self->{data} = \$val;
2226 }
2227  
2228 20 ▶ if( $locked & LOCK_EX )
Branch: 1 branch
BranchTrueFalseTotal
if ($locked & 2) { } 0 20 20
2229 {
2230 0 $self->{_changed}++;
2231 }
2232 else
2233 {
2234 20 ▶ print( STDERR "$prefix: unloading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 20 20
2235 20 ▶ $self->unload( $self->{data} ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->unload($self->{"data"}) or return $self->pass_error 20 0 20
2236 }
2237 20 return(1);
2238 }
2239  
2240 sub STORESIZE
2241 0 ▶{
Subroutine STORESIZE: not called CC=8 SCAR=42.8
2242 0 my $self = shift( @_ );
2243 0 my $len = shift( @_ );
2244 0 my $prefix = ref( $self ) . "::STORESIZE [pid $$]";
2245 0 ▶ print( STDERR "$prefix: called for the tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2246 0 my $locked = $self->locked;
2247 0 ▶ unless( $locked )
Branch: 1 branch
BranchTrueFalseTotal
unless ($locked) 0 0 0
2248 {
2249 0 ▶ print( STDERR "$prefix: loading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2250 0 ▶ $self->{data} = $self->load || return( $self->pass_error );
Condition0%0/2
$self->load || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->load || (return $self->pass_error)
$self->load
Truth table0%0/2
A
A= $self->load
Aresult
11
00
2251 }
2252 0 $#{$self->{data}} = $len - 1;
2253 0 ▶ if( $locked & LOCK_EX )
Branch: 1 branch
BranchTrueFalseTotal
if ($locked & 2) { } 0 0 0
2254 {
2255 0 $self->{_changed}++;
2256 }
2257 else
2258 {
2259 0 ▶ print( STDERR "$prefix: unloading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2260 0 ▶ $self->unload( $self->{data} ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->unload($self->{"data"}) or return $self->pass_error 0 0 0
2261 }
2262 0 return( $len );
2263 }
2264  
2265 sub UNSHIFT
2266 0 ▶{
Subroutine UNSHIFT: not called CC=8 SCAR=42.8
2267 0 my $self = shift( @_ );
2268 0 my $prefix = ref( $self ) . "::STORESIZE [pid $$]";
2269 0 ▶ print( STDERR "$prefix: called for the tied variable of type $self->{type}.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2270 0 my $locked = $self->locked;
2271 0 ▶ unless( $locked )
Branch: 1 branch
BranchTrueFalseTotal
unless ($locked) 0 0 0
2272 {
2273 0 ▶ print( STDERR "$prefix: loading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2274 0 ▶ $self->{data} = $self->load || return( $self->pass_error );
Condition0%0/2
$self->load || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->load || (return $self->pass_error)
$self->load
Truth table0%0/2
A
A= $self->load
Aresult
11
00
2275 }
2276 0 my $val = unshift( @{$self->{data}}, @_ );
2277 0 ▶ if( $locked & LOCK_EX )
Branch: 1 branch
BranchTrueFalseTotal
if ($locked & 2) { } 0 0 0
2278 {
2279 0 $self->{_changed}++;
2280 }
2281 else
2282 {
2283 0 ▶ print( STDERR "$prefix: unloading data.\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 0 0
2284 0 ▶ $self->unload( $self->{data} ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->unload($self->{"data"}) or return $self->pass_error 0 0 0
2285 }
2286 0 return( $val );
2287 }
2288  
2289 sub UNTIE
2290 0 ▶{
Subroutine UNTIE: not called CC=1 SCAR=6.9
2291 0 my $self = shift( @_ );
2292 }
2293  
2294 84 ▶sub addr { return( shift->{addr} ); }
Subroutine addr: called CC=1 SCAR=0.0
2295  
2296 sub load
2297 32 ▶{
Subroutine load: called CC=13 SCAR=32.7
2298 32 my $self = shift( @_ );
2299 32 my @info = caller;
2300 32 my $sub = [caller(1)]->[3];
2301 32 ▶ my $sh = $self->shared ||
Condition50%1/2
$self->shared || (return $self->error('No shared memory object found.'))
l!l
320
MC/DC0%0/1
$self->shared || (return $self->error('No shared memory object found.'))
$self->shared
Truth table50%1/2
A
A= $self->shared
Aresult
11
00
2302 return( $self->error( "No shared memory object found." ) );
2303 32 my $prefix = ref( $self ) . "::load [pid $$]";
2304 32 my $repo = $sh->read;
2305 32 ▶ $repo = {} if( !defined( $repo ) || !CORE::length( $repo ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $repo and length $repo 0 32 32
Condition33%1/3
defined $repo and length $repo
!ll&&!rl&&r
0032
MC/DC0%0/2
defined $repo and length $repo
defined $repo length $repo
Truth table33%1/3
A and B
A= defined $repoB= length $repo
ABresult
0X0
100
111
2306 32 ▶ warn( "Warning only: I was expecting an hash reference from reading the shared memory repository, but instead got '", ( $repo // '' ), "'" ) if( ref( $repo ) ne 'HASH' && $self->_warnings_is_enabled( 'Promise::Me' ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me") 0 32 32
Condition20%1/5
ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me")
!ll&&!rl&&r
3200
$repo // ""
l!l
00
MC/DC0%0/2
ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me")
ref $repo ne "HASH" $self->_warnings_is_enabled("Promise::Me")
MC/DC0%0/1
$repo // ""
$repo
Truth table33%1/3
A and B
A= ref $repo ne "HASH"B= $self->_warnings_is_enabled("Promise::Me")
ABresult
0X0
100
111
Truth table0%0/2
A
A= $repo
Aresult
11
00
2307 32 ▶ my $addr = $self->addr || return( $self->error( "No variable address found!" ) );
Condition50%1/2
$self->addr || (return $self->error('No variable address found!'))
l!l
320
MC/DC0%0/1
$self->addr || (return $self->error('No variable address found!'))
$self->addr
Truth table50%1/2
A
A= $self->addr
Aresult
11
00
2308 32 my $data = $repo->{ $addr };
2309 32 ▶ if( my $obj = tied( $self->{type} eq 'array' ? @$data : $self->{type} eq 'hash' ? %$data : $$data ) )
Branch: 3 branches
BranchTrueFalseTotal
if (my $obj = tied($self->{"type"} eq "array" ? @$data : ($self->{"type"} eq "hash" ? %$data : $$data))) 0 32 32
$self->{'type'} eq 'array' ? : 0 32 32
$self->{'type'} eq 'hash' ? : 0 32 32
2310 {
2311 0 die( "Data received ($data) is tied to class '", ref( $obj ), "'!\n" );
2312 }
2313  
2314 32 ▶ if( !ref( $data ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $data) { } 0 32 32
elsif (lc ref $data ne $self->{'type'}) { } 0 32 32
2315 {
2316 0 warn( "Shared memory block with id '", $sh->id, "' -> addr '$addr' does not contain a reference: '$data' (called from package $info[0] in file $info[1] at line $info[2] from subroutine $sub)" );
2317 }
2318 elsif( lc( ref( $data ) ) ne $self->{type} )
2319 {
2320 0 warn( "Data retrieved from shared memory with id '", $sh->id, "' -> addr '$addr' is expected to contain a reference of type '$self->{type}', but instead contains a reference of type '", lc( ref( $data ) ), "' (called from package $info[0] in file $info[1] at line $info[2] from subroutine $sub)" );
2321 }
2322 32 return( $data );
2323 }
2324  
2325 sub lock
2326 0 ▶{
Subroutine lock: not called CC=15 SCAR=54.8
2327 0 my $self = shift( @_ );
2328 0 ▶ my $sh = $self->shared ||
Condition0%0/2
$self->shared || (return $self->error('No shared memory object found.'))
l!l
00
MC/DC0%0/1
$self->shared || (return $self->error('No shared memory object found.'))
$self->shared
Truth table0%0/2
A
A= $self->shared
Aresult
11
00
2329 return( $self->error( "No shared memory object found." ) );
2330 0 my $prefix = ref( $self ) . "::lock [pid $$]";
2331 0 my $repo = $sh->read;
2332 0 ▶ $repo = {} if( !defined( $repo ) || !CORE::length( $repo ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $repo and length $repo 0 0 0
Condition0%0/3
defined $repo and length $repo
!ll&&!rl&&r
000
MC/DC0%0/2
defined $repo and length $repo
defined $repo length $repo
Truth table0%0/3
A and B
A= defined $repoB= length $repo
ABresult
0X0
100
111
2333 0 ▶ warn( "Warning only: I was expecting an hash reference from reading the shared memory repository, but instead got '", ( $repo // '' ), "'" ) if( ref( $repo ) ne 'HASH' && $self->_warnings_is_enabled( 'Promise::Me' ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me") 0 0 0
Condition0%0/5
ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me")
!ll&&!rl&&r
000
$repo // ""
l!l
00
MC/DC0%0/2
ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me")
ref $repo ne "HASH" $self->_warnings_is_enabled("Promise::Me")
MC/DC0%0/1
$repo // ""
$repo
Truth table0%0/3
A and B
A= ref $repo ne "HASH"B= $self->_warnings_is_enabled("Promise::Me")
ABresult
0X0
100
111
Truth table0%0/2
A
A= $repo
Aresult
11
00
2334 0 ▶ my $addr = $self->addr || return( $self->error( "No variable address found!" ) );
Condition0%0/2
$self->addr || (return $self->error('No variable address found!'))
l!l
00
MC/DC0%0/1
$self->addr || (return $self->error('No variable address found!'))
$self->addr
Truth table0%0/2
A
A= $self->addr
Aresult
11
00
2335 0 ▶ $repo->{_lock} = {} if( !CORE::exists( $repo->{_lock} ) || ref( $repo->{_lock} ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if not exists $repo->{"_lock"} or ref $repo->{"_lock"} ne "HASH" 0 0 0
Condition0%0/3
not exists $repo->{"_lock"} or ref $repo->{"_lock"} ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $repo->{"_lock"} or ref $repo->{"_lock"} ne "HASH"
not exists $repo->{"_lock"} ref $repo->{"_lock"} ne "HASH"
Truth table0%0/3
not(A) or B
A= not exists $repo->{"_lock"}B= ref $repo->{"_lock"} ne "HASH"
ABresult
1X1
011
000
2336 0 ▶ if( CORE::exists( $repo->{_lock}->{ $addr } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $repo->{"_lock"}{$addr}) 0 0 0
2337 {
2338 0 ▶ warn( "Variable '", $self->{value}, "' with address '$self->{addr}' is already locked by process (", $repo->{_lock}->{ $addr }, "). Is it us? ", ( $repo->{_lock}->{ $addr } == $$ ? 'Yes' : 'No' ) ) if( $self->_warnings_is_enabled( 'Promise::Me' ) || $DEBUG );
Branch: 2 branches
BranchTrueFalseTotal
if $self->_warnings_is_enabled("Promise::Me") or $Promise::Me::Share::DEBUG 0 0 0
$repo->{'_lock'}{$addr} == $$ ? : 0 0 0
Condition0%0/3
$self->_warnings_is_enabled("Promise::Me") or $Promise::Me::Share::DEBUG
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_warnings_is_enabled("Promise::Me") or $Promise::Me::Share::DEBUG
$self->_warnings_is_enabled("Promise::Me") $Promise::Me::Share::DEBUG
Truth table0%0/3
A or B
A= $self->_warnings_is_enabled("Promise::Me")B= $Promise::Me::Share::DEBUG
ABresult
1X1
011
000
2339 0 return( $self );
2340 }
2341 0 $repo->{_lock}->{ $addr } = $$;
2342 0 my $rv = $sh->write( $repo );
2343 0 ▶ return( $self->error( "Unable to write to shared memory with shared memory object $sh: ", $sh->error ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
2344 0 return( $self );
2345 }
2346  
2347 sub locked
2348 32 ▶{
Subroutine locked: called CC=10 SCAR=29.0
2349 32 my $self = shift( @_ );
2350 32 ▶ my $sh = $self->shared ||
Condition50%1/2
$self->shared || (return $self->error('No shared memory object found.'))
l!l
320
MC/DC0%0/1
$self->shared || (return $self->error('No shared memory object found.'))
$self->shared
Truth table50%1/2
A
A= $self->shared
Aresult
11
00
2351 return( $self->error( "No shared memory object found." ) );
2352 32 my $prefix = ref( $self ) . "::locked [pid $$]";
2353 32 my $repo = $sh->read;
2354 32 ▶ $repo = {} if( !defined( $repo ) || !CORE::length( $repo ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $repo and length $repo 0 32 32
Condition33%1/3
defined $repo and length $repo
!ll&&!rl&&r
0032
MC/DC0%0/2
defined $repo and length $repo
defined $repo length $repo
Truth table33%1/3
A and B
A= defined $repoB= length $repo
ABresult
0X0
100
111
2355 32 ▶ warn( "Warning only: I was expecting an hash reference from reading the shared memory repository, but instead got '", ( $repo // '' ), "'\n" ) if( ref( $repo ) ne 'HASH' && $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if ref $repo ne "HASH" and $self->_warnings_is_enabled 0 32 32
Condition20%1/5
ref $repo ne "HASH" and $self->_warnings_is_enabled
!ll&&!rl&&r
3200
$repo // ""
l!l
00
MC/DC0%0/2
ref $repo ne "HASH" and $self->_warnings_is_enabled
ref $repo ne "HASH" $self->_warnings_is_enabled
MC/DC0%0/1
$repo // ""
$repo
Truth table33%1/3
A and B
A= ref $repo ne "HASH"B= $self->_warnings_is_enabled
ABresult
0X0
100
111
Truth table0%0/2
A
A= $repo
Aresult
11
00
2356 32 ▶ my $addr = $self->addr || return( $self->error( "No variable address found!" ) );
Condition50%1/2
$self->addr || (return $self->error('No variable address found!'))
l!l
320
MC/DC0%0/1
$self->addr || (return $self->error('No variable address found!'))
$self->addr
Truth table50%1/2
A
A= $self->addr
Aresult
11
00
2357 32 ▶ $repo->{_lock} = {} if( !CORE::exists( $repo->{_lock} ) || ref( $repo->{_lock} ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if not exists $repo->{"_lock"} or ref $repo->{"_lock"} ne "HASH" 32 0 32
Condition33%1/3
not exists $repo->{"_lock"} or ref $repo->{"_lock"} ne "HASH"
l!l&&r!l&&!r
3200
MC/DC0%0/2
not exists $repo->{"_lock"} or ref $repo->{"_lock"} ne "HASH"
not exists $repo->{"_lock"} ref $repo->{"_lock"} ne "HASH"
Truth table33%1/3
not(A) or B
A= not exists $repo->{"_lock"}B= ref $repo->{"_lock"} ne "HASH"
ABresult
1X1
011
000
2358 32 return( CORE::exists( $repo->{_lock}->{ $addr } ) );
2359 }
2360  
2361 sub remove
2362 0 ▶{
Subroutine remove: not called CC=9 SCAR=45.0
2363 0 my $self = shift( @_ );
2364 0 ▶ my $sh = $self->shared ||
Condition0%0/2
$self->shared || (return $self->error('No shared memory object found.'))
l!l
00
MC/DC0%0/1
$self->shared || (return $self->error('No shared memory object found.'))
$self->shared
Truth table0%0/2
A
A= $self->shared
Aresult
11
00
2365 return( $self->error( "No shared memory object found." ) );
2366 0 my $prefix = ref( $self ) . "::remove [pid $$]";
2367 0 my $repo = $sh->read;
2368 0 ▶ $repo = {} if( !defined( $repo ) || !CORE::length( $repo ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $repo and length $repo 0 0 0
Condition0%0/3
defined $repo and length $repo
!ll&&!rl&&r
000
MC/DC0%0/2
defined $repo and length $repo
defined $repo length $repo
Truth table0%0/3
A and B
A= defined $repoB= length $repo
ABresult
0X0
100
111
2369 0 ▶ warn( "Warning only: I was expecting an hash reference from reading the shared memory repository, but instead got '", ( $repo // '' ), "'" ) if( ref( $repo ) ne 'HASH' && $self->_warnings_is_enabled( 'Promise::Me' ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me") 0 0 0
Condition0%0/5
ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me")
!ll&&!rl&&r
000
$repo // ""
l!l
00
MC/DC0%0/2
ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me")
ref $repo ne "HASH" $self->_warnings_is_enabled("Promise::Me")
MC/DC0%0/1
$repo // ""
$repo
Truth table0%0/3
A and B
A= ref $repo ne "HASH"B= $self->_warnings_is_enabled("Promise::Me")
ABresult
0X0
100
111
Truth table0%0/2
A
A= $repo
Aresult
11
00
2370 0 ▶ my $addr = $self->addr || return( $self->error( "No variable address found!" ) );
Condition0%0/2
$self->addr || (return $self->error('No variable address found!'))
l!l
00
MC/DC0%0/1
$self->addr || (return $self->error('No variable address found!'))
$self->addr
Truth table0%0/2
A
A= $self->addr
Aresult
11
00
2371 0 CORE::delete( $repo->{ $addr } );
2372 # Locking is done inside 'write'
2373 # $sh->lock( LOCK_EX );
2374 0 ▶ if( !$sh->write( $repo ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sh->write($repo)) 0 0 0
2375 {
2376 # $sh->unlock;
2377 0 return( $self->pass_error( $sh->error ) )
2378 }
2379 # $sh->unlock;
2380 0 return( $self );
2381 }
2382  
2383 # sub shared { return( shift->_set_get_scalar( 'shared', @_ ) ); }
2384 100 ▶sub shared { return( shift->{shared} ); }
Subroutine shared: called CC=1 SCAR=0.0
2385  
2386 sub unload
2387 20 ▶{
Subroutine unload: called CC=9 SCAR=26.2
2388 20 my $self = shift( @_ );
2389 20 ▶ my $sh = $self->shared ||
Condition50%1/2
$self->shared || (return $self->error('No shared memory object found.'))
l!l
200
MC/DC0%0/1
$self->shared || (return $self->error('No shared memory object found.'))
$self->shared
Truth table50%1/2
A
A= $self->shared
Aresult
11
00
2390 return( $self->error( "No shared memory object found." ) );
2391 20 my $prefix = ref( $self ) . "::unload [pid $$]";
2392 20 my $data = shift( @_ );
2393 20 ▶ my $addr = $self->addr || return( $self->error( "No variable address found!" ) );
Condition50%1/2
$self->addr || (return $self->error('No variable address found!'))
l!l
200
MC/DC0%0/1
$self->addr || (return $self->error('No variable address found!'))
$self->addr
Truth table50%1/2
A
A= $self->addr
Aresult
11
00
2394 20 my $repo = $sh->read;
2395 20 ▶ $repo = {} if( !defined( $repo ) || !CORE::length( $repo ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $repo and length $repo 0 20 20
Condition33%1/3
defined $repo and length $repo
!ll&&!rl&&r
0020
MC/DC0%0/2
defined $repo and length $repo
defined $repo length $repo
Truth table33%1/3
A and B
A= defined $repoB= length $repo
ABresult
0X0
100
111
2396 20 ▶ warn( "Warning only: I was expecting an hash reference from reading the shared memory repository, but instead got '", ( $repo // '' ), "'" ) if( ref( $repo ) ne 'HASH' && $self->_warnings_is_enabled( 'Promise::Me' ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me") 0 20 20
Condition20%1/5
ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me")
!ll&&!rl&&r
2000
$repo // ""
l!l
00
MC/DC0%0/2
ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me")
ref $repo ne "HASH" $self->_warnings_is_enabled("Promise::Me")
MC/DC0%0/1
$repo // ""
$repo
Truth table33%1/3
A and B
A= ref $repo ne "HASH"B= $self->_warnings_is_enabled("Promise::Me")
ABresult
0X0
100
111
Truth table0%0/2
A
A= $repo
Aresult
11
00
2397 20 $repo->{ $addr } = $data;
2398 # Locking is done inside 'write'
2399 # $sh->lock( LOCK_EX );
2400 20 my $rv = $sh->write( $repo );
2401 20 ▶ if( !defined( $rv ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rv) 0 20 20
2402 {
2403 # $sh->unlock;
2404 0 return( $self->error( "Unable to write to shared memory block with shared memory object $sh: ", $sh->error ) );
2405 }
2406 # $sh->unlock;
2407 20 return( $self );
2408 }
2409  
2410 sub unlock
2411 0 ▶{
Subroutine unlock: not called CC=11 SCAR=48.8
2412 0 my $self = shift( @_ );
2413 0 ▶ my $sh = $self->shared ||
Condition0%0/2
$self->shared || (return $self->error('No shared memory object found.'))
l!l
00
MC/DC0%0/1
$self->shared || (return $self->error('No shared memory object found.'))
$self->shared
Truth table0%0/2
A
A= $self->shared
Aresult
11
00
2414 return( $self->error( "No shared memory object found." ) );
2415 0 my $prefix = ref( $self ) . "::unlock [pid $$]";
2416 0 my $repo = $sh->read;
2417 0 ▶ $repo = {} if( !defined( $repo ) || !CORE::length( $repo ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $repo and length $repo 0 0 0
Condition0%0/3
defined $repo and length $repo
!ll&&!rl&&r
000
MC/DC0%0/2
defined $repo and length $repo
defined $repo length $repo
Truth table0%0/3
A and B
A= defined $repoB= length $repo
ABresult
0X0
100
111
2418 0 ▶ warn( "Warning only: I was expecting an hash reference from reading the shared memory repository, but instead got '", ( $repo // '' ), "'" ) if( ref( $repo ) ne 'HASH' && $self->_warnings_is_enabled( 'Promise::Me' ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me") 0 0 0
Condition0%0/5
ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me")
!ll&&!rl&&r
000
$repo // ""
l!l
00
MC/DC0%0/2
ref $repo ne "HASH" and $self->_warnings_is_enabled("Promise::Me")
ref $repo ne "HASH" $self->_warnings_is_enabled("Promise::Me")
MC/DC0%0/1
$repo // ""
$repo
Truth table0%0/3
A and B
A= ref $repo ne "HASH"B= $self->_warnings_is_enabled("Promise::Me")
ABresult
0X0
100
111
Truth table0%0/2
A
A= $repo
Aresult
11
00
2419 0 ▶ my $addr = $self->addr || return( $self->error( "No variable address found!" ) );
Condition0%0/2
$self->addr || (return $self->error('No variable address found!'))
l!l
00
MC/DC0%0/1
$self->addr || (return $self->error('No variable address found!'))
$self->addr
Truth table0%0/2
A
A= $self->addr
Aresult
11
00
2420 0 ▶ if( $repo->{_lock}->{ $addr } != $$ )
Branch: 1 branch
BranchTrueFalseTotal
if ($repo->{"_lock"}{$addr} != $$) 0 0 0
2421 {
2422 0 return( $self->error( "Unable to remove the lock. This process ($$) is not the owner of the lock (", $repo->{_lock}->{ $addr }, ")." ) );
2423 }
2424  
2425 # Credits to IPC::Shareable for the idea
2426 0 ▶ if( $self->{_changed} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_changed"}) 0 0 0
2427 {
2428 0 $repo->{ $addr } = $self->{data};
2429 0 $self->{_changed} = 0;
2430 }
2431 0 CORE::delete( $repo->{_lock}->{ $addr } );
2432 # Locking is done inside 'write'
2433 # $sh->lock( LOCK_EX );
2434 0 my $rv = $sh->write( $repo );
2435 0 ▶ if( !defined( $rv ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rv) 0 0 0
2436 {
2437 # $sh->unlock;
2438 0 return( $self->error( "Unable to write to shared memory with shared memory object $sh: ", $sh->error ) );
2439 }
2440 # $sh->unlock;
2441 0 return( $self );
2442 }
2443  
2444 sub _tie
2445 48 ▶{
Subroutine _tie: called CC=12 SCAR=28.3
2446 48 my $class = shift( @_ );
2447 48 my $opts = $class->_get_args_as_hash( @_ );
2448 48 ▶ return( $class->error( "No shared memory object provided." ) ) if( !CORE::exists( $opts->{shm} ) || !CORE::length( $opts->{shm} ) || !Scalar::Util::blessed( $opts->{shm} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"shm"} and length $opts->{"shm"} and builtin::blessed($opts->{"shm"}) 0 48 48
Condition33%2/6
exists $opts->{"shm"} and length $opts->{"shm"} and builtin::blessed($opts->{"shm"})
!ll&&!rl&&r
0048
exists $opts->{"shm"} and length $opts->{"shm"}
!ll&&!rl&&r
0048
MC/DC0%0/3
exists $opts->{"shm"} and length $opts->{"shm"} and builtin::blessed($opts->{"shm"})
exists $opts->{"shm"} length $opts->{"shm"} builtin::blessed($opts->{"shm"})
Truth table25%1/4
A and B and C
A= exists $opts->{"shm"}B= length $opts->{"shm"}C= builtin::blessed($opts->{"shm"})
ABCresult
0XX0
10X0
1100
1111
2449 48 ▶ return( $class->error( "No data type was provided for shared memory tie." ) ) if( !CORE::length( $opts->{type} ) || !CORE::length( $opts->{type} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $opts->{"type"} and length $opts->{"type"} 0 48 48
Condition33%1/3
length $opts->{"type"} and length $opts->{"type"}
!ll&&!rl&&r
0048
MC/DC0%0/2
length $opts->{"type"} and length $opts->{"type"}
length $opts->{"type"} length $opts->{"type"}
Truth table33%1/3
A and B
A= length $opts->{"type"}B= length $opts->{"type"}
ABresult
0X0
100
111
2450 48 ▶ return( $class->error( "Data type '$opts->{type}' is unsupported." ) ) if( $opts->{type} !~ /^(array|hash|scalar)$/i );
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"type"} =~ /^(array|hash|scalar)$/i 0 48 48
2451 48 my $prefix = $class . "::_tie [pid $$]";
2452 # if( !CORE::length( $opts->{type} ) && CORE::length( $opts->{value} ) )
2453 # {
2454 # return( $class->error( "Value provided ($opts->{value}) is not a reference!" ) ) if( !ref( $opts->{value} ) );
2455 # $opts->{type} = ref( $opts->{value} );
2456 # }
2457 48 $opts->{type} = lc( $opts->{type} );
2458 my $hash =
2459 {
2460 addr => $opts->{addr},
2461 debug => ( $opts->{debug} // 0 ),
2462 shared => $opts->{shm},
2463 type => $opts->{type},
2464 48 ▶ };
Condition50%1/2
$opts->{"debug"} // 0
l!l
480
MC/DC0%0/1
$opts->{"debug"} // 0
$opts->{"debug"}
Truth table50%1/2
A
A= $opts->{"debug"}
Aresult
11
00
2465 48 ▶ my $self = bless( $hash => ( ref( $class ) || $class ) );
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0480
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
2466  
2467 48 ▶ if( $opts->{type} eq 'scalar' )
Branch: 3 branches
BranchTrueFalseTotal
if ($opts->{'type'} eq 'scalar') { } 24 24 48
elsif ($opts->{'type'} eq 'array') { } 12 12 24
elsif ($opts->{'type'} eq 'hash') { } 12 0 12
2468 {
2469 24 $self->{data} = \'';
2470 }
2471 elsif( $opts->{type} eq 'array' )
2472 {
2473 12 $self->{data} = [];
2474 }
2475 elsif( $opts->{type} eq 'hash' )
2476 {
2477 12 $self->{data} = {};
2478 }
2479 48 return( $self );
2480 }
2481  
2482 sub DESTROY
2483 492 ▶{
Subroutine DESTROY: called CC=2 SCAR=7.1
2484 492 my $self = shift( @_ );
2485 492 my @info = caller();
2486 492 ▶ print( STDERR __PACKAGE__, "::DESTROY: called from package '$info[0]' in file '$info[1]' at line $info[2]\n" ) if( $DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Promise::Me::Share::DEBUG 0 492 492
2487 };
2488  
2489 sub FREEZE
2490 0 ▶{
Subroutine FREEZE: not called CC=8 SCAR=42.8
2491 0 my $self = shift( @_ );
2492 0 ▶ my $serialiser = shift( @_ ) // '';
Condition0%0/2
shift @_ // ""
l!l
00
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
2493 0 ▶ my $class = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
2494 0 my %hash = %$self;
2495 0 ▶ if( $self->{type} eq 'scalar' )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'type'} eq 'scalar') { } 0 0 0
elsif ($self->{'type'} eq 'array') { } 0 0 0
elsif ($self->{'type'} eq 'hash') { } 0 0 0
2496 {
2497 0 my $str = ${$self->{data}};
2498 0 $hash{data} = \$str;
2499 }
2500 elsif( $self->{type} eq 'array' )
2501 {
2502 0 my @ref = @{$self->{data}};
2503 0 $hash{data} = \@ref;
2504 }
2505 elsif( $self->{type} eq 'hash' )
2506 {
2507 0 my %ref = %{$self->{data}};
2508 0 $hash{data} = \%ref;
2509 }
2510 0 ▶ return( [$class, \%hash] ) if( $serialiser eq 'Sereal' && Sereal::Encoder->VERSION <= version->parse( '4.023' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023") 0 0 0
Condition0%0/3
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
!ll&&!rl&&r
000
MC/DC0%0/2
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
$serialiser eq "Sereal" "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
Truth table0%0/3
A and B
A= $serialiser eq "Sereal"B= "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
ABresult
0X0
100
111
2511 0 return( $class, \%hash );
2512 }
2513  
2514 0 ▶sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
2515  
2516 0 ▶sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
2517  
2518 sub THAW
2519 0 ▶{
Subroutine THAW: not called CC=10 SCAR=47.0
2520 0 my( $self, undef, @args ) = @_;
2521 0 ▶ my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
Branch: 1 branch
BranchTrueFalseTotal
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 0 0 0
Condition0%0/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
2522 0 ▶ my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && ref $ref eq 'ARRAY' && scalar @$ref > 1 ? : 0 0 0
Condition0%0/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
000
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
000
ref $self or $self
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref ref $ref eq "ARRAY" scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self $self
Truth table0%0/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
2523 0 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
2524 0 my $new;
2525 # Storable pattern requires to modify the object it created rather than returning a new one
2526 0 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
2527 {
2528 0 foreach( CORE::keys( %$hash ) )
2529 {
2530 0 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
2531 }
2532 0 $new = $self;
2533 }
2534 else
2535 {
2536 0 $new = CORE::bless( $hash => $class );
2537 }
2538 0 CORE::return( $new );
2539 }
2540  
2541 26 1;
2542 # NOTE: POD
2543 __END__
↑ Summary