SHARYANTO::File::Flock(3pm)

SHARYANTO::File::Flock3pm

Yet another flock module

Usage

 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;

Version

version 0.56

Overview

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.

Methods

$lock = SHARYANTO::File::Flock->lock($path, \%opts)

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.

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).

Available options:

•

retries => INT (default: 60)

Number of retries (equals number of seconds, since retry is done every second).

$lock->unlock

Unlock.

$lock->release

Synonym for unlock().

Caveats

Not yet tested on Windows. Some filesystems do not support inode?

Functions

None are exported by default, but they are exportable.

Releases

6 releases since Debian 8 (Jessie); the text changed 2 times.

  1. 8–10
  2. 11
  3. 12–13

Author

Steven Haryanto <[email protected]>

From libsharyanto-file-util-perl 0.56-2 in Debian 13 (Trixie). Parsed by carta from the page's man source.