1N/Apackage DirHandle;
1N/A
1N/Aour $VERSION = '1.00';
1N/A
1N/A=head1 NAME
1N/A
1N/ADirHandle - supply object methods for directory handles
1N/A
1N/A=head1 SYNOPSIS
1N/A
1N/A use DirHandle;
1N/A $d = new DirHandle ".";
1N/A if (defined $d) {
1N/A while (defined($_ = $d->read)) { something($_); }
1N/A $d->rewind;
1N/A while (defined($_ = $d->read)) { something_else($_); }
1N/A undef $d;
1N/A }
1N/A
1N/A=head1 DESCRIPTION
1N/A
1N/AThe C<DirHandle> method provide an alternative interface to the
1N/Aopendir(), closedir(), readdir(), and rewinddir() functions.
1N/A
1N/AThe only objective benefit to using C<DirHandle> is that it avoids
1N/Anamespace pollution by creating globs to hold directory handles.
1N/A
1N/A=head1 NOTES
1N/A
1N/A=over 4
1N/A
1N/A=item *
1N/A
1N/AOn Mac OS (Classic), the path separator is ':', not '/', and the
1N/Acurrent directory is denoted as ':', not '.'. You should be careful
1N/Aabout specifying relative pathnames. While a full path always begins
1N/Awith a volume name, a relative pathname should always begin with a
1N/A':'. If specifying a volume name only, a trailing ':' is required.
1N/A
1N/A=back
1N/A
1N/A=cut
1N/A
1N/Arequire 5.000;
1N/Ause Carp;
1N/Ause Symbol;
1N/A
1N/Asub new {
1N/A @_ >= 1 && @_ <= 2 or croak 'usage: new DirHandle [DIRNAME]';
1N/A my $class = shift;
1N/A my $dh = gensym;
1N/A if (@_) {
1N/A DirHandle::open($dh, $_[0])
1N/A or return undef;
1N/A }
1N/A bless $dh, $class;
1N/A}
1N/A
1N/Asub DESTROY {
1N/A my ($dh) = @_;
1N/A closedir($dh);
1N/A}
1N/A
1N/Asub open {
1N/A @_ == 2 or croak 'usage: $dh->open(DIRNAME)';
1N/A my ($dh, $dirname) = @_;
1N/A opendir($dh, $dirname);
1N/A}
1N/A
1N/Asub close {
1N/A @_ == 1 or croak 'usage: $dh->close()';
1N/A my ($dh) = @_;
1N/A closedir($dh);
1N/A}
1N/A
1N/Asub read {
1N/A @_ == 1 or croak 'usage: $dh->read()';
1N/A my ($dh) = @_;
1N/A readdir($dh);
1N/A}
1N/A
1N/Asub rewind {
1N/A @_ == 1 or croak 'usage: $dh->rewind()';
1N/A my ($dh) = @_;
1N/A rewinddir($dh);
1N/A}
1N/A
1N/A1;