| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 52 | 0 | for my $task (values %{ $self->{tasks} }) { | |||||||||||||||||||||||||||
| 53 | 0 | $task->REFRESH(); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ($e & EOF) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | $self->{is_connected} = 0; | |||||||||||||||||||||||||||
| 58 | 0 | for my $task (values %{ $self->{tasks} }) { | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | $task && $task->STOP(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 72 | 0 | weaken( $task->{manager} = $self ); | |||||||||||||||||||||||||||
| 73 | 0 | $self->{tasks}{ refaddr($task) } = $task; | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($self->{is_connected}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($self->{is_connected}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if (defined $self->{io}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||