File Coverage

blib/lib/AnyEvent/FTP/Client/Transfer/Active.pm
Criterion Covered Total %
statement 45 45 100.0
branch 3 4 75.0
condition 1 3 33.3
subroutine 13 13 100.0
pod 0 1 0.0
total 62 66 93.9


line stmt bran cond sub pod time code
1             package AnyEvent::FTP::Client::Transfer::Active;
2              
3 2     2   605 use strict;
  2         4  
  2         50  
4 2     2   8 use warnings;
  2         4  
  2         135  
5 2     2   10 use Moo;
  2         4  
  2         9  
6 2     2   578 use 5.010;
  2         7  
7 2     2   10 use AnyEvent;
  2         4  
  2         51  
8 2     2   7 use AnyEvent::Socket qw( tcp_server );
  2         4  
  2         681  
9              
10             extends 'AnyEvent::FTP::Client::Transfer';
11              
12             # ABSTRACT: Active transfer class for asynchronous ftp client
13             our $VERSION = '0.19'; # VERSION
14              
15             sub BUILD
16             {
17 29     29 0 394 my($self) = @_;
18              
19 29         216 my $local = $self->convert_local($self->local);
20              
21 29         58 my $count = 0;
22 29         47 my $guard;
23             $guard = tcp_server $self->client->{my_ip}, undef, sub {
24 29     29   2171 my($fh, $host, $port) = @_;
25             # TODO double check the host/port combo here.
26              
27 29 50       88 return close $fh if ++$count > 1;
28              
29 29         101 undef $guard; # close to additional connections.
30              
31 29         248 $self->xfer($fh,$local);
32             }, sub {
33              
34 29     29   5528 my($fh, $host, $port) = @_;
35 29         228 my $ip_and_port = join(',', split(/\./, $self->client->{my_ip}), $port >> 8, $port & 0xff);
36              
37 29         61 my $w;
38             $w = AnyEvent->timer(after => 0, cb => sub {
39 29 100       934 $self->push_command(
40             [ PORT => $ip_and_port ],
41             ($self->restart > 0 ? ([ REST => $self->restart ]) : ()),
42             $self->command,
43             );
44 29         328 undef $w;
45 29         287 });
46 29         389 };
47              
48             $self->cv->cb(sub {
49 20   33 20   146 my $res = eval { shift->recv } // $@;
  20         50  
50 20         72 $self->emit('close' => $res);
51 29         1887 });
52              
53             }
54              
55             package AnyEvent::FTP::Client::Transfer::Active::Fetch;
56              
57 2     2   12 use Moo;
  2         4  
  2         7  
58             extends 'AnyEvent::FTP::Client::Transfer::Active';
59              
60             with 'AnyEvent::FTP::Client::Role::FetchTransfer';
61              
62             package AnyEvent::FTP::Client::Transfer::Active::Store;
63              
64 2     2   520 use Moo;
  2         4  
  2         7  
65             extends 'AnyEvent::FTP::Client::Transfer::Active';
66              
67             with 'AnyEvent::FTP::Client::Role::StoreTransfer';
68              
69             package AnyEvent::FTP::Client::Transfer::Active::List;
70              
71 2     2   1899 use Moo;
  2         3  
  2         6  
72             extends 'AnyEvent::FTP::Client::Transfer::Active';
73              
74             with 'AnyEvent::FTP::Client::Role::ListTransfer';
75              
76             1;
77              
78             __END__