File Coverage

blib/lib/AnyEvent/FTP/Client/Transfer/Passive.pm
Criterion Covered Total %
statement 40 42 95.2
branch 5 8 62.5
condition 2 6 33.3
subroutine 11 11 100.0
pod 0 1 0.0
total 58 68 85.2


line stmt bran cond sub pod time code
1             package AnyEvent::FTP::Client::Transfer::Passive;
2              
3 24     24   705 use strict;
  24         44  
  24         620  
4 24     24   100 use warnings;
  24         42  
  24         498  
5 24     24   147 use Moo;
  24         37  
  24         134  
6 24     24   6995 use 5.010;
  24         81  
7 24     24   130 use AnyEvent::Socket qw( tcp_connect );
  24         49  
  24         6890  
8              
9             extends 'AnyEvent::FTP::Client::Transfer';
10              
11             # ABSTRACT: Passive transfer class for asynchronous ftp client
12             our $VERSION = '0.19'; # VERSION
13              
14             sub BUILD
15             {
16 41     41 0 556 my($self) = @_;
17              
18 41         312 my $local = $self->convert_local($self->local);
19              
20             my $data_connection = sub {
21 41     41   82 my $res = shift;
22 41 50       98 return if $res->is_preliminary;
23 41         194 my($ip, $port) = $res->get_address_and_port;
24 41 50 33     211 if(defined $ip && defined $port)
25             {
26             tcp_connect $ip, $port, sub {
27 41         2982 my($fh) = @_;
28 41 50       132 unless($fh)
29             {
30 0         0 return "unable to connect to data port: $!";
31             }
32              
33 41         172 $self->xfer($fh,$local);
34 41         618 };
35 41         13208 return;
36             }
37             else
38             {
39 0         0 $res;
40             }
41 41         234 };
42              
43 41 100       397 $self->push_command(
44             [ 'PASV', undef, $data_connection ],
45             ($self->restart > 0 ? ([ REST => $self->restart ]) : ()),
46             $self->command,
47             );
48              
49             $self->cv->cb(sub {
50 26   33 26   221 my $res = eval { shift->recv } // $@;
  26         91  
51 26         152 $self->emit('close' => $res);
52 41         904 });
53             }
54              
55             package AnyEvent::FTP::Client::Transfer::Passive::Fetch;
56              
57 24     24   153 use Moo;
  24         47  
  24         126  
58             extends 'AnyEvent::FTP::Client::Transfer::Passive';
59              
60             with 'AnyEvent::FTP::Client::Role::FetchTransfer';
61              
62             package AnyEvent::FTP::Client::Transfer::Passive::Store;
63              
64 24     24   6367 use Moo;
  24         49  
  24         93  
65             extends 'AnyEvent::FTP::Client::Transfer::Passive';
66              
67             with 'AnyEvent::FTP::Client::Role::StoreTransfer';
68              
69             package AnyEvent::FTP::Client::Transfer::Passive::List;
70              
71 24     24   6093 use Moo;
  24         71  
  24         110  
72             extends 'AnyEvent::FTP::Client::Transfer::Passive';
73              
74             with 'AnyEvent::FTP::Client::Role::ListTransfer';
75              
76             1;
77              
78             __END__