line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Wait; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
790
|
use Carp qw( croak ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
99
|
|
4
|
2
|
|
|
2
|
|
360
|
use Net::EmptyPort qw( wait_port ); |
|
2
|
|
|
|
|
24564
|
|
|
2
|
|
|
|
|
695
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub import { |
9
|
10
|
|
|
10
|
|
214091
|
my $package = shift; |
10
|
|
|
|
|
|
|
|
11
|
10
|
|
|
|
|
12
|
my @tests; |
12
|
10
|
|
|
|
|
20
|
my %opts = ( timeout => 10 ); |
13
|
|
|
|
|
|
|
|
14
|
10
|
|
|
|
|
25
|
while ( local $_ = shift ) { |
15
|
18
|
100
|
|
|
|
46
|
if (/^-verbose$/) { |
16
|
4
|
50
|
|
|
|
15
|
$opts{verbose} = 1 and next; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
14
|
100
|
|
|
|
28
|
if (/^-timeout$/) { |
20
|
6
|
|
|
|
|
11
|
my $timeout = shift; |
21
|
6
|
100
|
|
|
|
80
|
croak "Missing value for -timeout when loading $package" |
22
|
|
|
|
|
|
|
unless defined $timeout; |
23
|
|
|
|
|
|
|
|
24
|
5
|
|
|
|
|
8
|
$opts{timeout} = $timeout; |
25
|
5
|
|
|
|
|
11
|
next; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
8
|
100
|
|
|
|
21
|
if (/^-/) { |
29
|
1
|
|
|
|
|
95
|
croak "Found unknown option when loading $package: $_"; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
7
|
|
|
|
|
14
|
push @tests, $_; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
8
|
100
|
|
|
|
103
|
croak "Missing list of host/port pairs when loading $package" |
36
|
|
|
|
|
|
|
unless @tests; |
37
|
|
|
|
|
|
|
|
38
|
7
|
|
|
|
|
10
|
my $limit = ''; |
39
|
7
|
100
|
|
|
|
16
|
if ( $opts{timeout} > 0 ) { |
40
|
6
|
|
|
|
|
24
|
$limit = " up to $opts{timeout} second"; |
41
|
6
|
100
|
|
|
|
13
|
$limit .= 's' if $opts{timeout} != 1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
7
|
|
|
|
|
9
|
for (@tests) { |
45
|
7
|
|
|
|
|
23
|
my ( $host, $port ) = split /:/, $_, 2; |
46
|
|
|
|
|
|
|
|
47
|
7
|
100
|
66
|
|
|
99
|
croak "Cannot parse host and port from argument to $package: '$_'" |
48
|
|
|
|
|
|
|
unless $host && $port; |
49
|
|
|
|
|
|
|
|
50
|
6
|
100
|
|
|
|
131
|
warn "Waiting$limit for $_\n" if $opts{verbose}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
wait_port { |
53
|
|
|
|
|
|
|
host => $host, |
54
|
|
|
|
|
|
|
port => $port, |
55
|
|
|
|
|
|
|
max_wait => $opts{timeout}, |
56
|
6
|
100
|
|
|
|
44
|
proto => 'tcp', |
57
|
|
|
|
|
|
|
} or croak "$package timed out while waiting for $_"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
delete @Net::Wait::{qw( wait_port croak )}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |