MCE/Loop.pm

filter: Statementstmt 81.8% 140 / 171 Branchbran 52.2% 70 / 134 Conditioncond 44.0% 22 / 50 MC/DCmcdc 15.6% 5 / 32 Subroutinesub 86.6% 13 / 15 Podpod 100% 5 / 5 totaltotal 62.6% 255 / 407 SCAR 60.0
CC
87
Cov
65%
run_seq
54.6
import
51.4
run
44.3
CRAP 401.8
« MCE/Flow.pm ↑ Summary MCE/Core/Input/Handle.pm »
1 ###############################################################################
2 ## ----------------------------------------------------------------------------
3 ## MCE model for building parallel loops.
4 ##
5 ###############################################################################
6  
7 package MCE::Loop;
8  
9 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶no warnings qw( threads recursion uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 our $VERSION = '1.889';
15  
16 ## no critic (BuiltinFunctions::ProhibitStringyEval)
17 ## no critic (Subroutines::ProhibitSubroutinePrototypes)
18 ## no critic (TestingAndDebugging::ProhibitNoStrict)
19  
20 5 ▶use Scalar::Util qw( looks_like_number );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use MCE;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 5 our @CARP_NOT = qw( MCE );
24  
25 5 ▶my $_tid = $INC{'threads.pm'} ? threads->tid() : 0;
Branch: 1 branch
BranchTrueFalseTotal
$INC{'threads.pm'} ? : 0 5 5
26  
27 sub CLONE {
28 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
29 }
30  
31 ###############################################################################
32 ## ----------------------------------------------------------------------------
33 ## Import routine.
34 ##
35 ###############################################################################
36  
37 5 my ($_MCE, $_def, $_params, $_prev_c, $_tag) = ({}, {}, {}, {}, 'MCE::Loop');
38  
39 sub import {
40 5 ▶ my ($_class, $_pkg) = (shift, caller);
Subroutine import: called CC=13 SCAR=39.4
41  
42 5 my $_p = $_def->{$_pkg} = {
43 MAX_WORKERS => 'auto',
44 CHUNK_SIZE => 'auto',
45 };
46  
47 ## Import functions.
48 5 ▶ if ($_pkg !~ /^MCE::/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_pkg =~ /^MCE::/) 5 0 5
49 5 ▶ no strict 'refs'; no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
50 5 *{ $_pkg.'::mce_loop_f' } = \&run_file;
51 5 *{ $_pkg.'::mce_loop_s' } = \&run_seq;
52 5 *{ $_pkg.'::mce_loop' } = \&run;
53 }
54  
55 ## Process module arguments.
56 5 ▶ while ( my $_argument = shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $_argument = shift()) 0 5 5
57 0 my $_arg = lc $_argument;
58  
59 0 ▶ $_p->{MAX_WORKERS} = shift, next if ( $_arg eq 'max_workers' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "max_workers" 0 0 0
60 0 ▶ $_p->{CHUNK_SIZE} = shift, next if ( $_arg eq 'chunk_size' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "chunk_size" 0 0 0
61 0 ▶ $_p->{TMP_DIR} = shift, next if ( $_arg eq 'tmp_dir' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "tmp_dir" 0 0 0
62 0 ▶ $_p->{FREEZE} = shift, next if ( $_arg eq 'freeze' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "freeze" 0 0 0
63 0 ▶ $_p->{THAW} = shift, next if ( $_arg eq 'thaw' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "thaw" 0 0 0
64 0 ▶ $_p->{INIT_RELAY} = shift, next if ( $_arg eq 'init_relay' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "init_relay" 0 0 0
65 0 ▶ $_p->{USE_THREADS} = shift, next if ( $_arg eq 'use_threads' );
Branch: 1 branch
BranchTrueFalseTotal
if $_arg eq "use_threads" 0 0 0
66  
67 ## Sereal 3.015+, if available, is used automatically by MCE 1.8+.
68 0 ▶ if ( $_arg eq 'sereal' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_arg eq "sereal") 0 0 0
69 0 ▶ if ( shift eq '0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (shift() eq 0) 0 0 0
70 0 require Storable;
71 0 $_p->{FREEZE} = \&Storable::freeze;
72 0 $_p->{THAW} = \&Storable::thaw;
73 }
74 0 next;
75 }
76  
77 0 _croak("Error: ($_argument) invalid module option");
78 }
79  
80 5 $_p->{MAX_WORKERS} = MCE::_parse_max_workers($_p->{MAX_WORKERS});
81  
82 5 MCE::_validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS', $_tag);
83 MCE::_validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE', $_tag)
84 5 ▶ unless ($_p->{CHUNK_SIZE} eq 'auto');
Branch: 1 branch
BranchTrueFalseTotal
unless $_p->{"CHUNK_SIZE"} eq "auto" 0 5 5
85  
86 5 return;
87 }
88  
89 ###############################################################################
90 ## ----------------------------------------------------------------------------
91 ## Init and finish routines.
92 ##
93 ###############################################################################
94  
95 sub init (@) {
96  
97 6 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Loop');
Subroutine init: called CC=4 SCAR=15.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Loop" 6 0 6
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Loop"
!ll&&!rl&&r
006
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Loop"
defined $_[0] $_[0] eq "MCE::Loop"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Loop"
ABresult
0X0
100
111
98 6 my $_pkg = "$$.$_tid.".caller();
99  
100 6 ▶ $_params->{$_pkg} = (ref $_[0] eq 'HASH') ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 6 6
101  
102 6 @_ = ();
103  
104 6 return;
105 }
106  
107 sub finish (@) {
108  
109 11 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Loop');
Subroutine finish: called CC=9 SCAR=22.5
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Loop" 11 0 11
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Loop"
!ll&&!rl&&r
0011
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Loop"
defined $_[0] $_[0] eq "MCE::Loop"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Loop"
ABresult
0X0
100
111
110 11 ▶ my $_pkg = (defined $_[0]) ? shift : "$$.$_tid.".caller();
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 8 3 11
111  
112 11 ▶ if ( $_pkg eq 'MCE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_pkg eq 'MCE') { } 5 6 11
elsif ($_MCE->{$_pkg} and $_MCE->{$_pkg}{'_init_pid'} eq "${$}.$_tid") { } 3 3 6
113 5 for my $_k ( keys %{ $_MCE } ) { MCE::Loop->finish($_k, 1); }
114 }
115 ▶ elsif ( $_MCE->{$_pkg} && $_MCE->{$_pkg}{_init_pid} eq "$$.$_tid" ) {
Condition66%2/3
$_MCE->{$_pkg} and $_MCE->{$_pkg}{"_init_pid"} eq "${$}.$_tid"
!ll&&!rl&&r
033
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
116 3 ▶ $_MCE->{$_pkg}->shutdown(@_) if $_MCE->{$_pkg}{_spawned};
Branch: 1 branch
BranchTrueFalseTotal
if $_MCE->{$_pkg}{"_spawned"} 3 0 3
117  
118 3 delete $_prev_c->{$_pkg};
119 3 delete $_MCE->{$_pkg};
120 }
121  
122 11 @_ = ();
123  
124 11 return;
125 }
126  
127 ###############################################################################
128 ## ----------------------------------------------------------------------------
129 ## Parallel loop with MCE -- file.
130 ##
131 ###############################################################################
132  
133 sub run_file (&@) {
134  
135 4 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Loop');
Subroutine run_file: called CC=14 SCAR=30.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Loop" 0 4 4
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Loop"
!ll&&!rl&&r
040
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Loop"
defined $_[0] $_[0] eq "MCE::Loop"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Loop"
ABresult
0X0
100
111
136  
137 4 my $_code = shift; my $_file = shift;
138 4 my $_pid = "$$.$_tid.".caller();
139  
140 4 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 4 0 4
141 4 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 4 4
142 4 ▶ delete $_p->{sequence} if (exists $_p->{sequence});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"sequence"} 0 4 4
143 }
144 else {
145 0 $_params->{$_pid} = {};
146 }
147  
148 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
149 2 ▶ _croak("$_tag: ($_file) does not exist") unless (-e $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $_file 0 2 2
150 2 ▶ _croak("$_tag: ($_file) is not readable") unless (-r $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -r $_file 0 2 2
151 2 ▶ _croak("$_tag: ($_file) is not a plain file") unless (-f $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_file 0 2 2
152 2 $_params->{$_pid}{_file} = $_file;
153 }
154 ▶ 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
155 2 $_params->{$_pid}{_file} = $_file;
156 }
157 else {
158 0 _croak("$_tag: (file) is not specified or valid");
159 }
160  
161 4 @_ = ();
162  
163 4 return run($_code);
164 }
165  
166 ###############################################################################
167 ## ----------------------------------------------------------------------------
168 ## Parallel loop with MCE -- sequence.
169 ##
170 ###############################################################################
171  
172 sub run_seq (&@) {
173  
174 2 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Loop');
Subroutine run_seq: called CC=16 SCAR=40.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Loop" 0 2 2
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Loop"
!ll&&!rl&&r
020
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Loop"
defined $_[0] $_[0] eq "MCE::Loop"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Loop"
ABresult
0X0
100
111
175  
176 2 my $_code = shift;
177 2 my $_pid = "$$.$_tid.".caller();
178  
179 2 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 2 0 2
180 2 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 2 2
181 2 ▶ delete $_p->{_file} if (exists $_p->{_file});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"_file"} 0 2 2
182 }
183 else {
184 0 $_params->{$_pid} = {};
185 }
186  
187 2 my ($_begin, $_end);
188  
189 2 ▶ if (ref $_[0] eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 2 2
elsif (ref $_[0] eq 'ARRAY') { } 0 2 2
elsif (ref $_[0] eq '' or ref($_[0]) =~ /^Math::/) { } 2 0 2
190 0 $_begin = $_[0]->{begin}, $_end = $_[0]->{end};
191 0 $_params->{$_pid}{sequence} = $_[0];
192 }
193 elsif (ref $_[0] eq 'ARRAY') {
194 0 ▶ if (@{ $_[0] } > 3 && $_[0]->[3] =~ /\d$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$_[0];} > 3 and $_[0][3] =~ /\d$/) { } 0 0 0
Condition0%0/3
@{$_[0];} > 3 and $_[0][3] =~ /\d$/
!ll&&!rl&&r
000
MC/DC0%0/2
@{$_[0];} > 3 and $_[0][3] =~ /\d$/
@{$_[0];} > 3 $_[0][3] =~ /\d$/
Truth table0%0/3
A and B
A= @{$_[0];} > 3B= $_[0][3] =~ /\d$/
ABresult
0X0
100
111
195 0 $_begin = $_[0]->[0], $_end = $_[0]->[-1];
196 0 $_params->{$_pid}{sequence} = [ $_[0]->[0], $_[0]->[-1] ];
197 }
198 else {
199 0 $_begin = $_[0]->[0], $_end = $_[0]->[1];
200 0 $_params->{$_pid}{sequence} = $_[0];
201 }
202 }
203 ▶ elsif (ref $_[0] eq '' || ref($_[0]) =~ /^Math::/) {
Condition33%1/3
ref $_[0] eq "" or ref($_[0]) =~ /^Math::/
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $_[0] eq "" or ref($_[0]) =~ /^Math::/
ref $_[0] eq "" ref($_[0]) =~ /^Math::/
Truth table33%1/3
A or B
A= ref $_[0] eq ""B= ref($_[0]) =~ /^Math::/
ABresult
1X1
011
000
204 2 ▶ if (@_ > 3 && $_[3] =~ /\d$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 3 and $_[3] =~ /\d$/) { } 0 2 2
Condition33%1/3
@_ > 3 and $_[3] =~ /\d$/
!ll&&!rl&&r
200
MC/DC0%0/2
@_ > 3 and $_[3] =~ /\d$/
@_ > 3 $_[3] =~ /\d$/
Truth table33%1/3
A and B
A= @_ > 3B= $_[3] =~ /\d$/
ABresult
0X0
100
111
205 0 $_begin = $_[0], $_end = $_[-1];
206 0 $_params->{$_pid}{sequence} = [ $_[0], $_[-1] ];
207 }
208 else {
209 2 $_begin = $_[0], $_end = $_[1];
210 2 $_params->{$_pid}{sequence} = [ @_ ];
211 }
212 }
213 else {
214 0 _croak("$_tag: (sequence) is not specified or valid");
215 }
216  
217 2 ▶ _croak("$_tag: (begin) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_begin 0 2 2
218 unless (defined $_begin);
219 2 ▶ _croak("$_tag: (end) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_end 0 2 2
220 unless (defined $_end);
221  
222 2 $_params->{$_pid}{sequence_run} = undef;
223  
224 2 @_ = ();
225  
226 2 return run($_code);
227 }
228  
229 ###############################################################################
230 ## ----------------------------------------------------------------------------
231 ## Parallel loop with MCE.
232 ##
233 ###############################################################################
234  
235 sub run (&@) {
236  
237 14 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Loop');
Subroutine run: called CC=35 SCAR=37.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Loop" 0 14 14
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Loop"
!ll&&!rl&&r
0140
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Loop"
defined $_[0] $_[0] eq "MCE::Loop"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Loop"
ABresult
0X0
100
111
238  
239 14 my $_code = shift;
240 14 ▶ my $_pkg = caller() eq 'MCE::Loop' ? caller(1) : caller();
Branch: 1 branch
BranchTrueFalseTotal
caller() eq 'MCE::Loop' ? : 6 8 14
241 14 my $_pid = "$$.$_tid.$_pkg";
242  
243 14 my $_input_data; my $_max_workers = $_def->{$_pkg}{MAX_WORKERS};
244 14 my $_r = ref $_[0];
245  
246 14 ▶ if (@_ == 1 && $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::)/) 4 10 14
Condition66%2/3
@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::)/
!ll&&!rl&&r
1004
MC/DC50%1/2
@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::)/
@_ == 1 $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::)/
Truth table66%2/3
A and B
A= @_ == 1B= $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::)/
ABresult
0X0
100
111
247 4 $_input_data = shift;
248 }
249  
250 14 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 14 0 14
251 $_max_workers = MCE::_parse_max_workers($_p->{max_workers})
252 14 ▶ if (exists $_p->{max_workers});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"max_workers"} 14 0 14
253  
254 14 ▶ delete $_p->{sequence} if (defined $_input_data || scalar @_);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_input_data or scalar @_ 8 6 14
Condition100%2/2
defined $_input_data or scalar @_
l!l
410
MC/DC100%1/1
defined $_input_data or scalar @_
defined $_input_data
Truth table100%2/2
A
A= defined $_input_data
Aresult
11
00
255 14 ▶ delete $_p->{user_func} if (exists $_p->{user_func});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_func"} 0 14 14
256 14 ▶ delete $_p->{user_tasks} if (exists $_p->{user_tasks});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_tasks"} 0 14 14
257 }
258  
259 my $_chunk_size = MCE::_parse_chunk_size(
260 14 $_def->{$_pkg}{CHUNK_SIZE}, $_max_workers, $_params->{$_pid},
261 $_input_data, scalar @_
262 );
263  
264 14 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 14 0 14
265 14 ▶ if (exists $_p->{_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_p->{'_file'}) { } 4 10 14
266 4 $_input_data = delete $_p->{_file};
267 } else {
268 10 ▶ $_input_data = $_p->{input_data} if exists $_p->{input_data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 10 10
269 }
270 }
271  
272 ## -------------------------------------------------------------------------
273  
274 14 MCE::_save_state($_MCE->{$_pid});
275  
276 14 ▶ if (!defined $_prev_c->{$_pid} || $_prev_c->{$_pid} != $_code) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_prev_c->{$_pid} or $_prev_c->{$_pid} != $_code) 6 8 14
Condition66%2/3
not defined $_prev_c->{$_pid} or $_prev_c->{$_pid} != $_code
l!l&&r!l&&!r
608
MC/DC50%1/2
not defined $_prev_c->{$_pid} or $_prev_c->{$_pid} != $_code
not defined $_prev_c->{$_pid} $_prev_c->{$_pid} != $_code
Truth table66%2/3
not(A) or B
A= not defined $_prev_c->{$_pid}B= $_prev_c->{$_pid} != $_code
ABresult
1X1
011
000
277 6 ▶ $_MCE->{$_pid}->shutdown() if (defined $_MCE->{$_pid});
Branch: 1 branch
BranchTrueFalseTotal
if defined $_MCE->{$_pid} 0 6 6
278 6 $_prev_c->{$_pid} = $_code;
279  
280 6 my %_opts = (
281 max_workers => $_max_workers, task_name => $_tag,
282 user_func => $_code,
283 );
284  
285 6 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 6 0 6
286 6 for my $_k (keys %{ $_p }) {
287 10 ▶ next if ($_k eq 'sequence_run');
Branch: 1 branch
BranchTrueFalseTotal
if $_k eq "sequence_run" 0 10 10
288 10 ▶ next if ($_k eq 'input_data');
Branch: 1 branch
BranchTrueFalseTotal
if $_k eq "input_data" 0 10 10
289 10 ▶ next if ($_k eq 'chunk_size');
Branch: 1 branch
BranchTrueFalseTotal
if $_k eq "chunk_size" 0 10 10
290  
291 _croak("$_tag: ($_k) is not a valid constructor argument")
292 10 ▶ unless (exists $MCE::_valid_fields_new{$_k});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $MCE::_valid_fields_new{$_k} 0 10 10
293  
294 10 $_opts{$_k} = $_p->{$_k};
295 }
296 }
297  
298 6 for my $_k (qw/ tmp_dir freeze thaw init_relay use_threads /) {
299 $_opts{$_k} = $_def->{$_pkg}{uc($_k)}
300 30 ▶ 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 30 30
Condition33%1/3
exists $_def->{$_pkg}{uc $_k} and not exists $_opts{$_k}
!ll&&!rl&&r
3000
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
301 }
302  
303 6 $_MCE->{$_pid} = MCE->new(pkg => $_pkg, %_opts);
304 }
305  
306 ## -------------------------------------------------------------------------
307  
308 14 ▶ my @_a; my $_wa = wantarray; $_MCE->{$_pid}{gather} = \@_a if (defined $_wa);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_wa 2 12 14
309  
310 14 ▶ if (defined $_input_data) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_input_data) { } 8 6 14
elsif (scalar @_) { } 4 2 6
311 8 @_ = ();
312 8 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, $_input_data);
313 7 delete $_MCE->{$_pid}{input_data};
314 }
315 elsif (scalar @_) {
316 4 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, \@_);
317 2 delete $_MCE->{$_pid}{input_data};
318 }
319 else {
320 2 ▶ if (defined $_params->{$_pid} && exists $_params->{$_pid}{sequence}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_params->{$_pid} and exists $_params->{$_pid}{"sequence"}) 2 0 2
Condition33%1/3
defined $_params->{$_pid} and exists $_params->{$_pid}{"sequence"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $_params->{$_pid} and exists $_params->{$_pid}{"sequence"}
defined $_params->{$_pid} exists $_params->{$_pid}{"sequence"}
Truth table33%1/3
A and B
A= defined $_params->{$_pid}B= exists $_params->{$_pid}{"sequence"}
ABresult
0X0
100
111
321 $_MCE->{$_pid}->run({
322 chunk_size => $_chunk_size,
323 sequence => $_params->{$_pid}{sequence}
324 2 }, 0);
325 2 ▶ if (exists $_params->{$_pid}{sequence_run}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_params->{$_pid}{"sequence_run"}) 2 0 2
326 2 delete $_params->{$_pid}{sequence_run};
327 2 delete $_params->{$_pid}{sequence};
328 }
329 2 delete $_MCE->{$_pid}{sequence};
330 }
331 }
332  
333 11 MCE::_restore_state();
334  
335 11 ▶ delete $_MCE->{$_pid}{gather} if (defined $_wa);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_wa 1 10 11
336  
337 11 ▶ return ((defined $_wa) ? @_a : ());
Branch: 1 branch
BranchTrueFalseTotal
defined $_wa ? : 1 10 11
338 }
339  
340 ###############################################################################
341 ## ----------------------------------------------------------------------------
342 ## Private methods.
343 ##
344 ###############################################################################
345  
346 sub _croak {
347  
348 0 ▶ goto &MCE::_croak;
Subroutine _croak: not called CC=1 SCAR=6.9
349 }
350  
351 5 1;
352  
353 __END__
« MCE/Flow.pm ↑ Summary MCE/Core/Input/Handle.pm »