FlockDir - override perl flock() for network or portability purposes
use File::FlockDir qw (open close flock);
open (FH, ">$path");
flock(FH, 2);
close FH;
A flock module for Windows9x and other systems lacking
a good perl flock() function (not platform specific)
Usage:
use File::FlockDir qw (open close flock);
OR (careful)
use File::FlockDir qw (GLOBAL_open GLOBAL_close GLOBAL_flock);
Rationale: flock on Win95/98 is badly broken but
perl code needs to be portable. One way to do
this is to override perl's open(), flock(), and close().
We then get an absolute file specification for all opened
files and and use it in a hash to create a unique lock for
the file using the File::LockDir module from Perl Cookbook,
by Christiansen and Torkington (O'Reilly, 1998). This module may
be included in the CPAN distribution but belongs to those authors.
New code is deliberately kept at a minimum. As with nflock(),
this will allow flock() to work over a network (usually).
May be slow compared to unix flock(). This is mainly due to the fact
it depends upon non-buffered disk writes (directory creation) for its
implementation. May be speeded up somewhat by importing and setting
the variable $Max_SH_Processes to a smaller value as long as no more
than a few processes will be using shared locks at a time on any one file.
Abnormal termination may leave File::LockDir entries still on the drive. This means the directory locks set by File::LockDir may have to be removed after a system crash to prevent the module from assuming that files locked at the time of the crash are still locked later. This may be partially overcome by importing and setting the variable $Assume_LockDir_Zombie_Minutes to a value equal to the maximal number of minutes a lock is to be allowed to exist (defaults to one week or 10040 minutes).
Since the implementation creates a subdirectory in the directory
containing the file that you flock(), you must have permission to
create a directory where the file is located in order to flock()
that file over the network.
Perl Cookbook, by Tom Christiansen and Nathan Torkington.
This module is an extension of Perl Cookbook's nflock(), in
chapter 7, section 21 (7.21, pp 264-266).
William Herrera <wherrera@lynxview.com>