blib/lib/MapReduce/Framework/Simple.pm

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