MCE/Flow.pm

filter: Statementstmt 81.8% 207 / 253 Branchbran 59.9% 115 / 192 Conditioncond 57.5% 46 / 80 MC/DCmcdc 30.6% 15 / 49 Subroutinesub 82.3% 14 / 17 Podpod 100% 5 / 5 totaltotal 67.4% 402 / 596 CC 136 SCAR 41.9
CC
136
Cov
70%
run
110.8
import
51.4
run_seq
48.6
CRAP 65.8
« MCE/Step.pm ↑ Summary MCE/Core/Input/Request.pm »
1 ###############################################################################
2 ## ----------------------------------------------------------------------------
3 ## Parallel flow model for building creative applications.
4 ##
5 ###############################################################################
6  
7 package MCE::Flow;
8  
9 46 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 46 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 46 ▶no warnings qw( threads recursion uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 46 our $VERSION = '1.904';
15  
16 ## no critic (BuiltinFunctions::ProhibitStringyEval)
17 ## no critic (Subroutines::ProhibitSubroutinePrototypes)
18 ## no critic (TestingAndDebugging::ProhibitNoStrict)
19  
20 46 ▶use Scalar::Util qw( looks_like_number );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 46 ▶use MCE;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 46 our @CARP_NOT = qw( MCE );
24  
25 46 ▶my $_tid = $INC{'threads.pm'} ? threads->tid() : 0;
Branch: 1 branch
BranchTrueFalseTotal
$INC{'threads.pm'} ? : 0 46 46
26  
27 0 ▶sub CLONE {
Subroutine CLONE: not called CC=2 SCAR=17.9
28 0 ▶ $_tid = threads->tid() if $INC{'threads.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"threads.pm"} 0 0 0
29 }
30  
31 ###############################################################################
32 ## ----------------------------------------------------------------------------
33 ## Import routine.
34 ##
35 ###############################################################################
36  
37 46 my ($_MCE, $_def, $_params, $_tag) = ({}, {}, {}, 'MCE::Flow');
38 46 my ($_prev_c, $_prev_n, $_prev_t, $_prev_w) = ({}, {}, {}, {});
39 46 my ($_user_tasks) = ({});
40  
41 46 ▶sub import {
Subroutine import: called CC=13 SCAR=39.4
42 46 my ($_class, $_pkg) = (shift, caller);
43  
44 46 my $_p = $_def->{$_pkg} = {
45 MAX_WORKERS => 'auto',
46 CHUNK_SIZE => 'auto',
47 };
48  
49 ## Import functions.
50 46 ▶ if ($_pkg !~ /^MCE::/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_pkg =~ /^MCE::/) 46 0 46
51 46 ▶ no strict 'refs'; no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
52 46 *{ $_pkg.'::mce_flow_f' } = \&run_file;
53 46 *{ $_pkg.'::mce_flow_s' } = \&run_seq;
54 46 *{ $_pkg.'::mce_flow' } = \&run;
55 }
56  
57 ## Process module arguments.
58 46 ▶ while ( my $_argument = shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $_argument = shift()) 0 46 46
59 0 my $_arg = lc $_argument;
60  
61 0 ▶ $_p->{MAX_WORKERS} = shift, next if ( $_arg eq 'max_workers' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "max_workers" 0 0 0
62 0 ▶ $_p->{CHUNK_SIZE} = shift, next if ( $_arg eq 'chunk_size' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "chunk_size" 0 0 0
63 0 ▶ $_p->{TMP_DIR} = shift, next if ( $_arg eq 'tmp_dir' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "tmp_dir" 0 0 0
64 0 ▶ $_p->{FREEZE} = shift, next if ( $_arg eq 'freeze' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "freeze" 0 0 0
65 0 ▶ $_p->{THAW} = shift, next if ( $_arg eq 'thaw' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "thaw" 0 0 0
66 0 ▶ $_p->{INIT_RELAY} = shift, next if ( $_arg eq 'init_relay' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "init_relay" 0 0 0
67 0 ▶ $_p->{USE_THREADS} = shift, next if ( $_arg eq 'use_threads' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "use_threads" 0 0 0
68  
69 ## Sereal 3.015+, if available, is used automatically by MCE 1.8+.
70 0 ▶ if ( $_arg eq 'sereal' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_arg eq "sereal") 0 0 0
71 0 ▶ if ( shift eq '0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (shift() eq 0) 0 0 0
72 0 require Storable;
73 0 $_p->{FREEZE} = \&Storable::freeze;
74 0 $_p->{THAW} = \&Storable::thaw;
75 }
76 0 next;
77 }
78  
79 0 _croak("Error: ($_argument) invalid module option");
80 }
81  
82 46 $_p->{MAX_WORKERS} = MCE::_parse_max_workers($_p->{MAX_WORKERS});
83  
84 46 MCE::_validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS', $_tag);
85 MCE::_validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE', $_tag)
86 46 ▶ unless ($_p->{CHUNK_SIZE} eq 'auto');
Branch: 1 branch
BranchTrueFalseTotal
unless $_p->{"CHUNK_SIZE"} eq "auto" 0 46 46
87  
88 46 return;
89 }
90  
91 ###############################################################################
92 ## ----------------------------------------------------------------------------
93 ## Init and finish routines.
94 ##
95 ###############################################################################
96  
97 0 ▶sub MCE::Flow::_guard::DESTROY {
Subroutine DESTROY: not called CC=3 SCAR=24.8
98 0 my ($_pkg, $_id) = @{ $_[0] };
99  
100 0 ▶ if (defined $_pkg && $_id eq "$$.$_tid") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_pkg and $_id eq "${$}.$_tid") 0 0 0
Condition0%0/3
defined $_pkg and $_id eq "${$}.$_tid"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_pkg and $_id eq "${$}.$_tid"
defined $_pkg $_id eq "${$}.$_tid"
Truth table0%0/3
A and B
A= defined $_pkgB= $_id eq "${$}.$_tid"
ABresult
0X0
100
111
101 0 @{ $_[0] } = ();
102 0 MCE::Flow->finish($_pkg);
103 }
104  
105 0 return;
106 }
107  
108 29 ▶sub init (@) {
Subroutine init: called CC=5 SCAR=16.6
Pod documented
109  
110 29 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Flow');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Flow" 23 6 29
Condition66%2/3
defined $_[0] and $_[0] eq "MCE::Flow"
!ll&&!rl&&r
0623
MC/DC50%1/2
defined $_[0] and $_[0] eq "MCE::Flow"
defined $_[0] $_[0] eq "MCE::Flow"
Truth table66%2/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Flow"
ABresult
0X0
100
111
111 29 my $_pkg = "$$.$_tid.".caller();
112  
113 29 ▶ $_params->{$_pkg} = (ref $_[0] eq 'HASH') ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 29 29
114  
115 29 @_ = ();
116  
117 defined wantarray
118 29 ▶ ? bless([$_pkg, "$$.$_tid"], MCE::Flow::_guard::)
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray ? : 0 29 29
119 : ();
120 }
121  
122 115 ▶sub finish (@) {
Subroutine finish: called CC=9 SCAR=22.3
Pod documented
123  
124 115 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Flow');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Flow" 115 0 115
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Flow"
!ll&&!rl&&r
00115
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Flow"
defined $_[0] $_[0] eq "MCE::Flow"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Flow"
ABresult
0X0
100
111
125 115 ▶ my $_pkg = (defined $_[0]) ? shift : "$$.$_tid.".caller();
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 79 36 115
126  
127 115 ▶ if ( $_pkg eq 'MCE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_pkg eq 'MCE') { } 46 69 115
elsif ($_MCE->{$_pkg} and $_MCE->{$_pkg}{'_init_pid'} eq "${$}.$_tid") { } 36 33 69
128 46 for my $_k ( keys %{ $_MCE } ) { MCE::Flow->finish($_k, 1); }
129 }
130 ▶ elsif ( $_MCE->{$_pkg} && $_MCE->{$_pkg}{_init_pid} eq "$$.$_tid" ) {
Condition66%2/3
$_MCE->{$_pkg} and $_MCE->{$_pkg}{"_init_pid"} eq "${$}.$_tid"
!ll&&!rl&&r
03336
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
131 36 ▶ $_MCE->{$_pkg}->shutdown(@_) if $_MCE->{$_pkg}{_spawned};
Branch: 1 branch
BranchTrueFalseTotal
if $_MCE->{$_pkg}{"_spawned"} 36 0 36
132  
133 36 delete $_user_tasks->{$_pkg};
134 36 delete $_prev_c->{$_pkg};
135 36 delete $_prev_n->{$_pkg};
136 36 delete $_prev_t->{$_pkg};
137 36 delete $_prev_w->{$_pkg};
138 36 delete $_MCE->{$_pkg};
139 }
140  
141 115 @_ = ();
142  
143 115 return;
144 }
145  
146 ###############################################################################
147 ## ----------------------------------------------------------------------------
148 ## Parallel flow with MCE -- file.
149 ##
150 ###############################################################################
151  
152 4 ▶sub run_file (@) {
Subroutine run_file: called CC=21 SCAR=34.5
Pod documented
153  
154 4 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Flow');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Flow" 0 4 4
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Flow"
!ll&&!rl&&r
040
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Flow"
defined $_[0] $_[0] eq "MCE::Flow"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Flow"
ABresult
0X0
100
111
155  
156 4 ▶ my ($_file, $_pos); my $_start_pos = (ref $_[0] eq 'HASH') ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 4 0 4
157 4 my $_pid = "$$.$_tid.".caller();
158  
159 4 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 4 0 4
160 4 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 4 4
161 4 ▶ delete $_p->{sequence} if (exists $_p->{sequence});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"sequence"} 0 4 4
162 }
163 else {
164 0 $_params->{$_pid} = {};
165 }
166  
167 4 for my $_i ($_start_pos .. @_ - 1) {
168 8 my $_r = ref $_[$_i];
169 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::)/) 4 4 8
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
170 4 $_file = $_[$_i]; $_pos = $_i;
171 4 last;
172 }
173 }
174  
175 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
176 2 ▶ _croak("$_tag: ($_file) does not exist") unless (-e $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $_file 0 2 2
177 2 ▶ _croak("$_tag: ($_file) is not readable") unless (-r $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -r $_file 0 2 2
178 2 ▶ _croak("$_tag: ($_file) is not a plain file") unless (-f $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_file 0 2 2
179 2 $_params->{$_pid}{_file} = $_file;
180 }
181 ▶ 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
182 2 $_params->{$_pid}{_file} = $_file;
183 }
184 else {
185 0 _croak("$_tag: (file) is not specified or valid");
186 }
187  
188 4 ▶ if (defined $_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_pos) 4 0 4
189 4 pop @_ for ($_pos .. @_ - 1);
190 }
191  
192 4 return run(@_);
193 }
194  
195 ###############################################################################
196 ## ----------------------------------------------------------------------------
197 ## Parallel flow with MCE -- sequence.
198 ##
199 ###############################################################################
200  
201 2 ▶sub run_seq (@) {
Subroutine run_seq: called CC=22 SCAR=38.8
Pod documented
202  
203 2 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Flow');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Flow" 0 2 2
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Flow"
!ll&&!rl&&r
020
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Flow"
defined $_[0] $_[0] eq "MCE::Flow"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Flow"
ABresult
0X0
100
111
204  
205 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
206 2 my $_pid = "$$.$_tid.".caller();
207  
208 2 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 2 0 2
209 2 ▶ delete $_p->{sequence} if (exists $_p->{sequence});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"sequence"} 0 2 2
210 2 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 2 2
211 2 ▶ delete $_p->{_file} if (exists $_p->{_file});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"_file"} 0 2 2
212 }
213 else {
214 0 $_params->{$_pid} = {};
215 }
216  
217 2 for my $_i ($_start_pos .. @_ - 1) {
218 4 my $_r = ref $_[$_i];
219  
220 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") 2 2 4
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
221 2 $_pos = $_i;
222  
223 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
224 2 $_begin = $_[$_pos], $_end = $_[$_pos + 1];
225 $_params->{$_pid}{sequence} = [
226 2 $_[$_pos], $_[$_pos + 1], $_[$_pos + 2], $_[$_pos + 3]
227 ];
228 }
229 elsif ($_r eq 'HASH') {
230 0 $_begin = $_[$_pos]->{begin}, $_end = $_[$_pos]->{end};
231 0 $_params->{$_pid}{sequence} = $_[$_pos];
232 }
233 elsif ($_r eq 'ARRAY') {
234 0 $_begin = $_[$_pos]->[0], $_end = $_[$_pos]->[1];
235 0 $_params->{$_pid}{sequence} = $_[$_pos];
236 }
237  
238 2 last;
239 }
240 }
241  
242 _croak("$_tag: (sequence) is not specified or valid")
243 2 ▶ unless (exists $_params->{$_pid}{sequence});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_params->{$_pid}{"sequence"} 0 2 2
244 2 ▶ _croak("$_tag: (begin) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_begin 0 2 2
245 unless (defined $_begin);
246 2 ▶ _croak("$_tag: (end) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_end 0 2 2
247 unless (defined $_end);
248  
249 2 $_params->{$_pid}{sequence_run} = undef;
250  
251 2 ▶ if (defined $_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_pos) 2 0 2
252 2 pop @_ for ($_pos .. @_ - 1);
253 }
254  
255 2 return run(@_);
256 }
257  
258 ###############################################################################
259 ## ----------------------------------------------------------------------------
260 ## Parallel flow with MCE.
261 ##
262 ###############################################################################
263  
264 79 ▶sub run (@) {
Subroutine run: called CC=67 SCAR=47.1
Pod documented
265  
266 79 my $_caller = caller();
267 79 ▶ if ($_caller ne 'MCE::Flow' && !exists $_def->{$_caller}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_caller ne "MCE::Flow" and not exists $_def->{$_caller}) 0 79 79
Condition66%2/3
$_caller ne "MCE::Flow" and not exists $_def->{$_caller}
!ll&&!rl&&r
6730
MC/DC0%0/2
$_caller ne "MCE::Flow" and not exists $_def->{$_caller}
$_caller ne "MCE::Flow" not exists $_def->{$_caller}
Truth table66%2/3
A and not(B)
A= $_caller ne "MCE::Flow"B= not exists $_def->{$_caller}
ABresult
0X0
100
111
268 0 warn "MCE::Flow is not imported into the \"$_caller\" namespace. Aborting...\n";
269 0 return;
270 }
271  
272 79 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Flow');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Flow" 0 79 79
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Flow"
!ll&&!rl&&r
0790
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Flow"
defined $_[0] $_[0] eq "MCE::Flow"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Flow"
ABresult
0X0
100
111
273  
274 79 ▶ my $_pkg = $_caller eq 'MCE::Flow' ? caller(1) : $_caller;
Branch: 1 branch
BranchTrueFalseTotal
$_caller eq 'MCE::Flow' ? : 6 73 79
275 79 my $_pid = "$$.$_tid.$_pkg";
276  
277 79 ▶ if (ref $_[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "HASH") 53 26 79
278 53 ▶ $_params->{$_pid} = {} unless defined $_params->{$_pid};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_params->{$_pid} 14 39 53
279 53 for my $_p (keys %{ $_[0] }) {
280 82 $_params->{$_pid}{$_p} = $_[0]->{$_p};
281 }
282  
283 53 shift;
284 }
285  
286 ## -------------------------------------------------------------------------
287  
288 79 my (@_code, @_name, @_thrs, @_wrks); my $_init_mce = 0; my $_pos = 0;
289  
290 79 ▶ while (ref $_[0] eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "CODE") 99 79 178
291 99 push @_code, $_[0];
292  
293 99 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 99 0 99
294 push @_name, (ref $_p->{task_name} eq 'ARRAY')
295 99 ▶ ? $_p->{task_name}->[$_pos] : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_p->{'task_name'} eq 'ARRAY' ? : 28 71 99
296 push @_thrs, (ref $_p->{use_threads} eq 'ARRAY')
297 99 ▶ ? $_p->{use_threads}->[$_pos] : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_p->{'use_threads'} eq 'ARRAY' ? : 0 99 99
298 push @_wrks, (ref $_p->{max_workers} eq 'ARRAY')
299 99 ▶ ? $_p->{max_workers}->[$_pos] : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_p->{'max_workers'} eq 'ARRAY' ? : 40 59 99
300 }
301  
302 $_init_mce = 1 if (
303 !defined $_prev_c->{$_pid}[$_pos] ||
304 99 ▶ $_prev_c->{$_pid}[$_pos] != $_code[$_pos]
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_prev_c->{$_pid}[$_pos] or $_prev_c->{$_pid}[$_pos] != $_code[$_pos] 81 18 99
Condition66%2/3
not defined $_prev_c->{$_pid}[$_pos] or $_prev_c->{$_pid}[$_pos] != $_code[$_pos]
l!l&&r!l&&!r
81018
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
305 );
306  
307 99 ▶ $_init_mce = 1 if ($_prev_n->{$_pid}[$_pos] ne $_name[$_pos]);
Branch: 1 branch
BranchTrueFalseTotal
if $_prev_n->{$_pid}[$_pos] ne $_name[$_pos] 12 87 99
308 99 ▶ $_init_mce = 1 if ($_prev_t->{$_pid}[$_pos] ne $_thrs[$_pos]);
Branch: 1 branch
BranchTrueFalseTotal
if $_prev_t->{$_pid}[$_pos] ne $_thrs[$_pos] 0 99 99
309 99 ▶ $_init_mce = 1 if ($_prev_w->{$_pid}[$_pos] ne $_wrks[$_pos]);
Branch: 1 branch
BranchTrueFalseTotal
if $_prev_w->{$_pid}[$_pos] ne $_wrks[$_pos] 24 75 99
310  
311 99 $_prev_c->{$_pid}[$_pos] = $_code[$_pos];
312 99 $_prev_n->{$_pid}[$_pos] = $_name[$_pos];
313 99 $_prev_t->{$_pid}[$_pos] = $_thrs[$_pos];
314 99 $_prev_w->{$_pid}[$_pos] = $_wrks[$_pos];
315  
316 99 shift; $_pos++;
317 }
318  
319 79 ▶ if (defined $_prev_c->{$_pid}[$_pos]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_prev_c->{$_pid}[$_pos]) 0 79 79
320 0 pop @{ $_prev_c->{$_pid} } for ($_pos .. $#{ $_prev_c->{$_pid } });
321 0 pop @{ $_prev_n->{$_pid} } for ($_pos .. $#{ $_prev_n->{$_pid } });
322 0 pop @{ $_prev_t->{$_pid} } for ($_pos .. $#{ $_prev_t->{$_pid } });
323 0 pop @{ $_prev_w->{$_pid} } for ($_pos .. $#{ $_prev_w->{$_pid } });
324  
325 0 $_init_mce = 1;
326 }
327  
328 79 ▶ return unless (scalar @_code);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_code 0 79 79
329  
330 ## -------------------------------------------------------------------------
331  
332 79 my $_input_data; my $_max_workers = $_def->{$_pkg}{MAX_WORKERS};
333 79 my $_r = ref $_[0];
334  
335 79 ▶ if (@_ == 1 && $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::|Iterator::)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::|Iterator::)/) 4 75 79
Condition66%2/3
@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::|Iterator::)/
!ll&&!rl&&r
7504
MC/DC50%1/2
@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::|Iterator::)/
@_ == 1 $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::|Iterator::)/
Truth table66%2/3
A and B
A= @_ == 1B= $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::|Iterator::)/
ABresult
0X0
100
111
336 4 $_input_data = shift;
337 }
338  
339 79 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 79 0 79
340 $_max_workers = MCE::_parse_max_workers($_p->{max_workers})
341 79 ▶ 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" 59 20 79
Condition66%2/3
exists $_p->{"max_workers"} and ref $_p->{"max_workers"} ne "ARRAY"
!ll&&!rl&&r
02059
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
342  
343 79 ▶ delete $_p->{sequence} if (defined $_input_data || scalar @_);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_input_data or scalar @_ 10 69 79
Condition100%2/2
defined $_input_data or scalar @_
l!l
475
MC/DC100%1/1
defined $_input_data or scalar @_
defined $_input_data
Truth table100%2/2
A
A= defined $_input_data
Aresult
11
00
344 79 ▶ delete $_p->{user_func} if (exists $_p->{user_func});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_func"} 0 79 79
345 79 ▶ delete $_p->{user_tasks} if (exists $_p->{user_tasks});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_tasks"} 0 79 79
346 }
347  
348 79 ▶ if (@_code > 1 && $_max_workers > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_code > 1 and $_max_workers > 1) 20 59 79
Condition66%2/3
@_code > 1 and $_max_workers > 1
!ll&&!rl&&r
59020
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
349 20 $_max_workers = int($_max_workers / @_code + 0.5) + 1;
350 }
351  
352 my $_chunk_size = MCE::_parse_chunk_size(
353 79 $_def->{$_pkg}{CHUNK_SIZE}, $_max_workers, $_params->{$_pid},
354 $_input_data, scalar @_
355 );
356  
357 79 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 79 0 79
358 79 ▶ if (exists $_p->{_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_p->{'_file'}) { } 4 75 79
359 4 $_input_data = delete $_p->{_file};
360 } else {
361 75 ▶ $_input_data = $_p->{input_data} if exists $_p->{input_data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 75 75
362 }
363 }
364  
365 ## -------------------------------------------------------------------------
366  
367 79 MCE::_save_state($_MCE->{$_pid});
368  
369 79 ▶ if ($_init_mce) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_init_mce) { } 69 10 79
370 69 ▶ $_MCE->{$_pid}->shutdown() if (defined $_MCE->{$_pid});
Branch: 1 branch
BranchTrueFalseTotal
if defined $_MCE->{$_pid} 0 69 69
371  
372 ## must clear arrays for nested session to work with Perl < v5.14
373 69 _gen_user_tasks($_pid, [@_code], [@_name], [@_thrs], [@_wrks]);
374  
375 69 @_code = @_name = @_thrs = @_wrks = ();
376  
377 my %_opts = (
378 max_workers => $_max_workers, task_name => $_tag,
379 69 user_tasks => $_user_tasks->{$_pid},
380 );
381  
382 69 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 69 0 69
383 69 local $_;
384  
385 69 for (keys %{ $_p }) {
386 124 ▶ 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" 12 112 124
Condition100%3/3
$_ eq "max_workers" and ref $_p->{"max_workers"} eq "ARRAY"
!ll&&!rl&&r
555712
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
387 112 ▶ 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 106 112
Condition66%2/3
$_ eq "task_name" and ref $_p->{"task_name"} eq "ARRAY"
!ll&&!rl&&r
10606
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
388 106 ▶ 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 106 106
Condition33%1/3
$_ eq "use_threads" and ref $_p->{"use_threads"} eq "ARRAY"
!ll&&!rl&&r
10600
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
389  
390 106 ▶ next if ($_ eq 'chunk_size');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "chunk_size" 0 106 106
391 106 ▶ next if ($_ eq 'input_data');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "input_data" 0 106 106
392 106 ▶ next if ($_ eq 'sequence_run');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "sequence_run" 0 106 106
393  
394 _croak("$_tag: ($_) is not a valid constructor argument")
395 106 ▶ unless (exists $MCE::_valid_fields_new{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $MCE::_valid_fields_new{$_} 0 106 106
396  
397 106 $_opts{$_} = $_p->{$_};
398 }
399 }
400  
401 69 for my $_k (qw/ tmp_dir freeze thaw init_relay use_threads /) {
402 $_opts{$_k} = $_def->{$_pkg}{uc($_k)}
403 345 ▶ 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 345 345
Condition33%1/3
exists $_def->{$_pkg}{uc $_k} and not exists $_opts{$_k}
!ll&&!rl&&r
34500
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
404 }
405  
406 69 $_MCE->{$_pid} = MCE->new(pkg => $_pkg, %_opts);
407 }
408 else {
409 ## Workers may persist after running. Thus, updating the MCE instance.
410 ## These options do not require respawning.
411 10 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 10 0 10
412 10 for my $_k (qw(
413 RS interval stderr_file stdout_file user_error user_output
414 job_delay submit_delay on_post_exit on_post_run user_args
415 flush_file flush_stderr flush_stdout gather max_retries
416 )) {
417 160 ▶ $_MCE->{$_pid}{$_k} = $_p->{$_k} if (exists $_p->{$_k});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{$_k} 10 150 160
418 }
419 }
420 }
421  
422 ## -------------------------------------------------------------------------
423  
424 79 ▶ my @_a; my $_wa = wantarray; $_MCE->{$_pid}{gather} = \@_a if (defined $_wa);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_wa 31 48 79
425  
426 79 ▶ if (defined $_input_data) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_input_data) { } 8 71 79
elsif (scalar @_) { } 6 65 71
427 8 @_ = ();
428 8 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, $_input_data);
429 7 delete $_MCE->{$_pid}{input_data};
430 }
431 elsif (scalar @_) {
432 6 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, \@_);
433 2 delete $_MCE->{$_pid}{input_data};
434 }
435 else {
436 65 ▶ if (defined $_params->{$_pid} && exists $_params->{$_pid}{sequence}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_params->{$_pid} and exists $_params->{$_pid}{'sequence'}) { } 2 63 65
Condition66%2/3
defined $_params->{$_pid} and exists $_params->{$_pid}{"sequence"}
!ll&&!rl&&r
0632
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
437 $_MCE->{$_pid}->run({
438 chunk_size => $_chunk_size,
439 sequence => $_params->{$_pid}{sequence}
440 2 }, 0);
441 2 ▶ if (exists $_params->{$_pid}{sequence_run}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_params->{$_pid}{"sequence_run"}) 2 0 2
442 2 delete $_params->{$_pid}{sequence_run};
443 2 delete $_params->{$_pid}{sequence};
444 }
445 2 delete $_MCE->{$_pid}{sequence};
446 }
447 else {
448 63 $_MCE->{$_pid}->run({ chunk_size => $_chunk_size }, 0);
449 }
450 }
451  
452 46 MCE::_restore_state();
453  
454 46 ▶ delete $_MCE->{$_pid}{gather} if (defined $_wa);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_wa 18 28 46
455  
456 46 ▶ return ((defined $_wa) ? @_a : ());
Branch: 1 branch
BranchTrueFalseTotal
defined $_wa ? : 18 28 46
457 }
458  
459 ###############################################################################
460 ## ----------------------------------------------------------------------------
461 ## Private methods.
462 ##
463 ###############################################################################
464  
465 0 ▶sub _croak {
Subroutine _croak: not called CC=1 SCAR=6.9
466  
467 0 goto &MCE::_croak;
468 }
469  
470 69 ▶sub _gen_user_tasks {
Subroutine _gen_user_tasks: called CC=2 SCAR=6.9
471  
472 69 my ($_pid, $_code_ref, $_name_ref, $_thrs_ref, $_wrks_ref) = @_;
473  
474 69 @{ $_user_tasks->{$_pid} } = ();
475  
476 69 ▶ for (my $_i = 0; $_i < @{ $_code_ref }; $_i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_i < @{$_code_ref;}) 81 69 150
477 81 push @{ $_user_tasks->{$_pid} }, {
478 task_name => $_name_ref->[$_i],
479 use_threads => $_thrs_ref->[$_i],
480 max_workers => $_wrks_ref->[$_i],
481 user_func => $_code_ref->[$_i]
482 }
483 }
484  
485 69 return;
486 }
487  
488 46 1;
489  
490 __END__
« MCE/Step.pm ↑ Summary MCE/Core/Input/Request.pm »