blib/lib/POE/Component/IRC/Plugin/FTP/EasyUpload.pm

filter: Statementstmt 27.7% 20 / 72 Branchbran 0.0% 0 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 6 / 15 Podpod 20.0% 1 / 5 totaltotal 22.1% 27 / 122 SCAR 50.0
CC
16
Cov
20%
_process
72.0
_processed
42.0
new
12.0
CRAP 149.0
↑ Summary Build »
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.002';
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 sub new {
14 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
15 0 ▶ get_args_as_hash( \@_, \ my %args, {
Branch: 1 branch
BranchTrueFalseTotal
get_args_as_hash(\@_, \my %args, {"port", 21, "timeout", 30, "pub_uri", "", "retries", 5, "verbose_error", 1, "tag", qr/<irc_ftp:(.+?):(.*?):(.*?)>/}, ["host", "login", "pass"], ["host", "login", "pass", "obj_args", "timeout", "pub_uri", "debug", "retries", "tag", "port", "verbose_error", "unique"]) or croak($@) 0 0 0
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
BranchTrueFalseTotal
unless defined $args{"pub_uri"} 0 0 0
34  
35 0 my $self = bless \%args, $class;
36  
37 0 return $self;
38 }
39  
40 sub PCI_register {
41 0 ▶ my ($self, $irc) = @_;
Subroutine PCI_register: not called CC=1 SCAR=6.9
Pod undocumented
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 sub _process {
60 0 ▶ my ( $self, $irc, $out_ref ) = @_;
Subroutine _process: not called CC=8 SCAR=42.8
61 $self->{debug}
62 0 ▶ and carp "OUT: $$out_ref";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"debug"} and carp("OUT: $$out_ref") 0 0 0
63  
64
65 0 ▶ if ( my ( $file, $dir, $prefix ) = $$out_ref =~ /$self->{tag}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $$out_ref =~ /$self->{"tag"}/) 0 0 0
66 0 ▶ $prefix = ''
Branch: 1 branch
BranchTrueFalseTotal
unless defined $prefix 0 0 0
67 unless defined $prefix;
68  
69 $self->{debug}
70 0 ▶ and carp "[ file => $file, dir => $dir, prefix => $prefix ]";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"debug"} and carp("[ file => $file, dir => $dir, prefix => $prefix ]") 0 0 0
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: 3 branches
BranchTrueFalseTotal
$self->{"obj_args"} or [] 0 0 0
defined $dir ? : 0 0 0
$self->{'unique'} ? : 0 0 0
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 sub _processed {
102 0 ▶ my ( $kernel, $self, $in_ref ) = @_[ KERNEL, OBJECT, ARG0 ];
Subroutine _processed: not called CC=6 SCAR=37.4
103 0 my $out_message;
104 0 ▶ if ( $in_ref->{is_error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_ref->{'is_error'}) { } 0 0 0
105 $self->{debug}
106 and carp "FTP error on $in_ref->{error} command: "
107 0 ▶ . $in_ref->{last_error};
Branch: 1 branch
BranchTrueFalseTotal
$self->{"debug"} and carp(qq[FTP error on $in_ref->{"error"} command: ] . $in_ref->{"last_error"}) 0 0 0
108  
109 0 ▶ if ( $self->{retries} < $in_ref->{_try}++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"retries"} < $in_ref->{"_try"}++) 0 0 0
110 $self->{debug}
111 0 ▶ and carp "Retring after error [retry # $in_ref->{_try}]";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"debug"} and carp(qq[Retring after error [retry # $in_ref->{"_try"}]]) 0 0 0
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
BranchTrueFalseTotal
$self->{'verbose_error'} ? : 0 0 0
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 sub PCI_unregister {
133 0 ▶ my ($self, $irc) = @_;
Subroutine PCI_unregister: not called CC=1 SCAR=6.9
Pod undocumented
134 0 $poe_kernel->call( $self->{session_id} => '_shutdown' );
135 0 delete $self->{irc};
136  
137 0 return 1;
138 }
139  
140 sub _start {
141 0 ▶ my ( $kernel, $self ) = @_[KERNEL, OBJECT];
Subroutine _start: not called CC=2 SCAR=17.9
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
BranchTrueFalseTotal
$self->{'debug'} ? : 0 0 0
147 );
148  
149 0 return;
150 }
151  
152 sub _shutdown {
153 0 ▶ my ( $kernel, $self ) = @_[KERNEL, OBJECT];
Subroutine _shutdown: not called CC=1 SCAR=6.9
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__
↑ Summary Build »