| 1 | package AnyEvent::FTP::Client::Role::FetchTransfer; | ||||||||||||||||||
| 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: Fetch transfer interface for AnyEvent::FTP objects | ||||||||||||||||||
| 9 | 24 | our $VERSION = '0.19'; # VERSION | |||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | sub xfer | ||||||||||||||||||
| 12 | { | ||||||||||||||||||
| 13 | 21 | ▶ | my($self, $fh, $local) = @_; | ||||||||||||||||
|
Subroutine
xfer: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 14 | |||||||||||||||||||
| 15 | 21 | my $handle = $self->handle($fh); | |||||||||||||||||
| 16 | |||||||||||||||||||
| 17 | 21 | ▶ | return unless defined $local; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | $handle->on_read(sub { | ||||||||||||||||||
| 20 | $handle->push_read(sub { | ||||||||||||||||||
| 21 | 38 | ▶ | $local->($_[0]{rbuf}); | ||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 22 | 38 | $_[0]{rbuf} = ''; | |||||||||||||||||
| 23 | 19 | ▶ | }); | ||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 24 | 19 | }); | |||||||||||||||||
| 25 | } | ||||||||||||||||||
| 26 | |||||||||||||||||||
| 27 | sub convert_local | ||||||||||||||||||
| 28 | { | ||||||||||||||||||
| 29 | 21 | ▶ | my($self, $local) = @_; | ||||||||||||||||
|
Subroutine
convert_local: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||
| 30 | |||||||||||||||||||
| 31 | 21 | ▶ | return unless defined $local; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 32 | 19 | ▶ | return $local if ref($local) eq 'CODE'; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 33 | |||||||||||||||||||
| 34 | 15 | ▶ | if(ref($local) eq 'SCALAR') | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 35 | { | ||||||||||||||||||
| 36 | return sub { | ||||||||||||||||||
| 37 | 22 | ▶ | $$local .= shift; | ||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 38 | 11 | }; | |||||||||||||||||
| 39 | } | ||||||||||||||||||
| 40 | elsif(ref($local) eq 'GLOB') | ||||||||||||||||||
| 41 | { | ||||||||||||||||||
| 42 | return sub { | ||||||||||||||||||
| 43 | 4 | ▶ | print $local shift; | ||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 44 | 2 | }; | |||||||||||||||||
| 45 | } | ||||||||||||||||||
| 46 | elsif(ref($local) eq '') | ||||||||||||||||||
| 47 | { | ||||||||||||||||||
| 48 | 2 | open my $fh, '>', $local; | |||||||||||||||||
| 49 | 2 | ▶ | $self->on_close(sub { close $fh }); | ||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 50 | return sub { | ||||||||||||||||||
| 51 | 4 | ▶ | print $fh shift; | ||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 52 | 2 | }; | |||||||||||||||||
| 53 | } | ||||||||||||||||||
| 54 | else | ||||||||||||||||||
| 55 | { | ||||||||||||||||||
| 56 | 0 | die 'unimplemented: ' . ref $local; | |||||||||||||||||
| 57 | } | ||||||||||||||||||
| 58 | } | ||||||||||||||||||
| 59 | |||||||||||||||||||
| 60 | sub push_command | ||||||||||||||||||
| 61 | { | ||||||||||||||||||
| 62 | 21 | ▶ | my $self = shift; | ||||||||||||||||
|
Subroutine
push_command: called CC=1 SCAR=0.8
Pod
undocumented
| |||||||||||||||||||
| 63 | my $cv = $self->{client}->push_command( | ||||||||||||||||||
| 64 | 21 | @_, | |||||||||||||||||
| 65 | ); | ||||||||||||||||||
| 66 | |||||||||||||||||||
| 67 | $cv->cb(sub { | ||||||||||||||||||
| 68 | 0 | ▶ | eval { $cv->recv }; | ||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||
| 69 | 0 | my $err = $@; | |||||||||||||||||
| 70 | 0 | ▶ | $self->{cv}->croak($err) if $err; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 71 | 21 | }); | |||||||||||||||||
| 72 | |||||||||||||||||||
| 73 | $self->on_eof(sub { | ||||||||||||||||||
| 74 | $cv->cb(sub { | ||||||||||||||||||
| 75 | 21 | ▶ | my $res = eval { $cv->recv }; | ||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||
| 76 | 21 | ▶ | $self->{cv}->send($res) unless $@; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 77 | 21 | ▶ | }); | ||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 78 | 21 | }); | |||||||||||||||||
| 79 | } | ||||||||||||||||||
| 80 | |||||||||||||||||||
| 81 | 24 | 1; | |||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||