blib/lib/Net/Wait.pm

filter: Statementstmt 100% 33 / 33 Branchbran 95.8% 23 / 24 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 95.3% 62 / 65 CC 15 SCAR 25.9
CC
15
Cov
97%
import
15.0
BEGIN
1.0
BEGIN
1.0
CRAP 13.4
↑ Summary
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
BranchTrueFalseTotal
if (local $_ = shift()) 18 8 26
15 18 ▶ if (/^-verbose$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^-verbose$/) 4 14 18
16 4 ▶ $opts{verbose} = 1 and next;
Branch: 1 branch
BranchTrueFalseTotal
$opts{"verbose"} = 1 and next 4 0 4
17 }
18  
19 14 ▶ if (/^-timeout$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^-timeout$/) 6 8 14
20 6 my $timeout = shift;
21 6 ▶ croak "Missing value for -timeout when loading $package"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timeout 1 5 6
22 unless defined $timeout;
23  
24 5 $opts{timeout} = $timeout;
25 5 next;
26 }
27  
28 8 ▶ if (/^-/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^-/) 1 7 8
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
BranchTrueFalseTotal
unless @tests 1 7 8
36 unless @tests;
37  
38 7 my $limit = '';
39 7 ▶ if ( $opts{timeout} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"timeout"} > 0) 6 1 7
40 6 $limit = " up to $opts{timeout} second";
41 6 ▶ $limit .= 's' if $opts{timeout} != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"timeout"} != 1 5 1 6
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
BranchTrueFalseTotal
unless $host and $port 1 6 7
Condition66%2/3
$host and $port
!ll&&!rl&&r
016
MC/DC50%1/2
$host and $port
$host $port
Truth table66%2/3
A and B
A= $hostB= $port
ABresult
0X0
100
111
48 unless $host && $port;
49  
50 6 ▶ warn "Waiting$limit for $_\n" if $opts{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"verbose"} 4 2 6
51  
52 wait_port {
53 host => $host,
54 port => $port,
55 max_wait => $opts{timeout},
56 6 ▶ proto => 'tcp',
Branch: 1 branch
BranchTrueFalseTotal
wait_port({"host", $host, "port", $port, "max_wait", $opts{"timeout"}, "proto", "tcp"}) or croak("$package timed out while waiting for $_") 5 1 6
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__
↑ Summary