SHARYANTO::File::Flock - Yet another flock module
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:
I prefer this approach to blocking/waiting indefinitely or failing immediately.
Acquire an exclusive lock on
$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.
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).
Number of retries (equals number of seconds, since retry is done every second).
Synonym for unlock().
Not yet tested on Windows. Some filesystems do not support inode?
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.
Steven Haryanto <firstname.lastname@example.org>
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.
None are exported by default, but they are exportable.