blib/lib/Linux/Event/Connect.pm

filter: Statementstmt 84.1% 212 / 252 Branchbran 66.8% 111 / 166 Conditioncond 39.1% 27 / 69 MC/DCmcdc 8.8% 4 / 45 Subroutinesub 86.9% 20 / 23 Podpod 100% 7 / 7 totaltotal 67.7% 381 / 562 CC 108 SCAR 45.6
CC
108
Cov
72%
new
168.4
__ANON__
19.0
_attempt_next
16.9
CRAP 95.9
↑ Summary
1 package Linux::Event::Connect;
2 11 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 our $VERSION = '0.001';
7  
8 11 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 use Socket qw(
11 AF_INET AF_INET6 AF_UNIX
12 SOCK_STREAM
13 SOL_SOCKET SO_ERROR
14 inet_pton
15 pack_sockaddr_in
16 pack_sockaddr_in6
17 pack_sockaddr_un
18 getaddrinfo
19 11 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 11 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 use constant {
23 11 S_NEW => 0,
24 S_CONNECTING => 1,
25 S_DONE => 2,
26 11 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 ▶sub new ($class, %args) {
Subroutine new: called CC=71 SCAR=51.3
Pod documented
29 517 my $loop = delete $args{loop};
30 517 ▶ croak "loop is required" unless defined $loop && ref $loop;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $loop and ref $loop 0 517 517
Condition33%1/3
defined $loop and ref $loop
!ll&&!rl&&r
00517
MC/DC0%0/2
defined $loop and ref $loop
defined $loop ref $loop
Truth table33%1/3
A and B
A= defined $loopB= ref $loop
ABresult
0X0
100
111
31  
32 517 ▶ my $timeout_s = exists $args{timeout_s} ? delete $args{timeout_s} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'timeout_s'} ? : 507 10 517
33 517 my $data = delete $args{data};
34  
35 517 ▶ my $on_connect = exists $args{on_connect} ? delete $args{on_connect} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'on_connect'} ? : 508 9 517
36 517 ▶ my $on_error = exists $args{on_error} ? delete $args{on_error} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'on_error'} ? : 508 9 517
37  
38 517 ▶ my $nonblocking = exists $args{nonblocking} ? delete $args{nonblocking} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'nonblocking'} ? : 1 516 517
39 517 ▶ croak "nonblocking must be true" unless $nonblocking;
Branch: 1 branch
BranchTrueFalseTotal
unless $nonblocking 1 516 517
40  
41 516 ▶ croak "on_connect must be a coderef" if defined $on_connect && ref($on_connect) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_connect and ref $on_connect ne "CODE" 0 516 516
Condition66%2/3
defined $on_connect and ref $on_connect ne "CODE"
!ll&&!rl&&r
85080
MC/DC0%0/2
defined $on_connect and ref $on_connect ne "CODE"
defined $on_connect ref $on_connect ne "CODE"
Truth table66%2/3
A and B
A= defined $on_connectB= ref $on_connect ne "CODE"
ABresult
0X0
100
111
42 516 ▶ croak "on_error must be a coderef" if defined $on_error && ref($on_error) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_error and ref $on_error ne "CODE" 0 516 516
Condition66%2/3
defined $on_error and ref $on_error ne "CODE"
!ll&&!rl&&r
85080
MC/DC0%0/2
defined $on_error and ref $on_error ne "CODE"
defined $on_error ref $on_error ne "CODE"
Truth table66%2/3
A and B
A= defined $on_errorB= ref $on_error ne "CODE"
ABresult
0X0
100
111
43  
44 516 ▶ if (defined $timeout_s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $timeout_s) 507 9 516
45 507 ▶ croak "timeout_s must be a number >= 0"
Branch: 1 branch
BranchTrueFalseTotal
if not $timeout_s =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/u or $timeout_s < 0 0 507 507
Condition33%1/3
not $timeout_s =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/u or $timeout_s < 0
l!l&&r!l&&!r
00507
MC/DC0%0/2
not $timeout_s =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/u or $timeout_s < 0
not $timeout_s =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/u $timeout_s < 0
Truth table33%1/3
not(A) or B
A= not $timeout_s =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/uB= $timeout_s < 0
ABresult
1X1
011
000
46 if $timeout_s !~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/ || $timeout_s < 0;
47 507 $timeout_s = 0 + $timeout_s;
48 }
49  
50 # Address mode selection (exactly one):
51 516 ▶ my $have_hostport = (exists $args{host} || exists $args{port}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'host'} || exists $args{'port'} ? : 512 4 516
Condition100%3/3
exists $args{"host"} or exists $args{"port"}
l!l&&r!l&&!r
51114
MC/DC100%2/2
exists $args{"host"} or exists $args{"port"}
exists $args{"host"} exists $args{"port"}
Truth table100%3/3
A or B
A= exists $args{"host"}B= exists $args{"port"}
ABresult
1X1
011
000
52 516 ▶ my $have_unix = exists $args{unix} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'unix'} ? : 2 514 516
53 516 ▶ my $have_sockaddr = exists $args{sockaddr} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'sockaddr'} ? : 3 513 516
54  
55 516 ▶ my $modes = ($have_hostport ? 1 : 0) + ($have_unix ? 1 : 0) + ($have_sockaddr ? 1 : 0);
Branch: 3 branches
BranchTrueFalseTotal
$have_hostport ? : 512 4 516
$have_unix ? : 2 514 516
$have_sockaddr ? : 3 513 516
56 516 ▶ croak "exactly one address mode is required (host/port, unix, or sockaddr)" if $modes != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $modes != 1 1 515 516
57  
58 515 my ($host, $port, $unix, $sockaddr, $family);
59  
60 515 ▶ if ($have_hostport) {
Branch: 2 branches
BranchTrueFalseTotal
if ($have_hostport) { } 511 4 515
elsif ($have_unix) { } 1 3 4
61 511 $host = delete $args{host};
62 511 $port = delete $args{port};
63  
64 511 ▶ croak "host is required" unless defined $host;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 1 510 511
65 510 ▶ croak "host must be a non-empty string" if ref($host) || $host eq '';
Branch: 1 branch
BranchTrueFalseTotal
if ref $host or $host eq "" 0 510 510
Condition33%1/3
ref $host or $host eq ""
l!l&&r!l&&!r
00510
MC/DC0%0/2
ref $host or $host eq ""
ref $host $host eq ""
Truth table33%1/3
A or B
A= ref $hostB= $host eq ""
ABresult
1X1
011
000
66  
67 510 ▶ croak "port is required" unless defined $port;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $port 1 509 510
68 509 ▶ croak "port must be an integer" if ref($port) || $port !~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if ref $port or not $port =~ /\A\d+\z/u 1 508 509
Condition66%2/3
ref $port or not $port =~ /\A\d+\z/u
l!l&&r!l&&!r
01508
MC/DC50%1/2
ref $port or not $port =~ /\A\d+\z/u
ref $port not $port =~ /\A\d+\z/u
Truth table66%2/3
A or not(B)
A= ref $portB= not $port =~ /\A\d+\z/u
ABresult
1X1
011
000
69 508 $port = 0 + $port;
70 508 ▶ croak "port out of range" if $port < 0 || $port > 65535;
Branch: 1 branch
BranchTrueFalseTotal
if $port < 0 or $port > 65535 0 508 508
Condition33%1/3
$port < 0 or $port > 65535
l!l&&r!l&&!r
00508
MC/DC0%0/2
$port < 0 or $port > 65535
$port < 0 $port > 65535
Truth table33%1/3
A or B
A= $port < 0B= $port > 65535
ABresult
1X1
011
000
71  
72 508 ▶ croak "family is not allowed in host/port mode" if exists $args{family};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"family"} 1 507 508
73 507 ▶ croak "sockaddr is not allowed in host/port mode" if exists $args{sockaddr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"sockaddr"} 0 507 507
74 507 ▶ croak "unix is not allowed in host/port mode" if exists $args{unix};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"unix"} 0 507 507
75 507 ▶ croak "type is not allowed in host/port mode" if exists $args{type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"type"} 0 507 507
76 507 ▶ croak "proto is not allowed in host/port mode" if exists $args{proto};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"proto"} 0 507 507
77 }
78 elsif ($have_unix) {
79 1 $unix = delete $args{unix};
80 1 ▶ croak "unix must be a non-empty string" if !defined($unix) || ref($unix) || $unix eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $unix or ref $unix or $unix eq "" 0 1 1
Condition33%2/6
not defined $unix or ref $unix or $unix eq ""
l!l&&r!l&&!r
001
not defined $unix or ref $unix
l!l&&r!l&&!r
001
MC/DC0%0/3
not defined $unix or ref $unix or $unix eq ""
not defined $unix ref $unix $unix eq ""
Truth table25%1/4
not(A) or B or C
A= not defined $unixB= ref $unixC= $unix eq ""
ABCresult
1XX1
01X1
0011
0000
81  
82 1 ▶ croak "host is not allowed in unix mode" if exists $args{host};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"host"} 0 1 1
83 1 ▶ croak "port is not allowed in unix mode" if exists $args{port};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"port"} 0 1 1
84 1 ▶ croak "sockaddr is not allowed in unix mode" if exists $args{sockaddr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"sockaddr"} 0 1 1
85 1 ▶ croak "family is not allowed in unix mode" if exists $args{family};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"family"} 0 1 1
86 1 ▶ croak "type is not allowed in unix mode" if exists $args{type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"type"} 0 1 1
87 1 ▶ croak "proto is not allowed in unix mode" if exists $args{proto};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"proto"} 0 1 1
88 }
89 else { # sockaddr mode
90 3 $sockaddr = delete $args{sockaddr};
91 3 ▶ croak "sockaddr must be a defined scalar" if !defined($sockaddr) || ref($sockaddr);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $sockaddr or ref $sockaddr 0 3 3
Condition33%1/3
not defined $sockaddr or ref $sockaddr
l!l&&r!l&&!r
003
MC/DC0%0/2
not defined $sockaddr or ref $sockaddr
not defined $sockaddr ref $sockaddr
Truth table33%1/3
not(A) or B
A= not defined $sockaddrB= ref $sockaddr
ABresult
1X1
011
000
92  
93 3 $family = delete $args{family};
94 3 ▶ croak "family is required in sockaddr mode" unless defined $family;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $family 1 2 3
95 2 ▶ croak "family must be a numeric AF_* constant" if ref($family) || $family !~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if ref $family or not $family =~ /\A\d+\z/u 0 2 2
Condition33%1/3
ref $family or not $family =~ /\A\d+\z/u
l!l&&r!l&&!r
002
MC/DC0%0/2
ref $family or not $family =~ /\A\d+\z/u
ref $family not $family =~ /\A\d+\z/u
Truth table33%1/3
A or not(B)
A= ref $familyB= not $family =~ /\A\d+\z/u
ABresult
1X1
011
000
96 2 $family = 0 + $family;
97  
98 2 ▶ croak "host is not allowed in sockaddr mode" if exists $args{host};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"host"} 0 2 2
99 2 ▶ croak "port is not allowed in sockaddr mode" if exists $args{port};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"port"} 0 2 2
100 2 ▶ croak "unix is not allowed in sockaddr mode" if exists $args{unix};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"unix"} 0 2 2
101  
102 2 ▶ croak "type is not allowed in sockaddr mode (v0.001)" if exists $args{type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"type"} 1 1 2
103 1 ▶ croak "proto is not allowed in sockaddr mode (v0.001)" if exists $args{proto};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"proto"} 0 1 1
104 }
105  
106 509 ▶ if (%args) {
Branch: 1 branch
BranchTrueFalseTotal
if (%args) 1 508 509
107 1 my @k = sort keys %args;
108 1 croak "unknown option(s): " . join(", ", @k);
109 }
110  
111 508 my $self = bless {
112 _loop => $loop,
113 _data => $data,
114 _timeout_s => $timeout_s,
115 _cb_ok => $on_connect,
116 _cb_err => $on_error,
117  
118 _state => S_NEW,
119 _done => 0,
120 _cancelled => 0,
121 _errno => undef,
122 _gai_error => undef,
123  
124 _cand => [],
125 _idx => 0,
126  
127 _fh => undef,
128 _watch => undef,
129 _timer_id => undef,
130 }, $class;
131  
132 # Normalize to candidate list
133 508 ▶ if (defined $unix) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $unix) { } 1 507 508
elsif (defined $sockaddr) { } 1 506 507
134 1 push @{ $self->{_cand} }, [ AF_UNIX, pack_sockaddr_un($unix) ];
135 }
136 elsif (defined $sockaddr) {
137 1 push @{ $self->{_cand} }, [ $family, $sockaddr ];
138 }
139 else {
140 # host/port mode: IP literal fast-path, else synchronous getaddrinfo
141 506 my $h = $host;
142 506 $h =~ s/\A[ \t\r\n]+//;
143 506 $h =~ s/[ \t\r\n]+\z//;
144 506 ▶ if (index($h, '[') == 0 && substr($h, -1) eq ']') { $h = substr($h, 1, -1) }
Branch: 1 branch
BranchTrueFalseTotal
if (index($h, "[") == 0 and substr($h, -1) eq "]") 1 505 506
Condition66%2/3
index($h, "[") == 0 and substr($h, -1) eq "]"
!ll&&!rl&&r
50501
MC/DC50%1/2
index($h, "[") == 0 and substr($h, -1) eq "]"
index($h, "[") == 0 substr($h, -1) eq "]"
Truth table66%2/3
A and B
A= index($h, "[") == 0B= substr($h, -1) eq "]"
ABresult
0X0
100
111
145  
146 506 my $p4 = inet_pton(AF_INET, $h);
147 506 ▶ if (defined $p4) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p4) { } 505 1 506
148 505 push @{ $self->{_cand} }, [ AF_INET, pack_sockaddr_in($port, $p4) ];
149 }
150 else {
151 1 my $p6 = inet_pton(AF_INET6, $h);
152 1 ▶ if (defined $p6) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p6) { } 0 1 1
153 0 push @{ $self->{_cand} }, [ AF_INET6, pack_sockaddr_in6($port, $p6) ];
154 }
155 else {
156 1 my ($err, @res) = getaddrinfo($host, $port, { socktype => SOCK_STREAM });
157 1 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 1 0 1
158 1 $self->{_gai_error} = "$err";
159 1 ▶ my $mapped = ($err =~ /NONAME|NODATA|NO_DATA/i) ? Errno::ENOENT() : Errno::EIO();
Branch: 1 branch
BranchTrueFalseTotal
$err =~ /NONAME|NODATA|NO_DATA/iu ? : 0 1 1
160 1 $self->_finalize_err($mapped);
161 1 return $self;
162 }
163  
164 0 for my $r (@res) {
165 0 my $fam = $r->{family};
166 0 my $sa = $r->{addr};
167 0 ▶ next unless defined $fam && defined $sa;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fam and defined $sa 0 0 0
Condition0%0/3
defined $fam and defined $sa
!ll&&!rl&&r
000
MC/DC0%0/2
defined $fam and defined $sa
defined $fam defined $sa
Truth table0%0/3
A and B
A= defined $famB= defined $sa
ABresult
0X0
100
111
168 0 push @{ $self->{_cand} }, [ $fam, $sa ];
169 }
170  
171 0 ▶ if (!@{ $self->{_cand} }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"_cand"};}) 0 0 0
172 0 $self->_finalize_err(Errno::ENOENT());
173 0 return $self;
174 }
175 }
176 }
177 }
178  
179 507 $self->{_state} = S_CONNECTING;
180 507 ▶ $self->_arm_timeout if defined $timeout_s;
Branch: 1 branch
BranchTrueFalseTotal
if defined $timeout_s 507 0 507
181 507 $self->_attempt_next;
182 507 return $self;
183 }
184  
185 ▶sub cancel ($self) {
Subroutine cancel: called CC=2 SCAR=7.0
Pod documented
186 1 ▶ return if $self->{_done};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_done"} 0 1 1
187 1 $self->{_cancelled} = 1;
188 1 $self->{_done} = 1;
189 1 $self->{_state} = S_DONE;
190 1 $self->_teardown;
191 1 $self->{_cb_ok} = undef;
192 1 $self->{_cb_err} = undef;
193 1 return;
194 }
195  
196 0 ▶sub is_pending ($self) { return !$self->{_done} }
Subroutine is_pending: not called CC=1 SCAR=6.9
Pod documented
197 3 ▶sub is_done ($self) { return $self->{_done} }
Subroutine is_done: called CC=1 SCAR=0.0
Pod documented
198 1 ▶sub fh ($self) { return $self->{_fh} }
Subroutine fh: called CC=1 SCAR=0.0
Pod documented
199 0 ▶sub errno ($self) { return $self->{_errno} }
Subroutine errno: not called CC=1 SCAR=6.9
Pod documented
200 1 ▶sub gai_error ($self) { return $self->{_gai_error} }
Subroutine gai_error: called CC=1 SCAR=0.0
Pod documented
201  
202 ▶sub _arm_timeout ($self) {
Subroutine _arm_timeout: called CC=1 SCAR=2.9
203 ▶ my $id = $self->{_loop}->after($self->{_timeout_s}, sub ($loop) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
204 0 ▶ return if $self->{_done} || $self->{_cancelled};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_done"} or $self->{"_cancelled"} 0 0 0
Condition0%0/3
$self->{"_done"} or $self->{"_cancelled"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_done"} or $self->{"_cancelled"}
$self->{"_done"} $self->{"_cancelled"}
Truth table0%0/3
A or B
A= $self->{"_done"}B= $self->{"_cancelled"}
ABresult
1X1
011
000
205 0 $self->_finalize_err(Errno::ETIMEDOUT());
206 507 });
207 507 $self->{_timer_id} = $id;
208 507 return;
209 }
210  
211 ▶sub _attempt_next ($self) {
Subroutine _attempt_next: called CC=10 SCAR=28.3
212 1008 ▶ return if $self->{_done} || $self->{_cancelled};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_done"} or $self->{"_cancelled"} 0 1008 1008
Condition33%1/3
$self->{"_done"} or $self->{"_cancelled"}
l!l&&r!l&&!r
001008
MC/DC0%0/2
$self->{"_done"} or $self->{"_cancelled"}
$self->{"_done"} $self->{"_cancelled"}
Truth table33%1/3
A or B
A= $self->{"_done"}B= $self->{"_cancelled"}
ABresult
1X1
011
000
213  
214 1008 my $cand = $self->{_cand};
215 1008 my $n = @$cand;
216  
217 1008 ▶ while ($self->{_idx} < $n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_idx"} < $n) 507 501 1008
218 507 my ($family, $sockaddr) = @{ $cand->[ $self->{_idx}++ ] };
219  
220 507 my $fh;
221 507 ▶ if (!socket($fh, $family, SOCK_STREAM, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (socket $fh, $family, 1, 0) 0 507 507
222 0 $self->{_errno} = 0 + $!;
223 0 next;
224 }
225  
226 507 my $flags = fcntl($fh, F_GETFL, 0);
227 507 ▶ if (!defined $flags) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $flags) 0 507 507
228 0 $self->{_errno} = 0 + $!;
229 0 close $fh;
230 0 next;
231 }
232 507 ▶ if (!fcntl($fh, F_SETFL, $flags | O_NONBLOCK)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (fcntl $fh, 4, $flags | 2048) 0 507 507
233 0 $self->{_errno} = 0 + $!;
234 0 close $fh;
235 0 next;
236 }
237  
238 507 $self->{_fh} = $fh;
239  
240 507 ▶ if (connect($fh, $sockaddr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (connect $fh, $sockaddr) 1 506 507
241 1 $self->_finalize_ok($fh);
242 1 return;
243 }
244  
245 506 my $e = 0 + $!;
246 506 $self->{_errno} = $e;
247  
248 506 ▶ if ($e == Errno::EINPROGRESS()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e == 115) 506 0 506
249 ▶ my $w = $self->{_loop}->watch($fh,
Subroutine __ANON__: called CC=7 SCAR=29.4
250 write => sub ($loop, $fh2, $watcher) {
251 4 ▶ return if $self->{_done} || $self->{_cancelled};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_done"} or $self->{"_cancelled"} 0 4 4
Condition33%1/3
$self->{"_done"} or $self->{"_cancelled"}
l!l&&r!l&&!r
004
MC/DC0%0/2
$self->{"_done"} or $self->{"_cancelled"}
$self->{"_done"} $self->{"_cancelled"}
Truth table33%1/3
A or B
A= $self->{"_done"}B= $self->{"_cancelled"}
ABresult
1X1
011
000
252  
253 4 my $raw = getsockopt($fh2, SOL_SOCKET, SO_ERROR);
254 4 my $soerr = 0;
255 4 ▶ $soerr = unpack("i", $raw) if defined($raw) && length($raw) >= 4;
Branch: 1 branch
BranchTrueFalseTotal
if defined $raw and length $raw >= 4 4 0 4
Condition33%1/3
defined $raw and length $raw >= 4
!ll&&!rl&&r
004
MC/DC0%0/2
defined $raw and length $raw >= 4
defined $raw length $raw >= 4
Truth table33%1/3
A and B
A= defined $rawB= length $raw >= 4
ABresult
0X0
100
111
256  
257 4 ▶ if ($soerr == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($soerr == 0) 4 0 4
258 4 $self->_finalize_ok($fh2);
259 4 return;
260 }
261  
262 0 $self->{_errno} = $soerr;
263 0 eval { close $fh2; 1 };
264 0 $self->{_fh} = undef;
265  
266 # Drop watcher before attempting next
267 0 ▶ if (my $ww = delete $self->{_watch}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ww = delete $self->{"_watch"}) 0 0 0
268 0 eval { $ww->close; 1 };
269 }
270  
271 0 $self->_attempt_next;
272 0 return;
273 },
274 ▶ error => sub ($loop, $fh2, $watcher) {
Subroutine __ANON__: called CC=7 SCAR=21.6
275 501 ▶ return if $self->{_done} || $self->{_cancelled};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_done"} or $self->{"_cancelled"} 0 501 501
Condition33%1/3
$self->{"_done"} or $self->{"_cancelled"}
l!l&&r!l&&!r
00501
MC/DC0%0/2
$self->{"_done"} or $self->{"_cancelled"}
$self->{"_done"} $self->{"_cancelled"}
Truth table33%1/3
A or B
A= $self->{"_done"}B= $self->{"_cancelled"}
ABresult
1X1
011
000
276  
277 501 my $raw = getsockopt($fh2, SOL_SOCKET, SO_ERROR);
278 501 my $soerr = 0;
279 501 ▶ $soerr = unpack("i", $raw) if defined($raw) && length($raw) >= 4;
Branch: 1 branch
BranchTrueFalseTotal
if defined $raw and length $raw >= 4 501 0 501
Condition33%1/3
defined $raw and length $raw >= 4
!ll&&!rl&&r
00501
MC/DC0%0/2
defined $raw and length $raw >= 4
defined $raw length $raw >= 4
Truth table33%1/3
A and B
A= defined $rawB= length $raw >= 4
ABresult
0X0
100
111
280 501 ▶ $soerr ||= (0 + $!);
Condition33%1/3
$soerr ||= 0 + $!
l!l&&r!l&&!r
50100
MC/DC0%0/2
$soerr ||= 0 + $!
$soerr 0 + $!
Truth table33%1/3
A ||= B
A= $soerrB= 0 + $!
ABresult
1X1
011
000
281  
282 501 $self->{_errno} = $soerr;
283 501 eval { close $fh2; 1 };
284 501 $self->{_fh} = undef;
285  
286 501 ▶ if (my $ww = delete $self->{_watch}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ww = delete $self->{"_watch"}) 501 0 501
287 501 eval { $ww->close; 1 };
288 }
289  
290 501 $self->_attempt_next;
291 501 return;
292 },
293 506 );
294  
295 506 $self->{_watch} = $w;
296 506 return;
297 }
298  
299 # Immediate failure, try next
300 0 close $fh;
301 0 $self->{_fh} = undef;
302 }
303  
304 # exhausted candidates: report last errno if set, else EIO
305 501 my $last = $self->{_errno};
306 501 ▶ $last = Errno::EIO() if !defined $last;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $last 0 501 501
307 501 $self->_finalize_err($last);
308 501 return;
309 }
310  
311 ▶sub _teardown ($self) {
Subroutine _teardown: called CC=6 SCAR=18.0
312 503 ▶ if (my $w = delete $self->{_watch}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $w = delete $self->{"_watch"}) 1 502 503
313 1 ▶ eval { $w->close; 1 } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $w->close; 1 } } or do { if (my $fh = $self->{"_fh"}) { eval { do { $self->{"_loop"}->unwatch($fh); '???' } }; } } 1 0 1
314 # fallback if Watcher has no close
315 1 ▶ if (my $fh = $self->{_fh}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fh = $self->{"_fh"}) 1 0 1
316 1 eval { $self->{_loop}->unwatch($fh); 1 };
317 }
318 };
319 }
320  
321 503 ▶ if (defined(my $id = delete $self->{_timer_id})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $id = delete $self->{"_timer_id"})) 502 1 503
322 502 eval { $self->{_loop}->cancel($id); 1 };
323 }
324  
325 503 ▶ if (my $fh = delete $self->{_fh}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fh = delete $self->{"_fh"}) 1 502 503
326 1 eval { close $fh; 1 };
327 }
328  
329 503 return;
330 }
331  
332 ▶sub _finalize_ok ($self, $fh) {
Subroutine _finalize_ok: called CC=6 SCAR=18.4
333 5 ▶ return if $self->{_done} || $self->{_cancelled};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_done"} or $self->{"_cancelled"} 0 5 5
Condition33%1/3
$self->{"_done"} or $self->{"_cancelled"}
l!l&&r!l&&!r
005
MC/DC0%0/2
$self->{"_done"} or $self->{"_cancelled"}
$self->{"_done"} $self->{"_cancelled"}
Truth table33%1/3
A or B
A= $self->{"_done"}B= $self->{"_cancelled"}
ABresult
1X1
011
000
334  
335 5 $self->{_done} = 1;
336 5 $self->{_state} = S_DONE;
337  
338 # Make inert before callbacks
339 5 my $cb = $self->{_cb_ok};
340 5 my $data = $self->{_data};
341 5 $self->{_cb_ok} = undef;
342 5 $self->{_cb_err} = undef;
343  
344 # Teardown watcher/timer, but do NOT close $fh on success
345 5 ▶ if (my $w = delete $self->{_watch}) { eval { $w->close; 1 } }
Branch: 1 branch
BranchTrueFalseTotal
if (my $w = delete $self->{"_watch"}) 4 1 5
346 5 ▶ if (defined(my $id = delete $self->{_timer_id})) { eval { $self->{_loop}->cancel($id); 1 } }
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $id = delete $self->{"_timer_id"})) 5 0 5
347 5 $self->{_fh} = undef;
348  
349 5 ▶ $cb->($self, $fh, $data) if $cb;
Branch: 1 branch
BranchTrueFalseTotal
if $cb 5 0 5
350 5 return;
351 }
352  
353 ▶sub _finalize_err ($self, $errno) {
Subroutine _finalize_err: called CC=4 SCAR=14.3
354 502 ▶ return if $self->{_done} || $self->{_cancelled};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_done"} or $self->{"_cancelled"} 0 502 502
Condition33%1/3
$self->{"_done"} or $self->{"_cancelled"}
l!l&&r!l&&!r
00502
MC/DC0%0/2
$self->{"_done"} or $self->{"_cancelled"}
$self->{"_done"} $self->{"_cancelled"}
Truth table33%1/3
A or B
A= $self->{"_done"}B= $self->{"_cancelled"}
ABresult
1X1
011
000
355  
356 502 $self->{_errno} = $errno;
357  
358 502 $self->{_done} = 1;
359 502 $self->{_state} = S_DONE;
360  
361 502 my $cb = $self->{_cb_err};
362 502 my $data = $self->{_data};
363 502 $self->{_cb_ok} = undef;
364 502 $self->{_cb_err} = undef;
365  
366 502 $self->_teardown;
367  
368 502 ▶ $cb->($self, $errno, $data) if $cb;
Branch: 1 branch
BranchTrueFalseTotal
if $cb 502 0 502
369 502 return;
370 }
371  
372 11 1;
373  
374 __END__
↑ Summary