blib/lib/Linux/Event/_Resolver.pm

filter: Statementstmt 80.0% 48 / 60 Branchbran 50.0% 8 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 87.5% 14 / 16 Podpod 0.0% 0 / 3 totaltotal 71.0% 71 / 100 CC 12 SCAR 12.9
CC
12
Cov
72%
_fork_prepare_loop
12.6
submit
3.0
_ready
3.0
CRAP 3.6
« bench/run-timer-microbench.pl ↑ Summary blib/lib/Linux/Event/Framer/U32BE.pm »
1 package Linux::Event::_Resolver;
2 128 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 128 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 128 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 128 our $VERSION = '0.120';
7  
8 128 ▶use Hash::Util::FieldHash qw(fieldhash);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 128 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 128 require XSLoader;
12 128 XSLoader::load(__PACKAGE__, $VERSION);
13  
14 128 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 $self->{watcher} = $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 20 ▶sub _fork_prepare_loop ($class, $loop) {
Subroutine _fork_prepare_loop: called CC=4 SCAR=25.3
51 20 my $self = $FOR_LOOP{$loop};
52 20 ▶ return if !$self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 20 0 20
53 die "fork(): Loop has active resolver requests\n"
54 0 ▶ if keys %{ $self->{requests} };
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$self{"requests"};} 0 0 0
55 0 delete $FOR_LOOP{$loop};
56 0 ▶ if (my $watcher = delete $self->{watcher}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $watcher = delete $self->{"watcher"}) 0 0 0
57 0 $watcher->cancel;
58 }
59 0 delete $self->{native};
60 0 delete $self->{loop};
61 0 return;
62 }
63  
64 81 ▶sub _objects_for_loop ($class, $loop) {
Subroutine _objects_for_loop: called CC=2 SCAR=9.2
65 81 my $self = $FOR_LOOP{$loop};
66 81 ▶ return [] if !$self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 81 0 81
67 0 return [ values %{ $self->{requests} } ];
68 }
69  
70 6 ▶sub _ready ($self) {
Subroutine _ready: called CC=3 SCAR=11.0
71 6 for my $result (@{ $self->{native}->drain }) {
72 6 my $recipient = delete $self->{requests}{ $result->{id} };
73 6 ▶ next if !$recipient;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipient 1 5 6
74 5 $recipient->_resolver_completed($result);
75 }
76 6 return;
77 }
78  
79 2 ▶sub DESTROY ($self) {
Subroutine DESTROY: called CC=2 SCAR=7.0
80 2 ▶ if (my $watcher = delete $self->{watcher}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $watcher = delete $self->{"watcher"}) 2 0 2
81 2 eval { $watcher->cancel; 1 };
82 }
83 2 delete $self->{requests};
84 2 delete $self->{native};
85 2 return;
86 }
87  
88 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
89  
90 package Linux::Event::_Resolver::_Native;
91 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
92  
93 package Linux::Event::_Resolver;
94  
95 128 1;
« bench/run-timer-microbench.pl ↑ Summary blib/lib/Linux/Event/Framer/U32BE.pm »