RegMgr.pm

filter: Statementstmt 32.9% 26 / 79 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 8 / 16 Podpod 100% 3 / 3 totaltotal 29.6% 37 / 125 SCAR 49.3
CC
17
Cov
25%
_cb_event
110.0
DESTROY
20.0
attach
12.0
CRAP 138.9
« RegMgr/TCP.pm ↑ Summary RegMgr/Utils.pm »
1 package Inferno::RegMgr;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # update POD & Changes & README
8 2 ▶use version; our $VERSION = qv('0.1.7');
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # update DEPENDENCIES in POD & Makefile.PL & README
11 2 ▶use Scalar::Util qw( weaken refaddr );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use IO::Stream; # to import consts like CONNECTED
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use EV;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 2 ▶use constant RETRY => 1; # sec, delay between re-connections
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 sub new {
20 0 ▶ my ($class, $reg) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
21 0 my $self = {
22 registry => $reg,
23 is_connected => 0,
24 io => undef,
25 t => undef,
26 tasks => {},
27 };
28 0 bless $self, $class;
29 0 $self->_open_event();
30 0 return $self;
31 }
32  
33 sub _open_event {
34 0 ▶ my ($self) = @_;
Subroutine _open_event: not called CC=1 SCAR=6.9
35 0 weaken( my $this = $self );
36 $self->{io} = $self->{registry}->open_event({
37 0 ▶ cb => sub { $this->_cb_event(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 0 });
39 0 weaken( $self->{io} );
40 0 return;
41 }
42  
43 sub _cb_event {
44 0 ▶ my ($self, $e, $err) = @_;
Subroutine _cb_event: not called CC=10 SCAR=47.0
45 0 ▶ if ($e & CONNECTED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e & 2) 0 0 0
46 0 $self->{is_connected} = 1;
47 0 for my $task (values %{ $self->{tasks} }) {
48 0 $task->START();
49 }
50 }
51 0 ▶ if ($e & IN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e & 4) 0 0 0
52 0 for my $task (values %{ $self->{tasks} }) {
53 0 $task->REFRESH();
54 }
55 }
56 0 ▶ if ($e & EOF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e & 16) 0 0 0
57 0 $self->{is_connected} = 0;
58 0 for my $task (values %{ $self->{tasks} }) {
59 0 ▶ $task && $task->STOP();
Branch: 1 branch
BranchTrueFalseTotal
$task and $task->STOP 0 0 0
60 }
61 }
62 0 ▶ if ($e & EOF || $err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e & 16 or $err) 0 0 0
Condition0%0/3
$e & 16 or $err
l!l&&r!l&&!r
000
MC/DC0%0/2
$e & 16 or $err
$e & 16 $err
Truth table0%0/3
A or B
A= $e & 16B= $err
ABresult
1X1
011
000
63 0 weaken( my $this = $self );
64 0 ▶ $self->{t} = EV::timer RETRY, 0, sub { $this->_open_event() };
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 }
66 0 return;
67 }
68  
69 sub attach {
70 0 ▶ my ($self, $task) = @_;
Subroutine attach: not called CC=3 SCAR=24.8
Pod documented
71 0 ▶ croak 'already attached' if defined $task->{manager};
Branch: 1 branch
BranchTrueFalseTotal
if defined $task->{"manager"} 0 0 0
72 0 weaken( $task->{manager} = $self );
73 0 $self->{tasks}{ refaddr($task) } = $task;
74 0 ▶ if ($self->{is_connected}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"is_connected"}) 0 0 0
75 0 $task->START();
76 }
77 0 return;
78 }
79  
80 sub detach {
81 0 ▶ my ($self, $task) = @_;
Subroutine detach: not called CC=3 SCAR=24.8
Pod documented
82 0 ▶ croak 'not attached to this manager' if $task->{manager} != $self;
Branch: 1 branch
BranchTrueFalseTotal
if $task->{"manager"} != $self 0 0 0
83 0 ▶ if ($self->{is_connected}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"is_connected"}) 0 0 0
84 0 $task->STOP();
85 }
86 0 undef $task->{manager};
87 0 delete $self->{tasks}{ refaddr($task) };
88 0 return;
89 }
90  
91 sub DESTROY {
92 0 ▶ my ($self) = @_;
Subroutine DESTROY: not called CC=4 SCAR=30.0
93 0 for my $task (values %{ $self->{tasks} }) {
94 # $task can be already freed if DESTROY called while global destruction
95 0 ▶ $task && $self->detach($task);
Branch: 1 branch
BranchTrueFalseTotal
$task and $self->detach($task) 0 0 0
96 }
97 0 ▶ if (defined $self->{io}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"io"}) 0 0 0
98 0 $self->{io}->close();
99 }
100 0 $self->{t} = undef;
101 0 return;
102 }
103  
104  
105 2 1; # Magic true value required at end of module
106 __END__
« RegMgr/TCP.pm ↑ Summary RegMgr/Utils.pm »