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   1021 use strict;
  24         65  
  24         825  
4 24     24   135 use warnings;
  24         52  
  24         671  
5 24     24   189 use Moo;
  24         63  
  24         169  
6 24     24   9171 use 5.010;
  24         100  
7 24     24   179 use AnyEvent::Socket qw( tcp_connect );
  24         54  
  24         9776  
8              
9             extends 'AnyEvent::FTP::Client::Transfer';
10              
11             # ABSTRACT: Passive transfer class for asynchronous ftp client
12             our $VERSION = '0.17'; # VERSION
13              
14             sub BUILD
15             {
16 41     41 0 891 my($self) = @_;
17              
18 41         410 my $local = $self->convert_local($self->local);
19              
20             my $data_connection = sub {
21 41     41   107 my $res = shift;
22 41 50       163 return if $res->is_preliminary;
23 41         263 my($ip, $port) = $res->get_address_and_port;
24 41 50 33     315 if(defined $ip && defined $port)
25             {
26             tcp_connect $ip, $port, sub {
27 41         4814 my($fh) = @_;
28 41 50       173 unless($fh)
29             {
30 0         0 return "unable to connect to data port: $!";
31             }
32              
33 41         232 $self->xfer($fh,$local);
34 41         468 };
35 41         21098 return;
36             }
37             else
38             {
39 0         0 $res;
40             }
41 41         368 };
42              
43 41 100       553 $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   505 my $res = eval { shift->recv } // $@;
  26         156  
51 26         168 $self->emit('close' => $res);
52 41         1462 });
53             }
54              
55             package AnyEvent::FTP::Client::Transfer::Passive::Fetch;
56              
57 24     24   221 use Moo;
  24         79  
  24         161  
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   9202 use Moo;
  24         77  
  24         175  
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   8999 use Moo;
  24         64  
  24         149  
72             extends 'AnyEvent::FTP::Client::Transfer::Passive';
73              
74             with 'AnyEvent::FTP::Client::Role::ListTransfer';
75              
76             1;
77              
78             __END__