lib/Egg/Plugin/Net/Ping.pm

filter: Statementstmt 80.0% 28 / 35 Branchbran 16.6% 2 / 12 Conditioncond 50.0% 7 / 14 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 58.6% 44 / 75 CC 15 SCAR 29.9
CC
15
Cov
61%
ping
35.4
_setup
6.9
BEGIN
1.0
CRAP 20.0
↑ Summary
1 package Egg::Plugin::Net::Ping;
2 #
3 # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
4 #
5 # $Id: Ping.pm 271 2008-02-24 06:52:22Z lushe $
6 #
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Net::Ping;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 our $VERSION= '3.01';
13  
14 1 ▶sub _setup {
Subroutine _setup: called CC=6 SCAR=19.3
15 1 my($e)= @_;
16 1 ▶ my $conf= $e->config->{plugin_net_ping} ||= {};
Condition50%1/2
$e->config->{"plugin_net_ping"} ||= {}
l!l
10
MC/DC0%0/1
$e->config->{"plugin_net_ping"} ||= {}
$e->config->{"plugin_net_ping"}
Truth table50%1/2
A
A= $e->config->{"plugin_net_ping"}
Aresult
11
00
17 1 ▶ $conf->{protcol} ||= 'tcp';
Condition50%1/2
$conf->{"protcol"} ||= "tcp"
l!l
01
MC/DC0%0/1
$conf->{"protcol"} ||= "tcp"
$conf->{"protcol"}
Truth table50%1/2
A
A= $conf->{"protcol"}
Aresult
11
00
18 1 ▶ $conf->{timeout} ||= 3;
Condition50%1/2
$conf->{"timeout"} ||= 3
l!l
10
MC/DC0%0/1
$conf->{"timeout"} ||= 3
$conf->{"timeout"}
Truth table50%1/2
A
A= $conf->{"timeout"}
Aresult
11
00
19 1 ▶ $conf->{retry} ||= 1;
Condition50%1/2
$conf->{"retry"} ||= 1
l!l
10
MC/DC0%0/1
$conf->{"retry"} ||= 1
$conf->{"retry"}
Truth table50%1/2
A
A= $conf->{"retry"}
Aresult
11
00
20 1 ▶ $conf->{wait} ||= 0.5;
Condition50%1/2
$conf->{"wait"} ||= "0.5"
l!l
10
MC/DC0%0/1
$conf->{"wait"} ||= "0.5"
$conf->{"wait"}
Truth table50%1/2
A
A= $conf->{"wait"}
Aresult
11
00
21 1 $e->next::method;
22 }
23 1 ▶sub ping {
Subroutine ping: called CC=10 SCAR=35.7
Pod documented
24 1 my $e= shift;
25 1 ▶ my $host= shift || croak q{ I want target host. };
Condition50%1/2
shift() || croak(' I want target host. ')
l!l
10
MC/DC0%0/1
shift() || croak(' I want target host. ')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
26 my %option= (
27 1 %{$e->config->{plugin_net_ping}},
28 1 ▶ %{ $_[1] ? {@_}: ($_[0] || {}) },
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 1 1
Condition50%1/2
$_[0] or {}
l!l
01
MC/DC0%0/1
$_[0] or {}
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
29 );
30 1 ▶ $option{retry}= 5 if $option{retry}> 5;
Branch: 1 branch
BranchTrueFalseTotal
if $option{"retry"} > 5 0 1 1
31  
32 1 my $ping= Net::Ping->new($option{protcol});
33 0 ▶ $ping->bind($option{self_addr}) if $option{self_addr};
Branch: 1 branch
BranchTrueFalseTotal
if $option{"self_addr"} 0 0 0
34  
35 0 my($result, $count);
36 0 for (1..$option{retry}) {
37 0 ▶ ++$result if $ping->ping($host, $option{timeout});
Branch: 1 branch
BranchTrueFalseTotal
if $ping->ping($host, $option{"timeout"}) 0 0 0
38 0 ▶ ++$count>= $option{retry} and last;
Branch: 1 branch
BranchTrueFalseTotal
++$count >= $option{"retry"} and last 0 0 0
39 0 select(undef, undef, undef, $option{wait}); ## no critic
40 }
41  
42 0 ▶ $result || 0;
Branch: 1 branch
BranchTrueFalseTotal
$result or 0 0 0 0
43 }
44  
45 3 1;
46  
47 __END__
↑ Summary