1File::stat(3pm)        Perl Programmers Reference Guide        File::stat(3pm)
2
3
4

NAME

6       File::stat - by-name interface to Perl's built-in stat() functions
7

SYNOPSIS

9        use File::stat;
10        $st = stat($file) or die "No $file: $!";
11        if ( ($st->mode & 0111) && $st->nlink > 1) ) {
12            print "$file is executable with lotsa links\n";
13        }
14
15        if ( -x $st ) {
16            print "$file is executable\n";
17        }
18
19        use Fcntl "S_IRUSR";
20        if ( $st->cando(S_IRUSR, 1) ) {
21            print "My effective uid can read $file\n";
22        }
23
24        use File::stat qw(:FIELDS);
25        stat($file) or die "No $file: $!";
26        if ( ($st_mode & 0111) && ($st_nlink > 1) ) {
27            print "$file is executable with lotsa links\n";
28        }
29

DESCRIPTION

31       This module's default exports override the core stat() and lstat()
32       functions, replacing them with versions that return "File::stat"
33       objects.  This object has methods that return the similarly named
34       structure field name from the stat(2) function; namely, dev, ino, mode,
35       nlink, uid, gid, rdev, size, atime, mtime, ctime, blksize, and blocks.
36
37       As of version 1.02 (provided with perl 5.12) the object provides "-X"
38       overloading, so you can call filetest operators ("-f", "-x", and so on)
39       on it. It also provides a "->cando" method, called like
40
41        $st->cando( ACCESS, EFFECTIVE )
42
43       where ACCESS is one of "S_IRUSR", "S_IWUSR" or "S_IXUSR" from the Fcntl
44       module, and EFFECTIVE indicates whether to use effective (true) or real
45       (false) ids. The method interprets the "mode", "uid" and "gid" fields,
46       and returns whether or not the current process would be allowed the
47       specified access.
48
49       If you don't want to use the objects, you may import the "->cando"
50       method into your namespace as a regular function called "stat_cando".
51       This takes an arrayref containing the return values of "stat" or
52       "lstat" as its first argument, and interprets it for you.
53
54       You may also import all the structure fields directly into your
55       namespace as regular variables using the :FIELDS import tag.  (Note
56       that this still overrides your stat() and lstat() functions.)  Access
57       these fields as variables named with a preceding "st_" in front their
58       method names.  Thus, "$stat_obj->dev()" corresponds to $st_dev if you
59       import the fields.
60
61       To access this functionality without the core overrides, pass the "use"
62       an empty import list, and then access function functions with their
63       full qualified names.  On the other hand, the built-ins are still
64       available via the "CORE::" pseudo-package.
65

BUGS

67       As of Perl 5.8.0 after using this module you cannot use the implicit $_
68       or the special filehandle "_" with stat() or lstat(), trying to do so
69       leads into strange errors.  The workaround is for $_ to be explicit
70
71           my $stat_obj = stat $_;
72
73       and for "_" to explicitly populate the object using the unexported and
74       undocumented populate() function with CORE::stat():
75
76           my $stat_obj = File::stat::populate(CORE::stat(_));
77

ERRORS

79       -%s is not implemented on a File::stat object
80           The filetest operators "-t", "-T" and "-B" are not implemented, as
81           they require more information than just a stat buffer.
82

WARNINGS

84       These can all be disabled with
85
86           no warnings "File::stat";
87
88       File::stat ignores use filetest 'access'
89           You have tried to use one of the "-rwxRWX" filetests with "use
90           filetest 'access'" in effect. "File::stat" will ignore the pragma,
91           and just use the information in the "mode" member as usual.
92
93       File::stat ignores VMS ACLs
94           VMS systems have a permissions structure that cannot be completely
95           represented in a stat buffer, and unlike on other systems the
96           builtin filetest operators respect this. The "File::stat"
97           overloads, however, do not, since the information required is not
98           available.
99

NOTE

101       While this class is currently implemented using the Class::Struct
102       module to build a struct-like class, you shouldn't rely upon this.
103

AUTHOR

105       Tom Christiansen
106
107
108
109perl v5.30.1                      2019-11-29                   File::stat(3pm)
Impressum