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   1072 use strict;
  2         7  
  2         97  
4 2     2   11 use warnings;
  2         5  
  2         106  
5 2     2   9 use Moo;
  2         5  
  2         65  
6 2     2   817 use 5.010;
  2         8  
7 2     2   14 use AnyEvent;
  2         6  
  2         78  
8 2     2   11 use AnyEvent::Socket qw( tcp_server );
  2         3  
  2         1030  
9              
10             extends 'AnyEvent::FTP::Client::Transfer';
11              
12             # ABSTRACT: Active transfer class for asynchronous ftp client
13             our $VERSION = '0.20'; # VERSION
14              
15             sub BUILD
16             {
17 29     29 0 558 my($self) = @_;
18              
19 29         1197 my $local = $self->convert_local($self->local);
20              
21 29         74 my $count = 0;
22 29         73 my $guard;
23             $guard = tcp_server $self->client->{my_ip}, undef, sub {
24 29     29   3293 my($fh, $host, $port) = @_;
25             # TODO double check the host/port combo here.
26              
27 29 50       138 return close $fh if ++$count > 1;
28              
29 29         214 undef $guard; # close to additional connections.
30              
31 29         364 $self->xfer($fh,$local);
32             }, sub {
33              
34 29     29   9412 my($fh, $host, $port) = @_;
35 29         426 my $ip_and_port = join(',', split(/\./, $self->client->{my_ip}), $port >> 8, $port & 0xff);
36              
37 29         74 my $w;
38             $w = AnyEvent->timer(after => 0, cb => sub {
39 29 100       1424 $self->push_command(
40             [ PORT => $ip_and_port ],
41             ($self->restart > 0 ? ([ REST => $self->restart ]) : ()),
42             $self->command,
43             );
44 29         621 undef $w;
45 29         555 });
46 29         601 };
47              
48             $self->cv->cb(sub {
49 20   33 20   317 my $res = eval { shift->recv } // $@;
  20         107  
50 20         210 $self->emit('close' => $res);
51 29         4547 });
52              
53             }
54              
55             package AnyEvent::FTP::Client::Transfer::Active::Fetch;
56              
57 2     2   15 use Moo;
  2         4  
  2         11  
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   930 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   881 use Moo;
  2         5  
  2         7  
72             extends 'AnyEvent::FTP::Client::Transfer::Active';
73              
74             with 'AnyEvent::FTP::Client::Role::ListTransfer';
75              
76             1;
77              
78             __END__