line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Ping; |
2
|
|
|
|
|
|
|
$Test::Ping::VERSION = '0.204'; |
3
|
19
|
|
|
19
|
|
1263009
|
use strict; |
|
19
|
|
|
|
|
218
|
|
|
19
|
|
|
|
|
513
|
|
4
|
19
|
|
|
19
|
|
84
|
use warnings; |
|
19
|
|
|
|
|
34
|
|
|
19
|
|
|
|
|
610
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Testing pings using Net::Ping |
6
|
|
|
|
|
|
|
|
7
|
19
|
|
|
19
|
|
7084
|
use Test::Ping::Ties::BIND; |
|
19
|
|
|
|
|
62
|
|
|
19
|
|
|
|
|
784
|
|
8
|
19
|
|
|
19
|
|
7999
|
use Test::Ping::Ties::PORT; |
|
19
|
|
|
|
|
41
|
|
|
19
|
|
|
|
|
472
|
|
9
|
19
|
|
|
19
|
|
7420
|
use Test::Ping::Ties::PROTO; |
|
19
|
|
|
|
|
40
|
|
|
19
|
|
|
|
|
432
|
|
10
|
19
|
|
|
19
|
|
7098
|
use Test::Ping::Ties::HIRES; |
|
19
|
|
|
|
|
39
|
|
|
19
|
|
|
|
|
444
|
|
11
|
19
|
|
|
19
|
|
6775
|
use Test::Ping::Ties::TIMEOUT; |
|
19
|
|
|
|
|
41
|
|
|
19
|
|
|
|
|
440
|
|
12
|
19
|
|
|
19
|
|
7032
|
use Test::Ping::Ties::SOURCE_VERIFY; |
|
19
|
|
|
|
|
41
|
|
|
19
|
|
|
|
|
474
|
|
13
|
19
|
|
|
19
|
|
6974
|
use Test::Ping::Ties::SERVICE_CHECK; |
|
19
|
|
|
|
|
49
|
|
|
19
|
|
|
|
|
1845
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $CLASS = __PACKAGE__; |
16
|
|
|
|
|
|
|
my $OBJPATH = __PACKAGE__->builder->{'_net-ping_object'}; |
17
|
|
|
|
|
|
|
my $method_ignore = '__NONE'; |
18
|
|
|
|
|
|
|
our @EXPORT = qw( |
19
|
|
|
|
|
|
|
ping_ok |
20
|
|
|
|
|
|
|
ping_not_ok |
21
|
|
|
|
|
|
|
create_ping_object_ok |
22
|
|
|
|
|
|
|
create_ping_object_not_ok |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Net::Ping variables |
26
|
|
|
|
|
|
|
our $PORT; |
27
|
|
|
|
|
|
|
our $BIND; |
28
|
|
|
|
|
|
|
our $PROTO; |
29
|
|
|
|
|
|
|
our $HIRES; |
30
|
|
|
|
|
|
|
our $TIMEOUT; |
31
|
|
|
|
|
|
|
our $SOURCE_VERIFY; |
32
|
|
|
|
|
|
|
our $SERVICE_CHECK; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
BEGIN { |
35
|
19
|
|
|
19
|
|
7313
|
use parent 'Test::Builder::Module'; |
|
19
|
|
|
|
|
4934
|
|
|
19
|
|
|
|
|
89
|
|
36
|
19
|
|
|
19
|
|
1105
|
use Net::Ping; |
|
19
|
|
|
|
|
32
|
|
|
19
|
|
|
|
|
1685
|
|
37
|
|
|
|
|
|
|
|
38
|
19
|
|
|
19
|
|
111
|
__PACKAGE__->builder->{'_net-ping_object'} = Net::Ping->new($PROTO); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
## no critic qw(Miscellanea::ProhibitTies) |
41
|
19
|
|
|
|
|
12683
|
tie $PORT, 'Test::Ping::Ties::PORT'; |
42
|
19
|
|
|
|
|
74
|
tie $BIND, 'Test::Ping::Ties::BIND'; |
43
|
19
|
|
|
|
|
68
|
tie $PROTO, 'Test::Ping::Ties::PROTO'; |
44
|
19
|
|
|
|
|
63
|
tie $HIRES, 'Test::Ping::Ties::HIRES'; |
45
|
19
|
|
|
|
|
64
|
tie $TIMEOUT, 'Test::Ping::Ties::TIMEOUT'; |
46
|
19
|
|
|
|
|
61
|
tie $SOURCE_VERIFY, 'Test::Ping::Ties::SOURCE_VERIFY'; |
47
|
19
|
|
|
|
|
8650
|
tie $SERVICE_CHECK, 'Test::Ping::Ties::SERVICE_CHECK'; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub ping_ok { |
51
|
27
|
|
|
27
|
1
|
3051
|
my ( $host, $name ) = @_; |
52
|
27
|
|
|
|
|
118
|
my $tb = $CLASS->builder; |
53
|
27
|
|
|
|
|
270
|
my $pinger = $OBJPATH; |
54
|
|
|
|
|
|
|
|
55
|
27
|
|
|
|
|
98
|
my ( $ret, $duration ) = $pinger->ping( $host, $TIMEOUT ); |
56
|
27
|
|
|
|
|
724856
|
$tb->ok( $ret, $name ); |
57
|
|
|
|
|
|
|
|
58
|
27
|
|
|
|
|
9904
|
return ( $ret, $duration ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub ping_not_ok { |
62
|
3
|
|
|
3
|
1
|
16
|
my ( $host, $name ) = @_; |
63
|
3
|
|
|
|
|
24
|
my $tb = $CLASS->builder; |
64
|
3
|
|
|
|
|
37
|
my $pinger = $OBJPATH; |
65
|
|
|
|
|
|
|
|
66
|
3
|
|
|
|
|
14
|
my $alive = $pinger->ping( $host, $TIMEOUT ); |
67
|
3
|
|
|
|
|
14013502
|
$tb->ok( !$alive, $name ); |
68
|
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
1383
|
return 1; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub create_ping_object_ok { |
73
|
17
|
|
|
17
|
1
|
46491
|
my @args = @_; |
74
|
17
|
|
50
|
|
|
55
|
my $name = pop @args || q{}; |
75
|
17
|
|
|
|
|
107
|
my $tb = $CLASS->builder; |
76
|
|
|
|
|
|
|
|
77
|
17
|
|
|
|
|
163
|
my $success = eval { $OBJPATH = Net::Ping->new(@args); 1; }; |
|
17
|
|
|
|
|
121
|
|
|
17
|
|
|
|
|
2848
|
|
78
|
|
|
|
|
|
|
|
79
|
17
|
|
33
|
|
|
132
|
$tb->ok( $success && ref $OBJPATH eq 'Net::Ping', $name ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub create_ping_object_not_ok { |
83
|
1
|
|
|
1
|
1
|
9841
|
my @args = @_; |
84
|
1
|
|
50
|
|
|
6
|
my $name = pop @args || q{}; |
85
|
1
|
|
|
|
|
7
|
my $tb = $CLASS->builder; |
86
|
1
|
|
|
|
|
13
|
my $error; |
87
|
1
|
50
|
|
|
|
3
|
eval { Net::Ping->new(@args); 1; } |
|
1
|
|
|
|
|
7
|
|
|
0
|
|
|
|
|
0
|
|
88
|
|
|
|
|
|
|
or $error = $@; |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
250
|
$tb->ok( $error, $name ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _has_var_ok { ## no critic qw( Subroutines::ProhibitUnusedPrivateSubroutines ) |
94
|
6
|
|
|
6
|
|
30
|
my ( $var_name, $var_value, $name ) = @_; |
95
|
6
|
|
|
|
|
24
|
my $tb = $CLASS->builder; |
96
|
6
|
|
|
|
|
68
|
$tb->is_eq( $OBJPATH->{$var_name}, $var_value, $name ); |
97
|
6
|
|
|
|
|
3629
|
return 1; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _ping_object { ## no critic qw( Subroutines::ProhibitUnusedPrivateSubroutines Subroutines::RequireArgUnpacking ) |
101
|
110
|
|
50
|
110
|
|
19998331
|
my $obj = $_[1] || $_[0] || q{}; |
102
|
|
|
|
|
|
|
|
103
|
110
|
50
|
|
|
|
265
|
if ( ref $obj eq 'Net::Ping' ) { |
104
|
0
|
|
|
|
|
0
|
$OBJPATH = $obj; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
110
|
|
|
|
|
412
|
return $OBJPATH; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
15
|
|
|
15
|
|
29590
|
END { $OBJPATH->close(); } |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |