Manual integration error in #12235.
[p5sagit/p5-mst-13.2.git] / lib / File / stat.pm
CommitLineData
36477c24 1package File::stat;
3b825e41 2use 5.006;
3
36477c24 4use strict;
b395063c 5use warnings;
36477c24 6
17f410f9 7our(@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
8
b75c8c73 9our $VERSION = '1.00';
10
36477c24 11BEGIN {
12 use Exporter ();
36477c24 13 @EXPORT = qw(stat lstat);
14 @EXPORT_OK = qw( $st_dev $st_ino $st_mode
15 $st_nlink $st_uid $st_gid
16 $st_rdev $st_size
17 $st_atime $st_mtime $st_ctime
18 $st_blksize $st_blocks
19 );
20 %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] );
21}
d8574e8f 22use vars @EXPORT_OK;
36477c24 23
8cc95fdb 24# Class::Struct forbids use of @ISA
25sub import { goto &Exporter::import }
26
ee28235b 27use Class::Struct qw(struct);
36477c24 28struct 'File::stat' => [
29 map { $_ => '$' } qw{
30 dev ino mode nlink uid gid rdev size
31 atime mtime ctime blksize blocks
32 }
33];
34
35sub populate (@) {
36 return unless @_;
37 my $stob = new();
38 @$stob = (
39 $st_dev, $st_ino, $st_mode, $st_nlink, $st_uid, $st_gid, $st_rdev,
40 $st_size, $st_atime, $st_mtime, $st_ctime, $st_blksize, $st_blocks )
41 = @_;
42 return $stob;
43}
44
14d597e2 45sub lstat ($) { populate(CORE::lstat(shift)) }
36477c24 46
47sub stat ($) {
48 my $arg = shift;
49 my $st = populate(CORE::stat $arg);
50 return $st if $st;
51 no strict 'refs';
52 require Symbol;
53 return populate(CORE::stat \*{Symbol::qualify($arg)});
54}
55
561;
57__END__
58
59=head1 NAME
60
2ae324a7 61File::stat - by-name interface to Perl's built-in stat() functions
36477c24 62
63=head1 SYNOPSIS
64
65 use File::stat;
66 $st = stat($file) or die "No $file: $!";
67 if ( ($st->mode & 0111) && $st->nlink > 1) ) {
68 print "$file is executable with lotsa links\n";
69 }
70
71 use File::stat qw(:FIELDS);
72 stat($file) or die "No $file: $!";
73 if ( ($st_mode & 0111) && $st_nlink > 1) ) {
74 print "$file is executable with lotsa links\n";
75 }
76
77=head1 DESCRIPTION
78
79This module's default exports override the core stat()
80and lstat() functions, replacing them with versions that return
81"File::stat" objects. This object has methods that
82return the similarly named structure field name from the
83stat(2) function; namely,
84dev,
85ino,
86mode,
87nlink,
88uid,
89gid,
90rdev,
91size,
92atime,
93mtime,
94ctime,
95blksize,
96and
97blocks.
98
99You may also import all the structure fields directly into your namespace
100as regular variables using the :FIELDS import tag. (Note that this still
101overrides your stat() and lstat() functions.) Access these fields as
102variables named with a preceding C<st_> in front their method names.
103Thus, C<$stat_obj-E<gt>dev()> corresponds to $st_dev if you import
104the fields.
105
106To access this functionality without the core overrides,
107pass the C<use> an empty import list, and then access
108function functions with their full qualified names.
109On the other hand, the built-ins are still available
110via the C<CORE::> pseudo-package.
111
112=head1 NOTE
113
8cc95fdb 114While this class is currently implemented using the Class::Struct
36477c24 115module to build a struct-like class, you shouldn't rely upon this.
116
117=head1 AUTHOR
118
119Tom Christiansen