SHARYANTO::File::Flock - Yet another flock module
This document describes version 0.57 of SHARYANTO::File::Flock (from Perl distribution SHARYANTO-File-Util), released on 2014-05-17.
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;
This is yet another flock module. It is a more lightweight alternative to File::Flock with some other differences:
OO interface only
Autoretry (by default for 60s) when trying to acquire lock
I prefer this approach to blocking/waiting indefinitely or failing immediately.
Acquire an exclusive lock on $path. $path will be created if not already exists. If $path is already locked by another process, will retry (by default for 60 seconds). Will die if failed to acquire lock.
$path
Will automatically unlock if $lock goes out of scope. Upon unlock, will remove $path if it was created and is still empty (this behavior is the same as File::Flock).
$lock
Available options:
retries => INT (default: 60)
Number of retries (equals number of seconds, since retry is done every second).
Unlock.
Synonym for unlock().
Not yet tested on Windows. Some filesystems do not support inode?
SHARYANTO
File::Flock
File::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
flock() Perl function.
Please visit the project's homepage at https://metacpan.org/release/SHARYANTO-File-Util.
Source repository is at https://github.com/sharyanto/perl-SHARYANTO-File-Util.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=SHARYANTO-File-Util
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Steven Haryanto <stevenharyanto@gmail.com>
This software is copyright (c) 2014 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.
To install SHARYANTO::File::Util, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SHARYANTO::File::Util
CPAN shell
perl -MCPAN -e shell install SHARYANTO::File::Util
For more information on module installation, please visit the detailed CPAN module installation guide.