DirDB-FTP
view release on metacpan or search on metacpan
$ftp->rmdir( "$rootpath$key", 'recurse' );
return $retval;
};
sub CLEAR{
my ($ref , $key, $value) = @_;
my ($ftp,$rootpath) = @{$ref};
# maybe we can delete the whole thing?
# we will check to make sure this succeeds because we
# want to support clearing a whole directory that we
# have been issued by an administrator
$ftp->rmdir($rootpath, 'recurse')
and
$ftp->mkdir($rootpath)
and
return;
my @dirents = $ftp->ls($rootpath);
for my $ent (@dirents){
$ftp->delete("$rootpath$ent")
or
$ftp->rmdir("$rootpath$ent",1)
};
};
{
my %IteratorListings;
sub FIRSTKEY {
my ($ref , $key, $value) = @_;
my ($ftp,$rootpath) = @{$ref};
# opendir FSDBFH, $path or croak "opendir $path: $!";
# $IteratorListings{$ref} = [ grep {!($_ =~ /^\.\.?\Z/)} readdir FSDBFH ];
$IteratorListings{$ref} = [ $ftp->ls ];
$ref->NEXTKEY;
};
sub NEXTKEY{
my $ref = shift;
my ($ftp,$rootpath) = @{$ref};
#print "next key in path <$$ref> will be shifted from <@{$IteratorListings{$ref}}>\n";
@{$IteratorListings{$ref}} or return undef;
my $key = shift @{$IteratorListings{$ref}};
if ($key =~ s/^ //){
if ($key = m/^ /){
# we have unescaped a leading space.
}elsif ($key eq 'EMPTY'){
$key = ''
#}elsif($key eq 'REF'){
# return $ref->NEXTKEY(); # next
#}elsif($key =~ m/^ARRAY){
# return $ref->NEXTKEY(); # next
}else{
# per-container metadata does not
# appear in iterations through data.
return $ref->NEXTKEY(); # next
}
};
wantarray or return $key;
return @{[$key, $ref->FETCH($key)]};
};
sub DESTROY{
# no warnings;
delete $IteratorListings{$_[0]};
};
};
1;
__END__
=head1 NAME
DirDB::FTP - Perl extension to use a remote directory as a database
=head1 SYNOPSIS
use DirDB::FTP;
my $ftp = DirDB::FTP->new('some.host.name',$username,$password);
tie my %entries, DirDB::FTP, $ftp, => "/blog_entries";
$entries{'entry for '.localtime} = $entry_text;
=head1 DESCRIPTION
DirDB::FTP is a package that lets you access a DirDB
hash on a remote machine, through the FTP server.
The semantics of DirDB (version 0.06) are followed, including
directory locking and recursive memory loading on directory deletion.
Net::FTP is used for the connection, including the Net::FTP::blat
extensions.
Most actions can be done with ftp method return values, but
differentiating between directories and non=existent files is
done by parsing the C<message> for the phrase 'no such file'
so if you are using DirDB::FTP against a FTP server that issues
a different errore message when there is no such file, you
will have to edit your copy of the module.
The underlying object is an array containing the Net::FTP
connection object and the absolute path to
the directory, modulo any chrooting the FTP server might do
based on the provided credentials, of course.
Keys are names within the directory, values
are the contents of the files.
A leading space is used as an escape character, the empty
string as a key becomes ' EMPTY' just like in DirDB.
( run in 0.428 second using v1.01-cache-2.11-cpan-71847e10f99 )