NAME

Path::Class::Iterator - walk a directory structure

SYNOPSIS

use Path::Class::Iterator;

my $dir = shift @ARGV || '';

my $walker = Path::Class::Iterator->new(root => $dir);

while (my $f = $walker->next)
{
  # do something with $f
  # $f is a Path::Class::Dir or Path::Class::File object

  last if $walker->done;
}

DESCRIPTION

Path::Class::Iterator walks a directory structure using an iterator. It combines the Iterator closure technique with the magic of Path::Class.

It is similar in idea to Iterator::IO and IO::Dir::Recursive but uses Path::Class objects instead of IO::All objects. It is also similar to the Path::Class next() method, but automatically acts recursively. In fact, it is similar to many recursive File::Find-type modules, but not quite exactly like them. If it were exactly like them, I wouldn't have written it. I think.

I cribbed much of the Iterator logic directly from Iterator::IO and married it with Path::Class. I'd been wanting to try something like Iterator::IO since hearing MJD's HOP talk at OSCON 2006.

METHODS

new( %opts )

Instantiate a new iterator object. %opts may include:

root

The root directory in which you want to start iterating. This parameter is required.

follow_hidden

Files and directories starting with a dot . are skipped by default. Set this to true to include these hidden items in your iterations.

Symlinks (or whatever returns true with the built-in -l flag on your system) are skipped by default. Set this to true to follow symlinks.

next

Returns the next file or directory from the P::C::I object.

start

Returns the start time in Epoch seconds that the P::C::I object was first created.

done

Returns true if the P::C::I object has run out of items to iterate over.

iterator

Returns the internal Iterator object. You probably don't want that, but just in case.

root

Returns the root param set in new().

follow_symlinks

Get/set the param set in new().

follow_hidden

Get/set the param set in new().

TODO

Breadth vs. depth option to new() for how to walk each directory.

SEE ALSO

Higher Order Perl, Mark Jason Dominus, Morgan Kauffman 2005.

http://perl.plover.com/hop/

Iterator, Iterator::IO, Path::Class, IO::Dir::Recursive, IO::Dir

AUTHOR

Peter Karman, <karman@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2006 by Peter Karman

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.