Manager/Role/Outbox.pm

filter: Statementstmt 78.0% 64 / 82 Branchbran 47.0% 16 / 34 Conditioncond 56.5% 13 / 23 MC/DCmcdc 25.0% 3 / 12 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 10 totaltotal 62.2% 109 / 175 CC 33 SCAR 22.3
CC
33
Cov
67%
writable_handles
30.0
have_writable_handles
18.7
try_send_message
9.0
CRAP 9.3
« Manager/Base/DBI.pm ↑ Summary Manager/Client/ConnectionUnix.pm »
1 package IPC::Manager::Role::Outbox;
2 175 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 175 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 175 our $VERSION = '0.000035';
6  
7 175 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 175 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 175 requires qw{
12 _outbox_try_write
13 _outbox_writable_handle
14 _outbox_set_blocking
15 _outbox_can_send
16 };
17  
18 # Per-spec: queued messages may flush in any order. The role does not
19 # preserve order across queued messages or between a queued message
20 # and a directly-written message. Callers that need strict ordering
21 # must keep the client in send_blocking=1 (the default).
22  
23 sub try_send_message {
24 74 ▶ my $self = shift;
Subroutine try_send_message: called CC=6 SCAR=21.9
Pod undocumented
25  
26 # Match send_message's call signature: caller may pass a Message
27 # object, ($peer, \%content) pair, or full %args. build_message
28 # + serializer produce the wire payload exactly the same way the
29 # blocking path does.
30 74 my ($peer, $payload);
31 74 ▶ if (@_ >= 2 && ref($_[1]) eq '' && !ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ >= 2 and ref $_[1] eq '' and not ref $_[0]) { } 74 0 74
Condition33%2/6
@_ >= 2 and ref $_[1] eq "" and not ref $_[0]
!ll&&!rl&&r
0074
@_ >= 2 and ref $_[1] eq ""
!ll&&!rl&&r
0074
MC/DC0%0/3
@_ >= 2 and ref $_[1] eq "" and not ref $_[0]
@_ >= 2 ref $_[1] eq "" not ref $_[0]
Truth table25%1/4
A and B and not(C)
A= @_ >= 2B= ref $_[1] eq ""C= not ref $_[0]
ABCresult
0XX0
10X0
1100
1111
32 # Pre-serialized fast path: ($peer, $payload_string).
33 74 ($peer, $payload) = @_;
34 }
35 else {
36 0 my $msg = $self->build_message(@_);
37 0 ▶ $peer = $msg->to or croak "No peer specified";
Branch: 1 branch
BranchTrueFalseTotal
$peer = $msg->to or croak("No peer specified") 0 0 0
38 0 $payload = $self->serializer->serialize($msg);
39 }
40  
41 74 ▶ return 1 if $self->_outbox_try_write($peer, $payload);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_outbox_try_write($peer, $payload) 72 2 74
42  
43 2 push @{$self->{_OUTBOX}{$peer}} => [$payload];
44 2 return 0;
45 }
46  
47 sub drain_pending {
48 1 ▶ my $self = shift;
Subroutine drain_pending: called CC=7 SCAR=19.8
Pod undocumented
49  
50 1 my $delivered = 0;
51 1 ▶ for my $peer (keys %{$self->{_OUTBOX} // {}}) {
Condition50%1/2
$self->{"_OUTBOX"} // {}
l!l
10
MC/DC0%0/1
$self->{"_OUTBOX"} // {}
$self->{"_OUTBOX"}
Truth table50%1/2
A
A= $self->{"_OUTBOX"}
Aresult
11
00
52 1 ▶ my $q = $self->{_OUTBOX}{$peer} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $q = $self->{"_OUTBOX"}{$peer} or next 0 1 1
53 1 ▶ while (@$q) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$q) 1 1 2
54 1 my ($payload, $fields) = @{$q->[0]};
55 1 ▶ last unless $self->_outbox_try_write($peer, $payload, %$fields);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_outbox_try_write($peer, $payload, %$fields) 0 1 1
56 1 shift @$q;
57 1 $delivered++;
58 }
59 1 ▶ delete $self->{_OUTBOX}{$peer} unless @$q;
Branch: 1 branch
BranchTrueFalseTotal
unless @$q 1 0 1
60 }
61  
62 1 return $delivered;
63 }
64  
65 sub pending_sends {
66 2 ▶ my $self = shift;
Subroutine pending_sends: called CC=3 SCAR=11.1
Pod undocumented
67  
68 2 my $n = 0;
69 2 ▶ $n += scalar @$_ for values %{$self->{_OUTBOX} // {}};
Condition50%1/2
$self->{"_OUTBOX"} // {}
l!l
20
MC/DC0%0/1
$self->{"_OUTBOX"} // {}
$self->{"_OUTBOX"}
Truth table50%1/2
A
A= $self->{"_OUTBOX"}
Aresult
11
00
70 2 return $n;
71 }
72  
73 # Boolean fast path: prefer this over pending_sends() when callers only
74 # need "is there anything queued?" so we can short-circuit on the first
75 # non-empty queue instead of summing every peer's backlog.
76 sub have_pending_sends {
77 90 ▶ my $self = shift;
Subroutine have_pending_sends: called CC=4 SCAR=13.9
Pod undocumented
78 90 ▶ for my $q (values %{$self->{_OUTBOX} // {}}) {
Condition100%2/2
$self->{"_OUTBOX"} // {}
l!l
288
MC/DC100%1/1
$self->{"_OUTBOX"} // {}
$self->{"_OUTBOX"}
Truth table100%2/2
A
A= $self->{"_OUTBOX"}
Aresult
11
00
79 1 ▶ return 1 if @$q;
Branch: 1 branch
BranchTrueFalseTotal
if @$q 1 0 1
80 }
81 89 return 0;
82 }
83  
84 sub pending_sends_to {
85 96 ▶ my $self = shift;
Subroutine pending_sends_to: called CC=2 SCAR=6.9
Pod undocumented
86 96 my ($peer) = @_;
87 96 ▶ return scalar @{$self->{_OUTBOX}{$peer} // []};
Condition100%2/2
$self->{"_OUTBOX"}{$peer} // []
l!l
294
MC/DC100%1/1
$self->{"_OUTBOX"}{$peer} // []
$self->{"_OUTBOX"}{$peer}
Truth table100%2/2
A
A= $self->{"_OUTBOX"}{$peer}
Aresult
11
00
88 }
89  
90 sub have_writable_handles {
91 61 ▶ my $self = shift;
Subroutine have_writable_handles: called CC=6 SCAR=29.3
Pod undocumented
92 61 ▶ return 0 unless keys %{$self->{_OUTBOX} // {}};
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$self->{"_OUTBOX"} // {};} 61 0 61
Condition50%1/2
$self->{"_OUTBOX"} // {}
l!l
061
MC/DC0%0/1
$self->{"_OUTBOX"} // {}
$self->{"_OUTBOX"}
Truth table50%1/2
A
A= $self->{"_OUTBOX"}
Aresult
11
00
93  
94 0 for my $peer (keys %{$self->{_OUTBOX}}) {
95 0 ▶ next unless @{$self->{_OUTBOX}{$peer}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"_OUTBOX"}{$peer};} 0 0 0
96 0 ▶ return 1 if defined $self->_outbox_writable_handle($peer);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_outbox_writable_handle($peer) 0 0 0
97 }
98  
99 0 return 0;
100 }
101  
102 sub writable_handles {
103 0 ▶ my $self = shift;
Subroutine writable_handles: not called CC=5 SCAR=34.0
Pod undocumented
104 0 my @h;
105 0 ▶ for my $peer (keys %{$self->{_OUTBOX} // {}}) {
Condition0%0/2
$self->{"_OUTBOX"} // {}
l!l
00
MC/DC0%0/1
$self->{"_OUTBOX"} // {}
$self->{"_OUTBOX"}
Truth table0%0/2
A
A= $self->{"_OUTBOX"}
Aresult
11
00
106 0 ▶ next unless @{$self->{_OUTBOX}{$peer}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"_OUTBOX"}{$peer};} 0 0 0
107 0 my $h = $self->_outbox_writable_handle($peer);
108 0 ▶ push @h => $h if defined $h;
Branch: 1 branch
BranchTrueFalseTotal
if defined $h 0 0 0
109 }
110 0 return @h;
111 }
112  
113 sub send_blocking {
114 358 ▶ my $self = shift;
Subroutine send_blocking: called CC=2 SCAR=6.9
Pod undocumented
115 358 ▶ return $self->{_SEND_BLOCKING} // 1;
Condition100%2/2
$self->{"_SEND_BLOCKING"} // 1
l!l
96262
MC/DC100%1/1
$self->{"_SEND_BLOCKING"} // 1
$self->{"_SEND_BLOCKING"}
Truth table100%2/2
A
A= $self->{"_SEND_BLOCKING"}
Aresult
11
00
116 }
117  
118 sub set_send_blocking {
119 58 ▶ my ($self, $bool) = @_;
Subroutine set_send_blocking: called CC=4 SCAR=14.0
Pod undocumented
120 58 ▶ my $val = $bool ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$bool ? : 1 57 58
121 58 ▶ return if defined $self->{_SEND_BLOCKING} && $self->{_SEND_BLOCKING} == $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_SEND_BLOCKING"} and $self->{"_SEND_BLOCKING"} == $val 0 58 58
Condition66%2/3
defined $self->{"_SEND_BLOCKING"} and $self->{"_SEND_BLOCKING"} == $val
!ll&&!rl&&r
5710
MC/DC0%0/2
defined $self->{"_SEND_BLOCKING"} and $self->{"_SEND_BLOCKING"} == $val
defined $self->{"_SEND_BLOCKING"} $self->{"_SEND_BLOCKING"} == $val
Truth table66%2/3
A and B
A= defined $self->{"_SEND_BLOCKING"}B= $self->{"_SEND_BLOCKING"} == $val
ABresult
0X0
100
111
122 58 $self->{_SEND_BLOCKING} = $val;
123 58 $self->_outbox_set_blocking($val);
124 58 return;
125 }
126  
127 sub can_send_to {
128 2 ▶ my ($self, $peer) = @_;
Subroutine can_send_to: called CC=3 SCAR=11.1
Pod undocumented
129 2 ▶ return 0 if $self->pending_sends_to($peer);
Branch: 1 branch
BranchTrueFalseTotal
if $self->pending_sends_to($peer) 1 1 2
130 1 ▶ return $self->_outbox_can_send($peer) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_outbox_can_send($peer) ? : 1 0 1
131 }
132  
133 175 1;
134  
135 __END__
« Manager/Base/DBI.pm ↑ Summary Manager/Client/ConnectionUnix.pm »