blib/lib/DR/Tnt/FullCb/Reconnector/Sync.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 72 SCAR 40.3
CC
7
Cov
0%
event
20.0
check_pause
20.0
_restart
2.0
CRAP 56.0
1 use utf8;
2 use strict;
3 use warnings;
4  
5 package DR::Tnt::FullCb::Reconnector::Sync;
6 use Mouse;
7 use Time::HiRes;
8 use DR::Tnt::LowLevel::Connector::Sync;
9 use DR::Tnt::LowLevel;
10  
11 has fcb => is => 'ro', isa => 'Object', weak_ref => 1;
12 has pause_started =>
13 is => 'ro',
14 isa => 'Num',
15 default => 0,
16 writer => '_set_pause_started';
17  
18 sub event {
19 my ($self, $state, $old_state) = @_;
20 return unless $self->fcb;
21 return unless defined $self->fcb->reconnect_interval;
22 if ($state eq 'pause' and $old_state ne 'pause') {
23 $self->_set_pause_started(Time::HiRes::time);
24 return;
25 }
26 }
27  
28 sub _restart {
29 my ($self, $cb, $cbc) = @_;
30  
31 $cb->();
32 while ($cbc->()) {
33 $cb->();
34 }
35 }
36  
37 sub check_pause {
38 my ($self) = @_;
39 return unless $self->fcb;
40 return unless defined $self->fcb->reconnect_interval;
41 my $now = Time::HiRes::time;
42 my $pause = $self->fcb->reconnect_interval - ($now - $self->pause_started);
43 Time::HiRes::sleep $pause if $pause > 0;
44 $self->_set_pause_started(Time::HiRes::time);
45 }
46  
47 has ll =>
48 is => 'ro',
49 isa => 'DR::Tnt::LowLevel',
50 lazy => 1,
51 builder => sub {
52 my ($self) = @_;
53 DR::Tnt::LowLevel->new(
54 host => $self->fcb->host,
55 port => $self->fcb->port,
56 user => $self->fcb->user,
57 password => $self->fcb->password,
58 connector_class => 'DR::Tnt::LowLevel::Connector::Sync',
59 utf8 => $self->fcb->utf8,
60 );
61 };
62  
63 __PACKAGE__->meta->make_immutable;
64