lib/App/Followme/UploadFtp.pm

filter: Statementstmt 28.5% 22 / 77 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 46.6% 7 / 15 Podpod 75.0% 6 / 8 totaltotal 27.3% 35 / 128 CC 15 SCAR 27.5
CC
15
Cov
21%
add_file
42.0
open
20.0
add_directory
12.0
CRAP 15.6
« blib/lib/auto/share/dist/App-Followme/bundle.pl ↑ Summary lib/App/Followme/UploadSite.pm »
1 package App::Followme::UploadFtp;
2  
3 1 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use lib '../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use base qw(App::Followme::ConfiguredObject);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Net::FTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Spec::Functions qw(abs2rel splitdir catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our $VERSION = "2.03";
14  
15 #----------------------------------------------------------------------
16 # Read the default parameter values
17  
18 0 ▶sub parameters {
Subroutine parameters: not called CC=1 SCAR=6.9
Pod documented
19 0 my ($pkg) = @_;
20  
21 return (
22 0 ftp_url => '',
23 remote_directory => '',
24 ftp_debug => 0,
25 remote_pkg => 'File::Spec::Unix',
26 );
27 }
28  
29 #----------------------------------------------------------------------
30 # Add a directory to the remote site
31  
32 0 ▶sub add_directory {
Subroutine add_directory: not called CC=3 SCAR=24.8
Pod documented
33 0 my ($self, $dir) = @_;
34  
35 0 my $status;
36 0 $dir = $self->remote_name($dir);
37  
38 0 ▶ if ($self->{ftp}->ls($dir)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'ftp'}->ls($dir)) { } 0 0 0
elsif ($self->{'ftp'}->mkdir($dir)) { } 0 0 0
39 0 $status = 1;
40 } elsif ($self->{ftp}->mkdir($dir)) {
41 0 $status = 1;
42 }
43  
44 0 return $status;
45 }
46  
47 #----------------------------------------------------------------------
48 # Add a file to the remote site
49  
50 0 ▶sub add_file {
Subroutine add_file: not called CC=6 SCAR=37.4
Pod documented
51 0 my ($self, $local_filename, $remote_filename) = @_;
52  
53 0 my $status;
54 0 $remote_filename = $self->remote_name($remote_filename);
55  
56 # Delete file if already there
57 0 ▶ if ($self->{ftp}->mdtm($remote_filename)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ftp"}->mdtm($remote_filename)) 0 0 0
58 0 $self->{ftp}->delete($remote_filename);
59 }
60  
61 # Change upload mode if necessary
62 0 ▶ if (-B $local_filename) {
Branch: 2 branches
BranchTrueFalseTotal
if (-B $local_filename) { } 0 0 0
elsif (not $self->{'ascii'}) { } 0 0 0
63 0 ▶ if ($self->{ascii}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ascii"}) 0 0 0
64 0 $self->{ftp}->binary();
65 0 $self->{ascii} = 0;
66 }
67  
68 } elsif (! $self->{ascii}) {
69 0 $self->{ftp}->ascii();
70 0 $self->{ascii} = 1;
71 }
72  
73 # Upload the file
74 0 ▶ if ($self->{ftp}->put($local_filename, $remote_filename)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ftp"}->put($local_filename, $remote_filename)) 0 0 0
75 0 $status = 1;
76 }
77  
78 0 return $status;
79 }
80  
81 #----------------------------------------------------------------------
82 # Close the ftp connection
83  
84 0 ▶sub close {
Subroutine close: not called CC=1 SCAR=6.9
Pod documented
85 0 my ($self) = @_;
86  
87 0 $self->{ftp}->quit();
88 0 undef $self->{ftp};
89  
90 0 return;
91 }
92  
93 #----------------------------------------------------------------------
94 # Delete a directory on the remote site, including contents
95  
96 0 ▶sub delete_directory {
Subroutine delete_directory: not called CC=3 SCAR=24.8
Pod documented
97 0 my ($self, $dir) = @_;
98  
99 0 my $status;
100 0 $dir = $self->remote_name($dir);
101  
102 0 ▶ if ($self->{ftp}->ls($dir)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'ftp'}->ls($dir)) { } 0 0 0
103 0 ▶ if ($self->{ftp}->rmdir($dir)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ftp"}->rmdir($dir)) 0 0 0
104 0 $status = 1;
105 }
106  
107 } else {
108 0 $status = 1;
109 }
110  
111 0 return $status;
112 }
113  
114 #----------------------------------------------------------------------
115 # Delete a file on the remote site
116  
117 0 ▶sub delete_file {
Subroutine delete_file: not called CC=3 SCAR=24.8
Pod documented
118 0 my ($self, $filename) = @_;
119  
120 0 my $status;
121 0 $filename = $self->remote_name($filename);
122  
123 0 ▶ if ($self->{ftp}->mdtm($filename)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'ftp'}->mdtm($filename)) { } 0 0 0
124 0 ▶ if ($self->{ftp}->delete($filename)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ftp"}->delete($filename)) 0 0 0
125 0 $status = 1;
126 }
127  
128 } else {
129 0 $status = 1;
130 }
131  
132 0 return 1;
133 }
134  
135 #----------------------------------------------------------------------
136 # Open the connection to the remote site
137  
138 0 ▶sub open {
Subroutine open: not called CC=4 SCAR=30.0
Pod undocumented
139 0 my ($self, $user, $password) = @_;
140  
141 # Open the ftp connection
142  
143 my $ftp = Net::FTP->new($self->{ftp_url}, Debug => $self->{ftp_debug})
144 0 ▶ or die "Cannot connect to $self->{ftp_url}: $@";
Branch: 1 branch
BranchTrueFalseTotal
my $ftp = "Net::FTP"->new($self->{"ftp_url"}, "Debug", $self->{"ftp_debug"}) or die qq[Cannot connect to $self->{"ftp_url"}: $@] 0 0 0
145  
146 0 ▶ $ftp->login($user, $password) or die "Cannot login ", $ftp->message;
Branch: 1 branch
BranchTrueFalseTotal
$ftp->login($user, $password) or die "Cannot login ", $ftp->message 0 0 0
147  
148 $ftp->cwd($self->{remote_directory})
149 0 ▶ or die "Cannot change remote directory ", $ftp->message;
Branch: 1 branch
BranchTrueFalseTotal
$ftp->cwd($self->{"remote_directory"}) or die "Cannot change remote directory ", $ftp->message 0 0 0
150  
151 0 $ftp->binary();
152  
153 0 $self->{ftp} = $ftp;
154 0 $self->{ascii} = 0;
155  
156 0 return;
157 }
158  
159 #----------------------------------------------------------------------
160 # Get the name of the file on the remote system
161  
162 0 ▶sub remote_name {
Subroutine remote_name: not called CC=1 SCAR=6.9
Pod undocumented
163 0 my ($self, $remote_filename) = @_;
164  
165 0 my @path = splitdir($remote_filename);
166 0 $remote_filename = $self->{remote}->catfile(@path);
167 0 return $remote_filename;
168 }
169  
170 1 1;
171 __END__
« blib/lib/auto/share/dist/App-Followme/bundle.pl ↑ Summary lib/App/Followme/UploadSite.pm »