File-Stat-OO
view release on metacpan or search on metacpan
lib/File/Stat/OO.pm view on Meta::CPAN
Version 0.03
=cut
our $VERSION = '0.03';
=head1 SYNOPSIS
use File::Stat::OO;
my $foo = File::Stat::OO->new({file => '/etc/password'});
$foo->stat; # stat file specified at instantiation time
print $foo->size;
print $foo->mtime; # modification time in epoch seconds
or inflate epoch seconds into DateTime objects
my $foo = File::Stat::OO->new();
$foo->use_datetime(1);
# Or the two lines above can be combined as
# my $foo = File::Stat::OO->new({use_datetime => 1});
$foo->stat('/etc/password'); # pass file name to the stat method
print $foo->mtime; # returns DateTime object not an epoch
print $foo->mtime->epoch; # epoch seconds
=head1 METHODS
=head2 stat
Generate stat information. Takes an optional filename parameter
=cut
sub stat {
my $self = shift;
$self->file($_[0]) if ($_[0]);
die "No such file: " . $self->file unless -e $self->file;
my @file_stat = stat($self->file);
my $counter = 0;
foreach my $stat (@stat_keys) {
if ($stat =~ /^[a|m|c]time$/ && $self->use_datetime) {
$self->$stat(
DateTime->from_epoch(
epoch => $file_stat[$counter++],
time_zone => 'local'
)
);
} else {
$self->$stat($file_stat[$counter++]);
}
}
}
sub owner {
my $self = shift;
return (getpwuid($self->uid))[0];
}
sub group {
my $self = shift;
return (getgrgid($self->gid))[0];
}
=head2 use_datetime
If set, invocations of stat will record times as DateTime objects rather than
epoch seconds
=head2 dev
device number of filesystem
=head2 ino
inode number
=head2 mode
file mode type and permissions
=head2 nlink
number of (hard) links to the file
=head2 uid
numeric user ID of the file's owner
=head2 owner
name of the file owner
=head2 gid
numeric group ID of the file's owner
=head2 group
group name of the file's owner
=head2 rdev
the device identifier (special files only)
=head2 size
size of the file in bytes
=head2 atime
last access time (DateTime object)
=head2 mtime
last modify time (DateTime object)
( run in 1.706 second using v1.01-cache-2.11-cpan-39bf76dae61 )