NAME RenameLock - Simple exclusive lock by renaming lockfile. SYNOPSIS ### Simple One ### use RenameLock; my $lock = RenameLock->new(basename => "lockfile", lockdir => "./lock", timeout => 10, expiretime => 600); $lock->lock or die "busy!; my $fh = IO::File->new(">file"); # blash, blash, blash... undef $fh; # close $lock->unlock; ### Sample for using auto unlock when DESTROY ### use RenameLock; my @datafiles; foreach (qw(file_a file_b file_c)) { my $lock = RenameLock->new(basename => "$_.lock"); $lock->lock or die "busy!"; my $fh = IO::File->new(">$_"); push @datafiles, { fh => $fh, lock => $lock}; } # blash, blash, blash... my $selected_fh = $datafiles[1]->{fh}; print $selected_fh "moge\n"; # blash, blash, blash... delete $datafiles[1]; # auto close & unlock for "file_b" DESCRIPTION Simple exclusive lock by renaming lockfile. METHODS * new Create new object. - lockdir Assign directory for create lockfile. default is ".". This directory MUST be writable. (But, should NOT assign world writable directory. To avoid symlink attack.) - basename Lockfile's basename. You should create empty file before processing. - timeout Timeout(sec) for lock. default is 30(sec). - expiretime Timeout(sec) for force purge lock. Default is undef(=never). - nowarn If it is true, suppress non-serious warning message. * lock Do lock. return filename if success. * unlock Do unlock. return true for success. * is_locked Detects lockstatus. return true for locked. Notice: this method can NOT detect lock by other process or instance. only affects locked by self. EXPORT * default None. * all: lock, unlock. LICENSE Same as perl itself. AUTHOR Tatsuki Sugiura THANKS HZAKI Hiroki! (http://www.din.or.jp/~ohzaki/perl.htm#File_Lock) SEE ALSO perl.