package File::Listing;
sub Version { $VERSION; }
$VERSION = "5.814";
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(parse_dir);
use strict;
use Carp ();
use HTTP::Date qw(str2time);
sub parse_dir ($;$$$)
{
my($dir, $tz, $fstype, $error) = @_;
$fstype ||= 'unix';
$fstype = "File::Listing::" . lc $fstype;
my @args = $_[0];
push(@args, $tz) if(@_ >= 2);
push(@args, $error) if(@_ >= 4);
$fstype->parse(@args);
}
sub line { Carp::croak("Not implemented yet"); }
sub init { } # Dummy sub
sub file_mode ($)
{
# This routine was originally borrowed from Graham Barr's
# Net::FTP package.
local $_ = shift;
my $mode = 0;
my($type,$ch);
s/^(.)// and $type = $1;
while (/(.)/g) {
$mode <<= 1;
$mode |= 1 if $1 ne "-" &&
$1 ne 'S' &&
$1 ne 't' &&
$1 ne 'T';
}
$type eq "d" and $mode |= 0040000 or # Directory
$type eq "l" and $mode |= 0120000 or # Symbolic Link
$mode |= 0100000; # Regular File
$mode |= 0004000 if /^...s....../i;
$mode |= 0002000 if /^......s.../i;
$mode |= 0001000 if /^.........t/i;
$mode;
}
sub parse
{
my($pkg, $dir, $tz, $error) = @_;
# First let's try to determine what kind of dir parameter we have
# received. We allow both listings, reference to arrays and
# file handles to read from.
if (ref($dir) eq 'ARRAY') {
# Already splitted up
}
elsif (ref($dir) eq 'GLOB') {
# A file handle
}
elsif (ref($dir)) {
Carp::croak("Illegal argument to parse_dir()");
}
elsif ($dir =~ /^\*\w+(::\w+)+$/) {
# This scalar looks like a file handle, so we assume it is
}
else {
# A normal scalar listing
$dir = [ split(/\n/, $dir) ];
}
$pkg->init();
my @files = ();
if (ref($dir) eq 'ARRAY') {
for (@$dir) {
push(@files, $pkg->line($_, $tz, $error));
}
}
else {
=1= |