line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Ping; |
2
|
|
|
|
|
|
|
# ABSTRACT: Testing pings using Net::Ping |
3
|
|
|
|
|
|
|
$Test::Ping::VERSION = '0.210'; |
4
|
19
|
|
|
19
|
|
1548507
|
use strict; |
|
19
|
|
|
|
|
180
|
|
|
19
|
|
|
|
|
569
|
|
5
|
19
|
|
|
19
|
|
104
|
use warnings; |
|
19
|
|
|
|
|
33
|
|
|
19
|
|
|
|
|
507
|
|
6
|
|
|
|
|
|
|
|
7
|
19
|
|
|
19
|
|
9103
|
use Test::Ping::Ties::BIND; |
|
19
|
|
|
|
|
68
|
|
|
19
|
|
|
|
|
646
|
|
8
|
19
|
|
|
19
|
|
9435
|
use Test::Ping::Ties::PORT; |
|
19
|
|
|
|
|
53
|
|
|
19
|
|
|
|
|
615
|
|
9
|
19
|
|
|
19
|
|
9011
|
use Test::Ping::Ties::PROTO; |
|
19
|
|
|
|
|
50
|
|
|
19
|
|
|
|
|
546
|
|
10
|
19
|
|
|
19
|
|
8471
|
use Test::Ping::Ties::HIRES; |
|
19
|
|
|
|
|
50
|
|
|
19
|
|
|
|
|
541
|
|
11
|
19
|
|
|
19
|
|
8315
|
use Test::Ping::Ties::TIMEOUT; |
|
19
|
|
|
|
|
62
|
|
|
19
|
|
|
|
|
575
|
|
12
|
19
|
|
|
19
|
|
8239
|
use Test::Ping::Ties::SOURCE_VERIFY; |
|
19
|
|
|
|
|
70
|
|
|
19
|
|
|
|
|
574
|
|
13
|
19
|
|
|
19
|
|
8236
|
use Test::Ping::Ties::SERVICE_CHECK; |
|
19
|
|
|
|
|
52
|
|
|
19
|
|
|
|
|
2456
|
|
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
|
|
8993
|
use parent 'Test::Builder::Module'; |
|
19
|
|
|
|
|
5775
|
|
|
19
|
|
|
|
|
103
|
|
36
|
19
|
|
|
19
|
|
1378
|
use Net::Ping; |
|
19
|
|
|
|
|
37
|
|
|
19
|
|
|
|
|
2042
|
|
37
|
|
|
|
|
|
|
|
38
|
19
|
|
|
19
|
|
133
|
__PACKAGE__->builder->{'_net-ping_object'} = Net::Ping->new($PROTO); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
## no critic qw(Miscellanea::ProhibitTies) |
41
|
19
|
|
|
|
|
15727
|
tie $PORT, 'Test::Ping::Ties::PORT'; |
42
|
19
|
|
|
|
|
83
|
tie $BIND, 'Test::Ping::Ties::BIND'; |
43
|
19
|
|
|
|
|
84
|
tie $PROTO, 'Test::Ping::Ties::PROTO'; |
44
|
19
|
|
|
|
|
72
|
tie $HIRES, 'Test::Ping::Ties::HIRES'; |
45
|
19
|
|
|
|
|
75
|
tie $TIMEOUT, 'Test::Ping::Ties::TIMEOUT'; |
46
|
19
|
|
|
|
|
84
|
tie $SOURCE_VERIFY, 'Test::Ping::Ties::SOURCE_VERIFY'; |
47
|
19
|
|
|
|
|
79
|
tie $SERVICE_CHECK, 'Test::Ping::Ties::SERVICE_CHECK'; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub ping_ok { |
51
|
26
|
|
|
26
|
1
|
3631
|
my ( $host, $name ) = @_; |
52
|
26
|
|
|
|
|
133
|
my $tb = $CLASS->builder; |
53
|
26
|
|
|
|
|
311
|
my $pinger = $OBJPATH; |
54
|
|
|
|
|
|
|
|
55
|
26
|
|
|
|
|
109
|
my ( $ret, $duration ) = $pinger->ping( $host, $TIMEOUT ); |
56
|
26
|
|
|
|
|
618749
|
$tb->ok( $ret, $name ); |
57
|
|
|
|
|
|
|
|
58
|
26
|
|
|
|
|
11839
|
return ( $ret, $duration ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub ping_not_ok { |
62
|
3
|
|
|
3
|
1
|
23
|
my ( $host, $name ) = @_; |
63
|
3
|
|
|
|
|
33
|
my $tb = $CLASS->builder; |
64
|
3
|
|
|
|
|
52
|
my $pinger = $OBJPATH; |
65
|
|
|
|
|
|
|
|
66
|
3
|
|
|
|
|
15
|
my $alive = $pinger->ping( $host, $TIMEOUT ); |
67
|
3
|
|
|
|
|
14009269
|
$tb->ok( !$alive, $name ); |
68
|
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
2254
|
return 1; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub create_ping_object_ok { |
73
|
17
|
|
|
17
|
1
|
60004
|
my @args = @_; |
74
|
17
|
|
50
|
|
|
83
|
my $name = pop @args || q{}; |
75
|
17
|
|
|
|
|
111
|
my $tb = $CLASS->builder; |
76
|
|
|
|
|
|
|
|
77
|
17
|
|
|
|
|
222
|
my $success = eval { $OBJPATH = Net::Ping->new(@args); 1; }; |
|
17
|
|
|
|
|
111
|
|
|
17
|
|
|
|
|
3841
|
|
78
|
|
|
|
|
|
|
|
79
|
17
|
|
33
|
|
|
162
|
$tb->ok( $success && ref $OBJPATH eq 'Net::Ping', $name ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub create_ping_object_not_ok { |
83
|
1
|
|
|
1
|
1
|
776
|
my @args = @_; |
84
|
1
|
|
50
|
|
|
5
|
my $name = pop @args || q{}; |
85
|
1
|
|
|
|
|
4
|
my $tb = $CLASS->builder; |
86
|
1
|
|
|
|
|
9
|
my $error; |
87
|
1
|
50
|
|
|
|
2
|
eval { Net::Ping->new(@args); 1; } |
|
1
|
|
|
|
|
4
|
|
|
0
|
|
|
|
|
0
|
|
88
|
|
|
|
|
|
|
or $error = $@; |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
251
|
$tb->ok( $error, $name ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _has_var_ok { ## no critic qw( Subroutines::ProhibitUnusedPrivateSubroutines ) |
94
|
6
|
|
|
6
|
|
34
|
my ( $var_name, $var_value, $name ) = @_; |
95
|
6
|
|
|
|
|
23
|
my $tb = $CLASS->builder; |
96
|
6
|
|
|
|
|
93
|
$tb->is_eq( $OBJPATH->{$var_name}, $var_value, $name ); |
97
|
6
|
|
|
|
|
4239
|
return 1; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _ping_object { ## no critic qw( Subroutines::ProhibitUnusedPrivateSubroutines Subroutines::RequireArgUnpacking ) |
101
|
106
|
|
50
|
106
|
|
19801911
|
my $obj = $_[1] || $_[0] || q{}; |
102
|
|
|
|
|
|
|
|
103
|
106
|
50
|
|
|
|
296
|
if ( ref $obj eq 'Net::Ping' ) { |
104
|
0
|
|
|
|
|
0
|
$OBJPATH = $obj; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
106
|
|
|
|
|
436
|
return $OBJPATH; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
15
|
|
|
15
|
|
35869
|
END { $OBJPATH->close(); } |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |