File Coverage

blib/lib/Inferno/RegMgr/Service.pm
Criterion Covered Total %
statement 21 45 46.6
branch 0 4 0.0
condition n/a
subroutine 7 14 50.0
pod 2 5 40.0
total 30 68 44.1


line stmt bran cond sub pod time code
1             package Inferno::RegMgr::Service;
2              
3 1     1   1069 use warnings;
  1         1  
  1         24  
4 1     1   4 use strict;
  1         1  
  1         21  
5 1     1   4 use Carp;
  1         8  
  1         43  
6              
7             # update POD & Changes & README
8 1     1   5 use version; our $VERSION = qv('0.1.0');
  1         1  
  1         4  
9              
10             # update DEPENDENCIES in POD & Makefile.PL & README
11 1     1   66 use Scalar::Util qw( weaken );
  1         2  
  1         36  
12 1     1   875 use EV;
  1         2777  
  1         32  
13              
14              
15 1     1   8 use constant RETRY => 1; # sec, delay between re-connections
  1         3  
  1         438  
16              
17              
18             sub new {
19 0     0 1   my ($class, $opt) = @_;
20 0           my $self = {
21             name => $opt->{name},
22             attr => $opt->{attr},
23             manager => undef,
24             io => undef,
25             t => undef,
26             };
27 0           return bless $self, $class;
28             }
29              
30             sub START {
31 0     0 0   my ($self) = @_;
32 0           $self->{io} = $self->{manager}{registry}->open_new({
33             name => $self->{name},
34             attr => $self->{attr},
35             cb => $self,
36             method => '_cb_new',
37             });
38 0           weaken( $self->{io} );
39 0           return;
40             }
41              
42             sub _cb_new { ## no critic(ProhibitUnusedPrivateSubroutines)
43 0     0     my ($self, $err) = @_;
44 0     0     $self->{t} = EV::timer RETRY, 0, sub { $self->START() };
  0            
45 0           return;
46             }
47              
48             sub STOP {
49 0     0 0   my ($self) = @_;
50 0 0         if (defined $self->{io}) {
51 0           $self->{io}->close();
52             }
53 0           $self->{t} = undef;
54 0           return;
55             }
56              
57             sub update {
58 0     0 1   my ($self, $attrs) = @_;
59 0           while (my ($attr, $val) = each %{ $attrs }) {
  0            
60 0           $self->{attr}{ $attr } = $val;
61             }
62 0 0         if (defined $self->{io}) {
63 0           $self->{manager}{registry}->update($self->{io}, $attrs);
64             }
65 0           return;
66             }
67              
68 0     0 0   sub REFRESH {}
69              
70              
71             1; # Magic true value required at end of module
72             __END__