| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 51 | 0 | for my $task (values %{ $self->{tasks} }) { | |||||||||||||||||||||||||||
| 52 | 0 | $task->REFRESH(); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ($e & EOF) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | $self->{is_connected} = 0; | |||||||||||||||||||||||||||
| 57 | 0 | for my $task (values %{ $self->{tasks} }) { | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | $task && $task->STOP(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ($e & EOF || $err) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$e & 16 or $err
MC/DC0%0/2
$e & 16 or $err
$e & 16
$err
Truth table0%0/3
A or B
A= $e & 16B= $err
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 71 | 0 | weaken( $task->{manager} = $self ); | |||||||||||||||||||||||||||
| 72 | 0 | $self->{tasks}{ refaddr($task) } = $task; | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($self->{is_connected}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ($self->{is_connected}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if (defined $self->{io}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||