| 1 | |||
| 2 | package Clio::Server::TCP::Client::Handle; | ||
| 3 | 1 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | $Clio::Server::TCP::Client::Handle::AUTHORITY = 'cpan:AJGB'; | |
| 5 | } | ||
| 6 | { | ||
| 7 | 1 | $Clio::Server::TCP::Client::Handle::VERSION = '0.02'; | |
| 8 | } | ||
| 9 | # ABSTRACT: Clio TCP Client | ||
| 10 | |||
| 11 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | 1 | extends qw(Clio::Client); | |
| 15 | |||
| 16 | 1 | ▶ | use AnyEvent; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | 1 | ▶ | use AnyEvent::Handle; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | 1 | has 'fh' => ( | |
| 22 | is => 'ro', | ||
| 23 | required => 1, | ||
| 24 | ); | ||
| 25 | |||
| 26 | 1 | has '_handle' => ( | |
| 27 | is => 'rw', | ||
| 28 | lazy => 1, | ||
| 29 | builder => '_build_handle', | ||
| 30 | ); | ||
| 31 | |||
| 32 | 0 | ▶ | sub _build_handle { |
|
Subroutine
_build_handle: not called CC=1 SCAR=6.9
| |||
| 33 | 0 | my $self = shift; | |
| 34 | |||
| 35 | 0 | my $manager = $self->manager; | |
| 36 | |||
| 37 | return AnyEvent::Handle->new( | ||
| 38 | fh => $self->fh, | ||
| 39 | 0 | ▶ | on_error => sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 40 | 0 | my ($handle, $fatal, $msg) = @_; | |
| 41 | |||
| 42 | 0 | my $cid = $self->id; | |
| 43 | |||
| 44 | 0 | $self->log->error("Connection error for client $cid: $msg"); | |
| 45 | |||
| 46 | 0 | $manager->disconnect_client( $cid ); | |
| 47 | }, | ||
| 48 | 0 | ); | |
| 49 | } | ||
| 50 | |||
| 51 | |||
| 52 | 0 | ▶ | sub write { |
|
Subroutine
write: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 53 | 0 | my $self = shift; | |
| 54 | |||
| 55 | 0 | $self->log->trace("Client ", $self->id, " writing '@_'"); | |
| 56 | |||
| 57 | 0 | $self->_handle->push_write( @_ ); | |
| 58 | } | ||
| 59 | |||
| 60 | |||
| 61 | 0 | ▶ | sub attach_to_process { |
|
Subroutine
attach_to_process: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 62 | 0 | my ($self, $process) = @_; | |
| 63 | |||
| 64 | 0 | $self->log->debug("Attaching process ", $process->id, " to client ", $self->id); | |
| 65 | |||
| 66 | 0 | $self->_process($process); | |
| 67 | |||
| 68 | 0 | ▶ | my $reader; $reader = sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 69 | 0 | my ($handle, $cmd, $eol) = @_; | |
| 70 | |||
| 71 | 0 | $self->_process->write( $cmd ); | |
| 72 | |||
| 73 | 0 | $self->_handle->push_read( line => $reader ); | |
| 74 | 0 | }; | |
| 75 | 0 | $self->_handle->push_read( line => $reader ); | |
| 76 | |||
| 77 | } | ||
| 78 | |||
| 79 | |||
| 80 | 0 | ▶ | sub close { |
|
Subroutine
close: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 81 | 0 | my $self = shift; | |
| 82 | |||
| 83 | 0 | $self->_handle->destroy; | |
| 84 | } | ||
| 85 | |||
| 86 | |||
| 87 | 1 | 1; | |
| 88 | |||
| 89 | |||
| 90 | __END__ | ||