| 1 | package IPC::Manager::Role::Service::Requests; | ||||||||||||||||||||||||||||
| 2 | 209 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 209 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 209 | our $VERSION = '0.000036'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # Not included in role: | ||||||||||||||||||||||||||||
| 8 | 209 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 209 | ▶ | use List::Util qw/any/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 209 | ▶ | use Test2::Util::UUID qw/gen_uuid/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 209 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 209 | requires qw{ | |||||||||||||||||||||||||||
| 15 | client | ||||||||||||||||||||||||||||
| 16 | }; | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub clear_servicerequests_fields { | ||||||||||||||||||||||||||||
| 19 | 445 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
clear_servicerequests_fields: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 445 | delete $self->{_RESPONSES}; | |||||||||||||||||||||||||||
| 21 | 445 | delete $self->{_RESPONSE_HANDLER}; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub have_pending_responses { | ||||||||||||||||||||||||||||
| 25 | 62 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
have_pending_responses: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 62 | ▶ | return 1 if $self->{_RESPONSES} && any { !defined($_->{response}) } values %{$self->{_RESPONSES}}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition66%2/3
$self->{"_RESPONSES"} and &any(sub {
not defined $_->{"response"};
}
, values %{$$self{"_RESPONSES"};})
MC/DC50%1/2
$self->{"_RESPONSES"} and &any(sub {
not defined $_->{"response"};
}
, values %{$$self{"_RESPONSES"};})
$self->{"_RESPONSES"}
&any(sub {
not defined $_->{"response"};
}
, values %{$$self{"_RESPONSES"};})
Truth table66%2/3
A and B
A= $self->{"_RESPONSES"}B= &any(sub {
not defined $_->{"response"};
}
, values %{$$self{"_RESPONSES"};})
| |||||||||||||||||||||||||||||
| 28 | 61 | ▶ | return 1 if $self->{_RESPONSE_HANDLER} && any { defined($_) } values %{$self->{_RESPONSE_HANDLER}}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition100%3/3
$self->{"_RESPONSE_HANDLER"} and &any(sub {
defined $_;
}
, values %{$$self{"_RESPONSE_HANDLER"};})
MC/DC100%2/2
$self->{"_RESPONSE_HANDLER"} and &any(sub {
defined $_;
}
, values %{$$self{"_RESPONSE_HANDLER"};})
$self->{"_RESPONSE_HANDLER"}
&any(sub {
defined $_;
}
, values %{$$self{"_RESPONSE_HANDLER"};})
Truth table100%3/3
A and B
A= $self->{"_RESPONSE_HANDLER"}B= &any(sub {
defined $_;
}
, values %{$$self{"_RESPONSE_HANDLER"};})
| |||||||||||||||||||||||||||||
| 29 | 27 | return 0; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub handle_response { | ||||||||||||||||||||||||||||
| 33 | 169 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
handle_response: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 169 | my ($resp, $msg) = @_; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 169 | my $id = $resp->{ipcm_response_id}; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 169 | ▶ | if (my $entry = delete $self->{_RESPONSE_HANDLER}->{$id}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 41 | $entry->{cb}->($resp, $msg); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | else { | ||||||||||||||||||||||||||||
| 42 | 128 | ▶ | croak "Got an unexpected response for '$id'" unless exists $self->{_RESPONSES}->{$id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 126 | ▶ | croak "Got an extra response for '$id'" if defined $self->{_RESPONSES}->{$id}->{response}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 126 | $self->{_RESPONSES}->{$id}->{response} = $resp; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 167 | return; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | sub send_request { | ||||||||||||||||||||||||||||
| 51 | 181 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
send_request: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 181 | my ($peer, $req, $cb) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 181 | my $id = gen_uuid(); | |||||||||||||||||||||||||||
| 55 | 181 | my $pid = $self->client->peer_pid($peer); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 181 | $self->client->send_message( | |||||||||||||||||||||||||||
| 58 | $peer, | ||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||
| 60 | ipcm_request_id => $id, | ||||||||||||||||||||||||||||
| 61 | request => $req, | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 181 | ▶ | if ($cb) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 46 | $self->{_RESPONSE_HANDLER}->{$id} = {peer => $peer, pid => $pid, cb => $cb}; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | else { | ||||||||||||||||||||||||||||
| 69 | 135 | $self->{_RESPONSES}->{$id} = {peer => $peer, pid => $pid, response => undef}; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 181 | return $id; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | sub pending_response_peer { | ||||||||||||||||||||||||||||
| 76 | 358 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
pending_response_peer: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 77 | 358 | my ($id) = @_; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 358 | ▶ | my $entry = $self->{_RESPONSES}->{$id} // $self->{_RESPONSE_HANDLER}->{$id} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"_RESPONSES"}{$id} // $self->{"_RESPONSE_HANDLER"}{$id}
MC/DC0%0/2
$self->{"_RESPONSES"}{$id} // $self->{"_RESPONSE_HANDLER"}{$id}
$self->{"_RESPONSES"}{$id}
$self->{"_RESPONSE_HANDLER"}{$id}
Truth table33%1/3
A // B
A= $self->{"_RESPONSES"}{$id}B= $self->{"_RESPONSE_HANDLER"}{$id}
| |||||||||||||||||||||||||||||
| 80 | or return; | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 358 | return ($entry->{peer}, $entry->{pid}); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub get_response { | ||||||||||||||||||||||||||||
| 86 | 490 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_response: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 490 | my ($resp_id) = @_; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 490 | ▶ | my $resps = $self->{_RESPONSES} // {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"_RESPONSES"} // {}
MC/DC100%1/1
$self->{"_RESPONSES"} // {}
$self->{"_RESPONSES"}
Truth table100%2/2
A
A= $self->{"_RESPONSES"}
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | croak "Response id '$resp_id' has a callback assigned, cannot use both get_response() and a callback" | ||||||||||||||||||||||||||||
| 92 | 490 | ▶ | if exists $self->{_RESPONSE_HANDLER}->{$resp_id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | croak "Not expecting a response with id '$resp_id'" | ||||||||||||||||||||||||||||
| 95 | 489 | ▶ | unless exists $resps->{$resp_id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 488 | my $entry = $resps->{$resp_id}; | |||||||||||||||||||||||||||
| 98 | 488 | ▶ | return () unless defined $entry->{response}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 126 | delete $resps->{$resp_id}; | |||||||||||||||||||||||||||
| 100 | 126 | return $entry->{response}; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 209 | 1; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||||||||||