Remote/Loop.pm

filter: Statementstmt 67.5% 54 / 80 Branchbran 41.6% 5 / 12 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 61.2% 19 / 31 Podpod 0.0% 0 / 14 totaltotal 55.4% 81 / 146 CC 16 SCAR 10.3
CC
16
Cov
63%
run_while_wanted
6.0
run_while_wanted
6.0
want_stop
6.0
CRAP 2.8
« Remote/ModuleSender.pm ↑ Summary Remote/Logging/Logger.pm »
1 package Object::Remote::Loop;
2  
3 26 ▶use Scalar::Util qw( refaddr weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
4 104 ▶use Module::Runtime qw( use_module );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use Object::Remote::MiniLoop;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use Object::Remote::Logging qw( :log :dlog router );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 13 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=1.2
10 13 ▶ $SIG{PIPE} = sub { log_debug { "Got a PIPE signal" } };
Subroutine __ANON__: not called CC=1 SCAR=2.6
Subroutine __ANON__: not called CC=1 SCAR=2.6
11  
12 13 router()->exclude_forwarding
13 }
14  
15 has loop => (
16 is => 'ro',
17 13 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=8.1
18 13 ▶ if ($ENV{OBJECT_REMOTE_LOOP}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"OBJECT_REMOTE_LOOP"}) 0 13 13
19 0 return use_module($ENV{OBJECT_REMOTE_LOOP})->new;
20 }
21 Object::Remote::MiniLoop->new
22 13 });
23  
24 13 ▶has _timers => (is => 'ro', default => sub { {} });
Subroutine __ANON__: called CC=1 SCAR=0.0
25  
26 for my $fn (qw( watch_io unwatch_io
27 loop_once run stop await await_all
28 )) {
29 my $code = "sub ${fn} { my \$self = shift; \$self->loop->${fn}(\@_); }";
30 168 ▶ eval $code;
Subroutine await: called CC=1 SCAR=0.0
Subroutine await_all: called CC=1 SCAR=0.0
Subroutine loop_once: not called CC=1 SCAR=0.0
Subroutine run: called CC=1 SCAR=0.0
Subroutine stop: called CC=1 SCAR=0.0
Subroutine unwatch_io: called CC=1 SCAR=0.0
Subroutine watch_io: called CC=1 SCAR=0.0
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
31 }
32  
33 0 ▶sub want_run {
Subroutine want_run: not called CC=1 SCAR=6.9
Pod undocumented
34 0 ▶ my ($self) = @_;
Subroutine want_run: not called CC=1 SCAR=6.9
Pod undocumented
35 0 ▶ Dlog_debug { "Run loop: Incremeting want_running, is now $_" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 0 ++$self->{want_running};
37 }
38  
39 sub run_while_wanted {
40 0 ▶ my ($self) = @_;
Subroutine run_while_wanted: not called CC=2 SCAR=17.9
Pod undocumented
41 0 ▶ log_debug { my $wr = $self->{want_running}; "Run loop: run_while_wanted() invoked; want_running: $wr" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 0 ▶ $self->loop_once while $self->{want_running};
Branch: 1 branch
BranchTrueFalseTotal
$self->{"want_running"} and do { $self->loop_once } 0 0 0
43 0 ▶ log_debug { "Run loop: run_while_wanted() completed" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 0 return;
45 }
46  
47 sub want_stop {
48 0 ▶ my ($self) = @_;
Subroutine want_stop: not called CC=2 SCAR=17.9
Pod undocumented
49 0 ▶ if (! $self->{want_running}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"want_running"}) 0 0 0
50 0 ▶ log_debug { "Run loop: want_stop() was called but want_running was not true" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 0 return;
52 }
53 0 ▶ Dlog_debug { "Run loop: decrimenting want_running, is now $_" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
54 0 --$self->{want_running};
55 }
56  
57 sub new_future {
58 304 ▶ return $_[0]->loop->new_future;
Subroutine new_future: called CC=1 SCAR=0.0
Pod undocumented
59 }
60  
61 sub watch_time {
62 23 ▶ my ($self, %watch) = @_;
Subroutine watch_time: called CC=5 SCAR=16.4
Pod undocumented
63 23 my ($code, $id);
64 23 my $our_id;
65 23 ▶ if (not ($watch{every} or $watch{after} or $watch{at})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $watch{'every'} || $watch{'after'} || $watch{'at'}) { } 0 23 23
elsif ($watch{'every'}) { } 1 22 23
Condition50%3/6
$watch{'every'} || $watch{'after'} || $watch{'at'}
l!l&&r!l&&!r
2300
$watch{"every"} or $watch{"after"}
l!l&&r!l&&!r
1220
MC/DC0%0/3
$watch{'every'} || $watch{'after'} || $watch{'at'}
$watch{"every"} $watch{"after"} $watch{'at'}
Truth table50%2/4
A or B || C
A= $watch{"every"}B= $watch{"after"}C= $watch{'at'}
ABCresult
1XX1
01X1
0011
0000
66 0 die "watch_time requires every, after or at";
67 }
68 elsif ($watch{every}) {
69 $code = sub {
70 4 ▶ $id = $self->loop->watch_time( %watch, code => $code );
Subroutine __ANON__: called CC=1 SCAR=0.0
71 4 $watch{code}->(@_);
72 1 };
73 1 $watch{after} = delete $watch{every};
74 }
75 else {
76 $code = sub {
77 3 ▶ delete $self->_timers->{"$our_id"};
Subroutine __ANON__: called CC=1 SCAR=0.0
78 3 $watch{code}->(@_);
79 }
80 22 }
81 23 $our_id = refaddr $code;
82 23 $self->_timers->{$our_id} = \$id;
83 23 $id = $self->loop->watch_time( %watch, code => $code );
84 23 weaken($code);
85 23 return $our_id;
86 }
87  
88 sub unwatch_time {
89 1 ▶ my ($self, $id) = @_;
Subroutine unwatch_time: called CC=2 SCAR=7.0
Pod undocumented
90 1 my $timer = delete $self->_timers->{$id};
91 1 ▶ if ($timer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timer) 1 0 1
92 1 $self->loop->unwatch_time( ${$timer} )
93 }
94 }
95  
96 1;
« Remote/ModuleSender.pm ↑ Summary Remote/Logging/Logger.pm »