MCE/Stream.pm

filter: Statementstmt 76.3% 290 / 380 Branchbran 52.7% 134 / 254 Conditioncond 51.8% 55 / 106 MC/DCmcdc 19.7% 13 / 66 Subroutinesub 82.6% 19 / 23 Podpod 100% 5 / 5 totaltotal 61.8% 516 / 834 CC 180 SCAR 52.1
CC
180
Cov
65%
run
374.1
import
90.6
run_seq
48.6
CRAP 182.7
« MCE/Core/Input/Sequence.pm ↑ Summary MCE/Util.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.904';
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 0 ▶sub CLONE {
Subroutine CLONE: not called CC=2 SCAR=17.9
30 0 ▶ $_tid = threads->tid() if $INC{'threads.pm'};
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 10 ▶sub import {
Subroutine import: called CC=17 SCAR=45.1
44 10 my ($_class, $_pkg) = (shift, caller);
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 379 ▶sub _preserve_order {
Subroutine _preserve_order: called CC=3 SCAR=11.0
110  
111 379 $_tmp{$_[1]} = $_[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 102 ▶sub _task_end {
Subroutine _task_end: called CC=4 SCAR=14.1
127  
128 102 my ($_mce, $_task_id, $_task_name) = @_;
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 0 ▶sub MCE::Stream::_guard::DESTROY {
Subroutine DESTROY: not called CC=3 SCAR=24.8
151 0 my ($_pkg, $_id) = @{ $_[0] };
152  
153 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
154 0 @{ $_[0] } = ();
155 0 MCE::Stream->finish($_pkg);
156 }
157  
158 0 return;
159 }
160  
161 9 ▶sub init (@) {
Subroutine init: called CC=6 SCAR=20.3
Pod documented
162  
163 9 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Stream');
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
164 9 my $_pkg = "$$.$_tid.".caller();
165  
166 9 ▶ $_params->{$_pkg} = (ref $_[0] eq 'HASH') ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 9 9
167  
168 _croak("$_tag: (HASH) not allowed as input by this MCE model")
169 9 ▶ if ( ref $_params->{$_pkg}{input_data} eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_params->{$_pkg}{"input_data"} eq "HASH" 0 9 9
170  
171 9 @_ = ();
172  
173 defined wantarray
174 9 ▶ ? bless([$_pkg, "$$.$_tid"], MCE::Stream::_guard::)
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray ? : 0 9 9
175 : ();
176 }
177  
178 24 ▶sub finish (@) {
Subroutine finish: called CC=11 SCAR=24.4
Pod documented
179  
180 24 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Stream');
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
181 24 ▶ my $_pkg = (defined $_[0]) ? shift : "$$.$_tid.".caller();
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 18 6 24
182  
183 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
184 10 for my $_k ( keys %{ $_MCE } ) { MCE::Stream->finish($_k, 1); }
185 }
186 ▶ 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
187 6 ▶ $_MCE->{$_pkg}->shutdown(@_) if $_MCE->{$_pkg}{_spawned};
Branch: 1 branch
BranchTrueFalseTotal
if $_MCE->{$_pkg}{"_spawned"} 6 0 6
188 6 $_gather_ref = $_order_id = undef, undef %_tmp;
189  
190 6 delete $_user_tasks->{$_pkg};
191 6 delete $_prev_c->{$_pkg};
192 6 delete $_prev_m->{$_pkg};
193 6 delete $_prev_n->{$_pkg};
194 6 delete $_prev_w->{$_pkg};
195 6 delete $_MCE->{$_pkg};
196  
197 6 ▶ if (defined $_queue->{$_pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_queue->{$_pkg}) 6 0 6
198 6 local $_;
199 6 $_->DESTROY() for (@{ $_queue->{$_pkg} });
200 6 delete $_queue->{$_pkg};
201 }
202 }
203  
204 24 @_ = ();
205  
206 24 return;
207 }
208  
209 ###############################################################################
210 ## ----------------------------------------------------------------------------
211 ## Parallel stream with MCE -- file.
212 ##
213 ###############################################################################
214  
215 20 ▶sub run_file (@) {
Subroutine run_file: called CC=21 SCAR=34.5
Pod documented
216  
217 20 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Stream');
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
218  
219 20 ▶ my ($_file, $_pos); my $_start_pos = (ref $_[0] eq 'HASH') ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 20 20
220 20 my $_pid = "$$.$_tid.".caller();
221  
222 20 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 20 0 20
223 20 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 20 20
224 20 ▶ delete $_p->{sequence} if (exists $_p->{sequence});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"sequence"} 0 20 20
225 }
226 else {
227 0 $_params->{$_pid} = {};
228 }
229  
230 20 for my $_i ($_start_pos .. @_ - 1) {
231 50 my $_r = ref $_[$_i];
232 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::)/) 20 30 50
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
233 20 $_file = $_[$_i]; $_pos = $_i;
234 20 last;
235 }
236 }
237  
238 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
239 10 ▶ _croak("$_tag: ($_file) does not exist") unless (-e $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $_file 0 10 10
240 10 ▶ _croak("$_tag: ($_file) is not readable") unless (-r $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -r $_file 0 10 10
241 10 ▶ _croak("$_tag: ($_file) is not a plain file") unless (-f $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_file 0 10 10
242 10 $_params->{$_pid}{_file} = $_file;
243 }
244 ▶ 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
245 10 $_params->{$_pid}{_file} = $_file;
246 }
247 else {
248 0 _croak("$_tag: (file) is not specified or valid");
249 }
250  
251 20 ▶ if (defined $_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_pos) 20 0 20
252 20 pop @_ for ($_pos .. @_ - 1);
253 }
254  
255 20 return run(@_);
256 }
257  
258 ###############################################################################
259 ## ----------------------------------------------------------------------------
260 ## Parallel stream with MCE -- sequence.
261 ##
262 ###############################################################################
263  
264 10 ▶sub run_seq (@) {
Subroutine run_seq: called CC=22 SCAR=38.8
Pod documented
265  
266 10 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Stream');
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
267  
268 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
269 10 my $_pid = "$$.$_tid.".caller();
270  
271 10 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 10 0 10
272 10 ▶ delete $_p->{sequence} if (exists $_p->{sequence});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"sequence"} 0 10 10
273 10 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 10 10
274 10 ▶ delete $_p->{_file} if (exists $_p->{_file});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"_file"} 0 10 10
275 }
276 else {
277 0 $_params->{$_pid} = {};
278 }
279  
280 10 for my $_i ($_start_pos .. @_ - 1) {
281 25 my $_r = ref $_[$_i];
282  
283 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") 10 15 25
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
284 10 $_pos = $_i;
285  
286 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
287 10 $_begin = $_[$_pos], $_end = $_[$_pos + 1];
288 $_params->{$_pid}{sequence} = [
289 10 $_[$_pos], $_[$_pos + 1], $_[$_pos + 2], $_[$_pos + 3]
290 ];
291 }
292 elsif ($_r eq 'HASH') {
293 0 $_begin = $_[$_pos]->{begin}, $_end = $_[$_pos]->{end};
294 0 $_params->{$_pid}{sequence} = $_[$_pos];
295 }
296 elsif ($_r eq 'ARRAY') {
297 0 $_begin = $_[$_pos]->[0], $_end = $_[$_pos]->[1];
298 0 $_params->{$_pid}{sequence} = $_[$_pos];
299 }
300  
301 10 last;
302 }
303 }
304  
305 _croak("$_tag: (sequence) is not specified or valid")
306 10 ▶ unless (exists $_params->{$_pid}{sequence});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_params->{$_pid}{"sequence"} 0 10 10
307 10 ▶ _croak("$_tag: (begin) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_begin 0 10 10
308 unless (defined $_begin);
309 10 ▶ _croak("$_tag: (end) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_end 0 10 10
310 unless (defined $_end);
311  
312 10 $_params->{$_pid}{sequence_run} = undef;
313  
314 10 ▶ if (defined $_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_pos) 10 0 10
315 10 pop @_ for ($_pos .. @_ - 1);
316 }
317  
318 10 return run(@_);
319 }
320  
321 ###############################################################################
322 ## ----------------------------------------------------------------------------
323 ## Parallel stream with MCE.
324 ##
325 ###############################################################################
326  
327 59 ▶sub run (@) {
Subroutine run: called CC=89 SCAR=59.2
Pod documented
328  
329 59 my $_caller = caller();
330 59 ▶ if ($_caller ne 'MCE::Stream' && !exists $_def->{$_caller}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_caller ne "MCE::Stream" and not exists $_def->{$_caller}) 0 59 59
Condition66%2/3
$_caller ne "MCE::Stream" and not exists $_def->{$_caller}
!ll&&!rl&&r
30290
MC/DC0%0/2
$_caller ne "MCE::Stream" and not exists $_def->{$_caller}
$_caller ne "MCE::Stream" not exists $_def->{$_caller}
Truth table66%2/3
A and not(B)
A= $_caller ne "MCE::Stream"B= not exists $_def->{$_caller}
ABresult
0X0
100
111
331 0 warn "MCE::Stream is not imported into the \"$_caller\" namespace. Aborting...\n";
332 0 return;
333 }
334  
335 59 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Stream');
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
336  
337 59 ▶ my $_pkg = $_caller eq 'MCE::Stream' ? caller(1) : $_caller;
Branch: 1 branch
BranchTrueFalseTotal
$_caller eq 'MCE::Stream' ? : 30 29 59
338 59 my $_pid = "$$.$_tid.$_pkg";
339  
340 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
341 0 ▶ $_params->{$_pid} = {} unless defined $_params->{$_pid};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_params->{$_pid} 0 0 0
342 0 for my $_p (keys %{ $_[0] }) {
343 0 $_params->{$_pid}{$_p} = $_[0]->{$_p};
344 }
345  
346 0 shift;
347 }
348  
349 59 ▶ my $_aref; $_aref = shift if (ref $_[0] eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "ARRAY" 25 34 59
350  
351 59 $_order_id = 1; undef %_tmp;
352  
353 59 ▶ if (defined $_aref) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_aref) { } 25 34 59
354 25 $_gather_ref = $_aref; @{ $_aref } = ();
355 } else {
356 34 $_gather_ref = undef;
357 }
358  
359 ## -------------------------------------------------------------------------
360  
361 59 my (@_code, @_mode, @_name, @_wrks); my $_init_mce = 0; my $_pos = 0;
362 59 my $_default_mode = $_def->{$_pkg}{DEFAULT_MODE};
363  
364 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
365 118 ▶ if (ref $_[0] eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'CODE') { } 108 10 118
366 108 push @_code, $_[0];
367 108 push @_mode, $_default_mode;
368 }
369 else {
370 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
371  
372 10 ▶ push @_code, exists $_[0]->{code} ? $_[0]->{code} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]{'code'} ? : 10 0 10
373 10 ▶ push @_mode, exists $_[0]->{mode} ? $_[0]->{mode} : $_default_mode;
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]{'mode'} ? : 10 0 10
374  
375 10 ▶ unless (ref $_code[-1] eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_code[-1] eq "CODE") 0 10 10
376 0 @_ = (); _croak("$_tag: (code) is not valid");
377 }
378 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
379 0 @_ = (); _croak("$_tag: (mode) is not valid");
380 }
381 }
382  
383 118 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 118 0 118
384 push @_name, (ref $_p->{task_name} eq 'ARRAY')
385 118 ▶ ? $_p->{task_name}->[$_pos] : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_p->{'task_name'} eq 'ARRAY' ? : 118 0 118
386 push @_wrks, (ref $_p->{max_workers} eq 'ARRAY')
387 118 ▶ ? $_p->{max_workers}->[$_pos] : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_p->{'max_workers'} eq 'ARRAY' ? : 118 0 118
388 }
389  
390 $_init_mce = 1 if (
391 !defined $_prev_c->{$_pid}[$_pos] ||
392 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
393 );
394 $_init_mce = 1 if (
395 !defined $_prev_m->{$_pid}[$_pos] ||
396 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
397 );
398  
399 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
400 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
401  
402 118 $_prev_c->{$_pid}[$_pos] = $_code[$_pos];
403 118 $_prev_m->{$_pid}[$_pos] = $_mode[$_pos];
404 118 $_prev_n->{$_pid}[$_pos] = $_name[$_pos];
405 118 $_prev_w->{$_pid}[$_pos] = $_wrks[$_pos];
406  
407 118 shift; $_pos++;
408 }
409  
410 59 ▶ if (defined $_prev_c->{$_pid}[$_pos]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_prev_c->{$_pid}[$_pos]) 0 59 59
411 0 pop @{ $_prev_c->{$_pid} } for ($_pos .. $#{ $_prev_c->{$_pid } });
412 0 pop @{ $_prev_m->{$_pid} } for ($_pos .. $#{ $_prev_m->{$_pid } });
413 0 pop @{ $_prev_n->{$_pid} } for ($_pos .. $#{ $_prev_n->{$_pid } });
414 0 pop @{ $_prev_w->{$_pid} } for ($_pos .. $#{ $_prev_w->{$_pid } });
415  
416 0 $_init_mce = 1;
417 }
418  
419 59 ▶ return unless (scalar @_code);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_code 0 59 59
420  
421 ## -------------------------------------------------------------------------
422  
423 59 my $_input_data; my $_max_workers = $_def->{$_pkg}{MAX_WORKERS};
424 59 my $_r = ref $_[0];
425  
426 59 ▶ 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::)/) 10 49 59
Condition66%2/3
@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|GLOB|FileHandle|IO::|Iterator::)/
!ll&&!rl&&r
49010
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
427 10 ▶ _croak("$_tag: (HASH) not allowed as input by this MCE model")
Branch: 1 branch
BranchTrueFalseTotal
if $_r eq "HASH" 0 10 10
428 if $_r eq 'HASH';
429 10 $_input_data = shift;
430 }
431  
432 59 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 59 0 59
433 $_max_workers = MCE::_parse_max_workers($_p->{max_workers})
434 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
435  
436 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
437 59 ▶ delete $_p->{user_func} if (exists $_p->{user_func});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_func"} 0 59 59
438 59 ▶ delete $_p->{user_tasks} if (exists $_p->{user_tasks});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_tasks"} 0 59 59
439 59 ▶ delete $_p->{use_slurpio} if (exists $_p->{use_slurpio});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"use_slurpio"} 0 59 59
440 59 ▶ delete $_p->{bounds_only} if (exists $_p->{bounds_only});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"bounds_only"} 0 59 59
441 59 ▶ delete $_p->{gather} if (exists $_p->{gather});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"gather"} 0 59 59
442 }
443  
444 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
445 59 $_max_workers = int($_max_workers / @_code + 0.5) + 1;
446 }
447  
448 59 my $_chunk_size = do {
449 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
450 (defined $_p->{init_relay} || defined $_def->{$_pkg}{INIT_RELAY}) ? 1 :
451 MCE::_parse_chunk_size(
452 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
453 $_input_data, scalar @_
454 );
455 };
456  
457 59 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 59 0 59
458 59 ▶ if (exists $_p->{_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_p->{'_file'}) { } 20 39 59
459 20 $_input_data = delete $_p->{_file};
460 } else {
461 39 ▶ $_input_data = $_p->{input_data} if exists $_p->{input_data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 39 39
462 }
463 }
464  
465 ## -------------------------------------------------------------------------
466  
467 59 MCE::_save_state($_MCE->{$_pid});
468  
469 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
470 14 ▶ $_MCE->{$_pid}->shutdown() if (defined $_MCE->{$_pid});
Branch: 1 branch
BranchTrueFalseTotal
if defined $_MCE->{$_pid} 0 14 14
471 14 ▶ $_queue->{$_pid} = [] if (!defined $_queue->{$_pid});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_queue->{$_pid} 14 0 14
472  
473 14 my $_Q = $_queue->{$_pid};
474 0 pop(@{ $_Q })->DESTROY for (@_code .. @{ $_Q });
475  
476 14 push @{ $_Q }, MCE::Queue->new()
477 14 for (@{ $_Q } .. @_code - 2);
478  
479 ## must clear arrays for nested session to work with Perl < v5.14
480 14 _gen_user_tasks($_pid, $_Q, [@_code], [@_mode], [@_name], [@_wrks]);
481  
482 14 @_code = @_mode = @_name = @_wrks = ();
483  
484 my %_opts = (
485 max_workers => $_max_workers, task_name => $_tag,
486 14 user_tasks => $_user_tasks->{$_pid}, task_end => \&_task_end,
487 use_slurpio => 0,
488 );
489  
490 14 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 14 0 14
491 14 local $_;
492  
493 14 for (keys %{ $_p }) {
494 28 ▶ next if ($_ eq 'sequence_run');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "sequence_run" 0 28 28
495 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
496 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
497 0 ▶ next if ($_ eq 'input_data');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "input_data" 0 0 0
498 0 ▶ next if ($_ eq 'chunk_size');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "chunk_size" 0 0 0
499 0 ▶ next if ($_ eq 'task_end');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "task_end" 0 0 0
500  
501 _croak("$_tag: ($_) is not a valid constructor argument")
502 0 ▶ unless (exists $MCE::_valid_fields_new{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $MCE::_valid_fields_new{$_} 0 0 0
503  
504 0 $_opts{$_} = $_p->{$_};
505 }
506 }
507  
508 14 for my $_k (qw/ tmp_dir freeze thaw init_relay use_threads /) {
509 $_opts{$_k} = $_def->{$_pkg}{uc($_k)}
510 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
511 }
512  
513 14 $_MCE->{$_pid} = MCE->new(pkg => $_pkg, %_opts);
514 }
515 else {
516 ## Workers may persist after running. Thus, updating the MCE instance.
517 ## These options do not require respawning.
518 45 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 45 0 45
519 45 for my $_k (qw(
520 RS interval stderr_file stdout_file user_error user_output
521 job_delay submit_delay on_post_exit on_post_run user_args
522 flush_file flush_stderr flush_stdout max_retries
523 )) {
524 675 ▶ $_MCE->{$_pid}{$_k} = $_p->{$_k} if (exists $_p->{$_k});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{$_k} 0 675 675
525 }
526 }
527 }
528  
529 ## -------------------------------------------------------------------------
530  
531 59 ▶ if (defined $_input_data) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_input_data) { } 30 29 59
elsif (scalar @_) { } 19 10 29
532 30 @_ = ();
533 30 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, $_input_data);
534 30 delete $_MCE->{$_pid}{input_data};
535 }
536 elsif (scalar @_) {
537 19 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, \@_);
538 11 delete $_MCE->{$_pid}{input_data};
539 }
540 else {
541 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
542 $_MCE->{$_pid}->run({
543 chunk_size => $_chunk_size,
544 sequence => $_params->{$_pid}{sequence}
545 10 }, 0);
546 10 ▶ if (exists $_params->{$_pid}{sequence_run}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_params->{$_pid}{"sequence_run"}) 10 0 10
547 10 delete $_params->{$_pid}{sequence_run};
548 10 delete $_params->{$_pid}{sequence};
549 }
550 10 delete $_MCE->{$_pid}{sequence};
551 }
552 }
553  
554 51 MCE::_restore_state();
555  
556 # destroy queue(s) if MCE::run requested workers to shutdown
557 51 ▶ if (!$_MCE->{$_pid}{_spawned}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_MCE->{$_pid}{"_spawned"}) 0 51 51
558 0 $_->DESTROY() for @{ $_queue->{$_pid} };
559 0 delete $_queue->{$_pid};
560 }
561  
562 51 ▶ return map { @{ $_ } } delete @_tmp{ 1 .. $_order_id - 1 }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_aref 26 25 51
563 unless (defined $_aref);
564  
565 25 $_gather_ref = undef;
566  
567 25 return;
568 }
569  
570 ###############################################################################
571 ## ----------------------------------------------------------------------------
572 ## Private methods.
573 ##
574 ###############################################################################
575  
576 0 ▶sub _croak {
Subroutine _croak: not called CC=1 SCAR=6.9
577  
578 0 goto &MCE::_croak;
579 }
580  
581 14 ▶sub _gen_user_tasks {
Subroutine _gen_user_tasks: called CC=4 SCAR=15.9
582  
583 14 my ($_pid, $_queue_ref, $_code_ref, $_mode_ref, $_name_ref, $_wrks_ref) = @_;
584  
585 14 @{ $_user_tasks->{$_pid} } = ();
586  
587 ## For the code block farthest to the right.
588  
589 14 ▶ push @{ $_user_tasks->{$_pid} }, {
Branch: 1 branch
BranchTrueFalseTotal
@{$_code_ref;} > 1 ? : 14 0 14
590 task_name => $_name_ref->[-1],
591 max_workers => $_wrks_ref->[-1],
592  
593 14 gather => (@{ $_code_ref } > 1)
594 ? $_queue_ref->[-1] : \&_preserve_order,
595  
596 83 ▶ user_func => sub {
Subroutine __ANON__: called CC=5 SCAR=16.3
597 83 my ($_mce, $_chunk_ref, $_chunk_id) = @_;
598 83 my @_a; my $_code = $_code_ref->[-1];
599  
600 83 ▶ if (ref $_chunk_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_chunk_ref) { } 65 18 83
601 push @_a, ($_mode_ref->[-1] eq 'map')
602 72 ? map { &{ $_code } } @{ $_chunk_ref }
603 65 ▶ : grep { &{ $_code } } @{ $_chunk_ref };
Branch: 1 branch
BranchTrueFalseTotal
$_mode_ref->[-1] eq 'map' ? : 56 9 65
604 }
605 else {
606 push @_a, ($_mode_ref->[-1] eq 'map')
607 18 ? map { &{ $_code } } $_chunk_ref
608 0 ▶ : grep { &{ $_code } } $_chunk_ref;
Branch: 1 branch
BranchTrueFalseTotal
$_mode_ref->[-1] eq 'map' ? : 18 0 18
609 }
610  
611 83 ▶ MCE->gather( (@{ $_code_ref } > 1)
Branch: 1 branch
BranchTrueFalseTotal
@{$_code_ref;} > 1 ? : 83 0 83
612 ? MCE->freeze([ \@_a, $_chunk_id ])
613 : (\@_a, $_chunk_id)
614 );
615 }
616 14 };
617  
618 ## For in-between code blocks (processed from right to left).
619  
620 14 ▶ for (my $_i = @{ $_code_ref } - 2; $_i > 0; $_i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_i > 0) 0 14 14
621 0 my $_pos = $_i;
622  
623 0 push @{ $_user_tasks->{$_pid} }, {
624 task_name => $_name_ref->[$_pos],
625 max_workers => $_wrks_ref->[$_pos],
626 gather => $_queue_ref->[$_pos - 1],
627  
628 0 ▶ user_func => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
629 0 my $_q = $_queue_ref->[$_pos];
630  
631 0 while (1) {
632 0 my $_chunk = $_q->dequeue;
633 0 ▶ last unless (defined $_chunk);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_chunk 0 0 0
634  
635 0 my @_a; my $_code = $_code_ref->[$_pos];
636 0 $_chunk = MCE->thaw($_chunk);
637  
638 push @_a, ($_mode_ref->[$_pos] eq 'map')
639 0 ? map { &{ $_code } } @{ $_chunk->[0] }
640 0 ▶ : grep { &{ $_code } } @{ $_chunk->[0] };
Branch: 1 branch
BranchTrueFalseTotal
$_mode_ref->[$_pos] eq 'map' ? : 0 0 0
641  
642 0 MCE->gather(MCE->freeze([ \@_a, $_chunk->[1] ]));
643 }
644  
645 0 return;
646 }
647 0 };
648 }
649  
650 ## For the left-most code block.
651  
652 14 ▶ if (@{ $_code_ref } > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$_code_ref;} > 1) 14 0 14
653  
654 14 push @{ $_user_tasks->{$_pid} }, {
655 task_name => $_name_ref->[0],
656 max_workers => $_wrks_ref->[0],
657 gather => \&_preserve_order,
658  
659 22 ▶ user_func => sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
660 22 my $_q = $_queue_ref->[0];
661  
662 22 while (1) {
663 105 my $_chunk = $_q->dequeue;
664 105 ▶ last unless (defined $_chunk);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_chunk 22 83 105
665  
666 83 my @_a; my $_code = $_code_ref->[0];
667 83 $_chunk = MCE->thaw($_chunk);
668  
669 push @_a, ($_mode_ref->[0] eq 'map')
670 93 ? map { &{ $_code } } @{ $_chunk->[0] }
671 0 ▶ : grep { &{ $_code } } @{ $_chunk->[0] };
Branch: 1 branch
BranchTrueFalseTotal
$_mode_ref->[0] eq 'map' ? : 83 0 83
672  
673 83 MCE->gather(\@_a, $_chunk->[1]);
674 }
675  
676 22 return;
677 }
678 14 };
679 }
680  
681 14 return;
682 }
683  
684 10 1;
685  
686 __END__
« MCE/Core/Input/Sequence.pm ↑ Summary MCE/Util.pm »