| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 65 | |||||||||||
| 66 | # reconnect artefacts | ||||||||||
| 67 | 0 | ▶ | return unless $self->_fileno; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | ▶ | return unless $self->_fileno == fileno $self->fh->fh; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 82 | |||||||||||
| 83 | # reconnect artefacts | ||||||||||
| 84 | 0 | ▶ | return unless $self->_fileno; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 0 | ▶ | return unless $self->_fileno == fileno $self->fh->fh; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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; | |||||||||