DAVServer/DELETE.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 61 CC 8 SCAR 25.6
CC
8
Cov
0%
deleteDir
20.0
handle
12.0
deleteFile
12.0
CRAP 13.0
1  
2  
3 package HTTP::DAVServer::DELETE;
4  
5 our $VERSION=0.1;
6  
7 use strict;
8 use warnings;
9  
10 =head1 NAME
11  
12 HTTP::DAVServer::DELETE - Implements the DELETE method
13  
14 =cut
15  
16 sub handle {
17  
18 my ($self, $r, $url, $responder, $request) = @_;
19  
20 my $fullPath = $HTTP::DAVServer::ROOT . $url;
21 $url =~ m#^(.*)/([^/]+)$#;
22 my $path = $HTTP::DAVServer::ROOT . $1;
23 my $file = $2;
24  
25 if ( -d $fullPath ) {
26 $responder->multiStatus( $r, join "", deleteDir( $fullPath, $url ) );
27 }
28  
29 if ( -f $fullPath ) {
30 $responder->multiStatus( $r, deleteFile( $fullPath, $url ) );
31 }
32  
33 $responder->notFound( $r );
34  
35 }
36  
37 sub deleteFile {
38  
39 my ( $fullpath, $url ) = @_;
40  
41 my $response = qq(<response>\n<href>$HTTP::DAVServer::HOST$url</href>\n);
42 warn "DELETE $fullpath\n" if $HTTP::DAVServer::TRACE;
43 unless (unlink $fullpath) {
44 $response .= qq(<status>403 Forbidden</status>\n);
45 }
46 $response .= "</response>";
47  
48 return $response;
49  
50 }
51  
52 sub deleteDir {
53  
54 my ( $directory, $url ) = @_;
55  
56 my @responses=();
57 opendir MYDIR, $directory;
58  
59 while (my $entry = readdir MYDIR) {
60  
61 next if $entry =~ /^\.\.?$/;
62  
63 if ( -f "$directory/$entry" ) {
64 push @responses, deleteFile( "$directory/$entry", "$url/$entry" );
65 } else {
66 push @responses, deleteDir( "$directory/$entry", "$url/$entry" );
67 }
68  
69 }
70  
71 my $response = qq(<response>\n<href>$HTTP::DAVServer::HOST$url</href>\n);
72 my $resp=`rmdir $directory`;
73 warn "DELETE $directory\n" if $HTTP::DAVServer::TRACE;
74 $response .= "</response>";
75  
76 push @responses, $response;
77  
78 return @responses;
79  
80 }
81  
82 =head1 SUPPORT
83  
84 For technical support please email to jlawrenc@cpan.org ...
85 for faster service please include "HTTP::DAVServer" and "help" in your subject line.
86  
87 =head1 AUTHOR
88  
89 Jay J. Lawrence - jlawrenc@cpan.org
90 Infonium Inc., Canada
91 http://www.infonium.ca/
92  
93 =head1 COPYRIGHT
94  
95 Copyright (c) 2003 Jay J. Lawrence, Infonium Inc. All rights reserved.
96 This program is free software; you can redistribute
97 it and/or modify it under the same terms as Perl itself.
98  
99 The full text of the license can be found in the
100 LICENSE file included with this module.
101  
102 =head1 ACKNOWLEDGEMENTS
103  
104 Thank you to the authors of my prequisite modules. With out your help this code
105 would be much more difficult to write!
106  
107 XML::Simple - Grant McLean
108 XML::SAX - Matt Sergeant
109 DateTime - Dave Rolsky
110  
111 Also the authors of litmus, a very helpful tool indeed!
112  
113 =head1 SEE ALSO
114  
115 HTTP::DAV, HTTP::Webdav, http://www.webdav.org/, RFC 2518
116  
117 =cut
118  
119 1;
120