MCE/Map.pm

filter: Statementstmt 74.0% 183 / 247 Branchbran 48.2% 84 / 174 Conditioncond 42.6% 26 / 61 MC/DCmcdc 12.8% 5 / 39 Subroutinesub 78.9% 15 / 19 Podpod 100% 5 / 5 totaltotal 58.3% 318 / 545 CC 111 SCAR 41.1
CC
111
Cov
61%
run
122.0
run_seq
54.6
import
51.4
CRAP 60.7
« MCE/Grep.pm ↑ Summary MCE/Channel/ThreadsFast.pm »
1 ###############################################################################
2 ## ----------------------------------------------------------------------------
3 ## Parallel map model similar to the native map function.
4 ##
5 ###############################################################################
6  
7 package MCE::Map;
8  
9 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶no warnings qw( threads recursion uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 our $VERSION = '1.904';
15  
16 ## no critic (BuiltinFunctions::ProhibitStringyEval)
17 ## no critic (Subroutines::ProhibitSubroutinePrototypes)
18 ## no critic (TestingAndDebugging::ProhibitNoStrict)
19  
20 4 ▶use Scalar::Util qw( looks_like_number weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use MCE;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 4 our @CARP_NOT = qw( MCE );
24  
25 4 ▶my $_tid = $INC{'threads.pm'} ? threads->tid() : 0;
Branch: 1 branch
BranchTrueFalseTotal
$INC{'threads.pm'} ? : 0 4 4
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 4 my ($_MCE, $_def, $_params, $_prev_c, $_tag) = ({}, {}, {}, {}, 'MCE::Map');
38  
39 4 ▶sub import {
Subroutine import: called CC=13 SCAR=39.4
40 4 my ($_class, $_pkg) = (shift, caller);
41  
42 4 my $_p = $_def->{$_pkg} = {
43 MAX_WORKERS => 'auto',
44 CHUNK_SIZE => 'auto',
45 };
46  
47 ## Import functions.
48 4 ▶ if ($_pkg !~ /^MCE::/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_pkg =~ /^MCE::/) 4 0 4
49 4 ▶ no strict 'refs'; no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
50 4 *{ $_pkg.'::mce_map_f' } = \&run_file;
51 4 *{ $_pkg.'::mce_map_s' } = \&run_seq;
52 4 *{ $_pkg.'::mce_map' } = \&run;
53 }
54  
55 ## Process module arguments.
56 4 ▶ while ( my $_argument = shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $_argument = shift()) 0 4 4
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 4 $_p->{MAX_WORKERS} = MCE::_parse_max_workers($_p->{MAX_WORKERS});
81  
82 4 MCE::_validate_number($_p->{MAX_WORKERS}, 'MAX_WORKERS', $_tag);
83 MCE::_validate_number($_p->{CHUNK_SIZE}, 'CHUNK_SIZE', $_tag)
84 4 ▶ unless ($_p->{CHUNK_SIZE} eq 'auto');
Branch: 1 branch
BranchTrueFalseTotal
unless $_p->{"CHUNK_SIZE"} eq "auto" 0 4 4
85  
86 4 return;
87 }
88  
89 ###############################################################################
90 ## ----------------------------------------------------------------------------
91 ## Gather callback for storing by chunk_id => chunk_ref into a hash.
92 ##
93 ###############################################################################
94  
95 4 my ($_total_chunks, %_tmp);
96  
97 37 ▶sub _gather {
Subroutine _gather: called CC=1 SCAR=0.0
98  
99 37 my ($_chunk_id, $_data_ref) = @_;
100  
101 37 $_tmp{$_chunk_id} = $_data_ref;
102 37 $_total_chunks++;
103  
104 37 return;
105 }
106  
107 ###############################################################################
108 ## ----------------------------------------------------------------------------
109 ## Init and finish routines.
110 ##
111 ###############################################################################
112  
113 0 ▶sub MCE::Map::_guard::DESTROY {
Subroutine DESTROY: not called CC=3 SCAR=24.8
114 0 my ($_pkg, $_id) = @{ $_[0] };
115  
116 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
117 0 @{ $_[0] } = ();
118 0 MCE::Map->finish($_pkg);
119 }
120  
121 0 return;
122 }
123  
124 3 ▶sub init (@) {
Subroutine init: called CC=6 SCAR=20.3
Pod documented
125  
126 3 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Map');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Map" 3 0 3
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Map"
!ll&&!rl&&r
003
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Map"
defined $_[0] $_[0] eq "MCE::Map"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Map"
ABresult
0X0
100
111
127 3 my $_pkg = "$$.$_tid.".caller();
128  
129 3 ▶ $_params->{$_pkg} = (ref $_[0] eq 'HASH') ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 3 3
130  
131 _croak("$_tag: (HASH) not allowed as input by this MCE model")
132 3 ▶ if ( ref $_params->{$_pkg}{input_data} eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_params->{$_pkg}{"input_data"} eq "HASH" 0 3 3
133  
134 3 @_ = ();
135  
136 defined wantarray
137 3 ▶ ? bless([$_pkg, "$$.$_tid"], MCE::Map::_guard::)
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray ? : 0 3 3
138 : ();
139 }
140  
141 7 ▶sub finish (@) {
Subroutine finish: called CC=9 SCAR=22.5
Pod documented
142  
143 7 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Map');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Map" 7 0 7
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Map"
!ll&&!rl&&r
007
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Map"
defined $_[0] $_[0] eq "MCE::Map"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Map"
ABresult
0X0
100
111
144 7 ▶ my $_pkg = (defined $_[0]) ? shift : "$$.$_tid.".caller();
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 6 1 7
145  
146 7 ▶ if ( $_pkg eq 'MCE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_pkg eq 'MCE') { } 4 3 7
elsif ($_MCE->{$_pkg} and $_MCE->{$_pkg}{'_init_pid'} eq "${$}.$_tid") { } 1 2 3
147 4 for my $_k ( keys %{ $_MCE } ) { MCE::Map->finish($_k, 1); }
148 }
149 ▶ elsif ( $_MCE->{$_pkg} && $_MCE->{$_pkg}{_init_pid} eq "$$.$_tid" ) {
Condition66%2/3
$_MCE->{$_pkg} and $_MCE->{$_pkg}{"_init_pid"} eq "${$}.$_tid"
!ll&&!rl&&r
021
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
150 1 ▶ $_MCE->{$_pkg}->shutdown(@_) if $_MCE->{$_pkg}{_spawned};
Branch: 1 branch
BranchTrueFalseTotal
if $_MCE->{$_pkg}{"_spawned"} 1 0 1
151 1 $_total_chunks = undef, undef %_tmp;
152  
153 1 delete $_prev_c->{$_pkg};
154 1 delete $_MCE->{$_pkg};
155 }
156  
157 7 @_ = ();
158  
159 7 return;
160 }
161  
162 ###############################################################################
163 ## ----------------------------------------------------------------------------
164 ## Parallel map with MCE -- file.
165 ##
166 ###############################################################################
167  
168 2 ▶sub run_file (&@) {
Subroutine run_file: called CC=14 SCAR=30.8
Pod documented
169  
170 2 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Map');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Map" 0 2 2
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Map"
!ll&&!rl&&r
020
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Map"
defined $_[0] $_[0] eq "MCE::Map"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Map"
ABresult
0X0
100
111
171  
172 2 my $_code = shift; my $_file = shift;
173 2 my $_pid = "$$.$_tid.".caller();
174  
175 2 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 2 0 2
176 2 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 2 2
177 2 ▶ delete $_p->{sequence} if (exists $_p->{sequence});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"sequence"} 0 2 2
178 }
179 else {
180 0 $_params->{$_pid} = {};
181 }
182  
183 2 ▶ if (defined $_file && ref $_file eq '' && $_file ne '') {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_file and ref $_file eq '' and $_file ne '') { } 1 1 2
elsif (ref $_file eq 'SCALAR' or ref($_file) =~ /^(?:GLOB|FileHandle|IO::)/) { } 1 0 1
Condition66%4/6
defined $_file and ref $_file eq "" and $_file ne ""
!ll&&!rl&&r
101
defined $_file and ref $_file eq ""
!ll&&!rl&&r
011
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
184 1 ▶ _croak("$_tag: ($_file) does not exist") unless (-e $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $_file 0 1 1
185 1 ▶ _croak("$_tag: ($_file) is not readable") unless (-r $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -r $_file 0 1 1
186 1 ▶ _croak("$_tag: ($_file) is not a plain file") unless (-f $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_file 0 1 1
187 1 $_params->{$_pid}{_file} = $_file;
188 }
189 ▶ 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
010
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
190 1 $_params->{$_pid}{_file} = $_file;
191 }
192 else {
193 0 _croak("$_tag: (file) is not specified or valid");
194 }
195  
196 2 @_ = ();
197  
198 2 return run($_code);
199 }
200  
201 ###############################################################################
202 ## ----------------------------------------------------------------------------
203 ## Parallel map with MCE -- sequence.
204 ##
205 ###############################################################################
206  
207 1 ▶sub run_seq (&@) {
Subroutine run_seq: called CC=16 SCAR=40.0
Pod documented
208  
209 1 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Map');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Map" 0 1 1
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Map"
!ll&&!rl&&r
010
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Map"
defined $_[0] $_[0] eq "MCE::Map"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Map"
ABresult
0X0
100
111
210  
211 1 my $_code = shift;
212 1 my $_pid = "$$.$_tid.".caller();
213  
214 1 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 1 0 1
215 1 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 1 1
216 1 ▶ delete $_p->{_file} if (exists $_p->{_file});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"_file"} 0 1 1
217 }
218 else {
219 0 $_params->{$_pid} = {};
220 }
221  
222 1 my ($_begin, $_end);
223  
224 1 ▶ if (ref $_[0] eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 1 1
elsif (ref $_[0] eq 'ARRAY') { } 0 1 1
elsif (ref $_[0] eq '' or ref($_[0]) =~ /^Math::/) { } 1 0 1
225 0 $_begin = $_[0]->{begin}, $_end = $_[0]->{end};
226 0 $_params->{$_pid}{sequence} = $_[0];
227 }
228 elsif (ref $_[0] eq 'ARRAY') {
229 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
230 0 $_begin = $_[0]->[0], $_end = $_[0]->[-1];
231 0 $_params->{$_pid}{sequence} = [ $_[0]->[0], $_[0]->[-1] ];
232 }
233 else {
234 0 $_begin = $_[0]->[0], $_end = $_[0]->[1];
235 0 $_params->{$_pid}{sequence} = $_[0];
236 }
237 }
238 ▶ elsif (ref $_[0] eq '' || ref($_[0]) =~ /^Math::/) {
Condition33%1/3
ref $_[0] eq "" or ref($_[0]) =~ /^Math::/
l!l&&r!l&&!r
100
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
239 1 ▶ if (@_ > 3 && $_[3] =~ /\d$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 3 and $_[3] =~ /\d$/) { } 0 1 1
Condition33%1/3
@_ > 3 and $_[3] =~ /\d$/
!ll&&!rl&&r
100
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
240 0 $_begin = $_[0], $_end = $_[-1];
241 0 $_params->{$_pid}{sequence} = [ $_[0], $_[-1] ];
242 }
243 else {
244 1 $_begin = $_[0], $_end = $_[1];
245 1 $_params->{$_pid}{sequence} = [ @_ ];
246 }
247 }
248 else {
249 0 _croak("$_tag: (sequence) is not specified or valid");
250 }
251  
252 1 ▶ _croak("$_tag: (begin) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_begin 0 1 1
253 unless (defined $_begin);
254 1 ▶ _croak("$_tag: (end) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_end 0 1 1
255 unless (defined $_end);
256  
257 1 $_params->{$_pid}{sequence_run} = undef;
258  
259 1 @_ = ();
260  
261 1 return run($_code);
262 }
263  
264 ###############################################################################
265 ## ----------------------------------------------------------------------------
266 ## Parallel map with MCE.
267 ##
268 ###############################################################################
269  
270 7 ▶sub run (&@) {
Subroutine run: called CC=45 SCAR=48.0
Pod documented
271  
272 7 my $_caller = caller();
273 7 ▶ if ($_caller ne 'MCE::Map' && !exists $_def->{$_caller}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_caller ne "MCE::Map" and not exists $_def->{$_caller}) 0 7 7
Condition66%2/3
$_caller ne "MCE::Map" and not exists $_def->{$_caller}
!ll&&!rl&&r
340
MC/DC0%0/2
$_caller ne "MCE::Map" and not exists $_def->{$_caller}
$_caller ne "MCE::Map" not exists $_def->{$_caller}
Truth table66%2/3
A and not(B)
A= $_caller ne "MCE::Map"B= not exists $_def->{$_caller}
ABresult
0X0
100
111
274 0 warn "MCE::Map is not imported into the \"$_caller\" namespace. Aborting...\n";
275 0 return;
276 }
277  
278 7 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Map');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Map" 0 7 7
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Map"
!ll&&!rl&&r
070
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Map"
defined $_[0] $_[0] eq "MCE::Map"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Map"
ABresult
0X0
100
111
279  
280 7 my $_code = shift; $_total_chunks = 0; undef %_tmp;
281 7 ▶ my $_pkg = $_caller eq 'MCE::Map' ? caller(1) : $_caller;
Branch: 1 branch
BranchTrueFalseTotal
$_caller eq 'MCE::Map' ? : 3 4 7
282 7 my $_pid = "$$.$_tid.$_pkg";
283  
284 7 my $_input_data; my $_max_workers = $_def->{$_pkg}{MAX_WORKERS};
285 7 my $_r = ref $_[0];
286  
287 7 ▶ 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::)/) 1 6 7
Condition66%2/3
@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::|Iterator::)/
!ll&&!rl&&r
601
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
288 1 ▶ _croak("$_tag: (HASH) not allowed as input by this MCE model")
Branch: 1 branch
BranchTrueFalseTotal
if $_r eq "HASH" 0 1 1
289 if $_r eq 'HASH';
290 1 $_input_data = shift;
291 }
292  
293 7 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 7 0 7
294 $_max_workers = MCE::_parse_max_workers($_p->{max_workers})
295 7 ▶ if (exists $_p->{max_workers});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"max_workers"} 7 0 7
296  
297 7 ▶ delete $_p->{sequence} if (defined $_input_data || scalar @_);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_input_data or scalar @_ 4 3 7
Condition100%2/2
defined $_input_data or scalar @_
l!l
16
MC/DC100%1/1
defined $_input_data or scalar @_
defined $_input_data
Truth table100%2/2
A
A= defined $_input_data
Aresult
11
00
298 7 ▶ delete $_p->{user_func} if (exists $_p->{user_func});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_func"} 0 7 7
299 7 ▶ delete $_p->{user_tasks} if (exists $_p->{user_tasks});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_tasks"} 0 7 7
300 7 ▶ delete $_p->{use_slurpio} if (exists $_p->{use_slurpio});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"use_slurpio"} 0 7 7
301 7 ▶ delete $_p->{bounds_only} if (exists $_p->{bounds_only});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"bounds_only"} 0 7 7
302 7 ▶ delete $_p->{gather} if (exists $_p->{gather});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"gather"} 0 7 7
303 }
304  
305 7 my $_chunk_size = do {
306 7 ▶ my $_p = $_params->{$_pid} || {};
Condition50%1/2
$_params->{$_pid} || {}
l!l
70
MC/DC0%0/1
$_params->{$_pid} || {}
$_params->{$_pid}
Truth table50%1/2
A
A= $_params->{$_pid}
Aresult
11
00
307 (defined $_p->{init_relay} || defined $_def->{$_pkg}{INIT_RELAY}) ? 1 :
308 MCE::_parse_chunk_size(
309 7 ▶ $_def->{$_pkg}{CHUNK_SIZE}, $_max_workers, $_params->{$_pid},
Branch: 1 branch
BranchTrueFalseTotal
defined $_p->{'init_relay'} || defined $_def->{$_pkg}{'INIT_RELAY'} ? : 0 7 7
Condition33%1/3
defined $_p->{"init_relay"} or defined $_def->{$_pkg}{"INIT_RELAY"}
l!l&&r!l&&!r
007
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
310 $_input_data, scalar @_
311 );
312 };
313  
314 7 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 7 0 7
315 7 ▶ if (exists $_p->{_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_p->{'_file'}) { } 2 5 7
316 2 $_input_data = delete $_p->{_file};
317 } else {
318 5 ▶ $_input_data = $_p->{input_data} if exists $_p->{input_data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 5 5
319 }
320 }
321  
322 ## -------------------------------------------------------------------------
323  
324 7 MCE::_save_state($_MCE->{$_pid});
325  
326 7 ▶ if (!defined $_prev_c->{$_pid} || $_prev_c->{$_pid} != $_code) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_prev_c->{$_pid} or $_prev_c->{$_pid} != $_code) 3 4 7
Condition66%2/3
not defined $_prev_c->{$_pid} or $_prev_c->{$_pid} != $_code
l!l&&r!l&&!r
304
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
327 3 ▶ $_MCE->{$_pid}->shutdown() if (defined $_MCE->{$_pid});
Branch: 1 branch
BranchTrueFalseTotal
if defined $_MCE->{$_pid} 0 3 3
328 3 $_prev_c->{$_pid} = $_code;
329  
330 my %_opts = (
331 max_workers => $_max_workers, task_name => $_tag,
332 37 ▶ user_func => sub {
Subroutine __ANON__: called CC=11 SCAR=33.2
333  
334 37 my ($_mce, $_chunk_ref, $_chunk_id) = @_;
335 37 my $_wantarray = $_mce->{user_args}[0];
336  
337 37 ▶ if ($_wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_wantarray) { } 37 0 37
338 37 my @_a;
339  
340 37 ▶ if (ref $_chunk_ref eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_chunk_ref eq 'SCALAR') { } 1 36 37
341 1 ▶ local $/ = $_mce->{RS} if defined $_mce->{RS};
Branch: 1 branch
BranchTrueFalseTotal
if defined $_mce->{"RS"} 0 1 1
342 1 open my $_MEM_FH, '<', $_chunk_ref;
343 1 binmode $_MEM_FH, ':raw';
344 1 ▶ while (<$_MEM_FH>) { push @_a, &{ $_code }; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $_MEM_FH)) 9 1 10
345 1 close $_MEM_FH;
346 1 weaken $_MEM_FH;
347 }
348 else {
349 36 ▶ if (ref $_chunk_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_chunk_ref) { } 27 9 36
350 27 push @_a, map { &{ $_code } } @{ $_chunk_ref };
351 } else {
352 9 push @_a, map { &{ $_code } } $_chunk_ref;
353 }
354 }
355  
356 37 MCE->gather($_chunk_id, \@_a);
357 }
358 else {
359 0 my $_cnt = 0;
360  
361 0 ▶ if (ref $_chunk_ref eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_chunk_ref eq 'SCALAR') { } 0 0 0
362 0 ▶ local $/ = $_mce->{RS} if defined $_mce->{RS};
Branch: 1 branch
BranchTrueFalseTotal
if defined $_mce->{"RS"} 0 0 0
363 0 open my $_MEM_FH, '<', $_chunk_ref;
364 0 binmode $_MEM_FH, ':raw';
365 0 ▶ while (<$_MEM_FH>) { $_cnt++; &{ $_code }; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $_MEM_FH)) 0 0 0
366 0 close $_MEM_FH;
367 0 weaken $_MEM_FH;
368 }
369 else {
370 0 ▶ if (ref $_chunk_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_chunk_ref) { } 0 0 0
371 0 $_cnt += map { &{ $_code } } @{ $_chunk_ref };
372 } else {
373 0 $_cnt += map { &{ $_code } } $_chunk_ref;
374 }
375 }
376  
377 0 ▶ MCE->gather($_cnt) if defined $_wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_wantarray 0 0 0
378 }
379 },
380 3 );
381  
382 3 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 3 0 3
383 3 for my $_k (keys %{ $_p }) {
384 3 ▶ next if ($_k eq 'sequence_run');
Branch: 1 branch
BranchTrueFalseTotal
if $_k eq "sequence_run" 0 3 3
385 3 ▶ next if ($_k eq 'input_data');
Branch: 1 branch
BranchTrueFalseTotal
if $_k eq "input_data" 0 3 3
386 3 ▶ next if ($_k eq 'chunk_size');
Branch: 1 branch
BranchTrueFalseTotal
if $_k eq "chunk_size" 0 3 3
387  
388 _croak("$_tag: ($_k) is not a valid constructor argument")
389 3 ▶ unless (exists $MCE::_valid_fields_new{$_k});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $MCE::_valid_fields_new{$_k} 0 3 3
390  
391 3 $_opts{$_k} = $_p->{$_k};
392 }
393 }
394  
395 3 for my $_k (qw/ tmp_dir freeze thaw init_relay use_threads /) {
396 $_opts{$_k} = $_def->{$_pkg}{uc($_k)}
397 15 ▶ 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 15 15
Condition33%1/3
exists $_def->{$_pkg}{uc $_k} and not exists $_opts{$_k}
!ll&&!rl&&r
1500
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
398 }
399  
400 3 $_MCE->{$_pid} = MCE->new(pkg => $_pkg, %_opts);
401 }
402  
403 ## -------------------------------------------------------------------------
404  
405 7 my $_cnt = 0; my $_wantarray = wantarray;
406  
407 7 ▶ $_MCE->{$_pid}{use_slurpio} = ($_chunk_size > &MCE::MAX_RECS_SIZE) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_chunk_size > &MCE::MAX_RECS_SIZE ? : 1 6 7
408 7 $_MCE->{$_pid}{user_args} = [ $_wantarray ];
409  
410 $_MCE->{$_pid}{gather} = $_wantarray
411 0 ▶ ? \&_gather : sub { $_cnt += $_[0]; return; };
Subroutine __ANON__: not called CC=1 SCAR=2.0
Branch: 1 branch
BranchTrueFalseTotal
$_wantarray ? : 7 0 7
412  
413 7 ▶ if (defined $_input_data) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_input_data) { } 3 4 7
elsif (scalar @_) { } 3 1 4
414 3 @_ = ();
415 3 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, $_input_data);
416 3 delete $_MCE->{$_pid}{input_data};
417 }
418 elsif (scalar @_) {
419 3 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, \@_);
420 1 delete $_MCE->{$_pid}{input_data};
421 }
422 else {
423 1 ▶ if (defined $_params->{$_pid} && exists $_params->{$_pid}{sequence}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_params->{$_pid} and exists $_params->{$_pid}{"sequence"}) 1 0 1
Condition33%1/3
defined $_params->{$_pid} and exists $_params->{$_pid}{"sequence"}
!ll&&!rl&&r
001
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
424 $_MCE->{$_pid}->run({
425 chunk_size => $_chunk_size,
426 sequence => $_params->{$_pid}{sequence}
427 1 }, 0);
428 1 ▶ if (exists $_params->{$_pid}{sequence_run}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_params->{$_pid}{"sequence_run"}) 1 0 1
429 1 delete $_params->{$_pid}{sequence_run};
430 1 delete $_params->{$_pid}{sequence};
431 }
432 1 delete $_MCE->{$_pid}{sequence};
433 }
434 }
435  
436 5 MCE::_restore_state();
437  
438 5 ▶ if ($_wantarray) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_wantarray) { } 5 0 5
elsif (defined $_wantarray) { } 0 0 0
439 5 return map { @{ $_ } } delete @_tmp{ 1 .. $_total_chunks };
440 }
441 elsif (defined $_wantarray) {
442 0 return $_cnt;
443 }
444  
445 0 return;
446 }
447  
448 ###############################################################################
449 ## ----------------------------------------------------------------------------
450 ## Private methods.
451 ##
452 ###############################################################################
453  
454 0 ▶sub _croak {
Subroutine _croak: not called CC=1 SCAR=6.9
455  
456 0 goto &MCE::_croak;
457 }
458  
459 4 1;
460  
461 __END__
« MCE/Grep.pm ↑ Summary MCE/Channel/ThreadsFast.pm »