| 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"} ||= {}
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"}
| |||||||||||||||||||||
| 17 | 1 | ▶ | $conf->{protcol} ||= 'tcp'; | ||||||||||||||||||
|
Condition50%1/2
$conf->{"protcol"} ||= "tcp"
MC/DC0%0/1
$conf->{"protcol"} ||= "tcp"
$conf->{"protcol"}
Truth table50%1/2
A
A= $conf->{"protcol"}
| |||||||||||||||||||||
| 18 | 1 | ▶ | $conf->{timeout} ||= 3; | ||||||||||||||||||
|
Condition50%1/2
$conf->{"timeout"} ||= 3
MC/DC0%0/1
$conf->{"timeout"} ||= 3
$conf->{"timeout"}
Truth table50%1/2
A
A= $conf->{"timeout"}
| |||||||||||||||||||||
| 19 | 1 | ▶ | $conf->{retry} ||= 1; | ||||||||||||||||||
|
Condition50%1/2
$conf->{"retry"} ||= 1
MC/DC0%0/1
$conf->{"retry"} ||= 1
$conf->{"retry"}
Truth table50%1/2
A
A= $conf->{"retry"}
| |||||||||||||||||||||
| 20 | 1 | ▶ | $conf->{wait} ||= 0.5; | ||||||||||||||||||
|
Condition50%1/2
$conf->{"wait"} ||= "0.5"
MC/DC0%0/1
$conf->{"wait"} ||= "0.5"
$conf->{"wait"}
Truth table50%1/2
A
A= $conf->{"wait"}
| |||||||||||||||||||||
| 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. ')
MC/DC0%0/1
shift() || croak(' I want target host. ')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 26 | my %option= ( | ||||||||||||||||||||
| 27 | 1 | %{$e->config->{plugin_net_ping}}, | |||||||||||||||||||
| 28 | 1 | ▶ | %{ $_[1] ? {@_}: ($_[0] || {}) }, | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$_[0] or {}
MC/DC0%0/1
$_[0] or {}
$_[0]
Truth table50%1/2
A
A= $_[0]
| |||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||
| 30 | 1 | ▶ | $option{retry}= 5 if $option{retry}> 5; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 1 | my $ping= Net::Ping->new($option{protcol}); | |||||||||||||||||||
| 33 | 0 | ▶ | $ping->bind($option{self_addr}) if $option{self_addr}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | my($result, $count); | |||||||||||||||||||
| 36 | 0 | for (1..$option{retry}) { | |||||||||||||||||||
| 37 | 0 | ▶ | ++$result if $ping->ping($host, $option{timeout}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | 0 | ▶ | ++$count>= $option{retry} and last; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 0 | select(undef, undef, undef, $option{wait}); ## no critic | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | ▶ | $result || 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 3 | 1; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | __END__ | ||||||||||||||||||||