NAME
Ubic::Lockf - file locker with an automatic out-of-scope unlocking mechanism
VERSION
version 1.51
SYNOPSIS
use Ubic::Lockf;
$lock = lockf($filehandle);
$lock = lockf($filename);
undef $lock; # unlocks either
DESCRIPTION
lockf
is a perlfunc flock
wrapper. The lock is autotamically released as soon as the assotiated object is no longer referenced.
METHODS
- lockf($file, $options)
-
Create an Lockf instance. Always save the result in some variable(s), otherwise the lock will be released immediately.
The lock is automatically released when all the references to the Lockf object are lost. The lockf mandatory parameter can be either a string representing a filename or a reference to an already opened filehandle. The second optional parameter is a hash of boolean options. Supported options are:
-
OFF by default. Tells to achieve a shared lock. If not set, an exclusive lock is requested.
- blocking
-
ON by default. If unset, a non-blocking mode of flock is used. If this flock fails because the lock is already held by some other process,
undef
is returned. If the failure reason is somewhat different, permissions problems or the absence of a target file directory for example, an exception is raisen. - timeout
-
Undef by default. If set, specifies the wait timeout for acquiring the blocking lock. The value of 0 is equivalent to blocking => 0 option.
- mode
-
Undef by default. If set, a chmod with the specified mode is performed on a newly created file. Ignored when filehandle is passed instead of a filename.
-
- name()
-
Gives the name of the file, as it was when the lock was taken.
- dissolve()
-
Destroy lock object without unlocking.
This is useful in forking code, if you have one lock object in several processes and want to close locked fh in one process without unlocking in the other.
AUTHOR
Vyacheslav Matyukhin <mmcleric@yandex-team.ru>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Yandex LLC.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.