MCE/Stream.pm

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