RegMgr.pm

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