Tak/Loop.pm

filter: Statementstmt 29.4% 10 / 34 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 22.2% 2 / 9 Podpod 0.0% 0 / 5 totaltotal 22.2% 12 / 54 SCAR 30.5
CC
6
Cov
25%
pass_watches_to
6.0
watch_io
6.0
unwatch_io
6.0
CRAP 21.2
« Tak/REPL.pm ↑ Summary Tak/ObjectService.pm »
1 package Tak::Loop;
2  
3 1 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 has is_running => (is => 'rw', clearer => 'loop_stop');
7  
8 0 ▶has _read_watches => (is => 'ro', default => sub { {} });
Subroutine __ANON__: not called CC=1 SCAR=1.2
9 0 ▶has _read_select => (is => 'ro', default => sub { IO::Select->new });
Subroutine __ANON__: not called CC=1 SCAR=1.2
10  
11 sub pass_watches_to {
12 0 ▶ my ($self, $new_loop) = @_;
Subroutine pass_watches_to: not called CC=2 SCAR=17.9
Pod undocumented
13 0 foreach my $fh ($self->_read_select->handles) {
14 $new_loop->watch_io(
15 handle => $fh,
16 0 on_read_ready => $self->_read_watches->{$fh}
17 );
18 }
19 }
20  
21 sub watch_io {
22 0 ▶ my ($self, %watch) = @_;
Subroutine watch_io: not called CC=2 SCAR=17.9
Pod undocumented
23 0 my $fh = $watch{handle};
24 0 ▶ if (my $cb = $watch{on_read_ready}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $watch{"on_read_ready"}) 0 0 0
25 0 $self->_read_select->add($fh);
26 0 $self->_read_watches->{$fh} = $cb;
27 }
28 }
29  
30 sub unwatch_io {
31 0 ▶ my ($self, %watch) = @_;
Subroutine unwatch_io: not called CC=2 SCAR=17.9
Pod undocumented
32 0 my $fh = $watch{handle};
33 0 ▶ if ($watch{on_read_ready}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($watch{"on_read_ready"}) 0 0 0
34 0 $self->_read_select->remove($fh);
35 0 delete $self->_read_watches->{$fh};
36 }
37 }
38  
39 sub loop_once {
40 0 ▶ my ($self) = @_;
Subroutine loop_once: not called CC=2 SCAR=17.9
Pod undocumented
41 0 my $read = $self->_read_watches;
42 0 my ($readable) = IO::Select->select($self->_read_select, undef, undef, 0.5);
43 # I would love to trap errors in the select call but IO::Select doesn't
44 # differentiate between an error and a timeout.
45 # -- no, love, mst.
46 0 foreach my $fh (@$readable) {
47 0 $read->{$fh}();
48 }
49 }
50  
51 sub loop_forever {
52 0 ▶ my ($self) = @_;
Subroutine loop_forever: not called CC=2 SCAR=17.9
Pod undocumented
53 0 $self->is_running(1);
54 0 ▶ while ($self->is_running) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_running) 0 0 0
55 0 $self->loop_once;
56 }
57 }
58  
59 1 1;
« Tak/REPL.pm ↑ Summary Tak/ObjectService.pm »