lib/Net/FTPServer/PWP/DirHandle.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 93 CC 9 SCAR 21.6
CC
9
Cov
0%
get
20.0
new
12.0
is_root
6.0
CRAP 8.6
1 package Net::FTPServer::PWP::DirHandle;
2  
3 # $Id: DirHandle.pm,v 1.6 2002/11/15 23:55:43 lem Exp $
4  
5 use 5.00500;
6 use strict;
7  
8 require Exporter;
9 use vars qw($VERSION @ISA);
10  
11 use Net::FTPServer::PWP::Handle;
12 use Net::FTPServer::Full::DirHandle;
13  
14 @ISA = qw(
15 Net::FTPServer::PWP::Handle
16 Net::FTPServer::Full::DirHandle
17 );
18  
19 =pod
20  
21 =head1 NAME
22  
23 Net::FTPServer::PWP::DirHandle - Specialized ::DirHandle for Net::FTPServer::PWP
24  
25 =head1 SYNOPSIS
26  
27 use Net::FTPServer::PWP::DirHandle;
28  
29 =head1 DESCRIPTION
30  
31 This module complements C<Net::FTPServer::PWP> by encapsulating
32 directory-handling methods. Currently, it implements the following
33 methods:
34  
35 =over
36  
37 =cut
38  
39 $VERSION = '1.10';
40  
41 =pod
42  
43 =item C<-E<gt>new()>
44  
45 Override the C<-E<gt>new> method found in
46 L<Net::FTPServer::Full::DirHandle> to support hiding the mount point
47 of the directory for the user.
48  
49 =cut
50  
51 sub new {
52 my $class = shift;
53 my $ftps = shift;
54 my $path = shift || "/";
55  
56 my $self = Net::FTPServer::Full::DirHandle->new ($ftps, $path);
57  
58 # Fix the pathname
59  
60 if ($self->{ftps}->config('hide mount point')) {
61 $self->{_pathname} = $self->{ftps}->{pwp_root_dir};
62 $self->{_pathname} =~ s!/+$!! if $path =~ m!^/!;
63 }
64  
65 $self->{_pathname} .= $path;
66  
67 # warn "DH new pathname = $self->{_pathname}\n";
68  
69 return bless $self, $class;
70 }
71  
72 =pod
73  
74 =item C<-E<gt>get($path, $self)>
75  
76 Override the C<-E<gt>get> method found in
77 L<Net::FTPServer::Full::DirHandle> to support hiding the mount point
78 of the directory for the user.
79  
80 =cut
81  
82 sub get {
83 my $self = shift;
84 my $path = shift;
85 my $s = shift;
86  
87 my $h = $self->SUPER::get($path, $s);
88  
89 return undef unless $h;
90  
91 return bless $h, 'Net::FTPServer::PWP::FileHandle'
92 if $h->isa('Net::FTPServer::FileHandle');
93  
94 return bless $h, 'Net::FTPServer::PWP::DirHandle'
95 if $h->isa('Net::FTPServer::DirHandle');
96  
97 # warn "DH get($path, $s) = $h\n";
98  
99 return undef;
100 }
101  
102 =pod
103  
104 =item C<-E<gt>is_root>
105  
106 Override the C<-E<gt>is_root> method found in
107 L<Net::FTPServer::Full::DirHandle> to support hiding the mount point
108 of the directory for the user.
109  
110 =cut
111  
112 sub is_root {
113 my $self = shift;
114  
115 if ($self->{ftps}->config('hide mount point')) {
116 return $self->{_pathname} eq $self->{ftps}->{pwp_root_dir}
117 }
118  
119 return $self->SUPER::is_root();
120 }
121  
122 =pod
123  
124 =item C<-E<gt>parent>
125  
126 Override the C<-E<gt>parent> method found in
127 L<Net::FTPServer::Full::DirHandle> to support hiding the mount point
128 of the directory for the user.
129  
130 =cut
131  
132 sub parent {
133 my $self = shift;
134  
135 return $self if $self->is_root;
136  
137 bless $self->SUPER::parent(), ref $self;
138 }
139  
140 # This method should not be here. We should
141 # use Net::FTPServer::Full::delete, but the
142 # (as of this writing) version, tickles a
143 # bug in (so far), Darwin's rmdir().
144  
145 =pod
146  
147 =item C<-E<gt>delete>
148  
149 Mac OS X 10.1.5 (darwin) seems to have a bug in C<rmdir()> when
150 its argument ends in a slash. This method works around this limitation
151 by retrying the C<rmdir()> without the slash in case of failure.
152  
153 =cut
154  
155 sub delete
156 {
157 my $self = shift;
158  
159 # XXX - It looks like rmdir() with a
160 # trailing slash, makes some OSes sick
161  
162 unless (rmdir $self->{_pathname}) {
163 my $path = $self->{_pathname};
164 $path =~ s!/+$!!;
165 length $path && rmdir $path or return -1;
166 }
167  
168 return 0;
169 }
170  
171 1;
172  
173 __END__