Iterator-IO
view release on metacpan or search on metacpan
=for gpg
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
=head1 NAME
Iterator::IO - Filesystem and stream iterators.
=head1 VERSION
This documentation describes version 0.02 of Iterator::IO.pm, August 23, 2005.
=cut
use strict;
use warnings;
package Iterator::IO;
our $VERSION = '0.02';
use base 'Exporter';
use vars qw/@EXPORT @EXPORT_OK %EXPORT_TAGS/;
@EXPORT = qw(idir_listing idir_walk ifile ifile_reverse);
@EXPORT_OK = @EXPORT;
use Iterator;
# Function name: idir_listing
# Synopsis: $iter = idir_listing ($path)
# Description: Returns the full file names in the specified directory.
# Created: 07/28/2005 by EJR
# Parameters: $path - Directory. If omitted, uses current dir.
# Returns: Iterator
# Exceptions: Iterator::X::Am_Now_Exhausted
sub idir_listing
{
require IO::Dir;
require Cwd;
my $path = shift || Cwd::getcwd();
$path =~ s|/ \z||x; # remove any trailing slash
my $d = new IO::Dir $path;
Iterator::X::IO_Error (message => qq{Cannot read "$path": $!},
error => $!)
unless $d;
return Iterator->new (sub
{
# Get next file, skipping . and ..
my $next;
while (1)
{
$next = $d->read;
if (! defined $next)
{
undef $d; # allow garbage collection
Iterator::is_done();
}
last if $next ne '.' && $next ne '..';
=item * I/O Errors
Class: C<Iterator::X::IO_Error>
This exception is thrown when any sort of I/O error occurs; this
only happens with the filesystem iterators.
This exception has one method, C<os_error>, which returns the original
C<$!> that was trapped by the Iterator object.
As a string, this exception provides some human-readable information
along with C<$!>.
=item * Internal Errors
Class: C<Iterator::X::Internal_Error>
Something happened that I thought couldn't possibly happen. I would
appreciate it if you could send me an email message detailing the
circumstances of the error.
=back
=head1 REQUIREMENTS
Requires the following additional modules:
L<Iterator>
L<IO::Dir> and L<Cwd> are required if you use L</idir_listing> or
L</idir_walk>.
L<IO::File> is required if you use L</ifile> or L</ifile_reverse>
=head1 SEE ALSO
I<Higher Order Perl>, Mark Jason Dominus, Morgan Kauffman 2005.
L<http://perl.plover.com/hop/>
=head1 THANKS
Much thanks to Will Coleda and Paul Lalli (and the RPI lily crowd in
general) for suggestions for the pre-release version.
=head1 AUTHOR / COPYRIGHT
Eric J. Roode, roode@cpan.org
Copyright (c) 2005 by Eric J. Roode. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
To avoid my spam filter, please include "Perl", "module", or this
module's name in the message's subject line, and/or GPG-sign your
message.
=cut
=begin gpg
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)
iD8DBQFDC5SrY96i4h5M0egRAnaKAJ9VJIIEh1DqBRhw0wyk4ceczcRw0ACg9QOs
6bT8QG6x/dRiXj17nuiyWmk=
=VvwS
-----END PGP SIGNATURE-----
=end gpg
( run in 0.801 second using v1.01-cache-2.11-cpan-df04353d9ac )