Path::...e::Stat(3pm)
π Path::Class::File::Stat β the glow up edition π
okay bestie, so this is a page from the User Contributed Perl Documentation section, and in your terminal it shows up under the name Path::...e::Stat(3pm) (yes the title got truncated, that's just how manpages do, iconic behavior honestly). grab a strawberry π and let's get into it.
β¨ NAME β¨
Path::Class::File::Stat β the vibe check for whether the file underneath a Path::Class::File object has changed. π
πΈ SYNOPSIS πΈ
use Path::Class::File::Stat;
my $file = Path::Class::File::Stat->new('path','to','file');
# $file has all the magic of Path::Class::File
# sometime later
if ($file->changed) {
# do something provocative
}
not me writing $file->changed and doing something provocative about it π slay.
π¦ DESCRIPTION π¦
So Path::Class::File::Stat is literally just a lil extension of Path::Class::File. that's it. that's the whole personality. π
But the reason she exists is lowkey genius: she's for long-running programs (think stuff under mod_perl) where you've got a file handle just... sitting there open... and you need to know if the actual file underneath it has changed. main character energy fr fr. π
π METHODS π
Path::Class::File::Stat extends Path::Class::File objects in the following ways, periodt:
π use_md5
Call this method and it will attempt to load Digest::MD5 and then use that in addition to stat() when it's making file signatures. this is similar to how File::Modified works. ngl, kind of a flex. β¨
π changed
okay this is the big one, bestie. π«Ά
She returns the previously cached File::stat object if any of these glow-up-worthy things happened:
- the file's device number and inode number have changed, or
- the modification time or size has changed, or
- if
use_md5()is on, the MD5 signature of the file's contents has changed.
Otherwise she returns 0 (false). π
Now here's the tea: whileFile::Modifieduses an MD5 signature of thestat()of a file to figure out if it changed,changed()uses a simpler (and probably more naive) algorithm. so if you need a more sophisticated way of determining whether a file has changed, use therestat()method and compare the cachedFile::statobject it hands you with the currentFile::statobject. iykyk π
Example of your own changed() logic, if you wanna go off script:
my $oldstat = $file->restat;
my $newstat = $file->stat;
# compare $oldstat and $newstat any way you like
Or just use File::Modified instead. no pressure bestie, do what feels right π
π restat
Re-caches the File::stat object inside the Path::Class::File::Stat object. Returns the previously cached File::stat object. π«
and here's the cute part: the changed() method calls this method internally if changed() is going to return true. teamwork makes the dream work, fr fr. π
π SEE ALSO π
Path::ClassPath::Class::FileFile::SignatureFile::Modified
go read them, they're all part of the friend group π«Ά
π AUTHOR π
Peter Karman, <karman@cpan.org> β thank you for your service king π
π COPYRIGHT AND LICENSE π
Copyright (C) 2006, 2013 by Peter Karman
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. β¨
and that's the whole page, bestie!! this one came from perl v5.36.0 and it's dated 2022-11-19, so yeah β vintage but still absolutely serving. π
π bye ily, go check if your files changed π¦πΈ
π¦ where this page comes from
- debian bookworm: libpath-class-file-stat-perl 0.05-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libpath-class-file-stat-perl 0.05-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libpath-class-file-stat-perl 0.05-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libpath-class-file-stat-perl 0.05-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libpath-class-file-stat-perl 0.05-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms