MCE/Loop.pm

filter: Statementstmt 78.0% 142 / 182 Branchbran 51.4% 72 / 140 Conditioncond 42.8% 24 / 56 MC/DCmcdc 13.8% 5 / 36 Subroutinesub 81.2% 13 / 16 Podpod 100% 5 / 5 totaltotal 60.0% 261 / 435 CC 92 SCAR 35.9
CC
92
Cov
63%
run_seq
54.6
import
51.4
run
50.4
CRAP 36.3
« MCE/Mutex/Flock.pm ↑ Summary MCE/Queue.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.904';
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 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 5 my ($_MCE, $_def, $_params, $_prev_c, $_tag) = ({}, {}, {}, {}, 'MCE::Loop');
38  
39 5 ▶sub import {
Subroutine import: called CC=13 SCAR=39.4
40 5 my ($_class, $_pkg) = (shift, caller);
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 0 ▶sub MCE::Loop::_guard::DESTROY {
Subroutine DESTROY: not called CC=3 SCAR=24.8
96 0 my ($_pkg, $_id) = @{ $_[0] };
97  
98 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
99 0 @{ $_[0] } = ();
100 0 MCE::Loop->finish($_pkg);
101 }
102  
103 0 return;
104 }
105  
106 6 ▶sub init (@) {
Subroutine init: called CC=5 SCAR=18.1
Pod documented
107  
108 6 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Loop');
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
109 6 my $_pkg = "$$.$_tid.".caller();
110  
111 6 ▶ $_params->{$_pkg} = (ref $_[0] eq 'HASH') ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 6 6
112  
113 6 @_ = ();
114  
115 defined wantarray
116 6 ▶ ? bless([$_pkg, "$$.$_tid"], MCE::Loop::_guard::)
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray ? : 0 6 6
117 : ();
118 }
119  
120 11 ▶sub finish (@) {
Subroutine finish: called CC=9 SCAR=22.5
Pod documented
121  
122 11 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Loop');
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
123 11 ▶ my $_pkg = (defined $_[0]) ? shift : "$$.$_tid.".caller();
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 8 3 11
124  
125 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
126 5 for my $_k ( keys %{ $_MCE } ) { MCE::Loop->finish($_k, 1); }
127 }
128 ▶ 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
129 3 ▶ $_MCE->{$_pkg}->shutdown(@_) if $_MCE->{$_pkg}{_spawned};
Branch: 1 branch
BranchTrueFalseTotal
if $_MCE->{$_pkg}{"_spawned"} 3 0 3
130  
131 3 delete $_prev_c->{$_pkg};
132 3 delete $_MCE->{$_pkg};
133 }
134  
135 11 @_ = ();
136  
137 11 return;
138 }
139  
140 ###############################################################################
141 ## ----------------------------------------------------------------------------
142 ## Parallel loop with MCE -- file.
143 ##
144 ###############################################################################
145  
146 4 ▶sub run_file (&@) {
Subroutine run_file: called CC=14 SCAR=30.8
Pod documented
147  
148 4 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Loop');
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
149  
150 4 my $_code = shift; my $_file = shift;
151 4 my $_pid = "$$.$_tid.".caller();
152  
153 4 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 4 0 4
154 4 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 4 4
155 4 ▶ delete $_p->{sequence} if (exists $_p->{sequence});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"sequence"} 0 4 4
156 }
157 else {
158 0 $_params->{$_pid} = {};
159 }
160  
161 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
162 2 ▶ _croak("$_tag: ($_file) does not exist") unless (-e $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $_file 0 2 2
163 2 ▶ _croak("$_tag: ($_file) is not readable") unless (-r $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -r $_file 0 2 2
164 2 ▶ _croak("$_tag: ($_file) is not a plain file") unless (-f $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_file 0 2 2
165 2 $_params->{$_pid}{_file} = $_file;
166 }
167 ▶ 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
168 2 $_params->{$_pid}{_file} = $_file;
169 }
170 else {
171 0 _croak("$_tag: (file) is not specified or valid");
172 }
173  
174 4 @_ = ();
175  
176 4 return run($_code);
177 }
178  
179 ###############################################################################
180 ## ----------------------------------------------------------------------------
181 ## Parallel loop with MCE -- sequence.
182 ##
183 ###############################################################################
184  
185 2 ▶sub run_seq (&@) {
Subroutine run_seq: called CC=16 SCAR=40.0
Pod documented
186  
187 2 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Loop');
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
188  
189 2 my $_code = shift;
190 2 my $_pid = "$$.$_tid.".caller();
191  
192 2 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 2 0 2
193 2 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 2 2
194 2 ▶ delete $_p->{_file} if (exists $_p->{_file});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"_file"} 0 2 2
195 }
196 else {
197 0 $_params->{$_pid} = {};
198 }
199  
200 2 my ($_begin, $_end);
201  
202 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
203 0 $_begin = $_[0]->{begin}, $_end = $_[0]->{end};
204 0 $_params->{$_pid}{sequence} = $_[0];
205 }
206 elsif (ref $_[0] eq 'ARRAY') {
207 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
208 0 $_begin = $_[0]->[0], $_end = $_[0]->[-1];
209 0 $_params->{$_pid}{sequence} = [ $_[0]->[0], $_[0]->[-1] ];
210 }
211 else {
212 0 $_begin = $_[0]->[0], $_end = $_[0]->[1];
213 0 $_params->{$_pid}{sequence} = $_[0];
214 }
215 }
216 ▶ 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
217 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
218 0 $_begin = $_[0], $_end = $_[-1];
219 0 $_params->{$_pid}{sequence} = [ $_[0], $_[-1] ];
220 }
221 else {
222 2 $_begin = $_[0], $_end = $_[1];
223 2 $_params->{$_pid}{sequence} = [ @_ ];
224 }
225 }
226 else {
227 0 _croak("$_tag: (sequence) is not specified or valid");
228 }
229  
230 2 ▶ _croak("$_tag: (begin) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_begin 0 2 2
231 unless (defined $_begin);
232 2 ▶ _croak("$_tag: (end) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_end 0 2 2
233 unless (defined $_end);
234  
235 2 $_params->{$_pid}{sequence_run} = undef;
236  
237 2 @_ = ();
238  
239 2 return run($_code);
240 }
241  
242 ###############################################################################
243 ## ----------------------------------------------------------------------------
244 ## Parallel loop with MCE.
245 ##
246 ###############################################################################
247  
248 14 ▶sub run (&@) {
Subroutine run: called CC=37 SCAR=39.2
Pod documented
249  
250 14 my $_caller = caller();
251 14 ▶ if ($_caller ne 'MCE::Loop' && !exists $_def->{$_caller}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_caller ne "MCE::Loop" and not exists $_def->{$_caller}) 0 14 14
Condition66%2/3
$_caller ne "MCE::Loop" and not exists $_def->{$_caller}
!ll&&!rl&&r
680
MC/DC0%0/2
$_caller ne "MCE::Loop" and not exists $_def->{$_caller}
$_caller ne "MCE::Loop" not exists $_def->{$_caller}
Truth table66%2/3
A and not(B)
A= $_caller ne "MCE::Loop"B= not exists $_def->{$_caller}
ABresult
0X0
100
111
252 0 warn "MCE::Loop is not imported into the \"$_caller\" namespace. Aborting...\n";
253 0 return;
254 }
255  
256 14 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Loop');
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
257  
258 14 my $_code = shift;
259 14 ▶ my $_pkg = $_caller eq 'MCE::Loop' ? caller(1) : $_caller;
Branch: 1 branch
BranchTrueFalseTotal
$_caller eq 'MCE::Loop' ? : 6 8 14
260 14 my $_pid = "$$.$_tid.$_pkg";
261  
262 14 my $_input_data; my $_max_workers = $_def->{$_pkg}{MAX_WORKERS};
263 14 my $_r = ref $_[0];
264  
265 14 ▶ if (@_ == 1 && $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::|Iterator::)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::|Iterator::)/) 4 10 14
Condition66%2/3
@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::|Iterator::)/
!ll&&!rl&&r
1004
MC/DC50%1/2
@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::|Iterator::)/
@_ == 1 $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::|Iterator::)/
Truth table66%2/3
A and B
A= @_ == 1B= $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::|Iterator::)/
ABresult
0X0
100
111
266 4 $_input_data = shift;
267 }
268  
269 14 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 14 0 14
270 $_max_workers = MCE::_parse_max_workers($_p->{max_workers})
271 14 ▶ if (exists $_p->{max_workers});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"max_workers"} 14 0 14
272  
273 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
274 14 ▶ delete $_p->{user_func} if (exists $_p->{user_func});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_func"} 0 14 14
275 14 ▶ delete $_p->{user_tasks} if (exists $_p->{user_tasks});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_tasks"} 0 14 14
276 }
277  
278 my $_chunk_size = MCE::_parse_chunk_size(
279 14 $_def->{$_pkg}{CHUNK_SIZE}, $_max_workers, $_params->{$_pid},
280 $_input_data, scalar @_
281 );
282  
283 14 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 14 0 14
284 14 ▶ if (exists $_p->{_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_p->{'_file'}) { } 4 10 14
285 4 $_input_data = delete $_p->{_file};
286 } else {
287 10 ▶ $_input_data = $_p->{input_data} if exists $_p->{input_data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 10 10
288 }
289 }
290  
291 ## -------------------------------------------------------------------------
292  
293 14 MCE::_save_state($_MCE->{$_pid});
294  
295 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
296 6 ▶ $_MCE->{$_pid}->shutdown() if (defined $_MCE->{$_pid});
Branch: 1 branch
BranchTrueFalseTotal
if defined $_MCE->{$_pid} 0 6 6
297 6 $_prev_c->{$_pid} = $_code;
298  
299 6 my %_opts = (
300 max_workers => $_max_workers, task_name => $_tag,
301 user_func => $_code,
302 );
303  
304 6 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 6 0 6
305 6 for my $_k (keys %{ $_p }) {
306 10 ▶ next if ($_k eq 'sequence_run');
Branch: 1 branch
BranchTrueFalseTotal
if $_k eq "sequence_run" 0 10 10
307 10 ▶ next if ($_k eq 'input_data');
Branch: 1 branch
BranchTrueFalseTotal
if $_k eq "input_data" 0 10 10
308 10 ▶ next if ($_k eq 'chunk_size');
Branch: 1 branch
BranchTrueFalseTotal
if $_k eq "chunk_size" 0 10 10
309  
310 _croak("$_tag: ($_k) is not a valid constructor argument")
311 10 ▶ unless (exists $MCE::_valid_fields_new{$_k});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $MCE::_valid_fields_new{$_k} 0 10 10
312  
313 10 $_opts{$_k} = $_p->{$_k};
314 }
315 }
316  
317 6 for my $_k (qw/ tmp_dir freeze thaw init_relay use_threads /) {
318 $_opts{$_k} = $_def->{$_pkg}{uc($_k)}
319 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
320 }
321  
322 6 $_MCE->{$_pid} = MCE->new(pkg => $_pkg, %_opts);
323 }
324  
325 ## -------------------------------------------------------------------------
326  
327 14 ▶ my @_a; my $_wa = wantarray; $_MCE->{$_pid}{gather} = \@_a if (defined $_wa);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_wa 2 12 14
328  
329 14 ▶ if (defined $_input_data) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_input_data) { } 8 6 14
elsif (scalar @_) { } 4 2 6
330 8 @_ = ();
331 8 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, $_input_data);
332 7 delete $_MCE->{$_pid}{input_data};
333 }
334 elsif (scalar @_) {
335 4 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, \@_);
336 2 delete $_MCE->{$_pid}{input_data};
337 }
338 else {
339 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
340 $_MCE->{$_pid}->run({
341 chunk_size => $_chunk_size,
342 sequence => $_params->{$_pid}{sequence}
343 2 }, 0);
344 2 ▶ if (exists $_params->{$_pid}{sequence_run}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_params->{$_pid}{"sequence_run"}) 2 0 2
345 2 delete $_params->{$_pid}{sequence_run};
346 2 delete $_params->{$_pid}{sequence};
347 }
348 2 delete $_MCE->{$_pid}{sequence};
349 }
350 }
351  
352 11 MCE::_restore_state();
353  
354 11 ▶ delete $_MCE->{$_pid}{gather} if (defined $_wa);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_wa 1 10 11
355  
356 11 ▶ return ((defined $_wa) ? @_a : ());
Branch: 1 branch
BranchTrueFalseTotal
defined $_wa ? : 1 10 11
357 }
358  
359 ###############################################################################
360 ## ----------------------------------------------------------------------------
361 ## Private methods.
362 ##
363 ###############################################################################
364  
365 0 ▶sub _croak {
Subroutine _croak: not called CC=1 SCAR=6.9
366  
367 0 goto &MCE::_croak;
368 }
369  
370 5 1;
371  
372 __END__
« MCE/Mutex/Flock.pm ↑ Summary MCE/Queue.pm »