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