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   15050 use strict;
  24         60  
  24         798  
4 24     24   124 use warnings;
  24         53  
  24         573  
5 24     24   447 use 5.010;
  24         87  
6 24     24   126 use Moo;
  24         49  
  24         221  
7 24     24   8133 use AnyEvent;
  24         65  
  24         665  
8 24     24   143 use AnyEvent::Handle;
  24         58  
  24         807  
9 24     24   150 use Carp qw( confess );
  24         53  
  24         12497  
10              
11             # ABSTRACT: Transfer class for asynchronous ftp client
12             our $VERSION = '0.17'; # 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 890 sub cb { shift->{cv}->cb(@_) }
58 0     0 1 0 sub ready { shift->{cv}->ready }
59 46     46 1 4380 sub recv { shift->{cv}->recv }
60              
61             sub handle
62             {
63 70     70 0 204 my($self, $fh) = @_;
64              
65 70         162 my $handle;
66             $handle = AnyEvent::Handle->new(
67             fh => $fh,
68             on_error => sub {
69 21     21   920 my($hdl, $fatal, $msg) = @_;
70 21         109 $self->emit('eof');
71 21         100 $_[0]->destroy;
72             },
73             on_eof => sub {
74 24     24   2524 $self->emit('eof');
75 24         285 $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         927 autocork => 1,
81             );
82              
83 70         8249 $self->emit(open => $handle);
84              
85 70         261 $handle;
86             }
87              
88              
89             1;
90              
91             __END__