Manager/Role/Service/Select.pm

filter: Statementstmt 86.0% 37 / 43 Branchbran 75.0% 15 / 20 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 50.0% 2 / 4 totaltotal 83.7% 67 / 80 CC 12 SCAR 14.9
CC
12
Cov
83%
select
6.0
select_write
6.0
have_dynamic_handles_for_select
5.0
CRAP 4.4
« Manager/Client.pm ↑ Summary Manager/Serializer/JSON/Zstd.pm »
1 package IPC::Manager::Role::Service::Select;
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  
10 208 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 208 requires qw{
13 select_handles
14 };
15  
16 sub clear_serviceselect_fields {
17 445 ▶ my $self = shift;
Subroutine clear_serviceselect_fields: called CC=1 SCAR=0.0
Pod documented
18 445 delete $self->{_SELECT};
19 }
20  
21 # Returns true when the underlying client multiplexes a handle set that may
22 # change during normal operation (e.g. accepted SOCK_STREAM connections).
23 # Defaults to consulting the client; consumers that don't have a client
24 # accessor get the safe answer (false).
25 sub have_dynamic_handles_for_select {
26 773 ▶ my $self = shift;
Subroutine have_dynamic_handles_for_select: called CC=5 SCAR=16.1
Pod undocumented
27 773 ▶ return 0 unless $self->can('client');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can("client") 4 769 773
28 769 ▶ my $client = $self->client or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $client = $self->client or return 0 0 769 769
29 769 ▶ return 0 unless $client->can('have_dynamic_handles_for_select');
Branch: 1 branch
BranchTrueFalseTotal
unless $client->can("have_dynamic_handles_for_select") 230 539 769
30 539 ▶ return $client->have_dynamic_handles_for_select ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$client->have_dynamic_handles_for_select ? : 114 425 539
31 }
32  
33 sub select {
34 773 ▶ my $self = shift;
Subroutine select: called CC=6 SCAR=17.9
Pod documented
35  
36 773 my $dynamic = $self->have_dynamic_handles_for_select;
37  
38 773 ▶ return $self->{_SELECT} if !$dynamic && exists $self->{_SELECT};
Branch: 1 branch
BranchTrueFalseTotal
if not $dynamic and exists $self->{"_SELECT"} 477 296 773
Condition100%3/3
not $dynamic and exists $self->{"_SELECT"}
!ll&&!rl&&r
114182477
MC/DC100%2/2
not $dynamic and exists $self->{"_SELECT"}
not $dynamic exists $self->{"_SELECT"}
Truth table100%3/3
not(A) and B
A= not $dynamicB= exists $self->{"_SELECT"}
ABresult
0X0
100
111
39  
40 296 my @handles = $self->select_handles;
41 296 ▶ unless (@handles) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@handles) 123 173 296
42 123 ▶ $self->{_SELECT} = undef unless $dynamic;
Branch: 1 branch
BranchTrueFalseTotal
unless $dynamic 123 0 123
43 123 return undef;
44 }
45  
46 173 require IO::Select;
47 173 my $s = IO::Select->new;
48 173 $s->add(@handles);
49  
50 173 ▶ $self->{_SELECT} = $s unless $dynamic;
Branch: 1 branch
BranchTrueFalseTotal
unless $dynamic 59 114 173
51 173 return $s;
52 }
53  
54 # Build a fresh IO::Select for the client's writable handles, or
55 # return undef when no peer has a backlog. Built fresh per call
56 # because the writable-handle set tracks the outbox, which is
57 # transient by design.
58 sub select_write {
59 378 ▶ my $self = shift;
Subroutine select_write: called CC=3 SCAR=17.9
Pod undocumented
60 378 my $client = $self->client;
61  
62 378 ▶ return undef unless $client->have_writable_handles;
Branch: 1 branch
BranchTrueFalseTotal
unless $client->have_writable_handles 378 0 378
63  
64 0 my @handles = $client->writable_handles;
65 0 ▶ return undef unless @handles;
Branch: 1 branch
BranchTrueFalseTotal
unless @handles 0 0 0
66  
67 0 require IO::Select;
68 0 my $s = IO::Select->new;
69 0 $s->add(@handles);
70 0 return $s;
71 }
72  
73 208 1;
74  
75 __END__
« Manager/Client.pm ↑ Summary Manager/Serializer/JSON/Zstd.pm »