Manager/Client/ConnectionUnix.pm

filter: Statementstmt 86.9% 345 / 397 Branchbran 63.8% 120 / 188 Conditioncond 40.6% 26 / 64 MC/DCmcdc 5.7% 2 / 35 Subroutinesub 94.5% 52 / 55 Podpod 54.1% 13 / 24 totaltotal 73.1% 558 / 763 CC 135 SCAR 22.1
CC
135
Cov
76%
_resolve_pending
34.0
pending_sends_to
20.0
drain_pending
13.2
CRAP 9.1
« Manager/Role/Outbox.pm ↑ Summary Manager/Test.pm »
1 package IPC::Manager::Client::ConnectionUnix;
2 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 87 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 87 our $VERSION = '0.000035';
6  
7 87 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 87 ▶use Errno qw/EAGAIN EWOULDBLOCK EINTR/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 87 ▶use Fcntl qw/O_WRONLY O_CREAT O_EXCL/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 87 ▶use Time::HiRes qw/time/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 87 ▶use IO::Socket::UNIX 1.55 qw/SOCK_STREAM SOMAXCONN/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 87 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 87 ▶use IPC::Manager::Util qw/USE_IO_SELECT/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 87 ▶use parent 'IPC::Manager::Base::FS';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 87 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 87 with 'IPC::Manager::Role::Client::Connection';
19 87 with 'IPC::Manager::Role::Outbox';
20  
21 87 use Object::HashBase qw{
22 listen
23 +listen_socket
24 +connections
25 +backlog
26 87 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 # sun_path budget — same constraint as Client::UnixSocket.
29 87 ▶use constant _SUN_PATH_LIMIT => 104;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1 ▶sub _viable { require IO::Socket::UNIX; IO::Socket::UNIX->VERSION('1.55'); 1 }
Subroutine _viable: called CC=1 SCAR=0.0
32  
33 47 ▶sub suspend_supported { 0 }
Subroutine suspend_supported: called CC=1 SCAR=0.0
Pod undocumented
34 0 ▶sub suspend { croak "suspend is not supported by the ConnectionUnix driver" }
Subroutine suspend: not called CC=1 SCAR=6.9
Pod documented
35  
36 671 ▶sub check_path { -S $_[1] || -f $_[1] }
Subroutine check_path: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
-S $_[1] or -f $_[1] 77 594 671
37 141 ▶sub path_type { 'UNIX Socket or marker file' }
Subroutine path_type: called CC=1 SCAR=0.0
Pod documented
38  
39 sub max_on_disk_name_length {
40 1588 ▶ my $self = shift;
Subroutine max_on_disk_name_length: called CC=1 SCAR=0.0
Pod documented
41 1588 return _SUN_PATH_LIMIT - length($self->{+ROUTE}) - 2; # '/' + NUL
42 }
43  
44 119 ▶sub have_handles_for_select { 1 }
Subroutine have_handles_for_select: called CC=1 SCAR=0.0
Pod documented
45 118 ▶sub have_dynamic_handles_for_select { 1 }
Subroutine have_dynamic_handles_for_select: called CC=1 SCAR=0.0
Pod undocumented
46  
47 sub handles_for_select {
48 377 ▶ my $self = shift;
Subroutine handles_for_select: called CC=5 SCAR=16.3
Pod documented
49 377 my @h;
50 377 ▶ push @h => $self->{+LISTEN_SOCKET} if $self->{+LISTEN_SOCKET};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"listen_socket"} 369 8 377
51 377 ▶ for my $entry (values %{$self->{+CONNECTIONS} // {}}) {
Condition50%1/2
$self->{"connections"} // {}
l!l
3770
MC/DC0%0/1
$self->{"connections"} // {}
$self->{"connections"}
Truth table50%1/2
A
A= $self->{"connections"}
Aresult
11
00
52 221 ▶ push @h => $entry->{fh} if $entry->{fh};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"fh"} 221 0 221
53 }
54 377 return @h;
55 }
56  
57 sub init {
58 140 ▶ my $self = shift;
Subroutine init: called CC=4 SCAR=14.1
Pod undocumented
59  
60 140 ▶ $self->{+LISTEN} //= 1;
Condition100%2/2
$self->{"listen"} //= 1
l!l
4136
MC/DC100%1/1
$self->{"listen"} //= 1
$self->{"listen"}
Truth table100%2/2
A
A= $self->{"listen"}
Aresult
11
00
61 140 ▶ $self->{+CONNECTIONS} //= {};
Condition50%1/2
$self->{"connections"} //= {}
l!l
0140
MC/DC0%0/1
$self->{"connections"} //= {}
$self->{"connections"}
Truth table50%1/2
A
A= $self->{"connections"}
Aresult
11
00
62 140 ▶ $self->{+BACKLOG} //= SOMAXCONN;
Condition50%1/2
$self->{"backlog"} //= 4096
l!l
0140
MC/DC0%0/1
$self->{"backlog"} //= 4096
$self->{"backlog"}
Truth table50%1/2
A
A= $self->{"backlog"}
Aresult
11
00
63  
64 140 $self->SUPER::init();
65 }
66  
67 sub make_path {
68 140 ▶ my $self = shift;
Subroutine make_path: called CC=4 SCAR=14.0
Pod documented
69 140 my $path = $self->path;
70  
71 140 ▶ if ($self->{+LISTEN}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'listen'}) { } 136 4 140
72 my $s = IO::Socket::UNIX->new(
73 Type => SOCK_STREAM,
74 Local => $path,
75 136 ▶ Listen => $self->{+BACKLOG},
Branch: 1 branch
BranchTrueFalseTotal
my $s = "IO::Socket::UNIX"->new("Type", 1, "Local", $path, "Listen", $self->{"backlog"}, "Blocking", 0) or die "Cannot create listen socket '${path}': $!" 0 136 136
76 Blocking => 0,
77 ) or die "Cannot create listen socket '$path': $!";
78 136 $self->{+LISTEN_SOCKET} = $s;
79 }
80 else {
81 # Drop a regular empty file as a presence marker. Use sysopen with
82 # O_EXCL so we never silently clobber an existing socket file.
83 4 ▶ sysopen(my $fh, $path, O_WRONLY | O_CREAT | O_EXCL, 0600)
Branch: 1 branch
BranchTrueFalseTotal
sysopen my $fh, $path, 193, 384 or die "Cannot create marker file '${path}': $!" 0 4 4
84 or die "Cannot create marker file '$path': $!";
85 4 close($fh);
86 }
87 }
88  
89 sub pre_disconnect_hook {
90 113 ▶ my $self = shift;
Subroutine pre_disconnect_hook: called CC=4 SCAR=14.9
Pod documented
91 # Unlink the on-disk entry so no new peer can connect to us, but keep
92 # the listen socket fd and existing connection fds open: the base
93 # disconnect loop runs after this and still needs them to drain any
94 # pending inbound messages.
95 113 ▶ return unless defined $self->{+PATH};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"path"} 0 113 113
96 113 ▶ return unless -e $self->{+PATH};
Branch: 1 branch
BranchTrueFalseTotal
unless -e $self->{"path"} 0 113 113
97 113 ▶ unlink($self->{+PATH}) or warn "Could not unlink '$self->{+PATH}': $!";
Branch: 1 branch
BranchTrueFalseTotal
unlink $self->{"path"} or warn qq[Could not unlink '$self->{"path"}': $!] 0 113 113
98 }
99  
100 sub post_disconnect_hook {
101 113 ▶ my $self = shift;
Subroutine post_disconnect_hook: called CC=4 SCAR=13.9
Pod documented
102  
103 # Now safe to tear down sockets — base disconnect has already drained
104 # whatever messages it was going to drain.
105 113 ▶ for my $peer (keys %{$self->{+CONNECTIONS} // {}}) {
Condition50%1/2
$self->{"connections"} // {}
l!l
1130
MC/DC0%0/1
$self->{"connections"} // {}
$self->{"connections"}
Truth table50%1/2
A
A= $self->{"connections"}
Aresult
11
00
106 56 $self->_close_connection($peer);
107 }
108  
109 113 ▶ if (my $s = delete $self->{+LISTEN_SOCKET}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $s = delete $self->{"listen_socket"}) 109 4 113
110 109 eval { $s->close };
111 }
112  
113 113 $self->SUPER::post_disconnect_hook;
114 }
115  
116 sub peer_is_listener {
117 86 ▶ my $self = shift;
Subroutine peer_is_listener: called CC=3 SCAR=11.0
Pod documented
118 86 my ($peer) = @_;
119 86 ▶ my $path = $self->peer_exists($peer) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $path = $self->peer_exists($peer) or return 0 0 86 86
120 86 ▶ return -S $path ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
-S $path ? : 82 4 86
121 }
122  
123 sub listening_peers {
124 1 ▶ my $self = shift;
Subroutine listening_peers: called CC=1 SCAR=0.0
Pod documented
125 1 return grep { $self->peer_is_listener($_) } $self->peers;
126 }
127  
128 # --- Role::Client::Connection requirements ---
129  
130 18 ▶sub _connections { $_[0]->{+CONNECTIONS} }
Subroutine _connections: called CC=1 SCAR=0.0
131  
132 sub _close_connection {
133 120 ▶ my $self = shift;
Subroutine _close_connection: called CC=3 SCAR=11.2
134 120 my ($peer) = @_;
135  
136 120 ▶ my $entry = delete $self->{+CONNECTIONS}->{$peer} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $entry = delete $self->{"connections"}{$peer} or return 0 120 120
137 120 ▶ if (my $fh = $entry->{fh}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fh = $entry->{"fh"}) 120 0 120
138 120 eval { $fh->close };
139 }
140 120 return;
141 }
142  
143 # --- Wire framing ---
144 #
145 # Each frame: 4-byte big-endian length + JSON payload.
146 #
147 # After connecting outbound, the initiator immediately sends a hello frame:
148 # {"hello": "<my id>"}
149 # so the acceptor can key the cached connection by remote peer id.
150  
151 sub _send_frame {
152 174 ▶ my ($self, $fh, $payload) = @_;
Subroutine _send_frame: called CC=6 SCAR=18.8
153  
154 # Frame on the wire: 4-byte big-endian length prefix, then payload bytes.
155 174 my $bytes = pack('N', length $payload) . $payload;
156 174 my $total = length $bytes;
157 174 my $off = 0;
158  
159 # Sockets are non-blocking, but we need to deliver the whole frame before
160 # returning, so loop until every byte is written. Partial writes advance
161 # $off; EAGAIN/EWOULDBLOCK means the kernel buffer is full so we wait
162 # briefly with select() for it to drain. EINTR retries; anything else is
163 # a real I/O error and we propagate it to the caller.
164 174 ▶ while ($off < $total) {
Branch: 1 branch
BranchTrueFalseTotal
if ($off < $total) 174 173 347
165 174 my $n;
166 {
167 87 ▶ no warnings 'closed', 'unopened';
Subroutine BEGIN: called CC=1 SCAR=0.0
168 174 $n = syswrite($fh, $bytes, $total - $off, $off);
169 }
170 174 ▶ if (defined $n) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n) 173 1 174
171 173 $off += $n;
172 173 next;
173 }
174 1 ▶ if ($! == EAGAIN || $! == EWOULDBLOCK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($! == 11 or $! == 11) 0 1 1
Condition33%1/3
$! == 11 or $! == 11
l!l&&r!l&&!r
001
MC/DC0%0/2
$! == 11 or $! == 11
$! == 11 $! == 11
Truth table33%1/3
A or B
A= $! == 11B= $! == 11
ABresult
1X1
011
000
175 0 my $w = '';
176 0 vec($w, fileno($fh), 1) = 1;
177 0 select(undef, $w, undef, 0.5);
178 0 next;
179 }
180 1 ▶ next if $! == EINTR;
Branch: 1 branch
BranchTrueFalseTotal
if $! == 4 0 1 1
181 1 die "write failed: $!";
182 }
183 }
184  
185 # Non-blocking: drain as much of $entry->{send_buffer} as the kernel will
186 # accept right now, then return. Stops on EAGAIN/EWOULDBLOCK without
187 # blocking; retries on EINTR; raises on any other error.
188 sub _flush_send_buffer {
189 37 ▶ my ($self, $entry) = @_;
Subroutine _flush_send_buffer: called CC=8 SCAR=25.4
190 37 ▶ my $fh = $entry->{fh} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $fh = $entry->{"fh"} or return 0 0 37 37
191  
192 37 ▶ while (length $entry->{send_buffer}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $entry->{"send_buffer"}) 37 37 74
193 37 my $n;
194 {
195 87 ▶ no warnings 'closed', 'unopened';
Subroutine BEGIN: called CC=1 SCAR=0.0
196 37 $n = syswrite($fh, $entry->{send_buffer});
197 }
198 37 ▶ if (defined $n) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n) 37 0 37
199 37 substr($entry->{send_buffer}, 0, $n) = '';
200 37 next;
201 }
202 0 ▶ last if $! == EAGAIN || $! == EWOULDBLOCK;
Branch: 1 branch
BranchTrueFalseTotal
if $! == 11 or $! == 11 0 0 0
Condition0%0/3
$! == 11 or $! == 11
l!l&&r!l&&!r
000
MC/DC0%0/2
$! == 11 or $! == 11
$! == 11 $! == 11
Truth table0%0/3
A or B
A= $! == 11B= $! == 11
ABresult
1X1
011
000
203 0 ▶ next if $! == EINTR;
Branch: 1 branch
BranchTrueFalseTotal
if $! == 4 0 0 0
204 0 die "write failed: $!";
205 }
206  
207 37 ▶ return length($entry->{send_buffer}) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
length $entry->{'send_buffer'} ? : 0 37 37
208 }
209  
210 sub _drain_reads {
211 238 ▶ my ($self, $fh, $buf_ref) = @_;
Subroutine _drain_reads: called CC=7 SCAR=21.2
212  
213 # During global destruction perl may have already destroyed the
214 # IO::Socket::UNIX in $entry->{fh} before our Client's DESTROY runs
215 # disconnect. Treat a missing handle as already-closed.
216 238 ▶ return 1 unless defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 238 238
217  
218 # Pull everything currently readable on $fh into the caller's buffer
219 # without blocking, and report whether the peer has closed. Caller is
220 # responsible for slicing complete frames out of the buffer afterwards
221 # via _extract_frames.
222 238 my $eof = 0;
223 238 while (1) {
224 357 my $chunk;
225 357 my $n = sysread($fh, $chunk, 65536);
226 357 ▶ if (defined $n) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n) 187 170 357
227 # 0 bytes = peer closed cleanly; otherwise append and keep reading.
228 187 ▶ if ($n == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 0) 68 119 187
229 68 $eof = 1;
230 68 last;
231 }
232 119 $$buf_ref .= $chunk;
233 119 next;
234 }
235 # No more data right now — done draining, not an error.
236 170 ▶ last if $! == EAGAIN || $! == EWOULDBLOCK;
Branch: 1 branch
BranchTrueFalseTotal
if $! == 11 or $! == 11 170 0 170
Condition33%1/3
$! == 11 or $! == 11
l!l&&r!l&&!r
17000
MC/DC0%0/2
$! == 11 or $! == 11
$! == 11 $! == 11
Truth table33%1/3
A or B
A= $! == 11B= $! == 11
ABresult
1X1
011
000
237 0 ▶ next if $! == EINTR;
Branch: 1 branch
BranchTrueFalseTotal
if $! == 4 0 0 0
238 # Treat other read errors as EOF: connection is broken.
239 0 $eof = 1;
240 0 last;
241 }
242  
243 238 return $eof;
244 }
245  
246 sub _extract_frames {
247 238 ▶ my ($self, $buf_ref) = @_;
Subroutine _extract_frames: called CC=3 SCAR=11.0
248  
249 # Slice as many complete frames as are present out of the caller's read
250 # buffer, leaving any partial trailing frame in place for the next call.
251 # Each frame is `pack('N', $len) . $payload`; we peek at the length
252 # prefix, bail if the full payload has not arrived yet, and otherwise
253 # consume the prefix+payload from the buffer.
254 238 my @out;
255 238 ▶ while (length($$buf_ref) >= 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$buf_ref >= 4) 198 238 436
256 198 my $len = unpack('N', substr($$buf_ref, 0, 4));
257 198 ▶ last if length($$buf_ref) < 4 + $len;
Branch: 1 branch
BranchTrueFalseTotal
if length $$buf_ref < 4 + $len 0 198 198
258 198 my $payload = substr($$buf_ref, 4, $len);
259 198 substr($$buf_ref, 0, 4 + $len) = '';
260 198 push @out => $payload;
261 }
262 238 return @out;
263 }
264  
265 sub _connect_to_peer {
266 77 ▶ my $self = shift;
Subroutine _connect_to_peer: called CC=4 SCAR=14.0
267 77 my ($peer_id) = @_;
268  
269 77 my $sock = $self->peer_exists($peer_id);
270 77 ▶ die "'$peer_id' is not a valid message recipient" unless $sock;
Branch: 1 branch
BranchTrueFalseTotal
unless $sock 0 77 77
271 77 ▶ die "'$peer_id' is not listening" unless -S $sock;
Branch: 1 branch
BranchTrueFalseTotal
unless -S $sock 0 77 77
272  
273 77 ▶ my $s = IO::Socket::UNIX->new(
Branch: 1 branch
BranchTrueFalseTotal
my $s = "IO::Socket::UNIX"->new("Type", 1, "Peer", $sock) or die "Cannot connect to '${sock}': $!" 0 77 77
274 Type => SOCK_STREAM,
275 Peer => $sock,
276 ) or die "Cannot connect to '$sock': $!";
277  
278 77 $s->blocking(0);
279  
280 77 my $entry = {
281 fh => $s,
282 last_active => time,
283 role => 'initiator',
284 read_buffer => '',
285 send_buffer => '',
286 sent_hello => 0,
287 recv_hello => 1, # we initiated; we know who they are by definition
288 };
289  
290 # Send hello frame first.
291 77 my $hello = $self->{+SERIALIZER}->serialize({hello => $self->{+ID}});
292 77 $self->_send_frame($s, $hello);
293 77 $entry->{sent_hello} = 1;
294  
295 77 $self->{+CONNECTIONS}->{$peer_id} = $entry;
296 77 return $entry;
297 }
298  
299 sub _accept_pending {
300 154 ▶ my $self = shift;
Subroutine _accept_pending: called CC=3 SCAR=11.0
301  
302 154 ▶ my $ls = $self->{+LISTEN_SOCKET} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ls = $self->{"listen_socket"} or return 1 153 154
303  
304 153 ▶ while (my $client = $ls->accept) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $client = $ls->accept) 66 153 219
305 66 $client->blocking(0);
306  
307 # Park under a temporary key until we read the hello frame. We use a
308 # special hash slot keyed by stringified handle so the new connection
309 # is included in select handles immediately.
310 66 my $tmp_key = "_pending_" . fileno($client);
311 66 $self->{+CONNECTIONS}->{$tmp_key} = {
312 fh => $client,
313 last_active => time,
314 role => 'listener',
315 read_buffer => '',
316 send_buffer => '',
317 sent_hello => 0,
318 recv_hello => 0,
319 _pending_key => $tmp_key,
320 };
321 }
322 }
323  
324 sub _resolve_pending {
325 154 ▶ my $self = shift;
Subroutine _resolve_pending: called CC=16 SCAR=35.3
326  
327 154 my $cons = $self->{+CONNECTIONS};
328 154 for my $key (keys %$cons) {
329 172 ▶ next unless $key =~ /^_pending_/;
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ /^_pending_/ 104 68 172
330 68 my $entry = $cons->{$key};
331  
332 68 my $eof = $self->_drain_reads($entry->{fh}, \$entry->{read_buffer});
333 68 my @frames = $self->_extract_frames(\$entry->{read_buffer});
334  
335 68 ▶ if (@frames) {
Branch: 2 branches
BranchTrueFalseTotal
if (@frames) { } 66 2 68
elsif ($eof) { } 0 2 2
336 66 my $hello_raw = shift @frames;
337 66 my $hello;
338 66 my $hello_ok = eval { $hello = $self->{+SERIALIZER}->deserialize($hello_raw); 1 };
339 66 ▶ unless ($hello_ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hello_ok) 0 66 66
340 # Malformed hello — drop the connection.
341 0 warn "ConnectionUnix: malformed hello frame: $@";
342 0 eval { $entry->{fh}->close };
343 0 delete $cons->{$key};
344 0 next;
345 }
346  
347 66 ▶ my $peer_id = ref($hello) eq 'HASH' ? $hello->{hello} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $hello eq 'HASH' ? : 66 0 66
348 66 ▶ unless (defined $peer_id && length $peer_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $peer_id and length $peer_id) 0 66 66
Condition33%1/3
defined $peer_id and length $peer_id
!ll&&!rl&&r
0066
MC/DC0%0/2
defined $peer_id and length $peer_id
defined $peer_id length $peer_id
Truth table33%1/3
A and B
A= defined $peer_idB= length $peer_id
ABresult
0X0
100
111
349 0 warn "ConnectionUnix: hello frame missing peer id";
350 0 eval { $entry->{fh}->close };
351 0 delete $cons->{$key};
352 0 next;
353 }
354  
355 # If we already have a connection to this peer it is necessarily
356 # stale: the remote side dropped the previous fd and reconnected.
357 # Drain anything still buffered on the old entry, then close it,
358 # so the new connection becomes the live one.
359 66 ▶ if (my $old = delete $cons->{$peer_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $old = delete $cons->{$peer_id}) 4 62 66
360 4 ▶ if (my $lf = delete $old->{leftover_frames}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lf = delete $old->{"leftover_frames"}) 0 4 4
361 0 ▶ $entry->{leftover_frames} ||= [];
Condition0%0/2
$entry->{"leftover_frames"} ||= []
l!l
00
MC/DC0%0/1
$entry->{"leftover_frames"} ||= []
$entry->{"leftover_frames"}
Truth table0%0/2
A
A= $entry->{"leftover_frames"}
Aresult
11
00
362 0 unshift @{$entry->{leftover_frames}}, @$lf;
363 }
364 4 $self->_drain_reads($old->{fh}, \$old->{read_buffer});
365 4 my @stale = $self->_extract_frames(\$old->{read_buffer});
366 4 ▶ if (@stale) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stale) 0 4 4
367 0 ▶ $entry->{leftover_frames} ||= [];
Condition0%0/2
$entry->{"leftover_frames"} ||= []
l!l
00
MC/DC0%0/1
$entry->{"leftover_frames"} ||= []
$entry->{"leftover_frames"}
Truth table0%0/2
A
A= $entry->{"leftover_frames"}
Aresult
11
00
368 0 unshift @{$entry->{leftover_frames}}, @stale;
369 }
370 4 eval { $old->{fh}->close };
371 }
372  
373 66 $entry->{recv_hello} = 1;
374 66 $entry->{last_active} = time;
375 # Move to its real key.
376 66 delete $entry->{_pending_key};
377 66 $cons->{$peer_id} = $entry;
378 66 delete $cons->{$key};
379  
380 # Any frames after hello are real messages — push them back into
381 # the buffer so the normal reader picks them up. Easier: stash
382 # leftover frames on the entry and let _read_messages pull them.
383 66 ▶ if (@frames) {
Branch: 1 branch
BranchTrueFalseTotal
if (@frames) 66 0 66
384 66 ▶ $entry->{leftover_frames} ||= [];
Condition50%1/2
$entry->{"leftover_frames"} ||= []
l!l
066
MC/DC0%0/1
$entry->{"leftover_frames"} ||= []
$entry->{"leftover_frames"}
Truth table50%1/2
A
A= $entry->{"leftover_frames"}
Aresult
11
00
385 66 push @{$entry->{leftover_frames}} => @frames;
386 }
387 }
388 elsif ($eof) {
389 0 eval { $entry->{fh}->close };
390 0 delete $cons->{$key};
391 }
392 }
393 }
394  
395 sub _read_messages {
396 154 ▶ my $self = shift;
Subroutine _read_messages: called CC=11 SCAR=24.0
397  
398 154 my @msgs;
399  
400 154 my $cons = $self->{+CONNECTIONS};
401 154 for my $peer (keys %$cons) {
402 168 ▶ next if $peer =~ /^_pending_/;
Branch: 1 branch
BranchTrueFalseTotal
if $peer =~ /^_pending_/ 2 166 168
403 166 my $entry = $cons->{$peer};
404  
405 # Pop any leftover frames captured during hello resolution first.
406 166 ▶ if (my $lf = delete $entry->{leftover_frames}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lf = delete $entry->{"leftover_frames"}) 66 100 166
407 66 for my $raw (@$lf) {
408 71 ▶ my $msg = $self->_decode_message($raw, $entry, $peer) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $msg = $self->_decode_message($raw, $entry, $peer) or next 0 71 71
409 71 push @msgs => $msg;
410 }
411 }
412  
413 166 my $eof = $self->_drain_reads($entry->{fh}, \$entry->{read_buffer});
414 166 my @frames = $self->_extract_frames(\$entry->{read_buffer});
415  
416 166 for my $raw (@frames) {
417 61 ▶ my $msg = $self->_decode_message($raw, $entry, $peer) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $msg = $self->_decode_message($raw, $entry, $peer) or next 0 61 61
418 61 push @msgs => $msg;
419 }
420  
421 166 ▶ if (@frames) {
Branch: 1 branch
BranchTrueFalseTotal
if (@frames) 53 113 166
422 53 $entry->{last_active} = time;
423 }
424  
425 166 ▶ if ($eof && length($entry->{read_buffer}) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eof and length $entry->{"read_buffer"} == 0) 61 105 166
Condition66%2/3
$eof and length $entry->{"read_buffer"} == 0
!ll&&!rl&&r
105061
MC/DC50%1/2
$eof and length $entry->{"read_buffer"} == 0
$eof length $entry->{"read_buffer"} == 0
Truth table66%2/3
A and B
A= $eofB= length $entry->{"read_buffer"} == 0
ABresult
0X0
100
111
426 61 $self->_close_connection($peer);
427 }
428 }
429  
430 154 return @msgs;
431 }
432  
433 sub _decode_message {
434 132 ▶ my ($self, $raw, $entry, $peer) = @_;
Subroutine _decode_message: called CC=5 SCAR=17.8
435 132 my $data;
436 132 ▶ unless (eval { $data = $self->{+SERIALIZER}->deserialize($raw); 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $data = $self->{"serializer"}->deserialize($raw); 1 } }) 0 132 132
437 0 warn "ConnectionUnix: malformed frame from '$peer': $@";
438 0 return undef;
439 }
440 132 ▶ return undef unless ref($data) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 0 132 132
441 # Tolerate a stray hello (shouldn't happen on an already-resolved entry).
442 132 ▶ return undef if exists $data->{hello} && keys(%$data) == 1;
Branch: 1 branch
BranchTrueFalseTotal
if exists $data->{"hello"} and keys %$data == 1 0 132 132
Condition33%1/3
exists $data->{"hello"} and keys %$data == 1
!ll&&!rl&&r
13200
MC/DC0%0/2
exists $data->{"hello"} and keys %$data == 1
exists $data->{"hello"} keys %$data == 1
Truth table33%1/3
A and B
A= exists $data->{"hello"}B= keys %$data == 1
ABresult
0X0
100
111
443  
444 132 my $msg = IPC::Manager::Message->new($data);
445 132 $self->{+STATS}->{read}->{$msg->{from}}++;
446 132 return $msg;
447 }
448  
449 # --- Public API ---
450  
451 sub pending_messages {
452 258 ▶ my $self = shift;
Subroutine pending_messages: called CC=10 SCAR=25.7
Pod undocumented
453 258 $self->pid_check;
454  
455 258 ▶ return 1 if $self->have_resume_file;
Branch: 1 branch
BranchTrueFalseTotal
if $self->have_resume_file 0 258 258
456  
457 # Any buffered frames already?
458 258 my $cons = $self->{+CONNECTIONS};
459 258 for my $entry (values %$cons) {
460 150 ▶ return 1 if $entry->{leftover_frames} && @{$entry->{leftover_frames}};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"leftover_frames"} and @{$entry->{"leftover_frames"};} 0 150 150
Condition33%1/3
$entry->{"leftover_frames"} and @{$entry->{"leftover_frames"};}
!ll&&!rl&&r
15000
MC/DC0%0/2
$entry->{"leftover_frames"} and @{$entry->{"leftover_frames"};}
$entry->{"leftover_frames"} @{$entry->{"leftover_frames"};}
Truth table33%1/3
A and B
A= $entry->{"leftover_frames"}B= @{$entry->{"leftover_frames"};}
ABresult
0X0
100
111
461 return 1 if length($entry->{read_buffer} // '') >= 4
462 150 ▶ && length($entry->{read_buffer}) >= 4 + unpack('N', substr($entry->{read_buffer}, 0, 4));
Branch: 1 branch
BranchTrueFalseTotal
if length($entry->{"read_buffer"} // "") >= 4 and length $entry->{"read_buffer"} >= 4 + unpack("N", substr($entry->{"read_buffer"}, 0, 4)) 0 150 150
Condition40%2/5
length($entry->{"read_buffer"} // "") >= 4 and length $entry->{"read_buffer"} >= 4 + unpack("N", substr($entry->{"read_buffer"}, 0, 4))
!ll&&!rl&&r
15000
$entry->{"read_buffer"} // ""
l!l
1500
MC/DC0%0/2
length($entry->{"read_buffer"} // "") >= 4 and length $entry->{"read_buffer"} >= 4 + unpack("N", substr($entry->{"read_buffer"}, 0, 4))
$entry->{"read_buffer"} length $entry->{"read_buffer"} >= 4 + unpack("N", substr($entry->{"read_buffer"}, 0, 4))
Truth table0%0/3
A and B
A= $entry->{"read_buffer"}B= length $entry->{"read_buffer"} >= 4 + unpack("N", substr($entry->{"read_buffer"}, 0, 4))
ABresult
0X0
100
111
463 }
464  
465 258 if (USE_IO_SELECT()) {
466 258 my @h = $self->handles_for_select;
467 258 ▶ return 0 unless @h;
Branch: 1 branch
BranchTrueFalseTotal
unless @h 6 252 258
468 252 my $sel = IO::Select->new(@h);
469 252 ▶ return $sel->can_read(0) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$sel->can_read(0) ? : 34 218 252
470 }
471  
472 0 return 0;
473 }
474  
475 sub ready_messages {
476 129 ▶ my $self = shift;
Subroutine ready_messages: called CC=3 SCAR=11.0
Pod undocumented
477 129 $self->pid_check;
478  
479 129 ▶ return 1 if $self->have_resume_file;
Branch: 1 branch
BranchTrueFalseTotal
if $self->have_resume_file 0 129 129
480 129 ▶ return 1 if $self->pending_messages;
Branch: 1 branch
BranchTrueFalseTotal
if $self->pending_messages 17 112 129
481  
482 112 return 0;
483 }
484  
485 sub get_messages {
486 154 ▶ my $self = shift;
Subroutine get_messages: called CC=1 SCAR=0.0
Pod documented
487  
488 154 my @out;
489 154 push @out => $self->read_resume_file;
490  
491 154 $self->_accept_pending;
492 154 $self->_resolve_pending;
493  
494 154 push @out => $self->_read_messages;
495  
496 154 return $self->sort_messages(@out);
497 }
498  
499 sub send_message {
500 135 ▶ my $self = shift;
Subroutine send_message: called CC=9 SCAR=22.0
Pod documented
501 135 my $msg = $self->build_message(@_);
502  
503 135 ▶ my $peer_id = $msg->to or croak "No peer specified";
Branch: 1 branch
BranchTrueFalseTotal
my $peer_id = $msg->to or croak("No peer specified") 0 135 135
504  
505 135 $self->pid_check;
506  
507 135 my $payload = $self->{+SERIALIZER}->serialize($msg);
508  
509 # Inside a service the client has set_send_blocking(0) and the
510 # service event loop drains queued frames when the connection
511 # becomes writable. Outside a service we still block until the
512 # bytes are committed so short-lived caller code keeps the
513 # synchronous semantics it has always had.
514 135 ▶ return $self->try_send_message($peer_id, $payload)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->send_blocking 36 99 135
515 unless $self->send_blocking;
516  
517 99 my $entry = $self->{+CONNECTIONS}->{$peer_id};
518  
519 99 ▶ if (!$entry) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($entry) 76 23 99
520 # No cached connection — must be able to connect. peer_exists will
521 # be undef for unknown peers; peer_is_listener gates non-listeners.
522 76 ▶ die "'$peer_id' is not a valid message recipient" unless $self->peer_exists($peer_id);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->peer_exists($peer_id) 1 75 76
523 75 ▶ die "no active connection to '$peer_id' and peer is not listening"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->peer_is_listener($peer_id) 1 74 75
524 unless $self->peer_is_listener($peer_id);
525  
526 74 $entry = $self->_connect_to_peer($peer_id);
527 }
528  
529 # Drain any leftover non-blocking partial frame for this peer first,
530 # otherwise our new frame would interleave with it on the wire.
531 97 ▶ $self->_flush_send_buffer($entry) if length $entry->{send_buffer};
Branch: 1 branch
BranchTrueFalseTotal
if length $entry->{"send_buffer"} 0 97 97
532  
533 # Send the frame. No auto-reconnect: SOCK_STREAM peer churn is the
534 # caller's problem, just like with sockets generally. Auto-retrying
535 # would also silently lose any queued bytes already in send_buffer
536 # that were flushed (or partially flushed) before the EPIPE.
537 97 my $ok = eval { $self->_send_frame($entry->{fh}, $payload); 1 };
538 97 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 1 96 97
539 1 my $err = $@;
540 # Defensive eval: _close_connection only evals close() today, but
541 # future hooks could throw and would mask the real send error.
542 1 ▶ eval { $self->_close_connection($peer_id); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->_close_connection($peer_id); 1 } } or warn "ConnectionUnix: error closing connection to '${peer_id}' after send failure: $@" 0 1 1
543 or warn "ConnectionUnix: error closing connection to '$peer_id' after send failure: $@";
544 1 die $err;
545 }
546 96 $entry->{last_active} = time;
547  
548 96 $self->{+STATS}->{sent}->{$msg->{to}}++;
549 96 return 1;
550 }
551  
552 # --- Role::Outbox plumbing ---
553 #
554 # Connection-oriented framing means a partial write of a frame must NOT be
555 # re-sent from the start: the peer would see a corrupt mix of trailing bytes
556 # from the old attempt and length prefix from the new. So instead of using
557 # the role's whole-payload queue we maintain a per-connection
558 # $entry->{send_buffer} of raw outbound bytes. _outbox_try_write always
559 # accepts the new frame (returns 1), appending to send_buffer if necessary,
560 # and the role's queue stays empty. The framework calls drain_pending /
561 # writable_handles which we override to walk send_buffers instead.
562  
563 sub _outbox_try_write {
564 36 ▶ my ($self, $peer, $payload) = @_;
Subroutine _outbox_try_write: called CC=6 SCAR=20.1
565  
566 36 $self->pid_check;
567  
568 36 my $entry = $self->{+CONNECTIONS}->{$peer};
569 36 ▶ if (!$entry) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($entry) 3 33 36
570 3 ▶ die "'$peer' is not a valid message recipient" unless $self->peer_exists($peer);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->peer_exists($peer) 0 3 3
571 3 ▶ die "no active connection to '$peer' and peer is not listening"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->peer_is_listener($peer) 0 3 3
572 unless $self->peer_is_listener($peer);
573 3 $entry = $self->_connect_to_peer($peer);
574 }
575  
576 36 my $frame = pack('N', length $payload) . $payload;
577 36 $entry->{send_buffer} .= $frame;
578  
579 36 my $flushed_ok = eval { $self->_flush_send_buffer($entry); 1 };
580 36 ▶ unless ($flushed_ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($flushed_ok) 0 36 36
581 0 my $err = $@;
582 # Hard write error (e.g. EPIPE). Drop the connection and lose the
583 # in-flight bytes; future sends to this peer reconnect.
584 0 warn "ConnectionUnix: send to '$peer' failed: $err";
585 0 ▶ eval { $self->_close_connection($peer); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->_close_connection($peer); 1 } } or warn "ConnectionUnix: error closing connection to '${peer}' after send failure: $@" 0 0 0
586 or warn "ConnectionUnix: error closing connection to '$peer' after send failure: $@";
587 0 return 1;
588 }
589  
590 36 $entry->{last_active} = time;
591 36 $self->{+STATS}->{sent}->{$peer}++;
592 36 return 1;
593 }
594  
595 sub _outbox_writable_handle {
596 0 ▶ my ($self, $peer) = @_;
Subroutine _outbox_writable_handle: not called CC=2 SCAR=17.9
597 0 ▶ my $entry = $self->{+CONNECTIONS}->{$peer} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $entry = $self->{"connections"}{$peer} or return undef 0 0 0
598 0 return $entry->{fh};
599 }
600  
601 sub _outbox_set_blocking {
602 # Sockets stay non-blocking either way (reads need it). send_message
603 # branches on send_blocking() to choose the synchronous _send_frame
604 # loop or the deferred-via-send_buffer path.
605 29 ▶ return;
Subroutine _outbox_set_blocking: called CC=1 SCAR=0.0
606 }
607  
608 sub _outbox_can_send {
609 1 ▶ my ($self, $peer) = @_;
Subroutine _outbox_can_send: called CC=3 SCAR=11.7
610 1 ▶ my $entry = $self->{+CONNECTIONS}->{$peer} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $entry = $self->{"connections"}{$peer} or return 0 0 1 1
611 1 ▶ return length($entry->{send_buffer}) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
length $entry->{'send_buffer'} ? : 1 0 1
612 }
613  
614 # Override the role's queue-based bookkeeping: our partial frames live in
615 # per-connection send_buffers, not in the role's _OUTBOX hash, so the role
616 # would otherwise always report "nothing pending" and the service loop
617 # would never pick our writable handles.
618  
619 sub pending_sends {
620 4 ▶ my $self = shift;
Subroutine pending_sends: called CC=6 SCAR=18.3
Pod undocumented
621 4 my $n = 0;
622 4 ▶ for my $key (keys %{$self->{+CONNECTIONS} // {}}) {
Condition50%1/2
$self->{"connections"} // {}
l!l
40
MC/DC0%0/1
$self->{"connections"} // {}
$self->{"connections"}
Truth table50%1/2
A
A= $self->{"connections"}
Aresult
11
00
623 3 ▶ next if $key =~ /^_pending_/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^_pending_/ 0 3 3
624 3 my $entry = $self->{+CONNECTIONS}->{$key};
625 3 ▶ $n++ if length($entry->{send_buffer} // '');
Branch: 1 branch
BranchTrueFalseTotal
if length($entry->{"send_buffer"} // "") 1 2 3
Condition50%1/2
$entry->{"send_buffer"} // ""
l!l
30
MC/DC0%0/1
$entry->{"send_buffer"} // ""
$entry->{"send_buffer"}
Truth table50%1/2
A
A= $entry->{"send_buffer"}
Aresult
11
00
626 }
627 4 return $n;
628 }
629  
630 sub have_pending_sends {
631 106 ▶ my $self = shift;
Subroutine have_pending_sends: called CC=6 SCAR=18.5
Pod undocumented
632 106 ▶ for my $key (keys %{$self->{+CONNECTIONS} // {}}) {
Condition50%1/2
$self->{"connections"} // {}
l!l
1060
MC/DC0%0/1
$self->{"connections"} // {}
$self->{"connections"}
Truth table50%1/2
A
A= $self->{"connections"}
Aresult
11
00
633 51 ▶ next if $key =~ /^_pending_/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^_pending_/ 2 49 51
634 49 ▶ return 1 if length($self->{+CONNECTIONS}->{$key}->{send_buffer} // '');
Branch: 1 branch
BranchTrueFalseTotal
if length($self->{"connections"}{$key}{"send_buffer"} // "") 0 49 49
Condition50%1/2
$self->{"connections"}{$key}{"send_buffer"} // ""
l!l
490
MC/DC0%0/1
$self->{"connections"}{$key}{"send_buffer"} // ""
$self->{"connections"}{$key}{"send_buffer"}
Truth table50%1/2
A
A= $self->{"connections"}{$key}{"send_buffer"}
Aresult
11
00
635 }
636 106 return 0;
637 }
638  
639 sub pending_sends_to {
640 0 ▶ my ($self, $peer) = @_;
Subroutine pending_sends_to: not called CC=4 SCAR=30.0
Pod undocumented
641 0 ▶ my $entry = $self->{+CONNECTIONS}->{$peer} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $entry = $self->{"connections"}{$peer} or return 0 0 0 0
642 0 ▶ return length($entry->{send_buffer} // '') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
length($entry->{'send_buffer'} // '') ? : 0 0 0
Condition0%0/2
$entry->{"send_buffer"} // ""
l!l
00
MC/DC0%0/1
$entry->{"send_buffer"} // ""
$entry->{"send_buffer"}
Truth table0%0/2
A
A= $entry->{"send_buffer"}
Aresult
11
00
643 }
644  
645 sub drain_pending {
646 2 ▶ my $self = shift;
Subroutine drain_pending: called CC=9 SCAR=25.8
Pod undocumented
647  
648 2 my $delivered = 0;
649 2 ▶ for my $key (keys %{$self->{+CONNECTIONS} // {}}) {
Condition50%1/2
$self->{"connections"} // {}
l!l
20
MC/DC0%0/1
$self->{"connections"} // {}
$self->{"connections"}
Truth table50%1/2
A
A= $self->{"connections"}
Aresult
11
00
650 2 ▶ next if $key =~ /^_pending_/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^_pending_/ 0 2 2
651 2 my $entry = $self->{+CONNECTIONS}->{$key};
652 2 ▶ next unless length($entry->{send_buffer} // '');
Branch: 1 branch
BranchTrueFalseTotal
unless length($entry->{"send_buffer"} // "") 1 1 2
Condition50%1/2
$entry->{"send_buffer"} // ""
l!l
20
MC/DC0%0/1
$entry->{"send_buffer"} // ""
$entry->{"send_buffer"}
Truth table50%1/2
A
A= $entry->{"send_buffer"}
Aresult
11
00
653  
654 1 my $ok = eval { $self->_flush_send_buffer($entry); 1 };
655 1 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 1 1
656 0 my $err = $@;
657 0 warn "ConnectionUnix: send to '$key' failed during drain: $err";
658 0 ▶ eval { $self->_close_connection($key); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->_close_connection($key); 1 } } or warn "ConnectionUnix: error closing connection to '${key}' after drain failure: $@" 0 0 0
659 or warn "ConnectionUnix: error closing connection to '$key' after drain failure: $@";
660 0 next;
661 }
662  
663 1 ▶ if (!length($entry->{send_buffer})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $entry->{"send_buffer"}) 1 0 1
664 1 $entry->{last_active} = time;
665 1 $delivered++;
666 }
667 }
668  
669 2 return $delivered;
670 }
671  
672 sub have_writable_handles {
673 80 ▶ my $self = shift;
Subroutine have_writable_handles: called CC=6 SCAR=18.1
Pod undocumented
674 80 ▶ for my $key (keys %{$self->{+CONNECTIONS} // {}}) {
Condition50%1/2
$self->{"connections"} // {}
l!l
800
MC/DC0%0/1
$self->{"connections"} // {}
$self->{"connections"}
Truth table50%1/2
A
A= $self->{"connections"}
Aresult
11
00
675 33 ▶ next if $key =~ /^_pending_/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^_pending_/ 2 31 33
676 31 ▶ return 1 if length($self->{+CONNECTIONS}->{$key}->{send_buffer} // '');
Branch: 1 branch
BranchTrueFalseTotal
if length($self->{"connections"}{$key}{"send_buffer"} // "") 1 30 31
Condition50%1/2
$self->{"connections"}{$key}{"send_buffer"} // ""
l!l
310
MC/DC0%0/1
$self->{"connections"}{$key}{"send_buffer"} // ""
$self->{"connections"}{$key}{"send_buffer"}
Truth table50%1/2
A
A= $self->{"connections"}{$key}{"send_buffer"}
Aresult
11
00
677 }
678 79 return 0;
679 }
680  
681 sub writable_handles {
682 1 ▶ my $self = shift;
Subroutine writable_handles: called CC=7 SCAR=20.7
Pod undocumented
683 1 my @h;
684 1 ▶ for my $key (keys %{$self->{+CONNECTIONS} // {}}) {
Condition50%1/2
$self->{"connections"} // {}
l!l
10
MC/DC0%0/1
$self->{"connections"} // {}
$self->{"connections"}
Truth table50%1/2
A
A= $self->{"connections"}
Aresult
11
00
685 1 ▶ next if $key =~ /^_pending_/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^_pending_/ 0 1 1
686 1 my $entry = $self->{+CONNECTIONS}->{$key};
687 1 ▶ next unless length($entry->{send_buffer} // '');
Branch: 1 branch
BranchTrueFalseTotal
unless length($entry->{"send_buffer"} // "") 0 1 1
Condition50%1/2
$entry->{"send_buffer"} // ""
l!l
10
MC/DC0%0/1
$entry->{"send_buffer"} // ""
$entry->{"send_buffer"}
Truth table50%1/2
A
A= $entry->{"send_buffer"}
Aresult
11
00
688 1 ▶ push @h => $entry->{fh} if $entry->{fh};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"fh"} 1 0 1
689 }
690 1 return @h;
691 }
692  
693 87 1;
694  
695 __END__
« Manager/Role/Outbox.pm ↑ Summary Manager/Test.pm »