| 1 | package POE::Component::IRC::Plugin::FTP::EasyUpload; | ||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '0.003'; | |||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 9 | 1 | ▶ | use POE qw(Component::Net::FTP); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 10 | 1 | ▶ | use Devel::TakeHashArgs; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 11 | 1 | ▶ | use POE::Component::IRC::Plugin qw( :ALL ); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||
| 13 | 0 | ▶ | sub new { | ||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||
| 14 | 0 | my $class = shift; | |||||||||||||||||||||||
| 15 | 0 | ▶ | get_args_as_hash( \@_, \ my %args, { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 16 | port => 21, | ||||||||||||||||||||||||
| 17 | timeout => 30, | ||||||||||||||||||||||||
| 18 | pub_uri => '', | ||||||||||||||||||||||||
| 19 | retries => 5, | ||||||||||||||||||||||||
| 20 | verbose_error => 1, | ||||||||||||||||||||||||
| 21 | tag => qr/<irc_ftp:(.+?):(.*?):(.*?)>/, | ||||||||||||||||||||||||
| 22 | }, | ||||||||||||||||||||||||
| 23 | [ qw(host login pass) ], | ||||||||||||||||||||||||
| 24 | [ | ||||||||||||||||||||||||
| 25 | qw( host login pass obj_args timeout pub_uri debug | ||||||||||||||||||||||||
| 26 | retries tag port verbose_error unique | ||||||||||||||||||||||||
| 27 | ) | ||||||||||||||||||||||||
| 28 | ], | ||||||||||||||||||||||||
| 29 | ) or croak $@; | ||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||
| 32 | $args{pub_uri} = $args{host} | ||||||||||||||||||||||||
| 33 | 0 | ▶ | unless defined $args{pub_uri}; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||
| 35 | 0 | my $self = bless \%args, $class; | |||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||
| 37 | 0 | return $self; | |||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||
| 40 | 0 | ▶ | sub PCI_register { | ||||||||||||||||||||||
|
Subroutine
PCI_register: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 41 | 0 | my ($self, $irc) = @_; | |||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||
| 43 | 0 | $self->{irc} = $irc; | |||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||
| 45 | 0 | $irc->plugin_register( $self, 'USER', qw(privmsg notice) ); | |||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||
| 47 | 0 | $self->{session_id} = POE::Session->create( | |||||||||||||||||||||||
| 48 | object_states => [ | ||||||||||||||||||||||||
| 49 | $self => [qw(_start _processed _shutdown)], | ||||||||||||||||||||||||
| 50 | ], | ||||||||||||||||||||||||
| 51 | )->ID(); | ||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||
| 53 | 0 | return 1; | |||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||
| 56 | 0 | ▶ | sub U_privmsg { my $self = shift; $self->_process( @_ ); } | ||||||||||||||||||||||
|
Subroutine
U_privmsg: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 57 | 0 | ▶ | sub U_notice { my $self = shift; $self->_process( @_ ); } | ||||||||||||||||||||||
|
Subroutine
U_notice: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||
| 59 | 0 | ▶ | sub _process { | ||||||||||||||||||||||
|
Subroutine
_process: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||
| 60 | 0 | my ( $self, $irc, $out_ref ) = @_; | |||||||||||||||||||||||
| 61 | $self->{debug} | ||||||||||||||||||||||||
| 62 | 0 | ▶ | and carp "OUT: $$out_ref"; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( my ( $file, $dir, $prefix ) = $$out_ref =~ /$self->{tag}/ ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 66 | 0 | ▶ | $prefix = '' | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 67 | unless defined $prefix; | ||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||
| 69 | $self->{debug} | ||||||||||||||||||||||||
| 70 | 0 | ▶ | and carp "[ file => $file, dir => $dir, prefix => $prefix ]"; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||
| 72 | $self->{poco}->process( { | ||||||||||||||||||||||||
| 73 | event => '_processed', | ||||||||||||||||||||||||
| 74 | session => $self->{session_id}, | ||||||||||||||||||||||||
| 75 | _out => $$out_ref, | ||||||||||||||||||||||||
| 76 | _try => 0, | ||||||||||||||||||||||||
| 77 | _prefix => $prefix, | ||||||||||||||||||||||||
| 78 | commands => [ | ||||||||||||||||||||||||
| 79 | { new => [ | ||||||||||||||||||||||||
| 80 | $self->{host}, | ||||||||||||||||||||||||
| 81 | Timeout => $self->{timeout}, | ||||||||||||||||||||||||
| 82 | Port => $self->{port}, | ||||||||||||||||||||||||
| 83 | 0 | ▶ | @{ $self->{obj_args} || [] }, | ||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/2
$self->{'obj_args'} || []
MC/DC0%0/1
$self->{'obj_args'} || []
$self->{'obj_args'}
Truth table0%0/2
A
A= $self->{'obj_args'}
| |||||||||||||||||||||||||
| 84 | ], | ||||||||||||||||||||||||
| 85 | }, | ||||||||||||||||||||||||
| 86 | { login => [ $self->{login}, $self->{pass} ] }, | ||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||
| 88 | defined $dir ? ( { cwd => [ $dir ] } ) : (), | ||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||
| 90 | 0 | $self->{unique} ? { put_unique => [ $file ] } | |||||||||||||||||||||||
| 91 | : { put => [ $file ] }, | ||||||||||||||||||||||||
| 92 | ], | ||||||||||||||||||||||||
| 93 | }, | ||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||
| 96 | 0 | return PCI_EAT_ALL; | |||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||
| 98 | 0 | return PCI_EAT_NONE; | |||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||
| 101 | 0 | ▶ | sub _processed { | ||||||||||||||||||||||
|
Subroutine
_processed: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||
| 102 | 0 | my ( $kernel, $self, $in_ref ) = @_[ KERNEL, OBJECT, ARG0 ]; | |||||||||||||||||||||||
| 103 | 0 | my $out_message; | |||||||||||||||||||||||
| 104 | 0 | ▶ | if ( $in_ref->{is_error} ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 105 | $self->{debug} | ||||||||||||||||||||||||
| 106 | and carp "FTP error on $in_ref->{error} command: " | ||||||||||||||||||||||||
| 107 | 0 | ▶ | . $in_ref->{last_error}; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||
| 109 | 0 | ▶ | if ( $self->{retries} < $in_ref->{_try}++ ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 110 | $self->{debug} | ||||||||||||||||||||||||
| 111 | 0 | ▶ | and carp "Retring after error [retry # $in_ref->{_try}]"; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||
| 113 | 0 | delete @$in_ref{ qw(error responses) }; | |||||||||||||||||||||||
| 114 | 0 | $self->{poco}->process( $in_ref ); | |||||||||||||||||||||||
| 115 | 0 | return; | |||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||
| 117 | 0 | $in_ref->{last_error} =~ s/\n|\r//g; | |||||||||||||||||||||||
| 118 | $out_message = $self->{verbose_error} | ||||||||||||||||||||||||
| 119 | 0 | ▶ | ? "[FTP Error: $in_ref->{last_error}]" | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 120 | : '[FTP Error]'; | ||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||
| 122 | else { | ||||||||||||||||||||||||
| 123 | $out_message = $self->{pub_uri} | ||||||||||||||||||||||||
| 124 | . $in_ref->{_prefix} | ||||||||||||||||||||||||
| 125 | 0 | . $in_ref->{responses}[-1][0]; | |||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||
| 127 | 0 | $in_ref->{_out} =~ s/$self->{tag}/$out_message/g; | |||||||||||||||||||||||
| 128 | 0 | $kernel->post( $self->{irc} => quote => $in_ref->{_out} ); | |||||||||||||||||||||||
| 129 | 0 | return; | |||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||
| 132 | 0 | ▶ | sub PCI_unregister { | ||||||||||||||||||||||
|
Subroutine
PCI_unregister: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 133 | 0 | my ($self, $irc) = @_; | |||||||||||||||||||||||
| 134 | 0 | $poe_kernel->call( $self->{session_id} => '_shutdown' ); | |||||||||||||||||||||||
| 135 | 0 | delete $self->{irc}; | |||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||
| 137 | 0 | return 1; | |||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||
| 140 | 0 | ▶ | sub _start { | ||||||||||||||||||||||
|
Subroutine
_start: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||
| 141 | 0 | my ( $kernel, $self ) = @_[KERNEL, OBJECT]; | |||||||||||||||||||||||
| 142 | 0 | $self->{session_id} = $_[SESSION]->ID(); | |||||||||||||||||||||||
| 143 | 0 | $kernel->refcount_increment( $self->{session_id}, __PACKAGE__ ); | |||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||
| 145 | $self->{poco} = POE::Component::Net::FTP->spawn( | ||||||||||||||||||||||||
| 146 | 0 | ▶ | $self->{debug} ? ( debug => $self->{debug} ) : () | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||
| 149 | 0 | return; | |||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||
| 152 | 0 | ▶ | sub _shutdown { | ||||||||||||||||||||||
|
Subroutine
_shutdown: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||
| 153 | 0 | my ( $kernel, $self ) = @_[KERNEL, OBJECT]; | |||||||||||||||||||||||
| 154 | 0 | $self->{poco}->shutdown; | |||||||||||||||||||||||
| 155 | 0 | $kernel->alarm_remove_all(); | |||||||||||||||||||||||
| 156 | 0 | $kernel->refcount_decrement( $self->{session_id}, __PACKAGE__ ); | |||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||
| 158 | 0 | return; | |||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||
| 161 | 1 | 1; | |||||||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||||||