MCE/Grep.pm

filter: Statementstmt 77.0% 181 / 235 Branchbran 48.8% 84 / 172 Conditioncond 43.6% 24 / 55 MC/DCmcdc 14.2% 5 / 35 Subroutinesub 83.3% 15 / 18 Podpod 100% 5 / 5 totaltotal 60.3% 314 / 520 SCAR 65.8
CC
108
Cov
63%
run
110.6
run_seq
54.6
import
51.4
CRAP 720.4
« MCE/Mutex/Flock.pm ↑ Summary MCE/Map.pm »
1 ###############################################################################
2 ## ----------------------------------------------------------------------------
3 ## Parallel grep model similar to the native grep function.
4 ##
5 ###############################################################################
6  
7 package MCE::Grep;
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.889';
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 sub CLONE {
28 0 ▶ $_tid = threads->tid() if $INC{'threads.pm'};
Subroutine CLONE: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"threads.pm"} 0 0 0
29 }
30  
31 ###############################################################################
32 ## ----------------------------------------------------------------------------
33 ## Import routine.
34 ##
35 ###############################################################################
36  
37 4 my ($_MCE, $_def, $_params, $_prev_c, $_tag) = ({}, {}, {}, {}, 'MCE::Grep');
38  
39 sub import {
40 4 ▶ my ($_class, $_pkg) = (shift, caller);
Subroutine import: called CC=13 SCAR=39.4
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_grep_f' } = \&run_file;
51 4 *{ $_pkg.'::mce_grep_s' } = \&run_seq;
52 4 *{ $_pkg.'::mce_grep' } = \&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 sub _gather {
98  
99 37 ▶ my ($_chunk_id, $_data_ref) = @_;
Subroutine _gather: called CC=1 SCAR=0.0
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 sub init (@) {
114  
115 3 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Grep');
Subroutine init: called CC=5 SCAR=17.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Grep" 3 0 3
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Grep"
!ll&&!rl&&r
003
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Grep"
defined $_[0] $_[0] eq "MCE::Grep"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Grep"
ABresult
0X0
100
111
116 3 my $_pkg = "$$.$_tid.".caller();
117  
118 3 ▶ $_params->{$_pkg} = (ref $_[0] eq 'HASH') ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 3 3
119  
120 _croak("$_tag: (HASH) not allowed as input by this MCE model")
121 3 ▶ if ( ref $_params->{$_pkg}{input_data} eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_params->{$_pkg}{"input_data"} eq "HASH" 0 3 3
122  
123 3 @_ = ();
124  
125 3 return;
126 }
127  
128 sub finish (@) {
129  
130 7 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Grep');
Subroutine finish: called CC=9 SCAR=22.5
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Grep" 7 0 7
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Grep"
!ll&&!rl&&r
007
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Grep"
defined $_[0] $_[0] eq "MCE::Grep"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Grep"
ABresult
0X0
100
111
131 7 ▶ my $_pkg = (defined $_[0]) ? shift : "$$.$_tid.".caller();
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 6 1 7
132  
133 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
134 4 for my $_k ( keys %{ $_MCE } ) { MCE::Grep->finish($_k, 1); }
135 }
136 ▶ 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
137 1 ▶ $_MCE->{$_pkg}->shutdown(@_) if $_MCE->{$_pkg}{_spawned};
Branch: 1 branch
BranchTrueFalseTotal
if $_MCE->{$_pkg}{"_spawned"} 1 0 1
138 1 $_total_chunks = undef, undef %_tmp;
139  
140 1 delete $_prev_c->{$_pkg};
141 1 delete $_MCE->{$_pkg};
142 }
143  
144 7 @_ = ();
145  
146 7 return;
147 }
148  
149 ###############################################################################
150 ## ----------------------------------------------------------------------------
151 ## Parallel grep with MCE -- file.
152 ##
153 ###############################################################################
154  
155 sub run_file (&@) {
156  
157 2 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Grep');
Subroutine run_file: called CC=14 SCAR=30.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Grep" 0 2 2
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Grep"
!ll&&!rl&&r
020
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Grep"
defined $_[0] $_[0] eq "MCE::Grep"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Grep"
ABresult
0X0
100
111
158  
159 2 my $_code = shift; my $_file = shift;
160 2 my $_pid = "$$.$_tid.".caller();
161  
162 2 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 2 0 2
163 2 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 2 2
164 2 ▶ delete $_p->{sequence} if (exists $_p->{sequence});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"sequence"} 0 2 2
165 }
166 else {
167 0 $_params->{$_pid} = {};
168 }
169  
170 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
171 1 ▶ _croak("$_tag: ($_file) does not exist") unless (-e $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $_file 0 1 1
172 1 ▶ _croak("$_tag: ($_file) is not readable") unless (-r $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -r $_file 0 1 1
173 1 ▶ _croak("$_tag: ($_file) is not a plain file") unless (-f $_file);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_file 0 1 1
174 1 $_params->{$_pid}{_file} = $_file;
175 }
176 ▶ 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
177 1 $_params->{$_pid}{_file} = $_file;
178 }
179 else {
180 0 _croak("$_tag: (file) is not specified or valid");
181 }
182  
183 2 @_ = ();
184  
185 2 return run($_code);
186 }
187  
188 ###############################################################################
189 ## ----------------------------------------------------------------------------
190 ## Parallel grep with MCE -- sequence.
191 ##
192 ###############################################################################
193  
194 sub run_seq (&@) {
195  
196 1 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Grep');
Subroutine run_seq: called CC=16 SCAR=40.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Grep" 0 1 1
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Grep"
!ll&&!rl&&r
010
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Grep"
defined $_[0] $_[0] eq "MCE::Grep"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Grep"
ABresult
0X0
100
111
197  
198 1 my $_code = shift;
199 1 my $_pid = "$$.$_tid.".caller();
200  
201 1 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) { } 1 0 1
202 1 ▶ delete $_p->{input_data} if (exists $_p->{input_data});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 1 1
203 1 ▶ delete $_p->{_file} if (exists $_p->{_file});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"_file"} 0 1 1
204 }
205 else {
206 0 $_params->{$_pid} = {};
207 }
208  
209 1 my ($_begin, $_end);
210  
211 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
212 0 $_begin = $_[0]->{begin}, $_end = $_[0]->{end};
213 0 $_params->{$_pid}{sequence} = $_[0];
214 }
215 elsif (ref $_[0] eq 'ARRAY') {
216 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
217 0 $_begin = $_[0]->[0], $_end = $_[0]->[-1];
218 0 $_params->{$_pid}{sequence} = [ $_[0]->[0], $_[0]->[-1] ];
219 }
220 else {
221 0 $_begin = $_[0]->[0], $_end = $_[0]->[1];
222 0 $_params->{$_pid}{sequence} = $_[0];
223 }
224 }
225 ▶ 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
226 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
227 0 $_begin = $_[0], $_end = $_[-1];
228 0 $_params->{$_pid}{sequence} = [ $_[0], $_[-1] ];
229 }
230 else {
231 1 $_begin = $_[0], $_end = $_[1];
232 1 $_params->{$_pid}{sequence} = [ @_ ];
233 }
234 }
235 else {
236 0 _croak("$_tag: (sequence) is not specified or valid");
237 }
238  
239 1 ▶ _croak("$_tag: (begin) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_begin 0 1 1
240 unless (defined $_begin);
241 1 ▶ _croak("$_tag: (end) is not specified for sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_end 0 1 1
242 unless (defined $_end);
243  
244 1 $_params->{$_pid}{sequence_run} = undef;
245  
246 1 @_ = ();
247  
248 1 return run($_code);
249 }
250  
251 ###############################################################################
252 ## ----------------------------------------------------------------------------
253 ## Parallel grep with MCE.
254 ##
255 ###############################################################################
256  
257 sub run (&@) {
258  
259 7 ▶ shift if (defined $_[0] && $_[0] eq 'MCE::Grep');
Subroutine run: called CC=43 SCAR=47.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq "MCE::Grep" 0 7 7
Condition33%1/3
defined $_[0] and $_[0] eq "MCE::Grep"
!ll&&!rl&&r
070
MC/DC0%0/2
defined $_[0] and $_[0] eq "MCE::Grep"
defined $_[0] $_[0] eq "MCE::Grep"
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq "MCE::Grep"
ABresult
0X0
100
111
260  
261 7 my $_code = shift; $_total_chunks = 0; undef %_tmp;
262 7 ▶ my $_pkg = caller() eq 'MCE::Grep' ? caller(1) : caller();
Branch: 1 branch
BranchTrueFalseTotal
caller() eq 'MCE::Grep' ? : 3 4 7
263 7 my $_pid = "$$.$_tid.$_pkg";
264  
265 7 my $_input_data; my $_max_workers = $_def->{$_pkg}{MAX_WORKERS};
266 7 my $_r = ref $_[0];
267  
268 7 ▶ if (@_ == 1 && $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::)/) 1 6 7
Condition66%2/3
@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::)/
!ll&&!rl&&r
601
MC/DC50%1/2
@_ == 1 and $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::)/
@_ == 1 $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::)/
Truth table66%2/3
A and B
A= @_ == 1B= $_r =~ /^(?:ARRAY|HASH|SCALAR|CODE|GLOB|FileHandle|IO::)/
ABresult
0X0
100
111
269 1 ▶ _croak("$_tag: (HASH) not allowed as input by this MCE model")
Branch: 1 branch
BranchTrueFalseTotal
if $_r eq "HASH" 0 1 1
270 if $_r eq 'HASH';
271 1 $_input_data = shift;
272 }
273  
274 7 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 7 0 7
275 $_max_workers = MCE::_parse_max_workers($_p->{max_workers})
276 7 ▶ if (exists $_p->{max_workers});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"max_workers"} 7 0 7
277  
278 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
279 7 ▶ delete $_p->{user_func} if (exists $_p->{user_func});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_func"} 0 7 7
280 7 ▶ delete $_p->{user_tasks} if (exists $_p->{user_tasks});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"user_tasks"} 0 7 7
281 7 ▶ delete $_p->{use_slurpio} if (exists $_p->{use_slurpio});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"use_slurpio"} 0 7 7
282 7 ▶ delete $_p->{bounds_only} if (exists $_p->{bounds_only});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"bounds_only"} 0 7 7
283 7 ▶ delete $_p->{gather} if (exists $_p->{gather});
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"gather"} 0 7 7
284 }
285  
286 7 my $_chunk_size = do {
287 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
288 (defined $_p->{init_relay} || defined $_def->{$_pkg}{INIT_RELAY}) ? 1 :
289 MCE::_parse_chunk_size(
290 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
291 $_input_data, scalar @_
292 );
293 };
294  
295 7 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 7 0 7
296 7 ▶ if (exists $_p->{_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_p->{'_file'}) { } 2 5 7
297 2 $_input_data = delete $_p->{_file};
298 } else {
299 5 ▶ $_input_data = $_p->{input_data} if exists $_p->{input_data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_p->{"input_data"} 0 5 5
300 }
301 }
302  
303 ## -------------------------------------------------------------------------
304  
305 7 MCE::_save_state($_MCE->{$_pid});
306  
307 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
308 3 ▶ $_MCE->{$_pid}->shutdown() if (defined $_MCE->{$_pid});
Branch: 1 branch
BranchTrueFalseTotal
if defined $_MCE->{$_pid} 0 3 3
309 3 $_prev_c->{$_pid} = $_code;
310  
311 my %_opts = (
312 max_workers => $_max_workers, task_name => $_tag,
313 user_func => sub {
314  
315 37 ▶ my ($_mce, $_chunk_ref, $_chunk_id) = @_;
Subroutine __ANON__: called CC=13 SCAR=35.6
316 37 my $_wantarray = $_mce->{user_args}[0];
317  
318 37 ▶ if ($_wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_wantarray) { } 37 0 37
319 37 my @_a;
320  
321 37 ▶ if (ref $_chunk_ref eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_chunk_ref eq 'SCALAR') { } 1 36 37
322 1 ▶ local $/ = $_mce->{RS} if defined $_mce->{RS};
Branch: 1 branch
BranchTrueFalseTotal
if defined $_mce->{"RS"} 0 1 1
323 1 open my $_MEM_FH, '<', $_chunk_ref;
324 1 binmode $_MEM_FH, ':raw';
325 1 ▶ while (<$_MEM_FH>) { push (@_a, $_) if &{ $_code }; }
Branch: 2 branches
BranchTrueFalseTotal
if (defined($_ = readline $_MEM_FH)) 9 1 10
if &{$_code;} 3 6 9
326 1 close $_MEM_FH;
327 1 weaken $_MEM_FH;
328 }
329 else {
330 36 ▶ if (ref $_chunk_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_chunk_ref) { } 27 9 36
331 27 push @_a, grep { &{ $_code } } @{ $_chunk_ref };
332 } else {
333 9 push @_a, grep { &{ $_code } } $_chunk_ref;
334 }
335 }
336  
337 37 MCE->gather($_chunk_id, \@_a);
338 }
339 else {
340 0 my $_cnt = 0;
341  
342 0 ▶ if (ref $_chunk_ref eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_chunk_ref eq 'SCALAR') { } 0 0 0
343 0 ▶ local $/ = $_mce->{RS} if defined $_mce->{RS};
Branch: 1 branch
BranchTrueFalseTotal
if defined $_mce->{"RS"} 0 0 0
344 0 open my $_MEM_FH, '<', $_chunk_ref;
345 0 binmode $_MEM_FH, ':raw';
346 0 ▶ while (<$_MEM_FH>) { $_cnt++ if &{ $_code }; }
Branch: 2 branches
BranchTrueFalseTotal
if (defined($_ = readline $_MEM_FH)) 0 0 0
if &{$_code;} 0 0 0
347 0 close $_MEM_FH;
348 0 weaken $_MEM_FH;
349 }
350 else {
351 0 ▶ if (ref $_chunk_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_chunk_ref) { } 0 0 0
352 0 $_cnt += grep { &{ $_code } } @{ $_chunk_ref };
353 } else {
354 0 $_cnt += grep { &{ $_code } } $_chunk_ref;
355 }
356 }
357  
358 0 ▶ MCE->gather($_cnt) if defined $_wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_wantarray 0 0 0
359 }
360 },
361 3 );
362  
363 3 ▶ if (defined (my $_p = $_params->{$_pid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_p = $_params->{$_pid})) 3 0 3
364 3 for my $_k (keys %{ $_p }) {
365 3 ▶ next if ($_k eq 'sequence_run');
Branch: 1 branch
BranchTrueFalseTotal
if $_k eq "sequence_run" 0 3 3
366 3 ▶ next if ($_k eq 'input_data');
Branch: 1 branch
BranchTrueFalseTotal
if $_k eq "input_data" 0 3 3
367 3 ▶ next if ($_k eq 'chunk_size');
Branch: 1 branch
BranchTrueFalseTotal
if $_k eq "chunk_size" 0 3 3
368  
369 _croak("$_tag: ($_k) is not a valid constructor argument")
370 3 ▶ unless (exists $MCE::_valid_fields_new{$_k});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $MCE::_valid_fields_new{$_k} 0 3 3
371  
372 3 $_opts{$_k} = $_p->{$_k};
373 }
374 }
375  
376 3 for my $_k (qw/ tmp_dir freeze thaw init_relay use_threads /) {
377 $_opts{$_k} = $_def->{$_pkg}{uc($_k)}
378 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
379 }
380  
381 3 $_MCE->{$_pid} = MCE->new(pkg => $_pkg, %_opts);
382 }
383  
384 ## -------------------------------------------------------------------------
385  
386 7 my $_cnt = 0; my $_wantarray = wantarray;
387  
388 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
389 7 $_MCE->{$_pid}{user_args} = [ $_wantarray ];
390  
391 $_MCE->{$_pid}{gather} = $_wantarray
392 7 ▶ ? \&_gather : sub { $_cnt += $_[0]; return; };
Subroutine __ANON__: not called CC=1 SCAR=2.0
Branch: 1 branch
BranchTrueFalseTotal
$_wantarray ? : 7 0 7
393  
394 7 ▶ if (defined $_input_data) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_input_data) { } 3 4 7
elsif (scalar @_) { } 3 1 4
395 3 @_ = ();
396 3 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, $_input_data);
397 3 delete $_MCE->{$_pid}{input_data};
398 }
399 elsif (scalar @_) {
400 3 $_MCE->{$_pid}->process({ chunk_size => $_chunk_size }, \@_);
401 1 delete $_MCE->{$_pid}{input_data};
402 }
403 else {
404 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
405 $_MCE->{$_pid}->run({
406 chunk_size => $_chunk_size,
407 sequence => $_params->{$_pid}{sequence}
408 1 }, 0);
409 1 ▶ if (exists $_params->{$_pid}{sequence_run}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_params->{$_pid}{"sequence_run"}) 1 0 1
410 1 delete $_params->{$_pid}{sequence_run};
411 1 delete $_params->{$_pid}{sequence};
412 }
413 1 delete $_MCE->{$_pid}{sequence};
414 }
415 }
416  
417 5 MCE::_restore_state();
418  
419 5 ▶ if ($_wantarray) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_wantarray) { } 5 0 5
elsif (defined $_wantarray) { } 0 0 0
420 5 return map { @{ $_ } } delete @_tmp{ 1 .. $_total_chunks };
421 }
422 elsif (defined $_wantarray) {
423 0 return $_cnt;
424 }
425  
426 0 return;
427 }
428  
429 ###############################################################################
430 ## ----------------------------------------------------------------------------
431 ## Private methods.
432 ##
433 ###############################################################################
434  
435 sub _croak {
436  
437 0 ▶ goto &MCE::_croak;
Subroutine _croak: not called CC=1 SCAR=6.9
438 }
439  
440 4 1;
441  
442 __END__
« MCE/Mutex/Flock.pm ↑ Summary MCE/Map.pm »