File Coverage

blib/lib/Net/FTPServer/DirHandle.pm
Criterion Covered Total %
statement 37 43 86.0
branch 3 4 75.0
condition 1 2 50.0
subroutine 9 15 60.0
pod 9 9 100.0
total 59 73 80.8


line stmt bran cond sub pod time code
1             # -*- perl -*-
2              
3             # Net::FTPServer A Perl FTP Server
4             # Copyright (C) 2000 Bibliotech Ltd., Unit 2-3, 50 Carnwath Road,
5             # London, SW6 3EG, United Kingdom.
6             #
7             # This program is free software; you can redistribute it and/or modify
8             # it under the terms of the GNU General Public License as published by
9             # the Free Software Foundation; either version 2 of the License, or
10             # (at your option) any later version.
11             #
12             # This program is distributed in the hope that it will be useful,
13             # but WITHOUT ANY WARRANTY; without even the implied warranty of
14             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15             # GNU General Public License for more details.
16             #
17             # You should have received a copy of the GNU General Public License
18             # along with this program; if not, write to the Free Software
19             # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20              
21             =pod
22              
23             =head1 NAME
24              
25             Net::FTPServer::DirHandle - A Net::FTPServer directory handle.
26              
27             =head1 SYNOPSIS
28              
29             use Net::FTPServer::DirHandle;
30              
31             =head1 METHODS
32              
33             =cut
34              
35             package Net::FTPServer::DirHandle;
36              
37 75     75   422 use strict;
  75         127  
  75         2040  
38              
39 75     75   349 use vars qw($VERSION);
  75         120  
  75         4778  
40             ( $VERSION ) = '$Revision: 1.1 $ ' =~ /\$Revision:\s+([^\s]+)/;
41              
42 75     75   432 use Carp qw(confess);
  75         136  
  75         2817  
43              
44 75     75   416 use Net::FTPServer::Handle;
  75         213  
  75         1558  
45              
46 75     75   311 use vars qw(@ISA);
  75         116  
  75         26387  
47              
48             @ISA = qw(Net::FTPServer::Handle);
49              
50             =pod
51              
52             =over 4
53              
54             =item $dirh = new Net::FTPServer::DirHandle ($ftps);
55              
56             Create a new directory handle. The directory handle corresponds to "/".
57              
58             =cut
59              
60             sub new
61             {
62 74     74 1 155 my $class = shift;
63 74         124 my $ftps = shift;
64              
65             # Only internal calls will supply the $path argument. It must end
66             # with a "/".
67 74   50     209 my $path = shift || "/";
68              
69 74         593 my $self = Net::FTPServer::Handle->new ($ftps);
70 74         392 $self->{_pathname} = $path;
71              
72 74         269 return bless $self, $class;
73             }
74              
75             =pod
76              
77             =item $dirh = $dirh->parent;
78              
79             Return the parent directory of the directory C<$dirh>. If
80             the directory is already "/", this returns the same directory handle.
81              
82             =cut
83              
84             sub parent
85             {
86 2     2 1 3 my $self = shift;
87              
88             # Already in "/" ?
89 2 50       6 return $self if $self->is_root;
90              
91 2         4 my $new_pathname = $self->{_pathname};
92 2         14 $new_pathname =~ s,[^/]*/$,,;
93              
94 2         6 return Net::FTPServer::DirHandle->new ($self->{ftps}, $new_pathname);
95             }
96              
97             =pod
98              
99             =item $rv = $dirh->is_root;
100              
101             Return true if the current directory is the root directory.
102              
103             =cut
104              
105             sub is_root
106             {
107 5     5 1 10 my $self = shift;
108              
109 5         17 return $self->{_pathname} eq "/";
110             }
111              
112             =pod
113              
114             =item $handle = $dirh->get ($filename);
115              
116             Return the file or directory C<$handle> corresponding to
117             the file C<$filename> in directory C<$dirh>. If there is
118             no file or subdirectory of that name, then this returns
119             undef.
120              
121             =cut
122              
123             sub get
124             {
125 0     0 1 0 confess "virtual function";
126             }
127              
128             =pod
129              
130             =item $ref = $dirh->list ([$wildcard]);
131              
132             Return a list of the contents of directory C<$dirh>. The list
133             returned is a reference to an array of pairs:
134              
135             [ $filename, $handle ]
136              
137             The list returned does I include "." or "..".
138              
139             The list is sorted into alphabetical order automatically.
140              
141             =cut
142              
143             sub list
144             {
145 0     0 1 0 confess "virtual function";
146             }
147              
148              
149             =pod
150              
151             =item $ref = $dirh->_list_status ([$wildcard]);
152              
153             Just a dumb wrapper function. Returns the same thing as
154             list_status(), but also includes the special directories
155             "." and ".." if no wildcard is specified.
156              
157             =cut
158              
159             sub _list_status
160             {
161 3     3   5 my $self = shift;
162 3         5 my $wildcard = shift;
163 3         6 my @array = ();
164 3 100       7 unless ($wildcard)
165             {
166             # I suppose that there will be some FTP clients out there which
167             # will get confused if they don't see . and .. entries.
168 1         9 push (@array, [ ".", $self ]);
169 1         5 push (@array, [ "..", $self->parent ]);
170             }
171 3         6 push (@array, @{ $self->list_status ($wildcard) });
  3         16  
172 3         9 return \@array;
173             }
174              
175             =pod
176              
177             =item $ref = $dirh->list_status ([$wildcard]);
178              
179             Return a list of the contents of directory C<$dirh> and
180             status information. The list returned is a reference to
181             an array of triplets:
182              
183             [ $filename, $handle, $statusref ]
184              
185             where $statusref is the tuple returned from the C
186             method (see L).
187              
188             The list returned does I include "." or "..".
189              
190             The list is sorted into alphabetical order automatically.
191              
192             =cut
193              
194             sub list_status
195             {
196 0     0 1   confess "virtual function";
197             }
198              
199             =item $rv = $dirh->delete;
200              
201             Delete the current directory. If the delete command was
202             successful, then return 0, else if there was an error return -1.
203              
204             It is normally only possible to delete a directory if it
205             is empty.
206              
207             =cut
208              
209             sub delete
210             {
211 0     0 1   confess "virtual function";
212             }
213              
214             =item $rv = $dirh->mkdir ($name);
215              
216             Create a subdirectory called C<$name> within the current directory
217             C<$dirh>.
218              
219             =cut
220              
221             sub mkdir
222             {
223 0     0 1   confess "virtual function";
224             }
225              
226             =item $file = $dirh->open ($filename, "r"|"w"|"a");
227              
228             Open or create a file called C<$filename> in the current directory,
229             opening it for either read, write or append. This function
230             returns a C handle object.
231              
232             =cut
233              
234             sub open
235             {
236 0     0 1   confess "virtual function";
237             }
238              
239             1 # So that the require or use succeeds.
240              
241             __END__