blib/lib/Linux/Event/_Resolver.pm

filter: Statementstmt 91.3% 42 / 46 Branchbran 75.0% 6 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 86.6% 13 / 15 Podpod 0.0% 0 / 3 totaltotal 80.5% 62 / 77 CC 8 SCAR 7.0
CC
8
Cov
86%
submit
3.0
_ready
3.0
for_loop
2.5
CRAP 2.0
« blib/lib/Linux/Event/Framer/U32BE.pm ↑ Summary bench/run-process-microbench.pl »
1 package Linux::Event::_Resolver;
2 94 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 94 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 94 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 94 our $VERSION = '0.105';
7  
8 94 ▶use Hash::Util::FieldHash qw(fieldhash);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 94 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 94 require XSLoader;
12 94 XSLoader::load(__PACKAGE__, $VERSION);
13  
14 94 fieldhash my %FOR_LOOP;
15  
16 5 ▶sub for_loop ($class, $loop) {
Subroutine for_loop: called CC=2 SCAR=9.2
Pod undocumented
17 5 ▶ return $FOR_LOOP{$loop} //= $class->_new($loop);
Condition33%1/3
$FOR_LOOP{$loop} //= $class->_new($loop)
l!l&&r!l&&!r
050
MC/DC0%0/2
$FOR_LOOP{$loop} //= $class->_new($loop)
$FOR_LOOP{$loop} $class->_new($loop)
Truth table33%1/3
A //= B
A= $FOR_LOOP{$loop}B= $class->_new($loop)
ABresult
1X1
011
000
18 }
19  
20 5 ▶sub _new ($class, $loop) {
Subroutine _new: called CC=1 SCAR=0.0
21 5 my $self = bless {
22 loop => $loop,
23 native => Linux::Event::_Resolver::_Native->new(2),
24 requests => {},
25 }, $class;
26 5 weaken($self->{loop});
27 5 ▶ my $ready = sub { $self->_ready };
Subroutine __ANON__: called CC=1 SCAR=0.0
28 $loop->watch(
29 fd => $self->{native}->event_fd,
30 5 _internal => 1,
31 read => $ready,
32 no_args => 1,
33 lean => 1,
34 );
35 5 return $self;
36 }
37  
38 6 ▶sub submit ($self, $recipient, $host, $port, $socktype = undef) {
Subroutine submit: called CC=3 SCAR=11.0
Pod undocumented
39 my $id = defined($socktype)
40 ? $self->{native}->submit($host, "$port", $socktype)
41 6 ▶ : $self->{native}->submit($host, "$port");
Branch: 1 branch
BranchTrueFalseTotal
defined $socktype ? : 2 4 6
42 6 $self->{requests}{$id} = $recipient;
43 6 return $id;
44 }
45  
46 1 ▶sub cancel ($self, $id) {
Subroutine cancel: called CC=2 SCAR=7.6
Pod undocumented
47 1 ▶ return defined($id) ? !!delete($self->{requests}{$id}) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $id ? : 1 0 1
48 }
49  
50 28 ▶sub _objects_for_loop ($class, $loop) {
Subroutine _objects_for_loop: called CC=2 SCAR=9.2
51 28 my $self = $FOR_LOOP{$loop};
52 28 ▶ return [] if !$self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 28 0 28
53 0 return [ values %{ $self->{requests} } ];
54 }
55  
56 6 ▶sub _ready ($self) {
Subroutine _ready: called CC=3 SCAR=11.0
57 6 for my $result (@{ $self->{native}->drain }) {
58 6 my $recipient = delete $self->{requests}{ $result->{id} };
59 6 ▶ next if !$recipient;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipient 1 5 6
60 5 $recipient->_resolver_completed($result);
61 }
62 6 return;
63 }
64  
65 2 ▶sub DESTROY ($self) {
Subroutine DESTROY: called CC=1 SCAR=0.0
66 2 delete $self->{requests};
67 2 delete $self->{native};
68 2 return;
69 }
70  
71 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
72  
73 package Linux::Event::_Resolver::_Native;
74 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
75  
76 package Linux::Event::_Resolver;
77  
78 94 1;
« blib/lib/Linux/Event/Framer/U32BE.pm ↑ Summary bench/run-process-microbench.pl »