lib/DR/Tnt/LowLevel/Connector/AE.pm

filter: Statementstmt 40.9% 27 / 66 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 43.7% 7 / 16 Podpod 0.0% 0 / 1 totaltotal 33.6% 34 / 101 SCAR 37.2
CC
10
Cov
32%
__ANON__
20.0
__ANON__
20.0
__ANON__
6.0
CRAP 41.2
« blib/lib/DR/Tnt/Msgpack/Types/Str.pm ↑ Summary blib/lib/DR/Tnt/Client/AE.pm »
1 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package DR::Tnt::LowLevel::Connector::AE;
6  
7 3 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use AnyEvent::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use AnyEvent::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 extends 'DR::Tnt::LowLevel::Connector';
13  
14  
15 3 has _fileno => is => 'rw', isa => 'Maybe[Int]';
16 3 has _handle => is => 'rw', isa => 'Maybe[Object]';
17  
18 sub _connect {
19 0 ▶ my ($self, $cb) = @_;
Subroutine _connect: not called CC=1 SCAR=6.9
20  
21 my $h = tcp_connect
22 $self->host,
23 $self->port,
24 sub {
25 0 ▶ my ($fh) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
26 0 ▶ unless ($fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh) 0 0 0
27 0 $cb->(ER_CONNECT => $!);
28 0 return;
29 }
30 0 $self->_fileno(fileno $fh);
31 0 $self->_set_fh(new AnyEvent::Handle
32 fh => $fh,
33 on_read => $self->_on_read,
34 on_error => $self->_on_error,
35 );
36  
37 0 $cb->(OK => 'Connected');
38 }
39 0 ;
40 0 $self->_handle($h);
41 0 return;
42 }
43  
44 before _clean_fh => sub {
45 0 ▶ my ($self) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
46 0 ▶ $self->fh->destroy if $self->fh;
Branch: 1 branch
BranchTrueFalseTotal
if $self->fh 0 0 0
47 0 $self->_handle(undef);
48 3 };
49  
50 after _set_fh => sub {
51 0 ▶ my ($self) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
52 0 ▶ if ($self->fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fh) { } 0 0 0
53 0 $self->_fileno(fileno $self->fh->fh);
54 } else {
55 0 $self->_fileno(undef);
56 0 $self->_handle(undef);
57 }
58 3 };
59  
60 sub _on_read {
61 0 ▶ my ($self) = @_;
Subroutine _on_read: not called CC=1 SCAR=6.9
62 sub {
63 0 ▶ my ($handle) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
64 0 ▶ return unless $handle;
Branch: 1 branch
BranchTrueFalseTotal
unless $handle 0 0 0
65  
66 # reconnect artefacts
67 0 ▶ return unless $self->_fileno;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_fileno 0 0 0
68 0 ▶ return unless $self->_fileno == fileno $self->fh->fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_fileno == fileno $self->fh->fh 0 0 0
69  
70 0 $self->rbuf($self->rbuf . $handle->rbuf);
71 0 $handle->{rbuf} = '';
72 0 $self->check_rbuf;
73 0 };
74 }
75  
76 sub _on_error {
77 0 ▶ my ($self) = @_;
Subroutine _on_error: not called CC=1 SCAR=6.9
78  
79 sub {
80 0 ▶ my ($handle, $fatal, $message) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
81 0 ▶ return unless $fatal;
Branch: 1 branch
BranchTrueFalseTotal
unless $fatal 0 0 0
82
83 # reconnect artefacts
84 0 ▶ return unless $self->_fileno;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_fileno 0 0 0
85 0 ▶ return unless $self->_fileno == fileno $self->fh->fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_fileno == fileno $self->fh->fh 0 0 0
86  
87 0 $self->socket_error($message);
88 }
89 0 }
90  
91 sub send_pkt {
92 0 ▶ my ($self, $pkt, $cb) = @_;
Subroutine send_pkt: not called CC=1 SCAR=6.9
Pod undocumented
93  
94 0 $self->fh->push_write($pkt);
95 0 $cb->(OK => 'packet was queued to send');
96 0 return;
97 }
98  
99  
100 3 __PACKAGE__->meta->make_immutable;
« blib/lib/DR/Tnt/Msgpack/Types/Str.pm ↑ Summary blib/lib/DR/Tnt/Client/AE.pm »