MCE/Core/Input/Request.pm

filter: Statementstmt 80.7% 84 / 104 Branchbran 51.7% 30 / 58 Conditioncond 33.3% 5 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 50.0% 4 / 8 Podpod n/a totaltotal 63.0% 123 / 195 CC 36 SCAR 41.3
CC
36
Cov
67%
_worker_request_chunk
79.5
__ANON__
12.0
__ANON__
6.0
CRAP 62.2
« MCE/Flow.pm ↑ Summary MCE/Grep.pm »
1 ###############################################################################
2 ## ----------------------------------------------------------------------------
3 ## Array reference and Glob reference input reader.
4 ##
5 ## This package provides the request chunk method used internally by the worker
6 ## process. Distribution follows a bank-queuing model.
7 ##
8 ## There is no public API.
9 ##
10 ###############################################################################
11  
12 package MCE::Core::Input::Request;
13  
14 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 44 our $VERSION = '1.904';
18  
19 ## Items below are folded into MCE.
20  
21 package # hide from rpm
22 MCE;
23  
24 44 ▶no warnings qw( threads recursion uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 ###############################################################################
27 ## ----------------------------------------------------------------------------
28 ## Worker process -- Request chunk.
29 ##
30 ###############################################################################
31  
32 57 ▶sub _worker_request_chunk {
Subroutine _worker_request_chunk: called CC=33 SCAR=43.8
33  
34 57 my ($self, $_proc_type) = @_;
35  
36 57 @_ = ();
37  
38 _croak('MCE::_worker_request_chunk: (user_func) is not specified')
39 57 ▶ unless (defined $self->{user_func});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"user_func"} 0 57 57
40  
41 57 ▶ my $_is_MSWin32 = ($^O eq 'MSWin32') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 57 57
42 57 my $_chn = $self->{_chn};
43 57 my $_DAT_LOCK = $self->{_dat_lock};
44 57 my $_DAT_W_SOCK = $self->{_dat_w_sock}->[0];
45 57 my $_DAU_W_SOCK = $self->{_dat_w_sock}->[$_chn];
46 57 my $_lock_chn = $self->{_lock_chn};
47 57 my $_chunk_size = $self->{chunk_size};
48 57 my $_use_slurpio = $self->{use_slurpio};
49 57 ▶ my $_RS = $self->{RS} || $/;
Condition33%1/3
$self->{'RS'} || $/
l!l&&r!l&&!r
0570
MC/DC0%0/2
$self->{'RS'} || $/
$self->{'RS'} $/
Truth table33%1/3
A || B
A= $self->{'RS'}B= $/
ABresult
1X1
011
000
50 57 my $_wuf = $self->{_wuf};
51  
52 57 my ($_dat_ex, $_dat_un, $_pid);
53  
54 57 ▶ if ($_lock_chn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_lock_chn) 0 57 57
55 0 ▶ $_pid = $INC{'threads.pm'} ? $$ .'.'. threads->tid() : $$;
Branch: 1 branch
BranchTrueFalseTotal
$INC{'threads.pm'} ? : 0 0 0
56  
57 # inlined for performance
58 0 ▶ $_dat_ex = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
59 CORE::lock($_DAT_LOCK->{_t_lock}), MCE::Util::_sock_ready($_DAT_LOCK->{_r_sock})
60 0 ▶ if $_is_MSWin32;
Branch: 1 branch
BranchTrueFalseTotal
if $_is_MSWin32 0 0 0
61 MCE::Util::_sysread($_DAT_LOCK->{_r_sock}, my($b), 1), $_DAT_LOCK->{ $_pid } = 1
62 0 ▶ unless $_DAT_LOCK->{ $_pid };
Branch: 1 branch
BranchTrueFalseTotal
unless $_DAT_LOCK->{$_pid} 0 0 0
63 0 };
64 0 ▶ $_dat_un = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
65 syswrite($_DAT_LOCK->{_w_sock}, '0'), $_DAT_LOCK->{ $_pid } = 0
66 0 ▶ if $_DAT_LOCK->{ $_pid };
Branch: 1 branch
BranchTrueFalseTotal
if $_DAT_LOCK->{$_pid} 0 0 0
67 0 };
68 }
69  
70 57 my ($_chunk_id, $_len, $_output_tag);
71 57 my ($_chop_len, $_chop_str, $_p);
72  
73 57 ▶ if ($_proc_type == REQUEST_ARRAY) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_proc_type == 0) { } 40 17 57
elsif ($_proc_type == 2) { } 3 14 17
74 40 $_output_tag = OUTPUT_A_REF;
75 40 $_chop_len = 0;
76 }
77 elsif ($_proc_type == REQUEST_HASH) {
78 3 $_output_tag = OUTPUT_H_REF;
79 3 $_chop_len = 0;
80 }
81 else {
82 14 $_output_tag = OUTPUT_G_REF;
83 14 ▶ if (length $_RS > 1 && substr($_RS, 0, 1) eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_RS > 1 and substr($_RS, 0, 1) eq "\n") { } 0 14 14
Condition33%1/3
length $_RS > 1 and substr($_RS, 0, 1) eq "\n"
!ll&&!rl&&r
1400
MC/DC0%0/2
length $_RS > 1 and substr($_RS, 0, 1) eq "\n"
length $_RS > 1 substr($_RS, 0, 1) eq "\n"
Truth table33%1/3
A and B
A= length $_RS > 1B= substr($_RS, 0, 1) eq "\n"
ABresult
0X0
100
111
84 0 $_chop_str = substr($_RS, 1);
85 0 $_chop_len = length $_chop_str;
86 } else {
87 14 $_chop_str = '';
88 14 $_chop_len = 0;
89 }
90 }
91  
92 ## -------------------------------------------------------------------------
93  
94 0 ▶ $self->{_next_jmp} = sub { goto _WORKER_REQUEST_CHUNK__NEXT; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
95 0 ▶ $self->{_last_jmp} = sub { goto _WORKER_REQUEST_CHUNK__LAST; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
96  
97 57 local $_;
98  
99 _WORKER_REQUEST_CHUNK__NEXT:
100  
101 57 while (1) {
102 205 ▶ undef $_ if (length > MAX_GC_SIZE);
Branch: 1 branch
BranchTrueFalseTotal
if length $_ > 67108864 0 205 205
103  
104 205 $_ = '';
105  
106 ## Obtain the next chunk of data.
107 {
108 205 ▶ local $\ = undef if (defined $\);
Branch: 1 branch
BranchTrueFalseTotal
if defined $\ 0 205 205
109 205 ▶ local $/ = $LF if ($/ ne $LF );
Branch: 1 branch
BranchTrueFalseTotal
if $/ ne $MCE::LF 0 205 205
110  
111 205 ▶ $_dat_ex->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 205 205
112 205 print {$_DAT_W_SOCK} $_output_tag . $LF . $_chn . $LF;
113 205 ▶ MCE::Util::_sock_ready($_DAU_W_SOCK, -1) if $_is_MSWin32;
Branch: 1 branch
BranchTrueFalseTotal
if $_is_MSWin32 0 205 205
114 205 chomp($_len = <$_DAU_W_SOCK>);
115  
116 205 ▶ unless ($_len) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_len) 57 148 205
117 57 ▶ $_dat_un->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 57 57
118 57 return;
119 }
120  
121 148 chomp($_chunk_id = <$_DAU_W_SOCK>);
122  
123 148 ▶ if ($_chunk_id > 1 && $_chop_len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_chunk_id > 1 and $_chop_len) { } 0 148 148
Condition66%2/3
$_chunk_id > 1 and $_chop_len
!ll&&!rl&&r
291190
MC/DC0%0/2
$_chunk_id > 1 and $_chop_len
$_chunk_id > 1 $_chop_len
Truth table66%2/3
A and B
A= $_chunk_id > 1B= $_chop_len
ABresult
0X0
100
111
124 0 $_p = $_chop_len; $_ = $_chop_str;
125 } else {
126 148 $_p = 0;
127 }
128  
129 148 read $_DAU_W_SOCK, $_, $_len, $_p;
130  
131 148 ▶ $_dat_un->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 148 148
132 }
133  
134 ## Call user function.
135 148 ▶ if ($_proc_type == REQUEST_ARRAY) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_proc_type == 0) { } 126 22 148
elsif ($_proc_type == 2) { } 15 7 22
136 126 my $_chunk_ref = $self->{thaw}($_); undef $_;
137 126 ▶ $_ = ($_chunk_size == 1) ? $_chunk_ref->[0] : $_chunk_ref;
Branch: 1 branch
BranchTrueFalseTotal
$_chunk_size == 1 ? : 89 37 126
138 126 $_wuf->($self, $_chunk_ref, $_chunk_id);
139 }
140 elsif ($_proc_type == REQUEST_HASH) {
141 15 my $_chunk_ref = { @{ $self->{thaw}($_) } }; undef $_;
142 15 $_ = $_chunk_ref;
143 15 $_wuf->($self, $_chunk_ref, $_chunk_id);
144 }
145 else {
146 7 $_ = ${ $self->{thaw}($_) };
147 7 ▶ if ($_use_slurpio) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_use_slurpio) { } 2 5 7
148 2 ▶ if ($_chop_len && substr($_, -$_chop_len) eq $_chop_str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_chop_len and substr($_, -$_chop_len) eq $_chop_str) 0 2 2
Condition33%1/3
$_chop_len and substr($_, -$_chop_len) eq $_chop_str
!ll&&!rl&&r
200
MC/DC0%0/2
$_chop_len and substr($_, -$_chop_len) eq $_chop_str
$_chop_len substr($_, -$_chop_len) eq $_chop_str
Truth table33%1/3
A and B
A= $_chop_lenB= substr($_, -$_chop_len) eq $_chop_str
ABresult
0X0
100
111
149 0 substr($_, -$_chop_len, $_chop_len, '');
150 }
151 2 local $_ = \$_;
152 2 $_wuf->($self, $_, $_chunk_id);
153 }
154 else {
155 5 ▶ if ($_chunk_size == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_chunk_size == 1) { } 0 5 5
156 0 ▶ if ($_chop_len && substr($_, -$_chop_len) eq $_chop_str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_chop_len and substr($_, -$_chop_len) eq $_chop_str) 0 0 0
Condition0%0/3
$_chop_len and substr($_, -$_chop_len) eq $_chop_str
!ll&&!rl&&r
000
MC/DC0%0/2
$_chop_len and substr($_, -$_chop_len) eq $_chop_str
$_chop_len substr($_, -$_chop_len) eq $_chop_str
Truth table0%0/3
A and B
A= $_chop_lenB= substr($_, -$_chop_len) eq $_chop_str
ABresult
0X0
100
111
157 0 substr($_, -$_chop_len, $_chop_len, '');
158 }
159 0 $_wuf->($self, [ $_ ], $_chunk_id);
160 }
161 else {
162 5 my @_recs;
163 {
164 5 ▶ local $/ = $_RS if ($/ ne $_RS);
Branch: 1 branch
BranchTrueFalseTotal
if $/ ne $_RS 0 5 5
165 5 _sync_buffer_to_array(\$_, \@_recs, $_chop_str);
166 5 undef $_;
167 }
168 5 ▶ if ($_chop_len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_chop_len) 0 5 5
169 0 for my $i (0 .. @_recs - 1) {
170 0 ▶ if (substr($_recs[$i], -$_chop_len) eq $_chop_str) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($_recs[$i], -$_chop_len) eq $_chop_str) 0 0 0
171 0 substr($_recs[$i], -$_chop_len, $_chop_len, '');
172 }
173 }
174 }
175 5 local $_ = \@_recs;
176 5 $_wuf->($self, \@_recs, $_chunk_id);
177 }
178 }
179 }
180 }
181  
182 _WORKER_REQUEST_CHUNK__LAST:
183  
184 0 return;
185 }
186  
187 44 1;
188  
189 __END__
« MCE/Flow.pm ↑ Summary MCE/Grep.pm »