Manager/Role/Service/Requests.pm

filter: Statementstmt 100% 63 / 63 Branchbran 90.0% 18 / 20 Conditioncond 72.7% 8 / 11 MC/DCmcdc 57.1% 4 / 7 Subroutinesub 100% 14 / 14 Podpod 83.3% 5 / 6 totaltotal 92.5% 112 / 121 CC 15 SCAR 11.6
CC
15
Cov
95%
have_pending_responses
5.0
get_response
5.0
handle_response
4.0
CRAP 3.2
« Manager/Util.pm ↑ Summary Manager/Client/LocalMemory.pm »
1 package IPC::Manager::Role::Service::Requests;
2 208 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 208 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 208 our $VERSION = '0.000035';
6  
7 # Not included in role:
8 208 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 208 ▶use List::Util qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 208 ▶use Test2::Util::UUID qw/gen_uuid/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 208 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 208 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 64 ▶ my $self = shift;
Subroutine have_pending_responses: called CC=5 SCAR=16.1
Pod documented
26  
27 64 ▶ return 1 if $self->{_RESPONSES} && any { !defined($_->{response}) } values %{$self->{_RESPONSES}};
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_RESPONSES"} and &any(sub { not defined $_->{"response"}; } , values %{$$self{"_RESPONSES"};}) 1 63 64
Condition66%2/3
$self->{"_RESPONSES"} and &any(sub { not defined $_->{"response"}; } , values %{$$self{"_RESPONSES"};})
!ll&&!rl&&r
6301
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"};})
ABresult
0X0
100
111
28 63 ▶ return 1 if $self->{_RESPONSE_HANDLER} && any { defined($_) } values %{$self->{_RESPONSE_HANDLER}};
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_RESPONSE_HANDLER"} and &any(sub { defined $_; } , values %{$$self{"_RESPONSE_HANDLER"};}) 36 27 63
Condition100%3/3
$self->{"_RESPONSE_HANDLER"} and &any(sub { defined $_; } , values %{$$self{"_RESPONSE_HANDLER"};})
!ll&&!rl&&r
22536
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"};})
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (my $entry = delete $self->{'_RESPONSE_HANDLER'}{$id}) { } 41 128 169
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
BranchTrueFalseTotal
unless exists $self->{"_RESPONSES"}{$id} 2 126 128
43 126 ▶ croak "Got an extra response for '$id'" if defined $self->{_RESPONSES}->{$id}->{response};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_RESPONSES"}{$id}{"response"} 0 126 126
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
BranchTrueFalseTotal
if ($cb) { } 46 135 181
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
BranchTrueFalseTotal
my $entry = $self->{"_RESPONSES"}{$id} // $self->{"_RESPONSE_HANDLER"}{$id} or return 0 358 358
Condition33%1/3
$self->{"_RESPONSES"}{$id} // $self->{"_RESPONSE_HANDLER"}{$id}
l!l&&r!l&&!r
35800
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}
ABresult
1X1
011
000
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"} // {}
l!l
4882
MC/DC100%1/1
$self->{"_RESPONSES"} // {}
$self->{"_RESPONSES"}
Truth table100%2/2
A
A= $self->{"_RESPONSES"}
Aresult
11
00
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
BranchTrueFalseTotal
if exists $self->{"_RESPONSE_HANDLER"}{$resp_id} 1 489 490
93  
94 croak "Not expecting a response with id '$resp_id'"
95 489 ▶ unless exists $resps->{$resp_id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $resps->{$resp_id} 1 488 489
96  
97 488 my $entry = $resps->{$resp_id};
98 488 ▶ return () unless defined $entry->{response};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entry->{"response"} 362 126 488
99 126 delete $resps->{$resp_id};
100 126 return $entry->{response};
101 }
102  
103 208 1;
104  
105 __END__
« Manager/Util.pm ↑ Summary Manager/Client/LocalMemory.pm »