blib/lib/Horris/Connection/Plugin/Retry.pm untested

filter: Statementstmt 0.0% 0 / 19 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 32 CC 2 SCAR 12.8
CC
2
Cov
0%
on_connect
6.0
on_disconnect
2.0
BEGIN
2.0
CRAP 3.6
1 package Horris::Connection::Plugin::Retry;
2 # ABSTRACT: Auto Reconnect Plugin on Horris
3  
4  
5 use Moose;
6 use AnyEvent::RetryTimer;
7 extends 'Horris::Connection::Plugin';
8 with 'MooseX::Role::Pluggable::Plugin';
9  
10 my $timer;
11 sub on_connect {
12 if( $timer ) {
13 $timer->success;
14 undef $timer;
15 }
16 }
17 sub on_disconnect {
18 my ($self) = @_;
19 $timer ||= AnyEvent::RetryTimer->new (
20 on_retry => sub {
21 my ($timer) = @_;
22 $self->connection->irc->connect($self->connection->server, $self->connection->port, {
23 nick => $self->connection->nickname,
24 user => $self->connection->username,
25 password => $self->connection->password,
26 timeout => 1,
27 });
28  
29 $timer->retry;
30 },
31 );
32 }
33  
34 __PACKAGE__->meta->make_immutable;
35  
36 1;
37  
38 __END__