| 1 | package Net::Async::Ping::TCP; | ||||||||||||||||||||||||||||
| 2 | 1 | $Net::Async::Ping::TCP::VERSION = '0.002000'; | |||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings NONFATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Future; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use POSIX 'ECONNREFUSED'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Time::HiRes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | extends 'IO::Async::Notifier'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | has default_timeout => ( | |||||||||||||||||||||||||||
| 16 | is => 'ro', | ||||||||||||||||||||||||||||
| 17 | default => 5, | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | has service_check => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | has bind => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | has port_number => ( | |||||||||||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||||||||||
| 26 | default => 7, | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # Overrides method in IO::Async::Notifier to allow specific options in this class | ||||||||||||||||||||||||||||
| 30 | sub configure_unknown | ||||||||||||||||||||||||||||
| 31 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
configure_unknown: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 2 | my %params = @_; | |||||||||||||||||||||||||||
| 33 | 2 | delete $params{$_} foreach qw/default_timeout service_check bind/; | |||||||||||||||||||||||||||
| 34 | 2 | ▶ | return unless keys %params; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | my $class = ref $self; | |||||||||||||||||||||||||||
| 36 | 0 | croak "Unrecognised configuration keys for $class - " . join( " ", keys %params ); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub ping { | ||||||||||||||||||||||||||||
| 41 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
ping: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | # Maintain compat with old API | ||||||||||||||||||||||||||||
| 43 | 6 | my $legacy = ref $_[0] eq 'IO::Async::Loop::Poll'; | |||||||||||||||||||||||||||
| 44 | 6 | ▶ | my $loop = $legacy ? shift : $self->loop; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 6 | my ($host, $timeout) = @_; | |||||||||||||||||||||||||||
| 47 | 6 | ▶ | $timeout ||= $self->default_timeout; | ||||||||||||||||||||||||||
|
Condition33%1/3
$timeout ||= $self->default_timeout
MC/DC0%0/2
$timeout ||= $self->default_timeout
$timeout
$self->default_timeout
Truth table33%1/3
A ||= B
A= $timeoutB= $self->default_timeout
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 6 | my $service_check = $self->service_check; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 6 | my $t0 = [Time::HiRes::gettimeofday]; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | return Future->wait_any( | ||||||||||||||||||||||||||||
| 54 | $loop->connect( | ||||||||||||||||||||||||||||
| 55 | host => $host, | ||||||||||||||||||||||||||||
| 56 | service => $self->port_number, | ||||||||||||||||||||||||||||
| 57 | socktype => 'stream', | ||||||||||||||||||||||||||||
| 58 | ($self->bind ? ( | ||||||||||||||||||||||||||||
| 59 | local_host => $self->bind, | ||||||||||||||||||||||||||||
| 60 | ) : ()), | ||||||||||||||||||||||||||||
| 61 | ), | ||||||||||||||||||||||||||||
| 62 | $loop->timeout_future(after => $timeout) | ||||||||||||||||||||||||||||
| 63 | ) | ||||||||||||||||||||||||||||
| 64 | ->then( | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub { Future->done(Time::HiRes::tv_interval($t0)) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 66 | sub { | ||||||||||||||||||||||||||||
| 67 | 6 | ▶ | my ($human, $layer) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.5
| |||||||||||||||||||||||||||||
| 68 | 6 | my $ex = pop; | |||||||||||||||||||||||||||
| 69 | 6 | ▶ | if ($layer && $layer eq 'connect') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$layer and $layer eq "connect"
MC/DC100%2/2
$layer and $layer eq "connect"
$layer
$layer eq "connect"
Truth table100%3/3
A and B
A= $layerB= $layer eq "connect"
| |||||||||||||||||||||||||||||
| 70 | 2 | ▶ | return Future->done(Time::HiRes::tv_interval($t0)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $service_check and $ex == 111
MC/DC0%0/2
not $service_check and $ex == 111
not $service_check
$ex == 111
Truth table33%1/3
not(A) and B
A= not $service_checkB= $ex == 111
| |||||||||||||||||||||||||||||
| 71 | if !$service_check && $ex == ECONNREFUSED; | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 4 | Future->fail(Time::HiRes::tv_interval($t0)) | |||||||||||||||||||||||||||
| 74 | }, | ||||||||||||||||||||||||||||
| 75 | ) | ||||||||||||||||||||||||||||
| 76 | 6 | ▶ | } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | 1; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||||||||||