MCE/Step.pm

filter: Statementstmt 74.1% 264 / 356 Branchbran 49.5% 122 / 246 Conditioncond 47.4% 46 / 97 MC/DCmcdc 25.0% 15 / 60 Subroutinesub 75.0% 21 / 28 Podpod 55.5% 5 / 9 totaltotal 59.4% 473 / 796 SCAR 75.3
CC
174
Cov
62%
run
127.7
enqp
110.0
await
110.0
CRAP 1861.3
« MCE/Util.pm ↑ Summary MCE/Core/Input/Generator.pm »
1 ###############################################################################
2 ## ----------------------------------------------------------------------------
3 ## Parallel step model for building creative steps.
4 ##
5 ###############################################################################
6  
7 package MCE::Step;
8  
9 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 12 ▶no warnings qw( threads recursion uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 12 our $VERSION = '1.889';
15  
16 ## no critic (BuiltinFunctions::ProhibitStringyEval)
17 ## no critic (Subroutines::ProhibitSubroutinePrototypes)
18 ## no critic (TestingAndDebugging::ProhibitNoStrict)
19  
20 12 ▶use Scalar::Util qw( looks_like_number );
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 12 ▶use MCE;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 12 ▶use MCE::Queue;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 12 our @CARP_NOT = qw( MCE );
26  
27 12 ▶my $_tid = $INC{'threads.pm'} ? threads->tid() : 0;
Branch: 1 branch
BranchTrueFalseTotal
$INC{'threads.pm'} ? : 0 12 12
28  
29 sub CLONE {
30 0 ▶ $_tid = threads->tid() if $INC{'threads.pm'};
Subroutine CLONE: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"threads.pm"} 0 0 0
31 }
32  
33 ###############################################################################
34 ## ----------------------------------------------------------------------------
35 ## Import routine.
36 ##
37 ###############################################################################
38  
39 12 my ($_MCE, $_def, $_params, $_tag) = ({}, {}, {}, 'MCE::Step');
40 12 my ($_prev_c, $_prev_n, $_prev_t, $_prev_w) = ({}, {}, {}, {});
41 12 my ($_user_tasks, $_queue, $_last_task_id, $_lkup) = ({}, {}, {}, {});
42  
43 sub import {
44 12 ▶ my ($_class, $_pkg) = (shift, caller);
Subroutine import: called CC=14 SCAR=41.4
45  
46 12 my $_p = $_def->{$_pkg} = {
47 MAX_WORKERS => 'auto',
48 CHUNK_SIZE => 'auto',
49 };
50  
51 ## Import functions.
52 12 ▶ if ($_pkg !~ /^MCE::/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_pkg =~ /^MCE::/) 12 0 12
53 12 ▶ no strict 'refs'; no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
54 12 *{ $_pkg.'::mce_step_f' } = \&run_file;
55 12 *{ $_pkg.'::mce_step_s' } = \&run_seq;
56 12 *{ $_pkg.'::mce_step' } = \&run;
57 }
58  
59 ## Process module arguments.
60 12 ▶ while ( my $_argument = shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $_argument = shift()) 0 12 12
61 0 my $_arg = lc $_argument;
62  
63 0 ▶ $_p->{MAX_WORKERS} = shift, next if ( $_arg eq 'max_workers' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "max_workers" 0 0 0
64 0 ▶ $_p->{CHUNK_SIZE} = shift, next if ( $_arg eq 'chunk_size' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "chunk_size" 0 0 0
65 0 ▶ $_p->{TMP_DIR} = shift, next if ( $_arg eq 'tmp_dir' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "tmp_dir" 0 0 0
66 0 ▶ $_p->{FREEZE} = shift, next if ( $_arg eq 'freeze' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "freeze" 0 0 0
67 0 ▶ $_p->{THAW} = shift, next if ( $_arg eq 'thaw' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "thaw" 0 0 0
68 0 ▶ $_p->{INIT_RELAY} = shift, next if ( $_arg eq 'init_relay' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "init_relay" 0 0 0
69 0 ▶ $_p->{USE_THREADS} = shift, next if ( $_arg eq 'use_threads' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "use_threads" 0 0 0
70  
71 0 ▶ shift, next if ( $_arg eq 'fast' ); # ignored
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "fast" 0 0 0
72  
73 ## Sereal 3.015+, if available, is used automatically by MCE 1.8+.
74 0 ▶ if ( $_arg eq 'sereal' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_arg eq "sereal") 0 0 0
75 0 ▶ if ( shift eq '0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (shift() eq 0) 0 0 0
76 0 require Storable;
77 0 $_p->{FREEZE} = \&Storable::freeze;
78 0 $_p->{THAW} = \&Storable::thaw;
79 }
80 0 next;
81 }
82  
83 0 _croak("Error: ($_argument) invalid module option");
84 }
85  
86 12 $_p->{MAX_WORKERS} = MCE::_parse_max_workers($_p->{MAX_WORKERS});
87  
88 12 MCE::_validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS', $_tag);
89 MCE::_validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE', $_tag)
90 12 ▶ unless ($_p->{CHUNK_SIZE} eq 'auto');
Branch: 1 branch
BranchTrueFalseTotal
unless $_p->{"CHUNK_SIZE"} eq "auto" 0 12 12
91  
92 12 return;
93 }
94  
95 ###############################################################################
96 ## ----------------------------------------------------------------------------
97 ## The task end callback for when a task completes.
98 ##
99 ###############################################################################
100  
101 sub _task_end {
102  
103 22 ▶ my ($_mce, $_task_id, $_task_name) = @_;
Subroutine _task_end: called CC=4 SCAR=14.2
104 22 my $_pid = $_mce->{_init_pid}.'.'.$_mce->{_caller};
105  
106 22 ▶ if (defined $_mce->{user_tasks}->[$_task_id + 1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_mce->{"user_tasks"}[$_task_id + 1]) 10 12 22
107 10 my $n_workers = $_mce->{user_tasks}->[$_task_id + 1]->{max_workers};
108 10 $_queue->{$_pid}[$_task_id]->enqueue((undef) x $n_workers);
109 }
110  
111 $_params->{task_end}->($_mce, $_task_id, $_task_name)
112 22 ▶ if (exists $_params->{task_end} && ref $_params->{task_end} eq 'CODE');
Branch: 1 branch
BranchTrueFalseTotal
if exists $_params->{"task_end"} and ref $_params->{"task_end"} eq "CODE" 0 22 22
Condition33%1/3
exists $_params->{"task_end"} and ref $_params->{"task_end"} eq "CODE"
!ll&&!rl&&r
2200
MC/DC0%0/2
exists $_params->{"task_end"} and ref $_params->{"task_end"} eq "CODE"
exists $_params->{"task_end"} ref $_params->{"task_end"} eq "CODE"
Truth table33%1/3
A and B
A= exists $_params->{"task_end"}B= ref $_params->{"task_end"} eq "CODE"
ABresult
0X0
100
111
113  
114 22 return;
115 }
116  
117 ###############################################################################
118 ## ----------------------------------------------------------------------------
119 ## Methods for MCE; step, enq, enqp, await.
120 ##
121 ###############################################################################
122  
123 {
124 12 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
125  
126 sub MCE::step {
127  
128 21 ▶ my $x = shift; my $self = ref($x) ? $x : $MCE::MCE;
Subroutine step: called CC=4 SCAR=14.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 21 21
129 21 my $_pid = $self->{_init_pid}.'.'.$self->{_caller};
130  
131 _croak('MCE::step: method is not allowed by the manager process')
132 21 ▶ unless ($self->{_wid});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_wid"} 0 21 21
133  
134 21 my $_task_id = $self->{_task_id};
135  
136 21 ▶ if ($_task_id < $_last_task_id->{$_pid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_task_id < $_last_task_id->{$_pid}) { } 21 0 21
137 21 $_queue->{$_pid}[$_task_id]->enqueue($self->freeze([ @_ ]));
138 }
139 else {
140 0 _croak('MCE::step: method is not allowed by the last task');
141 }
142  
143 21 return;
144 }
145  
146 ############################################################################
147  
148 sub MCE::enq {
149  
150 0 ▶ my $x = shift; my $self = ref($x) ? $x : $MCE::MCE;
Subroutine enq: not called CC=8 SCAR=42.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
151 0 my $_pid = $self->{_init_pid}.'.'.$self->{_caller};
152 0 my $_name = shift;
153  
154 _croak('MCE::enq: method is not allowed by the manager process')
155 0 ▶ unless ($self->{_wid});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_wid"} 0 0 0
156 _croak('MCE::enq: (task_name) is not specified or valid')
157 0 ▶ if (!defined $_name || !exists $_lkup->{$_pid}{$_name});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_name and exists $_lkup->{$_pid}{$_name} 0 0 0
Condition0%0/3
defined $_name and exists $_lkup->{$_pid}{$_name}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_name and exists $_lkup->{$_pid}{$_name}
defined $_name exists $_lkup->{$_pid}{$_name}
Truth table0%0/3
A and B
A= defined $_nameB= exists $_lkup->{$_pid}{$_name}
ABresult
0X0
100
111
158 _croak('MCE::enq: stepping to same task or backwards is not allowed')
159 0 ▶ if ($_lkup->{$_pid}{$_name} <= $self->{_task_id});
Branch: 1 branch
BranchTrueFalseTotal
if $_lkup->{$_pid}{$_name} <= $self->{"_task_id"} 0 0 0
160  
161 0 my $_task_id = $_lkup->{$_pid}{$_name} - 1;
162  
163 0 ▶ if ($_task_id < $_last_task_id->{$_pid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_task_id < $_last_task_id->{$_pid}) { } 0 0 0
164 0 ▶ if (scalar @_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1) { } 0 0 0
165 0 my @_items = map { $self->freeze([ $_ ]) } @_;
166 0 $_queue->{$_pid}[$_task_id]->enqueue(@_items);
167 }
168 else {
169 0 $_queue->{$_pid}[$_task_id]->enqueue($self->freeze([ @_ ]));
170 }
171 }
172 else {
173 0 _croak('MCE::enq: method is not allowed by the last task');
174 }
175  
176 0 return;
177 }
178  
179 ############################################################################
180  
181 sub MCE::enqp {
182  
183 0 ▶ my $x = shift; my $self = ref($x) ? $x : $MCE::MCE;
Subroutine enqp: not called CC=10 SCAR=47.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
184 0 my $_pid = $self->{_init_pid}.'.'.$self->{_caller};
185 0 my ($_name, $_p) = (shift, shift);
186  
187 _croak('MCE::enqp: method is not allowed by the manager process')
188 0 ▶ unless ($self->{_wid});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_wid"} 0 0 0
189 _croak('MCE::enqp: (task_name) is not specified or valid')
190 0 ▶ if (!defined $_name || !exists $_lkup->{$_pid}{$_name});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_name and exists $_lkup->{$_pid}{$_name} 0 0 0
Condition0%0/3
defined $_name and exists $_lkup->{$_pid}{$_name}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_name and exists $_lkup->{$_pid}{$_name}
defined $_name exists $_lkup->{$_pid}{$_name}
Truth table0%0/3
A and B
A= defined $_nameB= exists $_lkup->{$_pid}{$_name}
ABresult
0X0
100
111
191 _croak('MCE::enqp: stepping to same task or backwards is not allowed')
192 0 ▶ if ($_lkup->{$_pid}{$_name} <= $self->{_task_id});
Branch: 1 branch
BranchTrueFalseTotal
if $_lkup->{$_pid}{$_name} <= $self->{"_task_id"} 0 0 0
193 0 ▶ _croak('MCE::enqp: (priority) is not an integer')
Branch: 1 branch
BranchTrueFalseTotal
if not &looks_like_number($_p) or int $_p != $_p 0 0 0
Condition0%0/3
not &looks_like_number($_p) or int $_p != $_p
l!l&&r!l&&!r
000
MC/DC0%0/2
not &looks_like_number($_p) or int $_p != $_p
not &looks_like_number($_p) int $_p != $_p
Truth table0%0/3
not(A) or B
A= not &looks_like_number($_p)B= int $_p != $_p
ABresult
1X1
011
000
194 if (!looks_like_number($_p) || int($_p) != $_p);
195  
196 0 my $_task_id = $_lkup->{$_pid}{$_name} - 1;
197  
198 0 ▶ if ($_task_id < $_last_task_id->{$_pid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_task_id < $_last_task_id->{$_pid}) { } 0 0 0
199 0 ▶ if (scalar @_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1) { } 0 0 0
200 0 my @_items = map { $self->freeze([ $_ ]) } @_;
201 0 $_queue->{$_pid}[$_task_id]->enqueuep($_p, @_items);
202 }
203 else {
204 0 $_queue->{$_pid}[$_task_id]->enqueuep($_p, $self->freeze([ @_ ]));
205 }
206 }
207 else {
208 0 _croak('MCE::enqp: method is not allowed by the last task');
209 }
210  
211 0 return;
212 }
213  
214 ############################################################################
215  
216 sub MCE::await {
217  
218 0 ▶ my $x = shift; my $self = ref($x) ? $x : $MCE::MCE;
Subroutine await: not called CC=10 SCAR=47.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
219 0 my $_pid = $self->{_init_pid}.'.'.$self->{_caller};
220 0 my $_name = shift;
221  
222 _croak('MCE::await: method is not allowed by the manager process')
223 0 ▶ unless ($self->{_wid});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_wid"} 0 0 0
224 _croak('MCE::await: (task_name) is not specified or valid')
225 0 ▶ if (!defined $_name || !exists $_lkup->{$_pid}{$_name});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_name and exists $_lkup->{$_pid}{$_name} 0 0 0
Condition0%0/3
defined $_name and exists $_lkup->{$_pid}{$_name}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_name and exists $_lkup->{$_pid}{$_name}
defined $_name exists $_lkup->{$_pid}{$_name}
Truth table0%0/3
A and B
A= defined $_nameB= exists $_lkup->{$_pid}{$_name}
ABresult
0X0
100
111
226 _croak('MCE::await: awaiting from same task or backwards is not allowed')
227 0 ▶ if ($_lkup->{$_pid}{$_name} <= $self->{_task_id});
Branch: 1 branch
BranchTrueFalseTotal
if $_lkup->{$_pid}{$_name} <= $self->{"_task_id"} 0 0 0
228  
229 0 ▶ my $_task_id = $_lkup->{$_pid}{$_name} - 1; my $_t = 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
230  
231 0 ▶ _croak('MCE::await: (threshold) is not an integer')
Branch: 1 branch
BranchTrueFalseTotal
if not &looks_like_number($_t) or int $_t != $_t 0 0 0
Condition0%0/3
not &looks_like_number($_t) or int $_t != $_t
l!l&&r!l&&!r
000
MC/DC0%0/2
not &looks_like_number($_t) or int $_t != $_t
not &looks_like_number($_t) int $_t != $_t
Truth table0%0/3
not(A) or B
A= not &looks_like_number($_t)B= int $_t != $_t
ABresult
1X1
011
000
232 if (!looks_like_number($_t) || int($_t) != $_t);
233  
234 0 ▶ if ($_task_id < $_last_task_id->{$_pid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_task_id < $_last_task_id->{$_pid}) { } 0 0 0
235 0 $_queue->{$_pid}[$_task_id]->await($_t);
236 } else {
237 0 _croak('MCE::await: method is not allowed by the last task');
238 }
239  
240 0 return;
241 }
242  
243 }
244  
245 ###############################################################################
246 ## ----------------------------------------------------------------------------
247 ## Init and finish routines.
248 ##
249 ###############################################################################
250  
251 12 sub init (@) {
252  
253 13 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Step');
Subroutine init: called CC=4 SCAR=15.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Step" 13 0 13
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Step"
!ll&&!rl&&r
0013
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Step"
defined $_[0] $_[0] eq "MCE::Step"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Step"
ABresult
0X0
100
111
254 13 my $_pkg = "$$.$_tid.".caller();
255  
256 13 ▶ $_params->{$_pkg} = (ref $_[0] eq 'HASH') ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 13 13
257  
258 13 @_ = ();
259  
260 13 return;
261 }
262  
263 sub finish (@) {
264  
265 25 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Step');
Subroutine finish: called CC=11 SCAR=24.3
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Step" 25 0 25
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Step"
!ll&&!rl&&r
0025
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Step"
defined $_[0] $_[0] eq "MCE::Step"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Step"
ABresult
0X0
100
111
266 25 ▶ my $_pkg = (defined $_[0]) ? shift : "$$.$_tid.".caller();
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 21 4 25
267  
268 25 ▶ if ( $_pkg eq 'MCE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_pkg eq 'MCE') { } 12 13 25
elsif ($_MCE->{$_pkg} and $_MCE->{$_pkg}{'_init_pid'} eq "${$}.$_tid") { } 4 9 13
269 12 for my $_k ( keys %{ $_MCE } ) { MCE::Step->finish($_k, 1); }
270 }
271 ▶ elsif ( $_MCE->{$_pkg} && $_MCE->{$_pkg}{_init_pid} eq "$$.$_tid" ) {
Condition66%2/3
$_MCE->{$_pkg} and $_MCE->{$_pkg}{"_init_pid"} eq "${$}.$_tid"
!ll&&!rl&&r
094
MC/DC50%1/2
$_MCE->{$_pkg} and $_MCE->{$_pkg}{"_init_pid"} eq "${$}.$_tid"
$_MCE->{$_pkg} $_MCE->{$_pkg}{"_init_pid"} eq "${$}.$_tid"
Truth table66%2/3
A and B
A= $_MCE->{$_pkg}B= $_MCE->{$_pkg}{"_init_pid"} eq "${$}.$_tid"
ABresult
0X0
100
111
272 4 ▶ $_MCE->{$_pkg}->shutdown(@_) if $_MCE->{$_pkg}{_spawned};
Branch: 1 branch
BranchTrueFalseTotal
if $_MCE->{$_pkg}{"_spawned"} 4 0 4
273  
274 4 delete $_lkup->{$_pkg};
275 4 delete $_last_task_id->{$_pkg};
276  
277 4 delete $_user_tasks->{$_pkg};
278 4 delete $_prev_c->{$_pkg};
279 4 delete $_prev_n->{$_pkg};
280 4 delete $_prev_t->{$_pkg};
281 4 delete $_prev_w->{$_pkg};
282 4 delete $_MCE->{$_pkg};
283  
284 4 ▶ if (defined $_queue->{$_pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_queue->{$_pkg}) 4 0 4
285 4 local $_;
286 4 $_->DESTROY() for (@{ $_queue->{$_pkg} });
287 4 delete $_queue->{$_pkg};
288 }
289 }
290  
291 25 @_ = ();
292  
293 25 return;
294 }
295  
296 ###############################################################################
297 ## ----------------------------------------------------------------------------
298 ## Parallel step with MCE -- file.
299 ##
300 ###############################################################################
301  
302 sub run_file (@) {
303  
304 4 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Step');
Subroutine run_file: called CC=21 SCAR=34.5
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Step" 0 4 4
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Step"
!ll&&!rl&&r
040
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Step"
defined $_[0] $_[0] eq "MCE::Step"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Step"
ABresult
0X0
100
111
305  
306 4 ▶ my ($_file, $_pos); my $_start_pos = (ref $_[0] eq 'HASH') ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 4 0 4
307 4 my $_pid = "$$.$_tid.".caller();
308  
309 4 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 4 0 4
310 4 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 4 4
311 4 ▶ delete $_p->{sequence} if (exists $_p->{sequence});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"sequence"} 0 4 4
312 }
313 else {
314 0 $_params->{$_pid} = {};
315 }
316  
317 4 for my $_i ($_start_pos .. @_ - 1) {
318 8 my $_r = ref $_[$_i];
319 8 ▶ if ($_r eq '' || $_r eq 'SCALAR' || $_r =~ /^(?:GLOB|FileHandle|IO::)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_r eq "" or $_r eq "SCALAR" or $_r =~ /^(?:GLOB|FileHandle|IO::)/) 2 4 6
Condition83%5/6
$_r eq "" or $_r eq "SCALAR" or $_r =~ /^(?:GLOB|FileHandle|IO::)/
l!l&&r!l&&!r
224
$_r eq "" or $_r eq "SCALAR"
l!l&&r!l&&!r
206
MC/DC66%2/3
$_r eq "" or $_r eq "SCALAR" or $_r =~ /^(?:GLOB|FileHandle|IO::)/
$_r eq "" $_r eq "SCALAR" $_r =~ /^(?:GLOB|FileHandle|IO::)/
Truth table75%3/4
A or B or C
A= $_r eq ""B= $_r eq "SCALAR"C= $_r =~ /^(?:GLOB|FileHandle|IO::)/
ABCresult
1XX1
01X1
0011
0000
320 4 $_file = $_[$_i]; $_pos = $_i;
321 4 last;
322 }
323 }
324  
325 4 ▶ if (defined $_file && ref $_file eq '' && $_file ne '') {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_file and ref $_file eq '' and $_file ne '') { } 2 2 4
elsif (ref $_file eq 'SCALAR' or ref($_file) =~ /^(?:GLOB|FileHandle|IO::)/) { } 2 0 2
Condition66%4/6
defined $_file and ref $_file eq "" and $_file ne ""
!ll&&!rl&&r
202
defined $_file and ref $_file eq ""
!ll&&!rl&&r
022
MC/DC33%1/3
defined $_file and ref $_file eq "" and $_file ne ""
defined $_file ref $_file eq "" $_file ne ""
Truth table50%2/4
A and B and C
A= defined $_fileB= ref $_file eq ""C= $_file ne ""
ABCresult
0XX0
10X0
1100
1111
326 2 ▶ _croak("$_tag: ($_file) does not exist") unless (-e $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $_file 0 2 2
327 2 ▶ _croak("$_tag: ($_file) is not readable") unless (-r $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -r $_file 0 2 2
328 2 ▶ _croak("$_tag: ($_file) is not a plain file") unless (-f $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_file 0 2 2
329 2 $_params->{$_pid}{_file} = $_file;
330 }
331 ▶ elsif (ref $_file eq 'SCALAR' || ref($_file) =~ /^(?:GLOB|FileHandle|IO::)/) {
Condition33%1/3
ref $_file eq "SCALAR" or ref($_file) =~ /^(?:GLOB|FileHandle|IO::)/
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $_file eq "SCALAR" or ref($_file) =~ /^(?:GLOB|FileHandle|IO::)/
ref $_file eq "SCALAR" ref($_file) =~ /^(?:GLOB|FileHandle|IO::)/
Truth table33%1/3
A or B
A= ref $_file eq "SCALAR"B= ref($_file) =~ /^(?:GLOB|FileHandle|IO::)/
ABresult
1X1
011
000
332 2 $_params->{$_pid}{_file} = $_file;
333 }
334 else {
335 0 _croak("$_tag: (file) is not specified or valid");
336 }
337  
338 4 ▶ if (defined $_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_pos) 4 0 4
339 4 pop @_ for ($_pos .. @_ - 1);
340 }
341  
342 4 return run(@_);
343 }
344  
345 ###############################################################################
346 ## ----------------------------------------------------------------------------
347 ## Parallel step with MCE -- sequence.
348 ##
349 ###############################################################################
350  
351 sub run_seq (@) {
352  
353 2 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Step');
Subroutine run_seq: called CC=22 SCAR=39.5
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Step" 0 2 2
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Step"
!ll&&!rl&&r
020
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Step"
defined $_[0] $_[0] eq "MCE::Step"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Step"
ABresult
0X0
100
111
354  
355 2 ▶ my ($_begin, $_end, $_pos); my $_start_pos = (ref $_[0] eq 'HASH') ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 2 0 2
356 2 my $_pid = "$$.$_tid.".caller();
357  
358 2 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 2 0 2
359 2 ▶ delete $_p->{sequence} if (exists $_p->{sequence});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"sequence"} 0 2 2
360 2 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 2 2
361 2 ▶ delete $_p->{_file} if (exists $_p->{_file});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"_file"} 0 2 2
362 }
363 else {
364 0 $_params->{$_pid} = {};
365 }
366  
367 2 for my $_i ($_start_pos .. @_ - 1) {
368 4 my $_r = ref $_[$_i];
369  
370 4 ▶ if ($_r eq '' || $_r =~ /^Math::/ || $_r eq 'HASH' || $_r eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_r eq "" or $_r =~ /^Math::/ or $_r eq "HASH" or $_r eq "ARRAY") 0 2 2
Condition66%6/9
$_r eq "" or $_r =~ /^Math::/ or $_r eq "HASH" or $_r eq "ARRAY"
l!l&&r!l&&!r
202
$_r eq "" or $_r =~ /^Math::/ or $_r eq "HASH"
l!l&&r!l&&!r
202
$_r eq "" or $_r =~ /^Math::/
l!l&&r!l&&!r
202
MC/DC25%1/4
$_r eq "" or $_r =~ /^Math::/ or $_r eq "HASH" or $_r eq "ARRAY"
$_r eq "" $_r =~ /^Math::/ $_r eq "HASH" $_r eq "ARRAY"
Truth table40%2/5
A or B or C or D
A= $_r eq ""B= $_r =~ /^Math::/C= $_r eq "HASH"D= $_r eq "ARRAY"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
371 2 $_pos = $_i;
372  
373 2 ▶ if ($_r eq '' || $_r =~ /^Math::/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($_r eq '' or $_r =~ /^Math::/) { } 2 0 2
elsif ($_r eq 'HASH') { } 0 0 0
elsif ($_r eq 'ARRAY') { } 0 0 0
Condition33%1/3
$_r eq "" or $_r =~ /^Math::/
l!l&&r!l&&!r
200
MC/DC0%0/2
$_r eq "" or $_r =~ /^Math::/
$_r eq "" $_r =~ /^Math::/
Truth table33%1/3
A or B
A= $_r eq ""B= $_r =~ /^Math::/
ABresult
1X1
011
000
374 2 $_begin = $_[$_pos], $_end = $_[$_pos + 1];
375 $_params->{$_pid}{sequence} = [
376 2 $_[$_pos], $_[$_pos + 1], $_[$_pos + 2], $_[$_pos + 3]
377 ];
378 }
379 elsif ($_r eq 'HASH') {
380 0 $_begin = $_[$_pos]->{begin}, $_end = $_[$_pos]->{end};
381 0 $_params->{$_pid}{sequence} = $_[$_pos];
382 }
383 elsif ($_r eq 'ARRAY') {
384 0 $_begin = $_[$_pos]->[0], $_end = $_[$_pos]->[1];
385 0 $_params->{$_pid}{sequence} = $_[$_pos];
386 }
387  
388 2 last;
389 }
390 }
391  
392 _croak("$_tag: (sequence) is not specified or valid")
393 2 ▶ unless (exists $_params->{$_pid}{sequence});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_params->{$_pid}{"sequence"} 0 2 2
394 2 ▶ _croak("$_tag: (begin) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_begin 0 2 2
395 unless (defined $_begin);
396 2 ▶ _croak("$_tag: (end) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_end 0 2 2
397 unless (defined $_end);
398  
399 2 $_params->{$_pid}{sequence_run} = undef;
400  
401 2 ▶ if (defined $_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_pos) 2 0 2
402 2 pop @_ for ($_pos .. @_ - 1);
403 }
404  
405 2 return run(@_);
406 }
407  
408 ###############################################################################
409 ## ----------------------------------------------------------------------------
410 ## Parallel step with MCE.
411 ##
412 ###############################################################################
413  
414 sub run (@) {
415  
416 21 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Step');
Subroutine run: called CC=73 SCAR=48.5
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Step" 0 21 21
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Step"
!ll&&!rl&&r
0210
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Step"
defined $_[0] $_[0] eq "MCE::Step"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Step"
ABresult
0X0
100
111
417  
418 21 ▶ my $_pkg = caller() eq 'MCE::Step' ? caller(1) : caller();
Branch: 1 branch
BranchTrueFalseTotal
caller() eq 'MCE::Step' ? : 6 15 21
419 21 my $_pid = "$$.$_tid.$_pkg";
420  
421 21 ▶ if (ref $_[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "HASH") 14 7 21
422 14 ▶ $_params->{$_pid} = {} unless defined $_params->{$_pid};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_params->{$_pid} 0 14 14
423 14 for my $_p (keys %{ $_[0] }) {
424 14 $_params->{$_pid}{$_p} = $_[0]->{$_p};
425 }
426  
427 14 shift;
428 }
429  
430 ## -------------------------------------------------------------------------
431  
432 21 my (@_code, @_name, @_thrs, @_wrks); my $_init_mce = 0; my $_pos = 0;
433  
434 21 %{ $_lkup->{$_pid} } = ();
435  
436 21 ▶ while (ref $_[0] eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "CODE") 35 21 56
437 35 push @_code, $_[0];
438  
439 35 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 35 0 35
440 push @_name, (ref $_p->{task_name} eq 'ARRAY')
441 35 ▶ ? $_p->{task_name}->[$_pos] : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_p->{'task_name'} eq 'ARRAY' ? : 28 7 35
442 push @_thrs, (ref $_p->{use_threads} eq 'ARRAY')
443 35 ▶ ? $_p->{use_threads}->[$_pos] : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_p->{'use_threads'} eq 'ARRAY' ? : 0 35 35
444 push @_wrks, (ref $_p->{max_workers} eq 'ARRAY')
445 35 ▶ ? $_p->{max_workers}->[$_pos] : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_p->{'max_workers'} eq 'ARRAY' ? : 28 7 35
446 }
447  
448 35 ▶ $_lkup->{$_pid}{ $_name[ $_pos ] } = $_pos if (defined $_name[ $_pos ]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_name[$_pos] 28 7 35
449  
450 $_init_mce = 1 if (
451 !defined $_prev_c->{$_pid}[$_pos] ||
452 35 ▶ $_prev_c->{$_pid}[$_pos] != $_code[$_pos]
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_prev_c->{$_pid}[$_pos] or $_prev_c->{$_pid}[$_pos] != $_code[$_pos] 19 16 35
Condition66%2/3
not defined $_prev_c->{$_pid}[$_pos] or $_prev_c->{$_pid}[$_pos] != $_code[$_pos]
l!l&&r!l&&!r
19016
MC/DC50%1/2
not defined $_prev_c->{$_pid}[$_pos] or $_prev_c->{$_pid}[$_pos] != $_code[$_pos]
not defined $_prev_c->{$_pid}[$_pos] $_prev_c->{$_pid}[$_pos] != $_code[$_pos]
Truth table66%2/3
not(A) or B
A= not defined $_prev_c->{$_pid}[$_pos]B= $_prev_c->{$_pid}[$_pos] != $_code[$_pos]
ABresult
1X1
011
000
453 );
454  
455 35 ▶ $_init_mce = 1 if ($_prev_n->{$_pid}[$_pos] ne $_name[$_pos]);
Branch: 1 branch
BranchTrueFalseTotal
if $_prev_n->{$_pid}[$_pos] ne $_name[$_pos] 12 23 35
456 35 ▶ $_init_mce = 1 if ($_prev_t->{$_pid}[$_pos] ne $_thrs[$_pos]);
Branch: 1 branch
BranchTrueFalseTotal
if $_prev_t->{$_pid}[$_pos] ne $_thrs[$_pos] 0 35 35
457 35 ▶ $_init_mce = 1 if ($_prev_w->{$_pid}[$_pos] ne $_wrks[$_pos]);
Branch: 1 branch
BranchTrueFalseTotal
if $_prev_w->{$_pid}[$_pos] ne $_wrks[$_pos] 12 23 35
458  
459 35 $_prev_c->{$_pid}[$_pos] = $_code[$_pos];
460 35 $_prev_n->{$_pid}[$_pos] = $_name[$_pos];
461 35 $_prev_t->{$_pid}[$_pos] = $_thrs[$_pos];
462 35 $_prev_w->{$_pid}[$_pos] = $_wrks[$_pos];
463  
464 35 shift; $_pos++;
465 }
466  
467 21 ▶ if (defined $_prev_c->{$_pid}[$_pos]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_prev_c->{$_pid}[$_pos]) 0 21 21
468 0 pop @{ $_prev_c->{$_pid} } for ($_pos .. $#{ $_prev_c->{$_pid } });
469 0 pop @{ $_prev_n->{$_pid} } for ($_pos .. $#{ $_prev_n->{$_pid } });
470 0 pop @{ $_prev_t->{$_pid} } for ($_pos .. $#{ $_prev_t->{$_pid } });
471 0 pop @{ $_prev_w->{$_pid} } for ($_pos .. $#{ $_prev_w->{$_pid } });
472  
473 0 $_init_mce = 1;
474 }
475  
476 21 ▶ return unless (scalar @_code);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_code 0 21 21
477  
478 ## -------------------------------------------------------------------------
479  
480 21 my $_input_data; my $_max_workers = $_def->{$_pkg}{MAX_WORKERS};
481 21 my $_r = ref $_[0];
482  
483 21 ▶ if (@_ == 1 && $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::)/) 4 17 21
Condition66%2/3
@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::)/
!ll&&!rl&&r
1704
MC/DC50%1/2
@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::)/
@_ == 1 $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::)/
Truth table66%2/3
A and B
A= @_ == 1B= $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::)/
ABresult
0X0
100
111
484 4 $_input_data = shift;
485 }
486  
487 21 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 21 0 21
488 $_max_workers = MCE::_parse_max_workers($_p->{max_workers})
489 21 ▶ if (exists $_p->{max_workers} && ref $_p->{max_workers} ne 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"max_workers"} and ref $_p->{"max_workers"} ne "ARRAY" 7 14 21
Condition66%2/3
exists $_p->{"max_workers"} and ref $_p->{"max_workers"} ne "ARRAY"
!ll&&!rl&&r
0147
MC/DC50%1/2
exists $_p->{"max_workers"} and ref $_p->{"max_workers"} ne "ARRAY"
exists $_p->{"max_workers"} ref $_p->{"max_workers"} ne "ARRAY"
Truth table66%2/3
A and B
A= exists $_p->{"max_workers"}B= ref $_p->{"max_workers"} ne "ARRAY"
ABresult
0X0
100
111
490  
491 21 ▶ delete $_p->{sequence} if (defined $_input_data || scalar @_);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_input_data or scalar @_ 10 11 21
Condition100%2/2
defined $_input_data or scalar @_
l!l
417
MC/DC100%1/1
defined $_input_data or scalar @_
defined $_input_data
Truth table100%2/2
A
A= defined $_input_data
Aresult
11
00
492 21 ▶ delete $_p->{user_func} if (exists $_p->{user_func});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_func"} 0 21 21
493 21 ▶ delete $_p->{user_tasks} if (exists $_p->{user_tasks});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_tasks"} 0 21 21
494 }
495  
496 21 ▶ if (@_code > 1 && $_max_workers > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_code > 1 and $_max_workers > 1) 14 7 21
Condition66%2/3
@_code > 1 and $_max_workers > 1
!ll&&!rl&&r
7014
MC/DC50%1/2
@_code > 1 and $_max_workers > 1
@_code > 1 $_max_workers > 1
Truth table66%2/3
A and B
A= @_code > 1B= $_max_workers > 1
ABresult
0X0
100
111
497 14 $_max_workers = int($_max_workers / @_code + 0.5) + 1;
498 }
499  
500 my $_chunk_size = MCE::_parse_chunk_size(
501 21 $_def->{$_pkg}{CHUNK_SIZE}, $_max_workers, $_params->{$_pid},
502 $_input_data, scalar @_
503 );
504  
505 21 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 21 0 21
506 21 ▶ if (exists $_p->{_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_p->{'_file'}) { } 4 17 21
507 4 $_input_data = delete $_p->{_file};
508 } else {
509 17 ▶ $_input_data = $_p->{input_data} if exists $_p->{input_data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 17 17
510 }
511 }
512  
513 ## -------------------------------------------------------------------------
514  
515 21 MCE::_save_state($_MCE->{$_pid});
516  
517 21 ▶ if ($_init_mce || !exists $_queue->{$_pid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_init_mce or not exists $_queue->{$_pid}) { } 13 8 21
Condition66%2/3
$_init_mce or not exists $_queue->{$_pid}
l!l&&r!l&&!r
1308
MC/DC50%1/2
$_init_mce or not exists $_queue->{$_pid}
$_init_mce not exists $_queue->{$_pid}
Truth table66%2/3
A or not(B)
A= $_init_mceB= not exists $_queue->{$_pid}
ABresult
1X1
011
000
518 13 ▶ $_MCE->{$_pid}->shutdown() if (defined $_MCE->{$_pid});
Branch: 1 branch
BranchTrueFalseTotal
if defined $_MCE->{$_pid} 0 13 13
519 13 ▶ $_queue->{$_pid} = [] if (!defined $_queue->{$_pid});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_queue->{$_pid} 13 0 13
520  
521 13 my $_Q = $_queue->{$_pid};
522 13 pop(@{ $_Q })->DESTROY for (@_code .. @{ $_Q });
523  
524 6 push @{ $_Q }, MCE::Queue->new(await => 1)
525 13 for (@{ $_Q } .. @_code - 2);
526  
527 13 $_last_task_id->{$_pid} = @_code - 1;
528  
529 ## must clear arrays for nested session to work with Perl < v5.14
530 13 _gen_user_tasks($_pid,$_Q, [@_code],[@_name],[@_thrs],[@_wrks], $_chunk_size);
531  
532 13 @_code = @_name = @_thrs = @_wrks = ();
533  
534 my %_opts = (
535 max_workers => $_max_workers, task_name => $_tag,
536 13 user_tasks => $_user_tasks->{$_pid}, task_end => \&_task_end,
537 );
538  
539 13 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 13 0 13
540 13 local $_;
541  
542 13 for (keys %{ $_p }) {
543 25 ▶ next if ($_ eq 'max_workers' && ref $_p->{max_workers} eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "max_workers" and ref $_p->{"max_workers"} eq "ARRAY" 6 19 25
Condition100%3/3
$_ eq "max_workers" and ref $_p->{"max_workers"} eq "ARRAY"
!ll&&!rl&&r
1276
MC/DC100%2/2
$_ eq "max_workers" and ref $_p->{"max_workers"} eq "ARRAY"
$_ eq "max_workers" ref $_p->{"max_workers"} eq "ARRAY"
Truth table100%3/3
A and B
A= $_ eq "max_workers"B= ref $_p->{"max_workers"} eq "ARRAY"
ABresult
0X0
100
111
544 19 ▶ next if ($_ eq 'task_name' && ref $_p->{task_name} eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "task_name" and ref $_p->{"task_name"} eq "ARRAY" 6 13 19
Condition66%2/3
$_ eq "task_name" and ref $_p->{"task_name"} eq "ARRAY"
!ll&&!rl&&r
1306
MC/DC50%1/2
$_ eq "task_name" and ref $_p->{"task_name"} eq "ARRAY"
$_ eq "task_name" ref $_p->{"task_name"} eq "ARRAY"
Truth table66%2/3
A and B
A= $_ eq "task_name"B= ref $_p->{"task_name"} eq "ARRAY"
ABresult
0X0
100
111
545 13 ▶ next if ($_ eq 'use_threads' && ref $_p->{use_threads} eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "use_threads" and ref $_p->{"use_threads"} eq "ARRAY" 0 13 13
Condition33%1/3
$_ eq "use_threads" and ref $_p->{"use_threads"} eq "ARRAY"
!ll&&!rl&&r
1300
MC/DC0%0/2
$_ eq "use_threads" and ref $_p->{"use_threads"} eq "ARRAY"
$_ eq "use_threads" ref $_p->{"use_threads"} eq "ARRAY"
Truth table33%1/3
A and B
A= $_ eq "use_threads"B= ref $_p->{"use_threads"} eq "ARRAY"
ABresult
0X0
100
111
546  
547 13 ▶ next if ($_ eq 'chunk_size');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "chunk_size" 0 13 13
548 13 ▶ next if ($_ eq 'input_data');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "input_data" 0 13 13
549 13 ▶ next if ($_ eq 'sequence_run');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "sequence_run" 0 13 13
550 13 ▶ next if ($_ eq 'task_end');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "task_end" 0 13 13
551  
552 _croak("$_tag: ($_) is not a valid constructor argument")
553 13 ▶ unless (exists $MCE::_valid_fields_new{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $MCE::_valid_fields_new{$_} 0 13 13
554  
555 13 $_opts{$_} = $_p->{$_};
556 }
557 }
558  
559 13 for my $_k (qw/ tmp_dir freeze thaw init_relay use_threads /) {
560 $_opts{$_k} = $_def->{$_pkg}{uc($_k)}
561 65 ▶ if (exists $_def->{$_pkg}{uc($_k)} && !exists $_opts{$_k});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_def->{$_pkg}{uc $_k} and not exists $_opts{$_k} 0 65 65
Condition33%1/3
exists $_def->{$_pkg}{uc $_k} and not exists $_opts{$_k}
!ll&&!rl&&r
6500
MC/DC0%0/2
exists $_def->{$_pkg}{uc $_k} and not exists $_opts{$_k}
exists $_def->{$_pkg}{uc $_k} not exists $_opts{$_k}
Truth table33%1/3
A and not(B)
A= exists $_def->{$_pkg}{uc $_k}B= not exists $_opts{$_k}
ABresult
0X0
100
111
562 }
563  
564 13 $_MCE->{$_pid} = MCE->new(pkg => $_pkg, %_opts);
565 }
566 else {
567 ## Workers may persist after running. Thus, updating the MCE instance.
568 ## These options do not require respawning.
569 8 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 8 0 8
570 8 for my $_k (qw(
571 RS interval stderr_file stdout_file user_error user_output
572 job_delay submit_delay on_post_exit on_post_run user_args
573 flush_file flush_stderr flush_stdout gather max_retries
574 )) {
575 128 ▶ $_MCE->{$_pid}{$_k} = $_p->{$_k} if (exists $_p->{$_k});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{$_k} 8 120 128
576 }
577 }
578 }
579  
580 ## -------------------------------------------------------------------------
581  
582 21 ▶ my @_a; my $_wa = wantarray; $_MCE->{$_pid}{gather} = \@_a if (defined $_wa);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_wa 7 14 21
583  
584 21 ▶ if (defined $_input_data) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_input_data) { } 8 13 21
elsif (scalar @_) { } 6 7 13
585 8 @_ = ();
586 8 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, $_input_data);
587 7 delete $_MCE->{$_pid}{input_data};
588 }
589 elsif (scalar @_) {
590 6 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, \@_);
591 2 delete $_MCE->{$_pid}{input_data};
592 }
593 else {
594 7 ▶ if (defined $_params->{$_pid} && exists $_params->{$_pid}{sequence}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_params->{$_pid} and exists $_params->{$_pid}{'sequence'}) { } 2 5 7
Condition66%2/3
defined $_params->{$_pid} and exists $_params->{$_pid}{"sequence"}
!ll&&!rl&&r
052
MC/DC50%1/2
defined $_params->{$_pid} and exists $_params->{$_pid}{"sequence"}
defined $_params->{$_pid} exists $_params->{$_pid}{"sequence"}
Truth table66%2/3
A and B
A= defined $_params->{$_pid}B= exists $_params->{$_pid}{"sequence"}
ABresult
0X0
100
111
595 $_MCE->{$_pid}->run({
596 chunk_size => $_chunk_size,
597 sequence => $_params->{$_pid}{sequence}
598 2 }, 0);
599 2 ▶ if (exists $_params->{$_pid}{sequence_run}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_params->{$_pid}{"sequence_run"}) 2 0 2
600 2 delete $_params->{$_pid}{sequence_run};
601 2 delete $_params->{$_pid}{sequence};
602 }
603 2 delete $_MCE->{$_pid}{sequence};
604 }
605 else {
606 5 $_MCE->{$_pid}->run({ chunk_size => $_chunk_size }, 0);
607 }
608 }
609  
610 12 MCE::_restore_state();
611  
612 # destroy queue(s) if MCE::run requested workers to shutdown
613 12 ▶ if (!$_MCE->{$_pid}{_spawned}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_MCE->{$_pid}{"_spawned"}) 0 12 12
614 0 $_->DESTROY() for @{ $_queue->{$_pid} };
615 0 delete $_queue->{$_pid};
616 }
617  
618 12 ▶ delete $_MCE->{$_pid}{gather} if (defined $_wa);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_wa 2 10 12
619  
620 12 ▶ return ((defined $_wa) ? @_a : ());
Branch: 1 branch
BranchTrueFalseTotal
defined $_wa ? : 2 10 12
621 }
622  
623 ###############################################################################
624 ## ----------------------------------------------------------------------------
625 ## Private methods.
626 ##
627 ###############################################################################
628  
629 sub _croak {
630  
631 0 ▶ goto &MCE::_croak;
Subroutine _croak: not called CC=1 SCAR=6.9
632 }
633  
634 sub _gen_user_func {
635  
636 6 ▶ my ($_qref, $_cref, $_chunk_size, $_pos) = @_;
Subroutine _gen_user_func: called CC=1 SCAR=0.0
637  
638 6 my $_q_in = $_qref->[$_pos - 1];
639 6 my $_code = $_cref->[$_pos];
640  
641 return sub {
642 10 ▶ my ($_mce) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
643  
644 10 ▶ $_mce->{_next_jmp} = sub { goto _MCE_STEP__NEXT; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
645 10 ▶ $_mce->{_last_jmp} = sub { goto _MCE_STEP__LAST; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
646  
647 _MCE_STEP__NEXT:
648  
649 10 ▶ while (defined (local $_ = $_q_in->dequeue())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(local $_ = $_q_in->dequeue)) 21 10 31
650 21 my $_args = $_mce->thaw($_); $_ = $_args->[0];
651 21 $_code->($_mce, @{ $_args });
652 }
653  
654 _MCE_STEP__LAST:
655  
656 10 return;
657 6 };
658 }
659  
660 sub _gen_user_tasks {
661  
662 13 ▶ my ($_pid, $_qref, $_cref, $_nref, $_tref, $_wref, $_chunk_size) = @_;
Subroutine _gen_user_tasks: called CC=2 SCAR=6.9
663  
664 13 @{ $_user_tasks->{$_pid} } = ();
665  
666 13 push @{ $_user_tasks->{$_pid} }, {
667 task_name => $_nref->[0],
668 use_threads => $_tref->[0],
669 max_workers => $_wref->[0],
670 30 ▶ user_func => sub { $_cref->[0]->(@_); return; }
Subroutine __ANON__: called CC=1 SCAR=0.0
671 13 };
672  
673 13 for my $_pos (1 .. @{ $_cref } - 1) {
674 6 push @{ $_user_tasks->{$_pid} }, {
675 task_name => $_nref->[$_pos],
676 use_threads => $_tref->[$_pos],
677 max_workers => $_wref->[$_pos],
678 user_func => _gen_user_func(
679 $_qref, $_cref, $_chunk_size, $_pos
680 )
681 };
682 }
683  
684 13 return;
685 }
686  
687 12 1;
688  
689 __END__
« MCE/Util.pm ↑ Summary MCE/Core/Input/Generator.pm »