AnyEvent/FTP/Server/Context/FS.pm

filter: Statementstmt 93.7% 149 / 159 Branchbran 82.6% 38 / 46 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 34 / 34 Podpod 9.0% 2 / 22 totaltotal 85.6% 226 / 264 SCAR 32.4
CC
25
Cov
91%
cmd_rnto
6.5
cmd_rnfr
5.3
cmd_size
4.0
CRAP 25.4
« AnyEvent/FTP/Client.pm ↑ Summary AnyEvent/FTP/Client/Role/RequestBuffer.pm »
1 package AnyEvent::FTP::Server::Context::FS;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use File::chdir;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 extends 'AnyEvent::FTP::Server::Context';
11  
12 # ABSTRACT: FTP server context that uses real file system (no transfers)
13 12 our $VERSION = '0.19'; # VERSION
14  
15  
16 12 with 'AnyEvent::FTP::Server::Role::Auth';
17 12 with 'AnyEvent::FTP::Server::Role::Help';
18 12 with 'AnyEvent::FTP::Server::Role::Old';
19 12 with 'AnyEvent::FTP::Server::Role::Type';
20  
21  
22 sub cwd
23 {
24 217 ▶ my($self, $value) = @_;
Subroutine cwd: called CC=3 SCAR=11.0
Pod documented
25 217 ▶ $self->{cwd} = $value if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 38 179 217
26 217 ▶ $self->{cwd} //= '/';
Condition100%2/2
$self->{"cwd"} //= "/"
l!l
18532
MC/DC100%1/1
$self->{"cwd"} //= "/"
$self->{"cwd"}
Truth table100%2/2
A
A= $self->{"cwd"}
Aresult
11
00
27 }
28  
29  
30 sub rename_from
31 {
32 18 ▶ my($self, $value) = @_;
Subroutine rename_from: called CC=2 SCAR=6.9
Pod documented
33 18 ▶ $self->{rename_from} = $value if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 6 12 18
34 18 $self->{rename_from};
35 }
36  
37  
38 1 ▶sub help_cwd { 'CWD <sp> pathname' }
Subroutine help_cwd: called CC=1 SCAR=0.0
Pod undocumented
39  
40 sub cmd_cwd
41 {
42 36 ▶ my($self, $con, $req) = @_;
Subroutine cmd_cwd: called CC=3 SCAR=11.0
Pod undocumented
43  
44 36 my $dir = $req->args;
45  
46 36 eval {
47 36 ▶ die unless $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 2 34 36
48 12 ▶ use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 34 local $CWD = $self->cwd;
50 34 $CWD = $dir;
51 33 $self->cwd($CWD);
52 33 $con->send_response(250 => 'CWD command successful');
53 };
54 36 ▶ $con->send_response(550 => 'CWD error') if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 3 33 36
55  
56 36 $self->done;
57 }
58  
59  
60 1 ▶sub help_cdup { 'CDUP' }
Subroutine help_cdup: called CC=1 SCAR=0.0
Pod undocumented
61  
62 sub cmd_cdup
63 {
64 5 ▶ my($self, $con, $req) = @_;
Subroutine cmd_cdup: called CC=2 SCAR=6.9
Pod undocumented
65  
66 5 eval {
67 12 ▶ use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 5 local $CWD = $self->cwd;
69 5 $CWD = File::Spec->updir;
70 5 $self->cwd($CWD);
71 5 $con->send_response(250 => 'CDUP command successful');
72 };
73 5 ▶ $con->send_response(550 => 'CDUP error') if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 5 5
74  
75 5 $self->done;
76 }
77  
78  
79 1 ▶sub help_pwd { 'PWD' }
Subroutine help_pwd: called CC=1 SCAR=0.0
Pod undocumented
80  
81 sub cmd_pwd
82 {
83 9 ▶ my($self, $con, $req) = @_;
Subroutine cmd_pwd: called CC=2 SCAR=7.6
Pod undocumented
84  
85 9 my $cwd = $self->cwd;
86 9 ▶ if($^O eq 'MSWin32')
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 9 9
87 {
88 0 (undef,$cwd) = File::Spec->splitpath($cwd, 1);
89 0 $cwd =~ s{\\}{/}g;
90 }
91 9 $con->send_response(257 => "\"$cwd\" is the current directory");
92 9 $self->done;
93 }
94  
95  
96 1 ▶sub help_size { 'SIZE <sp> pathname' }
Subroutine help_size: called CC=1 SCAR=0.0
Pod undocumented
97  
98 sub cmd_size
99 {
100 12 ▶ my($self, $con, $req) = @_;
Subroutine cmd_size: called CC=4 SCAR=13.9
Pod undocumented
101  
102 12 eval {
103 12 ▶ use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
104 12 local $CWD = $self->cwd;
105 12 ▶ if(-f $req->args)
Branch: 2 branches
BranchTrueFalseTotal
if (-f $req->args) { } 8 4 12
elsif (-e $req->args) { } 2 2 4
106 {
107 8 my $size = -s $req->args;
108 8 $con->send_response(213 => $size);
109 }
110 elsif(-e $req->args)
111 {
112 2 $con->send_response(550 => $req->args . ": not a regular file");
113 }
114 else
115 {
116 2 die;
117 }
118 };
119 12 ▶ if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 2 10 12
120 {
121 2 $con->send_response(550 => $req->args . ": No such file or directory");
122 }
123 12 $self->done;
124 }
125  
126  
127 1 ▶sub help_mkd { 'MKD <sp> pathname' }
Subroutine help_mkd: called CC=1 SCAR=0.0
Pod undocumented
128  
129 sub cmd_mkd
130 {
131 7 ▶ my($self, $con, $req) = @_;
Subroutine cmd_mkd: called CC=2 SCAR=6.9
Pod undocumented
132  
133 7 my $dir = $req->args;
134 7 eval {
135 12 ▶ use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
136 7 local $CWD = $self->cwd;
137 7 mkdir $dir;
138 5 $con->send_response(257 => "Directory created");
139 };
140 7 ▶ $con->send_response(550 => "MKD error") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 2 5 7
141 7 $self->done;
142 }
143  
144  
145 1 ▶sub help_rmd { 'RMD <sp> pathname' }
Subroutine help_rmd: called CC=1 SCAR=0.0
Pod undocumented
146  
147 sub cmd_rmd
148 {
149 9 ▶ my($self, $con, $req) = @_;
Subroutine cmd_rmd: called CC=2 SCAR=6.9
Pod undocumented
150  
151 9 my $dir = $req->args;
152 9 eval {
153 12 ▶ use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
154 9 local $CWD = $self->cwd;
155 9 rmdir $dir;
156 5 $con->send_response(250 => "Directory removed");
157 };
158 9 ▶ $con->send_response(550 => "RMD error") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 4 5 9
159 9 $self->done;
160 }
161  
162  
163 1 ▶sub help_dele { 'DELE <sp> pathname' }
Subroutine help_dele: called CC=1 SCAR=0.0
Pod undocumented
164  
165 sub cmd_dele
166 {
167 10 ▶ my($self, $con, $req) = @_;
Subroutine cmd_dele: called CC=2 SCAR=6.9
Pod undocumented
168  
169 10 my $file = $req->args;
170 10 eval {
171 12 ▶ use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
172 10 local $CWD = $self->cwd;
173 10 unlink $file;
174 5 $con->send_response(250 => "File removed");
175 };
176 10 ▶ $con->send_response(550 => "DELE error") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 5 5 10
177 10 $self->done;
178 }
179  
180  
181 1 ▶sub help_rnfr { 'RNFR <sp> pathname' }
Subroutine help_rnfr: called CC=1 SCAR=0.0
Pod undocumented
182  
183 sub cmd_rnfr
184 {
185 10 ▶ my($self, $con, $req) = @_;
Subroutine cmd_rnfr: called CC=5 SCAR=16.6
Pod undocumented
186  
187 10 my $path = $req->args;
188  
189 10 ▶ if($path)
Branch: 1 branch
BranchTrueFalseTotal
if ($path) { } 8 2 10
190 {
191 8 eval {
192 8 local $CWD = $self->cwd;
193 8 ▶ if(!-e $path)
Branch: 2 branches
BranchTrueFalseTotal
if (not -e $path) { } 2 6 8
elsif (-w $path) { } 6 0 6
194 {
195 2 $con->send_response(550 => 'No such file or directory');
196 }
197 elsif(-w $path)
198 {
199 6 $self->rename_from($path);
200 6 $con->send_response(350 => 'File or directory exists, ready for destination name');
201 }
202 else
203 {
204 0 $con->send_response(550 => 'Permission denied');
205 }
206 };
207 8 ▶ if(my $error = $@)
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 8 8
208 {
209 0 warn $error;
210 0 $con->send_response(550 => 'Rename failed');
211 }
212 }
213 else
214 {
215 2 $con->send_response(501 => 'Invalid number of arguments');
216 }
217 10 $self->done;
218 }
219  
220  
221 1 ▶sub help_rnto { 'RNTO <sp> pathname' }
Subroutine help_rnto: called CC=1 SCAR=0.0
Pod undocumented
222  
223 sub cmd_rnto
224 {
225 6 ▶ my($self, $con, $req) = @_;
Subroutine cmd_rnto: called CC=5 SCAR=18.7
Pod undocumented
226  
227 6 my $path = $req->args;
228  
229 6 ▶ if(! defined $self->rename_from)
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $self->rename_from) { } 0 6 6
elsif (not $path) { } 0 6 6
230 {
231 0 $con->send_response(503 => 'Bad sequence of commands');
232 }
233 elsif(!$path)
234 {
235 0 $con->send_response(501 => 'Invalid number of arguments');
236 }
237 else
238 {
239 6 eval {
240 6 local $CWD = $self->cwd;
241 6 ▶ if(! -e $path)
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $path) { } 6 0 6
242 {
243 6 rename $self->rename_from, $path;
244 6 $con->send_response(250 => 'Rename successful');
245 }
246 else
247 {
248 0 $con->send_response(550 => 'File already exists');
249 }
250 };
251 6 ▶ if(my $error = $@)
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 6 6
252 {
253 0 warn $error;
254 0 $con->send_response(550 => 'Rename failed');
255 }
256 }
257 6 $self->done;
258 }
259  
260  
261 1 ▶sub help_stat { 'STAT [<sp> pathname]' }
Subroutine help_stat: called CC=1 SCAR=0.0
Pod undocumented
262  
263 sub cmd_stat
264 {
265 9 ▶ my($self, $con, $req) = @_;
Subroutine cmd_stat: called CC=4 SCAR=13.9
Pod undocumented
266  
267 9 my $path = $req->args;
268  
269 9 ▶ if($path)
Branch: 1 branch
BranchTrueFalseTotal
if ($path) { } 6 3 9
270 {
271 6 do {
272 6 local $CWD = $self->cwd;
273 6 ▶ if(-d $path)
Branch: 2 branches
BranchTrueFalseTotal
if (-d $path) { } 3 3 6
elsif (-f $path) { } 2 1 3
274 {
275 3 $con->send_response(211 => "it's a directory");
276 }
277 elsif(-f $path)
278 {
279 2 $con->send_response(211 => "it's a file");
280 }
281 else
282 {
283 1 $con->send_response(450 => 'No such file or directory');
284 }
285 };
286 }
287 else
288 {
289 # TODO: did I have a good reason for making this
290 # not be an error?
291 3 $con->send_response(211 => "it's all good.");
292 }
293 9 $self->done;
294 }
295  
296 12 1;
297  
298 __END__
« AnyEvent/FTP/Client.pm ↑ Summary AnyEvent/FTP/Client/Role/RequestBuffer.pm »