| 1 | package AnyEvent::FTP::Client::Transfer; | ||||||||||||
| 2 | |||||||||||||
| 3 | 24 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 24 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 24 | ▶ | use 5.010; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 24 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 24 | ▶ | use AnyEvent; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 24 | ▶ | use AnyEvent::Handle; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 24 | ▶ | use Carp qw( confess ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | # ABSTRACT: Transfer class for asynchronous ftp client | ||||||||||||
| 12 | 24 | our $VERSION = '0.19'; # VERSION | |||||||||||
| 13 | |||||||||||||
| 14 | |||||||||||||
| 15 | # TODO: implement ABOR | ||||||||||||
| 16 | |||||||||||||
| 17 | |||||||||||||
| 18 | 24 | with 'AnyEvent::FTP::Role::Event'; | |||||||||||
| 19 | |||||||||||||
| 20 | |||||||||||||
| 21 | 24 | __PACKAGE__->define_events(qw( open close eof )); | |||||||||||
| 22 | |||||||||||||
| 23 | has cv => ( | ||||||||||||
| 24 | is => 'ro', | ||||||||||||
| 25 | lazy => 1, | ||||||||||||
| 26 | 70 | ▶ | default => sub { AnyEvent->condvar }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | 24 | ); | |||||||||||
| 28 | |||||||||||||
| 29 | 24 | has client => ( | |||||||||||
| 30 | is => 'ro', | ||||||||||||
| 31 | required => 1, | ||||||||||||
| 32 | ); | ||||||||||||
| 33 | |||||||||||||
| 34 | has remote_name => ( | ||||||||||||
| 35 | is => 'rw', | ||||||||||||
| 36 | lazy => 1, | ||||||||||||
| 37 | 2 | ▶ | default => sub { shift->command->[1] }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 38 | 24 | ); | |||||||||||
| 39 | |||||||||||||
| 40 | 24 | has local => ( | |||||||||||
| 41 | is => 'ro', | ||||||||||||
| 42 | required => 1, | ||||||||||||
| 43 | ); | ||||||||||||
| 44 | |||||||||||||
| 45 | 24 | has command => ( | |||||||||||
| 46 | is => 'ro', | ||||||||||||
| 47 | required => 1, | ||||||||||||
| 48 | ); | ||||||||||||
| 49 | |||||||||||||
| 50 | has restart => ( | ||||||||||||
| 51 | is => 'ro', | ||||||||||||
| 52 | 49 | ▶ | default => sub { 0 }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 53 | 70 | ▶ | coerce => sub { $_[0] // 0 }, | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[0] // 0
MC/DC100%1/1
$_[0] // 0
$_[0]
Truth table100%2/2
A
A= $_[0]
| |||||||||||||
| 54 | 24 | ); | |||||||||||
| 55 | |||||||||||||
| 56 | |||||||||||||
| 57 | 24 | ▶ | sub cb { shift->{cv}->cb(@_) } | ||||||||||
|
Subroutine
cb: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 58 | 0 | ▶ | sub ready { shift->{cv}->ready } | ||||||||||
|
Subroutine
ready: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 59 | 46 | ▶ | sub recv { shift->{cv}->recv } | ||||||||||
|
Subroutine
recv: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 60 | |||||||||||||
| 61 | sub handle | ||||||||||||
| 62 | { | ||||||||||||
| 63 | 70 | ▶ | my($self, $fh) = @_; | ||||||||||
|
Subroutine
handle: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 64 | |||||||||||||
| 65 | 70 | my $handle; | |||||||||||
| 66 | $handle = AnyEvent::Handle->new( | ||||||||||||
| 67 | fh => $fh, | ||||||||||||
| 68 | on_error => sub { | ||||||||||||
| 69 | 21 | ▶ | my($hdl, $fatal, $msg) = @_; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 70 | 21 | $self->emit('eof'); | |||||||||||
| 71 | 21 | $_[0]->destroy; | |||||||||||
| 72 | }, | ||||||||||||
| 73 | on_eof => sub { | ||||||||||||
| 74 | 24 | ▶ | $self->emit('eof'); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 75 | 24 | $handle->destroy; | |||||||||||
| 76 | }, | ||||||||||||
| 77 | # this avoids deep recursion exception error (usually | ||||||||||||
| 78 | # a warning) in example fput.pl when the buffer is | ||||||||||||
| 79 | # small (1024 on my debian VM) | ||||||||||||
| 80 | 70 | autocork => 1, | |||||||||||
| 81 | ); | ||||||||||||
| 82 | |||||||||||||
| 83 | 70 | $self->emit(open => $handle); | |||||||||||
| 84 | |||||||||||||
| 85 | 70 | $handle; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | |||||||||||||
| 89 | 24 | 1; | |||||||||||
| 90 | |||||||||||||
| 91 | __END__ | ||||||||||||