M: Added entryList() method.

This commit is contained in:
Jens Luedicke
2013-03-09 13:51:52 +01:00
parent 0a3f85d5bf
commit 42b1a13c62

View File

@@ -19,12 +19,12 @@ use strict;
use Carp; use Carp;
use File::Basename; use File::Basename;
use File::Spec; use File::Spec::Functions qw(no_upwards splitdir catfile);
use constant SUCCESS => 1; use constant SUCCESS => 1;
use constant FAILED => 0; use constant FAILED => 0;
use constant ABORTED => -1; use constant ABORTED => -1;
use constant PRUNE => -10; use constant PRUNE => -10;
sub new { sub new {
my ($class) = @_; my ($class) = @_;
@@ -37,11 +37,10 @@ sub new {
$self->{onDirLeave} = sub { SUCCESS }; $self->{onDirLeave} = sub { SUCCESS };
$self->{depth} = 0; $self->{depth} = 0;
$self->{depthCount} = 0; $self->{depthCount} = 0;
$self->{count} = 0; $self->{entryList} = [];
$self->{count} = 0;
# $self->{customResponse} = {};
return $self; return $self;
} }
@@ -124,6 +123,11 @@ sub count {
return $self->{count}; return $self->{count};
} }
sub entryList {
my ($self) = @_;
return $self->{entryList};
}
sub walk { sub walk {
my ($self,$path) = @_; my ($self,$path) = @_;
@@ -150,22 +154,19 @@ sub walk {
} }
opendir (my $dirh, $path) || return FAILED; opendir (my $dirh, $path) || return FAILED;
my @dir_contents = readdir $dirh; $self->{entryList} = [ no_upwards(readdir $dirh) ];
@dir_contents = File::Spec->no_upwards(@dir_contents); $self->{count} = scalar @{$self->{entryList}};
$self->{count} = scalar @dir_contents;
++$self->{depthCount}; ++$self->{depthCount};
if ((my $r = $self->{onDirEnter}->($path)) != SUCCESS) { if ((my $r = $self->{onDirEnter}->($path)) != SUCCESS) {
return $r; return $r;
} }
# be portable. # be portable.
my @dirs = File::Spec->splitdir($path); my @dirs = splitdir($path);
foreach my $f (@{$self->{entryList}}) {
foreach my $f (@dir_contents) {
# be portable. # be portable.
my $path = File::Spec->catfile(@dirs, $f); my $path = catfile(@dirs, $f);
my $r = $self->walk($path); my $r = $self->walk($path);
@@ -333,6 +334,11 @@ Returns the current base name of the current path:
Returns the number of elements wthin the current directory. Returns the number of elements wthin the current directory.
Excludes . and .. Excludes . and ..
=item entryList
Returns an array reference to the elements wthin the current directory.
Excludes . and ..
=item walk($path) =item walk($path)
Begin the walk through the given directory tree. This method returns if the walk Begin the walk through the given directory tree. This method returns if the walk