SHARYA...:Flock(3pm)
π SHARYA...:Flock β the manual page, but make it cute π
okay bestie, we're in the User Contributed Perl Documentation section, and this little page lives under the name SHARYA...:Flock. yes the title is truncated, that's just how the man page header rolls, don't come for it. π
β¨ NAME β¨
SHARYANTO::File::Flock β yet another flock module π¦
πΈ VERSION πΈ
version 0.56
π SYNOPSIS π
use SHARYANTO::File::Flock;
# try to acquire exclusive lock. if fail to acquire lock within 60s, die.
my $lock = SHARYANTO::File::Flock->lock($file);
# explicitly unlock
$lock->release;
# automatically unlock if object is DESTROY-ed.
undef $lock;
like, that's the whole vibe. grab a lock, drop the lock, or just let the object go out of scope and let it handle itself. main character energy fr. π
π DESCRIPTION π
This is yet another flock module. It's a more lightweight alternative to File::Flock, with some other differences too:
- OO interface only, periodt. no sneaky procedural stuff.
- Autoretry (by default for
60s) when trying to acquire a lock.
ngl, I prefer this approach over blocking/waiting indefinitely or just failing immediately. like, give it a minute, it's trying its best. π
π«Ά METHODS π«Ά
$lock = SHARYANTO::File::Flock->lock($path, \%opts)
Acquire an exclusive lock on $path. And listen β $path will be created if it doesn't already exist. β¨ If $path is already locked by another process, it will retry (by default for 60 seconds). Will die if it fails to acquire the lock. π
It will automatically unlock if $lock goes out of scope. Upon unlock, it will remove $path if it was created and is still empty (this behavior is the same as File::Flock). cute, tidy, considerate. π§
Available options:
retries => INT(default:60) β number of retries (which equals the number of seconds, since the retry happens every second).
$lock->unlock
Unlock. that's it. that's the whole thing. π
$lock->release
Synonym for unlock(). same energy, different name. π
π CAVEATS π
Not yet tested on Windows. Some filesystems do not support inode? π (yes, with the question mark, I'm just the messenger)
lowkey important: this is untested territory on Windows, and the inode thing is genuinely an open question. don't be shocked if a filesystem gives you the side-eye.
π SEE ALSO π
File::FlockFile::Flock::Tiny, which is also tiny, but does not have the autoremove and autoretry capability which I want. See also:https://github.com/trinitum/perl-File-Flock-Tiny/issues/1- the
flock()Perl function.
π AUTHOR π
Steven Haryanto <stevenharyanto@gmail.com>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2013 by Steven Haryanto.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
β FUNCTIONS β
None are exported by default, but they are exportable. so like, nothing shows up unless you ask for it. consent-first exports, we love to see it. π«Ά
and that's a wrap bestie!! πΈ this page was living in perl v5.34.0 and got its last lil glow-up on 2022-06-17, and the man page name is SHARYA...:Flock(3pm) in case you need to cite your sources. slay, go lock some files responsibly. π
β¨
π¦ where this page comes from
- debian bookworm: libsharyanto-file-util-perl 0.56-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libsharyanto-file-util-perl 0.56-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libsharyanto-file-util-perl 0.56-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libsharyanto-file-util-perl 0.56-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libsharyanto-file-util-perl 0.56-2 Β· 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