AnyEvent/FTP/Client/Role/StoreTransfer.pm

filter: Statementstmt 97.6% 42 / 43 Branchbran 92.8% 13 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 3 totaltotal 93.0% 67 / 72 SCAR 20.8
CC
8
Cov
96%
convert_local
6.0
xfer
2.0
__ANON__
2.0
CRAP 8.0
« AnyEvent/FTP/Client/Role/FetchTransfer.pm ↑ Summary AnyEvent/FTP/Client/Transfer/Passive.pm »
1 package AnyEvent::FTP::Client::Role::StoreTransfer;
2  
3 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 24 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 24 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # ABSTRACT: Store transfer interface for AnyEvent::FTP objects
9 24 our $VERSION = '0.19'; # VERSION
10  
11 sub xfer
12 {
13 25 ▶ my($self, $fh, $local) = @_;
Subroutine xfer: called CC=2 SCAR=6.9
Pod undocumented
14  
15 25 my $handle = $self->handle($fh);
16  
17 25 ▶ return unless defined $local;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $local 2 23 25
18  
19 $handle->on_drain(sub {
20 46 ▶ my $data = $local->();
Subroutine __ANON__: called CC=2 SCAR=6.9
21 46 ▶ if(defined $data)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data) { } 23 23 46
22 {
23 23 $handle->push_write($data);
24 }
25 else
26 {
27 23 $handle->push_shutdown;
28 23 $handle->destroy;
29 }
30 23 });
31 }
32  
33 sub convert_local
34 {
35 25 ▶ my($self, $local) = @_;
Subroutine convert_local: called CC=6 SCAR=17.9
Pod undocumented
36  
37 25 ▶ return unless defined $local;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $local 2 23 25
38 23 ▶ return $local if ref($local) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $local eq "CODE" 2 21 23
39  
40 21 ▶ if(ref($local) eq '')
Branch: 3 branches
BranchTrueFalseTotal
if (ref $local eq '') { } 4 17 21
elsif (ref $local eq 'SCALAR') { } 13 4 17
elsif (ref $local eq 'GLOB') { } 4 0 4
41 {
42 4 open my $fh, '<', $local;
43 4 ▶ $self->on_close(sub { close $fh });
Subroutine __ANON__: called CC=1 SCAR=0.0
44 return sub {
45 8 ▶ local $/;
Subroutine __ANON__: called CC=1 SCAR=0.0
46 8 <$fh>;
47 4 };
48 }
49 elsif(ref($local) eq 'SCALAR')
50 {
51 13 my $buffer = $$local;
52 return sub {
53 26 ▶ my $tmp = $buffer;
Subroutine __ANON__: called CC=1 SCAR=0.0
54 26 undef $buffer;
55 26 $tmp;
56 13 };
57 }
58 elsif(ref($local) eq 'GLOB')
59 {
60 sub {
61 # TODO: for big files, maybe
62 # break this up into batches
63 8 ▶ local $/;
Subroutine __ANON__: called CC=1 SCAR=0.0
64 8 <$local>;
65 4 };
66 }
67 else
68 {
69 0 die 'bad local type';
70 }
71 }
72  
73 sub push_command
74 {
75 25 ▶ my $self = shift;
Subroutine push_command: called CC=1 SCAR=0.0
Pod undocumented
76 $self->{client}->push_command(
77 25 @_,
78 $self->cv,
79 );
80 }
81  
82 24 1;
83  
84 __END__
« AnyEvent/FTP/Client/Role/FetchTransfer.pm ↑ Summary AnyEvent/FTP/Client/Transfer/Passive.pm »