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