M: Added currentDepth() method.
The getDepth() method will return the default (or user-specified) directory traversel depth. Calling the setDepth method with a negative value will make the method die.
This commit is contained in:
@@ -87,10 +87,19 @@ sub onDirLeave {
|
|||||||
|
|
||||||
sub setDepth {
|
sub setDepth {
|
||||||
my ($self,$v) = @_;
|
my ($self,$v) = @_;
|
||||||
|
if ($v < 0) {
|
||||||
|
croak("Directory depth is negative: $v");
|
||||||
|
}
|
||||||
|
|
||||||
$self->{depth} = $v;
|
$self->{depth} = $v;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getDepth {
|
sub getDepth {
|
||||||
|
my ($self) = @_;
|
||||||
|
return $self->{depth};
|
||||||
|
}
|
||||||
|
|
||||||
|
sub currentDepth {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
return $self->{depthCount};
|
return $self->{depthCount};
|
||||||
}
|
}
|
||||||
@@ -268,10 +277,16 @@ Specify a function to be run when leaving a directory.
|
|||||||
|
|
||||||
Set the directory traversal depth. Once the specified directory depth
|
Set the directory traversal depth. Once the specified directory depth
|
||||||
has been reached, the C<walk> method returns. The default value is 0.
|
has been reached, the C<walk> method returns. The default value is 0.
|
||||||
|
Precondition: The value has to be positive. The method will die
|
||||||
|
if called with a negative value.
|
||||||
|
|
||||||
=item getDepth
|
=item getDepth
|
||||||
|
|
||||||
Returns the directory traversal depth.
|
Returns the user-specified directory traversal depth. The default value is 0.
|
||||||
|
|
||||||
|
=item currentDepth
|
||||||
|
|
||||||
|
Returns the current directory traversal depth.
|
||||||
|
|
||||||
=item currentDir
|
=item currentDir
|
||||||
|
|
||||||
@@ -369,7 +384,7 @@ version can be found on GitHub: L<https://github.com/nullmedium/File-DirWalk>
|
|||||||
|
|
||||||
=head1 CHANGES
|
=head1 CHANGES
|
||||||
|
|
||||||
Version 0.5: bugfixes.
|
Version 0.5: bugfixes, improved testing, new currentDepth() method.
|
||||||
|
|
||||||
Version 0.4: add more methods, better testing, more documentation.
|
Version 0.4: add more methods, better testing, more documentation.
|
||||||
|
|
||||||
|
|||||||
6
t/1.t
6
t/1.t
@@ -11,6 +11,12 @@ $dw = new File::DirWalk();
|
|||||||
|
|
||||||
ok( ref($dw) eq 'File::DirWalk' );
|
ok( ref($dw) eq 'File::DirWalk' );
|
||||||
|
|
||||||
|
is ($dw->getDepth(), 0);
|
||||||
|
dies_ok { $dw->setDepth(-1) };
|
||||||
|
is ($dw->getDepth(), 0);
|
||||||
|
ok ($dw->setDepth(1));
|
||||||
|
is ($dw->getDepth(), 1);
|
||||||
|
|
||||||
ok ($dw->setHandler(onBeginWalk => sub { SUCCESS }));
|
ok ($dw->setHandler(onBeginWalk => sub { SUCCESS }));
|
||||||
ok ($dw->setHandler(onLink => sub { SUCCESS }));
|
ok ($dw->setHandler(onLink => sub { SUCCESS }));
|
||||||
ok ($dw->setHandler(onFile => sub { SUCCESS }));
|
ok ($dw->setHandler(onFile => sub { SUCCESS }));
|
||||||
|
|||||||
Reference in New Issue
Block a user