1N/Apackage File::stat;
1N/Ause 5.006;
1N/A
1N/Ause strict;
1N/Ause warnings;
1N/A
1N/Aour(@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
1N/A
1N/Aour $VERSION = '1.00';
1N/A
1N/ABEGIN {
1N/A use Exporter ();
1N/A @EXPORT = qw(stat lstat);
1N/A @EXPORT_OK = qw( $st_dev $st_ino $st_mode
1N/A $st_nlink $st_uid $st_gid
1N/A $st_rdev $st_size
1N/A $st_atime $st_mtime $st_ctime
1N/A $st_blksize $st_blocks
1N/A );
1N/A %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] );
1N/A}
1N/Ause vars @EXPORT_OK;
1N/A
1N/A# Class::Struct forbids use of @ISA
1N/Asub import { goto &Exporter::import }
1N/A
1N/Ause Class::Struct qw(struct);
1N/Astruct 'File::stat' => [
1N/A map { $_ => '$' } qw{
1N/A dev ino mode nlink uid gid rdev size
1N/A atime mtime ctime blksize blocks
1N/A }
1N/A];
1N/A
1N/Asub populate (@) {
1N/A return unless @_;
1N/A my $stob = new();
1N/A @$stob = (
1N/A $st_dev, $st_ino, $st_mode, $st_nlink, $st_uid, $st_gid, $st_rdev,
1N/A $st_size, $st_atime, $st_mtime, $st_ctime, $st_blksize, $st_blocks )
1N/A = @_;
1N/A return $stob;
1N/A}
1N/A
1N/Asub lstat ($) { populate(CORE::lstat(shift)) }
1N/A
1N/Asub stat ($) {
1N/A my $arg = shift;
1N/A my $st = populate(CORE::stat $arg);
1N/A return $st if $st;
1N/A my $fh;
1N/A {
1N/A local $!;
1N/A no strict 'refs';
1N/A require Symbol;
1N/A $fh = \*{ Symbol::qualify( $arg, caller() )};
1N/A return unless defined fileno $fh;
1N/A }
1N/A return populate(CORE::stat $fh);
1N/A}
1N/A
1N/A1;
1N/A__END__
1N/A
1N/A=head1 NAME
1N/A
1N/AFile::stat - by-name interface to Perl's built-in stat() functions
1N/A
1N/A=head1 SYNOPSIS
1N/A
1N/A use File::stat;
1N/A $st = stat($file) or die "No $file: $!";
1N/A if ( ($st->mode & 0111) && $st->nlink > 1) ) {
1N/A print "$file is executable with lotsa links\n";
1N/A }
1N/A
1N/A use File::stat qw(:FIELDS);
1N/A stat($file) or die "No $file: $!";
1N/A if ( ($st_mode & 0111) && $st_nlink > 1) ) {
1N/A print "$file is executable with lotsa links\n";
1N/A }
1N/A
1N/A=head1 DESCRIPTION
1N/A
1N/AThis module's default exports override the core stat()
1N/Aand lstat() functions, replacing them with versions that return
1N/A"File::stat" objects. This object has methods that
1N/Areturn the similarly named structure field name from the
1N/Astat(2) function; namely,
1N/Adev,
1N/Aino,
1N/Amode,
1N/Anlink,
1N/Auid,
1N/Agid,
1N/Ardev,
1N/Asize,
1N/Aatime,
1N/Amtime,
1N/Actime,
1N/Ablksize,
1N/Aand
1N/Ablocks.
1N/A
1N/AYou may also import all the structure fields directly into your namespace
1N/Aas regular variables using the :FIELDS import tag. (Note that this still
1N/Aoverrides your stat() and lstat() functions.) Access these fields as
1N/Avariables named with a preceding C<st_> in front their method names.
1N/AThus, C<$stat_obj-E<gt>dev()> corresponds to $st_dev if you import
1N/Athe fields.
1N/A
1N/ATo access this functionality without the core overrides,
1N/Apass the C<use> an empty import list, and then access
1N/Afunction functions with their full qualified names.
1N/AOn the other hand, the built-ins are still available
1N/Avia the C<CORE::> pseudo-package.
1N/A
1N/A=head1 BUGS
1N/A
1N/AAs of Perl 5.8.0 after using this module you cannot use the implicit
1N/AC<$_> or the special filehandle C<_> with stat() or lstat(), trying
1N/Ato do so leads into strange errors. The workaround is for C<$_> to
1N/Abe explicit
1N/A
1N/A my $stat_obj = stat $_;
1N/A
1N/Aand for C<_> to explicitly populate the object using the unexported
1N/Aand undocumented populate() function with CORE::stat():
1N/A
1N/A my $stat_obj = File::stat::populate(CORE::stat(_));
1N/A
1N/A=head1 NOTE
1N/A
1N/AWhile this class is currently implemented using the Class::Struct
1N/Amodule to build a struct-like class, you shouldn't rely upon this.
1N/A
1N/A=head1 AUTHOR
1N/A
1N/ATom Christiansen