Path::...e::Stat(3pm)

πŸ“¦
version 0.05 Β· 2 versions
  • 0.05 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.05 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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: while File::Modified uses an MD5 signature of the stat() 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 the restat() method and compare the cached File::stat object it hands you with the current File::stat object. 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::Class
  • Path::Class::File
  • File::Signature
  • File::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 (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