File Coverage

blib/lib/AnyEvent/FTP/Client/Transfer.pm
Criterion Covered Total %
statement 32 33 96.9
branch n/a
condition n/a
subroutine 12 13 92.3
pod 3 4 75.0
total 47 50 94.0


line stmt bran cond sub pod time code
1             package AnyEvent::FTP::Client::Transfer;
2              
3 24     24   14048 use strict;
  24         57  
  24         987  
4 24     24   121 use warnings;
  24         45  
  24         1177  
5 24     24   430 use 5.010;
  24         88  
6 24     24   132 use Moo;
  24         66  
  24         165  
7 24     24   9705 use AnyEvent;
  24         76  
  24         738  
8 24     24   144 use AnyEvent::Handle;
  24         41  
  24         830  
9 24     24   143 use Carp qw( confess );
  24         55  
  24         12309  
10              
11             # ABSTRACT: Transfer class for asynchronous ftp client
12             our $VERSION = '0.20'; # VERSION
13              
14              
15             # TODO: implement ABOR
16              
17              
18             with 'AnyEvent::FTP::Role::Event';
19              
20              
21             __PACKAGE__->define_events(qw( open close eof ));
22              
23             has cv => (
24             is => 'ro',
25             lazy => 1,
26             default => sub { AnyEvent->condvar },
27             );
28              
29             has client => (
30             is => 'ro',
31             required => 1,
32             );
33              
34             has remote_name => (
35             is => 'rw',
36             lazy => 1,
37             default => sub { shift->command->[1] },
38             );
39              
40             has local => (
41             is => 'ro',
42             required => 1,
43             );
44              
45             has command => (
46             is => 'ro',
47             required => 1,
48             );
49              
50             has restart => (
51             is => 'ro',
52             default => sub { 0 },
53             coerce => sub { $_[0] // 0 },
54             );
55              
56              
57 24     24 1 925 sub cb { shift->{cv}->cb(@_) }
58 0     0 1 0 sub ready { shift->{cv}->ready }
59 46     46 1 4098 sub recv { shift->{cv}->recv }
60              
61             sub handle
62             {
63 70     70 0 214 my($self, $fh) = @_;
64              
65 70         161 my $handle;
66             $handle = AnyEvent::Handle->new(
67             fh => $fh,
68             on_error => sub {
69 21     21   766 my($hdl, $fatal, $msg) = @_;
70 21         148 $self->emit('eof');
71 21         135 $_[0]->destroy;
72             },
73             on_eof => sub {
74 24     24   2096 $self->emit('eof');
75 24         216 $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         1235 autocork => 1,
81             );
82              
83 70         7806 $self->emit(open => $handle);
84              
85 70         196 $handle;
86             }
87              
88              
89             1;
90              
91             __END__