| 1 | package IPC::Manager::Role::Outbox; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 176 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 176 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 176 | our $VERSION = '0.000036'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 176 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 176 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 176 | 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
Condition33%2/6
@_ >= 2 and ref $_[1] eq "" and not ref $_[0]
@_ >= 2 and ref $_[1] eq ""
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]
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $payload = $self->serializer->serialize($msg); | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 74 | ▶ | return 1 if $self->_outbox_try_write($peer, $payload); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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"} // {}
MC/DC0%0/1
$self->{"_OUTBOX"} // {}
$self->{"_OUTBOX"}
Truth table50%1/2
A
A= $self->{"_OUTBOX"}
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | my $q = $self->{_OUTBOX}{$peer} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | while (@$q) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | my ($payload, $fields) = @{$q->[0]}; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | last unless $self->_outbox_try_write($peer, $payload, %$fields); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | shift @$q; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | $delivered++; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | ▶ | delete $self->{_OUTBOX}{$peer} unless @$q; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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"} // {}
MC/DC0%0/1
$self->{"_OUTBOX"} // {}
$self->{"_OUTBOX"}
Truth table50%1/2
A
A= $self->{"_OUTBOX"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 91 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
have_pending_sends: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 91 | ▶ | for my $q (values %{$self->{_OUTBOX} // {}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"_OUTBOX"} // {}
MC/DC100%1/1
$self->{"_OUTBOX"} // {}
$self->{"_OUTBOX"}
Truth table100%2/2
A
A= $self->{"_OUTBOX"}
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | return 1 if @$q; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 90 | 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} // []
MC/DC100%1/1
$self->{"_OUTBOX"}{$peer} // []
$self->{"_OUTBOX"}{$peer}
Truth table100%2/2
A
A= $self->{"_OUTBOX"}{$peer}
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | sub have_writable_handles { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 62 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
have_writable_handles: called CC=6 SCAR=29.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 62 | ▶ | return 0 unless keys %{$self->{_OUTBOX} // {}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->{"_OUTBOX"} // {}
MC/DC0%0/1
$self->{"_OUTBOX"} // {}
$self->{"_OUTBOX"}
Truth table50%1/2
A
A= $self->{"_OUTBOX"}
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | for my $peer (keys %{$self->{_OUTBOX}}) { | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | next unless @{$self->{_OUTBOX}{$peer}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | return 1 if defined $self->_outbox_writable_handle($peer); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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"} // {}
MC/DC0%0/1
$self->{"_OUTBOX"} // {}
$self->{"_OUTBOX"}
Truth table0%0/2
A
A= $self->{"_OUTBOX"}
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | next unless @{$self->{_OUTBOX}{$peer}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my $h = $self->_outbox_writable_handle($peer); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | push @h => $h if defined $h; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
$self->{"_SEND_BLOCKING"} // 1
$self->{"_SEND_BLOCKING"}
Truth table100%2/2
A
A= $self->{"_SEND_BLOCKING"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 58 | ▶ | return if defined $self->{_SEND_BLOCKING} && $self->{_SEND_BLOCKING} == $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"_SEND_BLOCKING"} and $self->{"_SEND_BLOCKING"} == $val
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | ▶ | return $self->_outbox_can_send($peer) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 176 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | __END__ | ||||||||||||||||||||||||||||||||||||||||||