File Coverage

blib/lib/POE/Component/Net/FTP.pm
Criterion Covered Total %
statement 19 56 33.9
branch 0 28 0.0
condition 0 13 0.0
subroutine 7 11 63.6
pod 1 1 100.0
total 27 109 24.7


line stmt bran cond sub pod time code
1             package POE::Component::Net::FTP;
2              
3 1     1   265415 use warnings;
  1         3  
  1         36  
4 1     1   6 use strict;
  1         1  
  1         52  
5              
6             our $VERSION = '0.001';
7              
8 1     1   5 use Carp;
  1         8  
  1         74  
9 1     1   5 use POE;
  1         2  
  1         6  
10 1     1   348 use Net::FTP;
  1         8  
  1         42  
11 1     1   4 use base 'POE::Component::NonBlockingWrapper::Base';
  1         2  
  1         870  
12              
13             my %True_False_Commands = map { $_ => 1 }
14             qw( new login authorize ascii binary rename delete
15             cwd cdup restart rmdir mkdir alloc
16             nlst list retr stor stou appe port
17             pasv_xfer pasv_xfer_unique pasv_wait abort quit
18             );
19              
20             my %Undef_On_Fail_Commands = map { $_ => 1 }
21             qw( site pwd get put put_unique append unique_name
22             mdtm size pasv quot
23             );
24              
25             my %In_List_Context_Commands = map { $_ => 1 }
26             qw( ls dir feature);
27             # feature will return empty list if feature is not supported
28              
29             my %In_Scalar_Context_No_Fail_Commands = map { $_ => 1 }
30             qw(supported hash);
31              
32             sub _methods_define {
33 1     1   372 return ( process => '_wheel_entry', );
34             }
35              
36             sub process {
37 0     0 1   $poe_kernel->post( shift->{session_id} => process => @_ );
38             }
39              
40             sub _check_args {
41 0     0     my ( $self, $in_ref ) = @_;
42 0 0 0       exists $in_ref->{commands}
43             or carp "Missing `commands` argument"
44             and return;
45              
46 0           return 1;
47             }
48              
49             sub _prepare_wheel {
50 0     0     my $self = shift;
51 0 0         $self->{stop_on_error} = 1
52             unless exists $self->{stop_on_error};
53             }
54              
55             sub _process_request {
56 0     0     my ( $self, $in_ref ) = @_;
57              
58 0           my @responses;
59 0           my ( $is_error, $last_error );
60 0           for ( @{ $in_ref->{commands} } ) {
  0            
61             last
62 0 0 0       if $self->{stop_on_error} and $is_error;
63              
64 0           my ( $command, $options_ref ) = %$_;
65 0           $command = lc $command;
66 0           eval {
67 0 0         if ( $command eq 'new' ) {
    0          
    0          
    0          
    0          
68 0 0 0       $self->{obj} = Net::FTP->new( @$options_ref )
      0        
      0        
69             or push @responses, [ $@ ]
70             and $is_error = $command
71             and $last_error = $@
72             and next;
73 0           push @responses, [ 1 ];
74             }
75             elsif ( exists $True_False_Commands{ $command } ) {
76 0 0         if ( my $res = $self->{obj}->$command( @$options_ref ) ) {
77 0           push @responses, [ $res ];
78             }
79             else {
80 0           my $error = $self->{obj}->message;
81 0           push @responses, [ $error ];
82 0           $is_error = $command;
83 0           $last_error = $error;
84             }
85             }
86             elsif ( exists $Undef_On_Fail_Commands{ $command } ) {
87 0 0         if ( defined(
88             my $res = $self->{obj}->$command( @$options_ref )
89             ) ) {
90 0           push @responses, [ $res ];
91             }
92             else {
93 0           my $error = $self->{obj}->message;
94 0           push @responses, [ $error ];
95 0           $is_error = $command;
96             }
97             }
98             elsif ( exists $In_List_Context_Commands{ $command } ) {
99 0           push @responses,
100             [ $self->{obj}->$command( @$options_ref ) ];
101             }
102             elsif ( exists $In_Scalar_Context_No_Fail_Commands{ $command } ) {
103 0           push @responses,
104             [ scalar $self->{obj}->$command( @$options_ref ) ];
105             }
106             else {
107 0           croak "Invalid command `$command` was specified";
108             }
109             };
110 0 0         if ( $@ ) { carp "Fatal error occured during execution: $@\n"; }
  0            
111             }
112              
113 0 0         $in_ref->{is_error} = $is_error
114             if $is_error;
115              
116 0 0         $in_ref->{last_error} = $last_error
117             if $last_error;
118              
119 0           $in_ref->{responses} = \@responses;
120             }
121              
122             1;
123             __END__