blib/lib/MapReduce/Framework/Simple.pm

filter: Statementstmt 28.7% 101 / 351 Branchbran 15.0% 15 / 100 Conditioncond 15.0% 3 / 20 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 58.6% 17 / 29 Podpod 80.0% 4 / 5 totaltotal 27.0% 140 / 517 CC 80 SCAR 59.1
CC
80
Cov
25%
create_assigned_data
930.0
map_reduce
350.4
worker
30.0
CRAP 369.3
↑ Summary
1 package MapReduce::Framework::Simple;
2 6 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use B::Deparse;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Data::MessagePack;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Parallel::ForkManager;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Plack::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use List::Util qw(shuffle);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use Data::Serializer;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶no warnings qw(once);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 $Storable::Deparse = 1;
16 6 $Storable::Eval = 1;
17 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 6 our $VERSION = "0.09";
20  
21 6 has 'verify_hostname' => (is => 'rw', isa => 'Int', default => 1);
22 6 has 'skip_undef_result' => (is => 'rw', isa => 'Int', default => 1);
23 6 has 'warn_discarded_data' => (is => 'rw', isa => 'Int', default => 1);
24 6 has 'die_discarded_data' => (is => 'rw', isa => 'Int', default => 0);
25 6 has 'worker_log' => (is => 'rw', isa => 'Int', default => 0);
26 6 has 'force_plackup' => (is => 'rw', isa => 'Int', default => 0);
27 5 ▶has 'server_spec' => (is => 'rw', isa => 'HashRef', default => sub{{cores => 1, clock => 2000, mem => 1}});
Subroutine __ANON__: called CC=1 SCAR=0.0
28 6 has 'worker_num' => (is => 'rw', isa => 'Int', default => 1);
29 6 has 'port' => (is => 'rw', isa => 'Int', default => 5000);
30 6 has 'path' => (is => 'rw', isa => 'Str', default => '/eval');
31  
32  
33 # To make load balanced data.
34 0 ▶sub create_assigned_data {
Subroutine create_assigned_data: not called CC=30 SCAR=68.4
Pod documented
35 0 my $self = shift;
36 0 my $data = shift;
37 0 my $servers = shift;
38 0 my $options = shift;
39 0 my $chunk_num = 10;
40 0 my $method = 'volume_uniform';
41 0 ▶ if(defined($options)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options) 0 0 0
42 0 ▶ if(defined($options->{chunk_num})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options->{"chunk_num"}) 0 0 0
43 0 $chunk_num = $options->{chunk_num};
44 }
45 0 ▶ if(defined($options->{method})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options->{"method"}) 0 0 0
46 0 $method = $options->{method};
47 }
48 }
49 0 my $output;
50 0 ▶ if($method eq 'element_shuffle'){
Branch: 5 branches
BranchTrueFalseTotal
if ($method eq 'element_shuffle') { } 0 0 0
elsif ($method eq 'element_sequential') { } 0 0 0
elsif ($method eq 'element_server_cores') { } 0 0 0
elsif ($method eq 'element_server_workers') { } 0 0 0
elsif ($method eq 'element_server_core_clock') { } 0 0 0
51  
52 0 @$data = shuffle(@$data);
53 0 for(0 .. $#$data){
54 0 push(@{$output->[$_ % $chunk_num]->[0]},$data->[$_]);
55 }
56 0 for(0 .. $#$output){
57 0 $output->[$_]->[1] = $servers->[$_ % scalar(@$servers)];
58 }
59 }elsif($method eq 'element_sequential'){
60 0 for(0 .. $#$data){
61 0 push(@{$output->[$_ % $chunk_num]->[0]},$data->[$_]);
62 }
63 0 for(0 .. $#$output){
64 0 $output->[$_]->[1] = $servers->[$_ % scalar(@$servers)];
65 }
66 }elsif($method eq 'element_server_cores'){
67 0 @$data = shuffle(@$data);
68 0 my $server_spec = $self->check_server_spec($servers);
69 0 my $tmp_server_list;
70 0 foreach my $key (keys %$server_spec){
71 0 push(@$tmp_server_list,$key);
72 0 for(2 .. $server_spec->{$key}->{server_spec}->{cores}){
73 0 push(@$tmp_server_list,$key);
74 }
75 }
76 0 for(0 .. $#$data){
77 0 push(@{$output->[$_ % scalar(@$tmp_server_list)]->[0]},$data->[$_]);
78 }
79 0 for(0 .. $#$output){
80 0 $output->[$_]->[1] = $tmp_server_list->[$_ % scalar(@$tmp_server_list)];
81 }
82 }elsif($method eq 'element_server_workers'){
83 0 @$data = shuffle(@$data);
84 0 my $server_spec = $self->check_server_spec($servers);
85 0 my $tmp_server_list;
86 0 foreach my $key (keys %$server_spec){
87 0 push(@$tmp_server_list,$key);
88 0 for(2 .. $server_spec->{$key}->{server_spec}->{worker_num}){
89 0 push(@$tmp_server_list,$key);
90 }
91 }
92 0 for(0 .. $#$data){
93 0 push(@{$output->[$_ % scalar(@$tmp_server_list)]->[0]},$data->[$_]);
94 }
95 0 for(0 .. $#$output){
96 0 $output->[$_]->[1] = $tmp_server_list->[$_ % scalar(@$tmp_server_list)];
97 }
98 }elsif($method eq 'element_server_core_clock'){
99 0 @$data = shuffle(@$data);
100 0 my $server_spec = $self->check_server_spec($servers);
101 0 my $tmp_server_list;
102  
103 0 my $tmp_max_cc = 0;
104 0 my $tmp_min_cc = 1_000_000_000_000;
105 0 foreach my $key (keys %$server_spec){
106 my $tmp_cc = ($server_spec->{$key}->{server_spec}->{cores} + 0.0001)
107 0 * ($server_spec->{$key}->{server_spec}->{clock} + 0.0001);
108 0 ▶ if($tmp_max_cc < $tmp_cc){
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp_max_cc < $tmp_cc) 0 0 0
109 0 $tmp_max_cc = $tmp_cc;
110 }
111 0 ▶ if($tmp_min_cc > $tmp_cc){
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp_min_cc > $tmp_cc) 0 0 0
112 0 $tmp_min_cc = $tmp_cc;
113 }
114 }
115  
116 0 my $pre_ratio = ((log($tmp_max_cc) / log(10))+(log($tmp_max_cc) / log(10)));
117 0 my $ratio = 1/ 10 ** int($pre_ratio / 2);
118 0 foreach my $key (keys %$server_spec){
119 0 push(@$tmp_server_list,$key);
120 my $tmp_cc = $server_spec->{$key}->{server_spec}->{cores}
121 0 * $server_spec->{$key}->{server_spec}->{clock};
122 0 my $add_num = int($tmp_cc * $ratio);
123 0 for(2 .. $add_num){
124 0 push(@$tmp_server_list,$key);
125 }
126 }
127 0 for(0 .. $#$data){
128 0 push(@{$output->[$_ % scalar(@$tmp_server_list)]->[0]},$data->[$_]);
129 }
130 0 for(0 .. $#$output){
131 0 $output->[$_]->[1] = $tmp_server_list->[$_ % scalar(@$tmp_server_list)];
132 }
133 }else{
134 0 my $mp = Data::MessagePack->new();
135 @$data = map $_->[0],
136 0 sort {$a->[1] <=> $b->[1]} map [$_, bytes::length $mp->pack($_)],
137 @$data;
138 0 for(0 .. $#$data){
139 0 push(@{$output->[$_ % $chunk_num]->[0]},$data->[$_]);
140 }
141 0 for(0 .. $#$output){
142 0 $output->[$_]->[1] = $servers->[$_ % scalar(@$servers)];
143 }
144 }
145 0 return($output);
146 }
147  
148 # MapReduce client(Master)
149 5 ▶sub map_reduce {
Subroutine map_reduce: called CC=33 SCAR=58.6
Pod documented
150 5 my $self = shift;
151 5 my $data = shift;
152 5 my $mapper_ref = shift;
153 5 my $reducer_ref = shift;
154 5 my $max_proc = shift;
155 5 my $options = shift;
156 5 my $remote_flg = 1;
157 5 ▶ if(defined($options) and defined($options->{remote})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options and defined $options->{"remote"}) 5 0 5
Condition33%1/3
defined $options and defined $options->{"remote"}
!ll&&!rl&&r
005
MC/DC0%0/2
defined $options and defined $options->{"remote"}
defined $options defined $options->{"remote"}
Truth table33%1/3
A and B
A= defined $optionsB= defined $options->{"remote"}
ABresult
0X0
100
111
158 5 $remote_flg = $options->{remote};
159 }
160 5 my $storable_flg = 0;
161 5 ▶ if(defined($options) and defined($options->{storable})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options and defined $options->{"storable"}) 0 5 5
Condition33%1/3
defined $options and defined $options->{"storable"}
!ll&&!rl&&r
050
MC/DC0%0/2
defined $options and defined $options->{"storable"}
defined $options defined $options->{"storable"}
Truth table33%1/3
A and B
A= defined $optionsB= defined $options->{"storable"}
ABresult
0X0
100
111
162 0 $storable_flg = $options->{storable};
163 }
164 5 my $stringified_code = B::Deparse->new->coderef2text($mapper_ref);
165 5 my $result;
166 my $succeeded_remotes;
167 5 my $failed_remotes;
168 5 my $failed_data;
169 5 my $discarded_data;
170 5 my $pm = Parallel::ForkManager->new($max_proc);
171  
172 5 my $ds;
173 5 ▶ if($storable_flg == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($storable_flg == 1) 0 5 5
174 0 $ds = Data::Serializer->new(
175 serializer => 'Storable',
176 compress => 1
177 );
178 }
179  
180 $pm->run_on_finish(
181 4 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=13.0
182 4 my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data_structure) = @_;
183 4 ▶ if (defined $data_structure) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data_structure) 4 0 4
184 4 ▶ if($data_structure->{is_success} == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($data_structure->{'is_success'} == 1) { } 4 0 4
185 4 $succeeded_remotes->{$data_structure->{remote}} = 1;
186 4 $result->[$data_structure->{id}] = $data_structure->{result};
187 }else{
188 0 $failed_remotes->{$data_structure->{remote}} = 1;
189 0 push(@$failed_data,$data_structure->{failed_data});
190 0 $result->[$data_structure->{id}] = undef;
191 }
192 }
193 }
194 5 );
195 5 ▶ if($remote_flg == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($remote_flg == 1) { } 0 5 5
196 0 ▶ for(my $k=0; $k <= $#$data; $k++){
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= $data->$#*) 0 0 0
197 0 ▶ $pm->start and next;
Branch: 1 branch
BranchTrueFalseTotal
$pm->start and next 0 0 0
198 0 my $payload;
199 0 ▶ if($storable_flg == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($storable_flg == 1) { } 0 0 0
200 0 $payload = $ds->serialize(
201 {
202 data => $data->[$k]->[0],
203 code => $stringified_code
204 }
205 );
206 }else{
207 0 $payload = _perl_to_msgpack(
208 {
209 data => $data->[$k]->[0],
210 code => $stringified_code
211 }
212 );
213 }
214 0 my $path_add = '';
215 0 ▶ if($storable_flg == 1){ $path_add = '/STORABLE'; };
Branch: 1 branch
BranchTrueFalseTotal
if ($storable_flg == 1) 0 0 0
216 0 my $content_type_name = 'application/x-msgpack; charset=x-user-defined';
217 0 ▶ if($storable_flg == 1){ $content_type_name = 'application/octet-stream; charset=x-user-defined'; };
Branch: 1 branch
BranchTrueFalseTotal
if ($storable_flg == 1) 0 0 0
218 0 my $result_chil_from_remote = _post_content(
219 $data->[$k]->[1].$path_add,
220 $content_type_name,
221 $payload,
222 $self->verify_hostname
223 );
224 0 my $result_with_id;
225 0 ▶ if($result_chil_from_remote->{is_success}){
Branch: 1 branch
BranchTrueFalseTotal
if ($result_chil_from_remote->{'is_success'}) { } 0 0 0
226 0 my $result_chil;
227 0 ▶ if($storable_flg == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($storable_flg == 1) { } 0 0 0
228 0 $result_chil = $ds->deserialize($result_chil_from_remote->{res});
229 }else{
230 0 $result_chil = _msgpack_to_perl($result_chil_from_remote->{res});
231 }
232 0 $result_with_id = {id => $k, result => $result_chil->{result}, remote => $data->[$k]->[1], is_success => 1};
233 }else{
234 0 $result_with_id = {id => $k, remote => $data->[$k]->[0], is_success => 0, failed_data => $data->[$k]};
235 }
236 0 $pm->finish(0,$result_with_id);
237 }
238 }else{
239 5 ▶ for(my $k=0; $k <= $#$data; $k++){
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= $data->$#*) 14 1 15
240 14 ▶ $pm->start and next;
Branch: 1 branch
BranchTrueFalseTotal
$pm->start and next 10 4 14
241 4 my $result_chil = $mapper_ref->($data->[$k]);
242 4 my $result_with_id = {id => $k, result => $result_chil, is_success => 1, remote => 'LOCAL'};
243 4 $pm->finish(0,$result_with_id);
244 }
245 }
246 1 $pm->wait_all_children;
247 1 my $result_failover;
248 1 ▶ if($remote_flg == 1 and $#$failed_data >= 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($remote_flg == 1 and $failed_data->$#* >= 0) 0 1 1
Condition33%1/3
$remote_flg == 1 and $failed_data->$#* >= 0
!ll&&!rl&&r
100
MC/DC0%0/2
$remote_flg == 1 and $failed_data->$#* >= 0
$remote_flg == 1 $failed_data->$#* >= 0
Truth table33%1/3
A and B
A= $remote_flg == 1B= $failed_data->$#* >= 0
ABresult
0X0
100
111
249 0 my @succeeded_remotes_list;
250 0 foreach my $key (keys %$succeeded_remotes){
251 0 push(@succeeded_remotes_list,$key);
252 }
253 0 my $pm2 = Parallel::ForkManager->new($max_proc);
254 $pm2->run_on_finish(
255 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
256 0 my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data_structure) = @_;
257 0 ▶ if (defined $data_structure) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data_structure) 0 0 0
258 0 ▶ if($data_structure->{is_success} == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($data_structure->{'is_success'} == 1) { } 0 0 0
259 0 $succeeded_remotes->{$data_structure->{remote}} = 1;
260 0 $result_failover->[$data_structure->{id}] = $data_structure->{result};
261 }else{
262 0 $failed_remotes->{$data_structure->{remote}} = 1;
263 0 push(@$discarded_data,$data_structure->{failed_data});
264 0 $result_failover->[$data_structure->{id}] = undef;
265 }
266 }
267 }
268 0 );
269  
270 0 ▶ for(my $k=0; $k <= $#$failed_data; $k++){
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= $failed_data->$#*) 0 0 0
271 0 ▶ $pm2->start and next;
Branch: 1 branch
BranchTrueFalseTotal
$pm2->start and next 0 0 0
272 0 my $payload;
273 0 ▶ if($storable_flg == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($storable_flg == 1) { } 0 0 0
274 0 $payload = $ds->serialize(
275 {
276 data => $failed_data->[$k]->[0],
277 code => $stringified_code
278 }
279 );
280 }else{
281 0 $payload = _perl_to_msgpack(
282 {
283 data => $failed_data->[$k]->[0],
284 code => $stringified_code
285 }
286 );
287 }
288  
289 0 my $path_add = '';
290 0 ▶ if($storable_flg == 1){ $path_add = '/STORABLE' };
Branch: 1 branch
BranchTrueFalseTotal
if ($storable_flg == 1) 0 0 0
291 0 my $content_type_name = 'application/x-msgpack; charset=x-user-defined';
292 0 ▶ if($storable_flg == 1){ $content_type_name = 'application/octet-stream; charset=x-user-defined'; };
Branch: 1 branch
BranchTrueFalseTotal
if ($storable_flg == 1) 0 0 0
293 0 my $rand_remote = $succeeded_remotes_list[int(rand($#succeeded_remotes_list))];
294 0 my $result_chil_from_remote = _post_content(
295 $rand_remote.$path_add,
296 $content_type_name,
297 $payload,
298 $self->verify_hostname
299 );
300 0 my $result_with_id;
301 0 ▶ if($result_chil_from_remote->{is_success}){
Branch: 1 branch
BranchTrueFalseTotal
if ($result_chil_from_remote->{'is_success'}) { } 0 0 0
302 0 my $result_chil;
303 0 ▶ if($storable_flg == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($storable_flg == 1) { } 0 0 0
304 0 $result_chil = $ds->deserialize($result_chil_from_remote->{res});
305 }else{
306 0 $result_chil = _msgpack_to_perl($result_chil_from_remote->{res});
307 }
308 0 $result_with_id = {id => $#$data + $k, result => $result_chil->{result}, remote => $rand_remote, is_success => 1};
309 }else{
310 0 $result_with_id = {id => $#$data + $k, remote => $rand_remote, is_success => 0, failed_data => $failed_data->[$k]};
311 }
312 0 $pm2->finish(0,$result_with_id);
313 }
314 0 $pm2->wait_all_children;
315 }
316 1 my $result_merged;
317 1 push(@$result_merged,@$result);
318 1 ▶ if($#$result_failover >= 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($result_failover->$#* >= 0) 0 1 1
319 0 push(@$result_merged,@$result_failover);
320 }
321 1 ▶ if($#$discarded_data >= 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($discarded_data->$#* >= 0) 0 1 1
322 0 ▶ if($self->die_discarded_data == 1){
Branch: 2 branches
BranchTrueFalseTotal
if ($self->die_discarded_data == 1) { } 0 0 0
elsif ($self->warn_discarded_data == 1) { } 0 0 0
323 0 die "Fatal: Discarded data exist due to remote server couldn't process requested data.\n";
324 }elsif($self->warn_discarded_data == 1){
325 0 warn "Warning: Discarded data exist.\n";
326 }
327 }
328 1 ▶ if($self->skip_undef_result == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->skip_undef_result == 1) { } 1 0 1
329 1 my $result_skip;
330 1 for(0 .. $#$result_merged){
331 4 ▶ if(defined($result_merged->[$_])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result_merged->[$_]) 4 0 4
332 4 push(@$result_skip,$result_merged->[$_]);
333 }
334 }
335 1 return($reducer_ref->($result_skip));
336 }else{
337 0 return($reducer_ref->($result_merged));
338 }
339 }
340  
341 0 ▶sub worker {
Subroutine worker: not called CC=5 SCAR=34.0
Pod documented
342 0 my $self = shift;
343 0 my $path = shift;
344 0 my $worker = shift;
345 0 my $port = shift;
346  
347 0 $self->{path} = $path;
348  
349 0 ▶ unless(defined($worker)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $worker) 0 0 0
350 0 $worker = 4;
351 }
352 0 $self->{worker_num} = $worker;
353  
354 0 ▶ unless(defined($port)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $port) 0 0 0
355 0 $port = 5000;
356 }
357 0 $self->{port} = $port;
358  
359 0 my $rc = eval{
360 0 require Plack::Handler::Starlet;
361 0 1;
362 };
363 0 ▶ if($rc and $self->force_plackup == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($rc and $self->force_plackup == 0) { } 0 0 0
Condition0%0/3
$rc and $self->force_plackup == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$rc and $self->force_plackup == 0
$rc $self->force_plackup == 0
Truth table0%0/3
A and B
A= $rcB= $self->force_plackup == 0
ABresult
0X0
100
111
364 0 print "Starting MapReduce Framework Worker by Starlet\n";
365 0 print "Path: $path\nPort: $port\n";
366 0 my $app = $self->load_worker_plack_app($path);
367 0 my $handler = Plack::Handler::Starlet->new(
368 max_workers => $worker,
369 port => $port
370 );
371 0 $handler->run($app);
372 }else{
373 0 $self->{worker_num} = 1;
374 0 require Plack::Runner;
375 0 my $runner = Plack::Runner->new;
376 0 print "Starting MapReduce Framework Worker by plackup. The number of workers will be ignored.\n";
377 0 print "Path: $path\nPort: $port\n";
378 0 my $app = $self->load_worker_plack_app($path);
379 0 $runner->parse_options('--port',$port);
380 0 $runner->run($app);
381 }
382 }
383  
384 0 ▶sub load_worker_plack_app {
Subroutine load_worker_plack_app: not called CC=1 SCAR=6.9
Pod documented
385 0 my $self = shift;
386 0 my $path = shift;
387 0 ▶ my $app = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
388 0 my $env = shift;
389 0 my $req = Plack::Request->new($env);
390 0 ▶ if($self->worker_log == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->worker_log == 1) 0 0 0
391 0 print "REQ,$$,".$req->address.',';
392 0 my @tar = localtime(time());
393 0 printf(
394 "%04d-%02d-%02d %02d:%02d:%02d",
395 $tar[5]+1900,$tar[4]+1,$tar[3],$tar[2],$tar[1],$tar[0]
396 );
397 0 print "\n";
398 }
399 my $response = {
400 0 ▶ $path => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
401 0 ▶ my $msg_req = $req->content //
Condition0%0/2
$req->content // (return [400, ["Content-Type", "text/plain"], ["Content body required."]])
l!l
00
MC/DC0%0/1
$req->content // (return [400, ["Content-Type", "text/plain"], ["Content body required."]])
$req->content
Truth table0%0/2
A
A= $req->content
Aresult
11
00
402 return [400,['Content-Type' => 'text/plain'],['Content body required.']];
403 0 ▶ my $perl_req = _msgpack_to_perl($msg_req) //
Condition0%0/2
_msgpack_to_perl($msg_req) // (return [400, ["Content-Type", "text/plain"], ["Valid MessagePack required"]])
l!l
00
MC/DC0%0/1
_msgpack_to_perl($msg_req) // (return [400, ["Content-Type", "text/plain"], ["Valid MessagePack required"]])
_msgpack_to_perl($msg_req)
Truth table0%0/2
A
A= _msgpack_to_perl($msg_req)
Aresult
11
00
404 return [400,['Content-Type' => 'text/plain'],['Valid MessagePack required']];
405 0 my $data = $perl_req->{data};
406 0 my $code_text = $perl_req->{code};
407 0 my $code_ref;
408 0 eval('$code_ref = sub '.$code_text.';');
409 0 my $result = $code_ref->($data);
410 0 return [200,['Content-Type' => 'application/x-msgpack; charset=x-user-defined'],[_perl_to_msgpack({result => $result})]];
411 },
412 0 ▶ $path.'/server_spec' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
413 0 my $server_spec = $self->{server_spec};
414 0 $server_spec->{worker_num} = $self->{worker_num};
415 0 $server_spec->{port} = $self->{port};
416 0 $server_spec->{path} = $self->{path};
417  
418 0 return [200,['Content-Type' => 'application/x-msgpack; charset=x-user-defined'],[_perl_to_msgpack({server_spec => $server_spec})]];
419 },
420 0 ▶ $path.'/STORABLE' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
421 0 my $ds = Data::Serializer->new(
422 serializer => 'Storable',
423 compress => 1
424 );
425 0 ▶ my $msg_req = $req->content //
Condition0%0/2
$req->content // (return [400, ["Content-Type", "text/plain"], ["Content body required."]])
l!l
00
MC/DC0%0/1
$req->content // (return [400, ["Content-Type", "text/plain"], ["Content body required."]])
$req->content
Truth table0%0/2
A
A= $req->content
Aresult
11
00
426 return [400,['Content-Type' => 'text/plain'],['Content body required.']];
427 0 ▶ my $perl_req = $ds->deserialize($msg_req) //
Condition0%0/2
$ds->deserialize($msg_req) // (return [400, ["Content-Type", "text/plain"], ["Valid MessagePack required"]])
l!l
00
MC/DC0%0/1
$ds->deserialize($msg_req) // (return [400, ["Content-Type", "text/plain"], ["Valid MessagePack required"]])
$ds->deserialize($msg_req)
Truth table0%0/2
A
A= $ds->deserialize($msg_req)
Aresult
11
00
428 return [400,['Content-Type' => 'text/plain'],['Valid MessagePack required']];
429 0 my $data = $perl_req->{data};
430 0 my $code_text = $perl_req->{code};
431 0 my $code_ref;
432 0 eval('$code_ref = sub '.$code_text.';');
433 0 my $result_pre = $code_ref->($data);
434 0 my $result = $ds->serialize({result => $result_pre});
435 0 return [200,['Content-Type' => 'application/octet-stream; charset=x-user-defined'],[$result]];
436 },
437 0 };
438 0 ▶ if($self->worker_log == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->worker_log == 1) 0 0 0
439 0 print "END,$$,".$req->address.',';
440 0 my @tar = localtime(time());
441 0 printf(
442 "%04d-%02d-%02d %02d:%02d:%02d",
443 $tar[5]+1900,$tar[4]+1,$tar[3],$tar[2],$tar[1],$tar[0]
444 );
445 0 print "\n";
446 }
447 0 ▶ if(defined($response->{$env->{PATH_INFO}})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$response{$env->{'PATH_INFO'}}) { } 0 0 0
448 0 return $response->{$env->{PATH_INFO}}->();
449 }else{
450 0 return [404,['Content-Type' => 'text/plain'],['Not Found']];
451 }
452  
453 0 };
454 0 return($app);
455 }
456  
457 0 ▶sub check_server_spec {
Subroutine check_server_spec: not called CC=3 SCAR=24.8
Pod undocumented
458 0 my $self = shift;
459 0 my $server_list = shift;
460 0 my $output;
461 0 ▶ for(my $k=0; $k <= $#$server_list; $k++){
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= $server_list->$#*) 0 0 0
462 0 my $result_chil_from_remote = _post_content(
463 $server_list->[$k] . '/server_spec',
464 'application/x-msgpack; charset=x-user-defined',
465 '',
466 $self->verify_hostname
467 );
468 0 ▶ if($result_chil_from_remote->{is_success}){
Branch: 1 branch
BranchTrueFalseTotal
if ($result_chil_from_remote->{"is_success"}) 0 0 0
469 0 my $tmp_spec = _msgpack_to_perl($result_chil_from_remote->{res});
470 0 $output->{$server_list->[$k]} = $tmp_spec;
471 }
472 }
473 0 return $output;
474 }
475  
476 0 ▶sub _post_content {
Subroutine _post_content: not called CC=2 SCAR=17.9
477 0 my $url = shift;
478 0 my $content_type = shift;
479 0 my $data = shift;
480 0 my $ssl_opt = shift;
481 0 my $ua = WWW::Mechanize->new(
482 ssl_opts => {
483 verify_hostname => $ssl_opt
484 }
485 );
486 0 my $is_success = 1;
487 0 eval{
488 0 $ua->post($url,'Content-Type' => $content_type, Content => $data);
489 };
490 0 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
491 0 $is_success = 0;
492 }
493 0 my $res = $ua->content();
494 0 return {res => $res, is_success => $is_success};
495 }
496  
497 0 ▶sub _perl_to_msgpack {
Subroutine _perl_to_msgpack: not called CC=1 SCAR=6.9
498 0 my $data = shift;
499 0 my $msgpack = Data::MessagePack->new();
500 0 my $packed = $msgpack->pack($data);
501 0 return($packed);
502 }
503  
504 0 ▶sub _msgpack_to_perl {
Subroutine _msgpack_to_perl: not called CC=1 SCAR=6.9
505 0 my $msg_text = shift;
506 0 my $msgpack = Data::MessagePack->new();
507 0 my $unpacked = $msgpack->unpack($msg_text);
508 0 return($unpacked);
509 }
510  
511  
512  
513 6 __PACKAGE__->meta->make_immutable();
514  
515 6 1;
516 __END__
↑ Summary