File::Stat::Moose - Status info for a file - Moose-based
use File::Stat::Moose; $st = File::Stat::Moose->new( file => '/etc/passwd' ); print "Size: ", $st->size, "\n"; # named attribute print "Blocks: ". $st->[12], "\n"; # numbered attribute
This class provides methods that returns status info for a file. It is the OO-style version of stat/lstat functions. It also throws an exception immediately after error is occurred.
By default, the class does not export its symbols.
Imports stat and/or lstat functions.
stat
lstat
use File::Stat::Moose 'stat', 'lstat';
Imports all available symbols.
use File::Stat::Moose ':all';
extends Moose::Object
Thrown whether a methods is called with wrong arguments.
Thrown whether an IO error is occurred.
Contains the file for check. The attribute can hold file name or file handler or IO object.
If the value is true and the file for check is symlink, then follows it than checking the symlink itself.
On Win32 "stat" in perlfunc needs to open the file to determine the link count and update attributes that may have been changed through hard links. If the sloppy is set to true value, "stat" in perlfunc speeds up by not performing this operation.
By default the accessors might be avoided for performance reason. This optimization can be disabled if the attribute is set to true value.
ID of device containing file. If this value and following has no meaning on the platform, it will contain undefined value.
inode number.
Unix mode for file.
Number of hard links.
User ID of owner.
Group ID of owner.
Device ID (if special file).
Total size, in bytes.
Time of last access as DateTime object.
Time of last modification as DateTime object.
Time of last status change as DateTime object.
Block size for filesystem I/O.
Number of blocks allocated.
If File::Stat::Moose object is dereferenced as array it returns an array with the same order of values as in "stat" in perlfunc or "lstat" in perlfunc functions. Attributes atime, ctime and mtime are returned as number values (Unix timestamp).
File::Stat::Moose
atime
ctime
mtime
$st = File::Stat::Moose->new( file => '/etc/passwd' ); @st = @$st;
Creates the File::Stat::Moose object and calls update method.
update
If the file is symlink and the follow is true, it will check the file that it refers to. If the follow is false, it will check the symlink itself.
$st = File::Stat::Moose->new( file => '/etc/cdrom', follow => 1 ); print "Device: ", $st->rdev, "\n"; # check real device, not symlink
The object is dereferenced in array context to the array reference which contains the same values as "stat" in perlfunc function output.
$st = File::Stat::Moose->new( file => '/etc/passwd' ); print "Size: ", $st->size, "\n"; # object's attribute print "Size: ", $st->[7], "\n"; # array dereference
Updates all attributes which represent status of file.
Calls "stat" in perlfunc function if follow method is true value or "lstat" in perlfunc function otherwise.
follow
Calls stat on given file. If the file is undefined, the $_ variable is used instead.
$_
If it is called in array context, it returns an array with the same values as for output of core stat function.
use File::Stat::Moose 'stat'; $_ = '/etc/passwd'; @st = stat; print "Size: $st[7]\n";
If it is called with scalar context, it returns the File::Stat::Moose object.
use File::Stat::Moose 'stat'; $st = stat '/etc/passwd'; @st = @$st;
It is identical to stat, except that if file is a symbolic link, then the link itself is checked, not the file that it refers to.
use File::Stat::Moose 'lstat'; @st = lstat '/etc/motd';
stat and lstat functions does not accept special handler _ written as bareword. You have to use it as a glob reference \*_.
_
\*_
use File::Stat::Moose 'stat'; stat "/etc/passwd"; # set the special filehandle _ @st = stat _; # does not work @st = stat \*_; # ok
The File::Stat::Moose module is 4 times slower than File::stat module and 30 times slower than "stat" in perlfunc function. The function interface is 1.5 times slower than OO interface. The strict accessors are 2.5 times slower that optimized direct access to hash.
Exception::Base, MooseX::Types::OpenHandle, MooseX::Types::CacheFileHandle, Moose, File::stat, DateTime.
Piotr Roszatycki <dexter@cpan.org>
Copyright (C) 2007, 2008, 2009 by Piotr Roszatycki <dexter@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
To install File::Stat::Moose, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::Stat::Moose
CPAN shell
perl -MCPAN -e shell install File::Stat::Moose
For more information on module installation, please visit the detailed CPAN module installation guide.