/usr/lib/perl5/IO/Dirent.pm is in libio-dirent-perl 0.05-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | package IO::Dirent;
use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
require Exporter;
require DynaLoader;
@ISA = qw(Exporter DynaLoader);
@EXPORT_OK = qw( DT_UNKNOWN
DT_FIFO
DT_CHR
DT_DIR
DT_BLK
DT_REG
DT_LNK
DT_SOCK
DT_WHT
);
@EXPORT = qw( readdirent nextdirent );
%EXPORT_TAGS = ('ALL' => [@EXPORT, @EXPORT_OK]);
$VERSION = '0.05';
use constant DT_UNKNOWN => 0;
use constant DT_FIFO => 1; ## named pipe (fifo)
use constant DT_CHR => 2; ## character special
use constant DT_DIR => 4; ## directory
use constant DT_BLK => 6; ## block special
use constant DT_REG => 8; ## regular
use constant DT_LNK => 10; ## symbolic link
use constant DT_SOCK => 12; ## socket
use constant DT_WHT => 14; ## whiteout
bootstrap IO::Dirent $VERSION;
1;
__END__
=head1 NAME
IO::Dirent - Access to dirent structs returned by readdir
=head1 SYNOPSIS
use IO::Dirent;
## slurp-style
opendir DIR, "/usr/local/foo";
my @entries = readdirent(DIR);
closedir DIR;
print $entries[0]->{name}, "\n";
print $entries[0]->{type}, "\n";
print $entries[0]->{inode}, "\n";
## using the enumerator
opendir DIR, "/etc";
while( my $entry = nextdirent(DIR) ) {
print $entry->{name} . "\n";
}
closedir DIR;
=head1 DESCRIPTION
B<readdirent> returns a list of hashrefs. Each hashref contains the
name of the directory entry, its inode for the filesystem it resides
on and its type (if available). If the file type or inode are not
available, it won't be there!
B<nextdirent> returns the next dirent as a hashref, allowing you to
iterate over directory entries one by one. This may be helpful in
low-memory situations or where you have enormous directories.
B<IO::Dirent> exports the following symbols by default:
readdirent
nextdirent
The following tags may be exported to your namespace:
ALL
which includes B<readdirent>, B<nextdirent> and the following symbols:
DT_UNKNOWN
DT_FIFO
DT_CHR
DT_DIR
DT_BLK
DT_REG
DT_LNK
DT_SOCK
DT_WHT
These symbols can be used to test the file type returned by
B<readdirent> in the following manner:
for my $entry ( readdirent(DIR) ) {
next unless $entry->{'type'} == DT_LNK;
print $entry->{'name'} . " is a symbolic link.\n";
}
For platforms that do not implement file type in its dirent struct,
B<readdirent> will return a hashref with a single key/value of 'name'
and the filename (effectively the same as readdir). This is subject
to change, if I can implement some of the to do items below.
=head1 CAVEATS
This was written on FreeBSD and OS X which implement a robust (but
somewhat non-standard) dirent struct and which includes a file type
entry. I have plans to make this module more portable and useful by
doing a stat on each directory entry to find the file type and inode
number when the dirent.h does not implement it otherwise.
Improvements and additional ports are welcome.
=head1 TO DO
=over 4
=item *
For platforms that do not implement a dirent struct with file type,
do a stat on the entry and populate the structure anyway.
=item *
Do some memory profiling (I'm not sure if I have any leaks or not).
=back
=head1 COPYRIGHT
Copyright 2002, 2011 Scott Wiersdorf.
This library is free software; you can redistribute it and/or modify
it under the terms of the Perl Artistic License.
=head1 AUTHOR
Scott Wiersdorf, E<lt>scott@perlcode.orgE<gt>
=head1 ACKNOWLEDGEMENTS
Thanks to Nick Ing-Simmons for his help on the perl-xs mailing list.
=head1 SEE ALSO
dirent(5), L<perlxstut>, L<perlxs>, L<perlguts>, L<perlapi>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2007 by Scott Wiersdorf
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.1 or,
at your option, any later version of Perl 5 you may have available.
=cut
|