File Coverage

blib/lib/AnyEvent/FTP/Client/Role/StoreTransfer.pm
Criterion Covered Total %
statement 39 40 97.5
branch 13 14 92.8
condition n/a
subroutine 12 12 100.0
pod 0 3 0.0
total 64 69 92.7


line stmt bran cond sub pod time code
1             package AnyEvent::FTP::Client::Role::StoreTransfer;
2              
3 24     24   15619 use strict;
  24         68  
  24         801  
4 24     24   140 use warnings;
  24         64  
  24         634  
5 24     24   443 use 5.010;
  24         106  
6 24     24   139 use Moo::Role;
  24         67  
  24         192  
7              
8             # ABSTRACT: Store transfer interface for AnyEvent::FTP objects
9             our $VERSION = '0.17'; # VERSION
10              
11             sub xfer
12             {
13 25     25 0 77 my($self, $fh, $local) = @_;
14              
15 25         142 my $handle = $self->handle($fh);
16              
17 25 100       117 return unless defined $local;
18              
19             $handle->on_drain(sub {
20 46     46   3069 my $data = $local->();
21 46 100       203 if(defined $data)
22             {
23 23         89 $handle->push_write($data);
24             }
25             else
26             {
27 23         94 $handle->push_shutdown;
28             }
29 23         239 });
30             }
31              
32             sub convert_local
33             {
34 25     25 0 107 my($self, $local) = @_;
35              
36 25 100       119 return unless defined $local;
37 23 100       122 return $local if ref($local) eq 'CODE';
38              
39 21 100       165 if(ref($local) eq '')
    100          
    50          
40             {
41 4         165 open my $fh, '<', $local;
42 4     4   118 $self->on_close(sub { close $fh });
  4         157  
43             return sub {
44 8     8   44 local $/;
45 8         222 <$fh>;
46 4         47 };
47             }
48             elsif(ref($local) eq 'SCALAR')
49             {
50 13         45 my $buffer = $$local;
51             return sub {
52 26     26   60 my $tmp = $buffer;
53 26         55 undef $buffer;
54 26         77 $tmp;
55 13         162 };
56             }
57             elsif(ref($local) eq 'GLOB')
58             {
59             sub {
60             # TODO: for big files, maybe
61             # break this up into batches
62 8     8   39 local $/;
63 8         214 <$local>;
64 4         57 };
65             }
66             else
67             {
68 0         0 die 'bad local type';
69             }
70             }
71              
72             sub push_command
73             {
74 25     25 0 76 my $self = shift;
75             $self->{client}->push_command(
76 25         774 @_,
77             $self->cv,
78             );
79             }
80              
81             1;
82              
83             __END__