The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


Path::Class::File::Lockable - lock your files with Path::Class::File


 my $file = Path::Class::File::Lockable->new('path/to/file');
 # do stuff with $file


Path::Class::File::Lockable uses simple files to indicate whether a file is locked or not. It does not use flock(), since that is unstable over NFS. Effort has been made to avoid race conditions.

Path::Class::File::Lockable is intended for long-standing locks, as in a Subversion workspace. See SVN::Class for example.


This is a subclass of Path::Class::File. Only new or overridden methods are documented here.


Returns the file extension used to indicate a lock file. Default is .lock.


Returns a Path::Class::File object representing the lock file itself. No check is made as to whether the lock file exists.


Returns a colon-limited string with the contents of the lock file. Will croak if the lock file does not exist.

Note that the owner and timestamp in the file contents are not from a stat() of the file. They are written at the time the lock file is created. So chown'ing or touch'ing a lock file do not alter its status.

See lock_owner() and lock_time() for easier ways to get at specific information.


Returns the name of the person who locked the file.


Returns the time the file was locked (in Epoch seconds).


Returns the PID of the process that locked the file.


Returns true if the file has an existing lock file.

lock( [owner] )

Acquire a lock on the file.

This method should be NFS-safe via File::NFSLock.


Removes lock file. Uses system() call to enable unlinking across NFS. Will croak on any error.


Peter Karman, <karman at>


Please report any bugs or feature requests to bug-path-class-file-lockable at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Path::Class::File::Lockable

You can also look for information at:


There are lots of lock file modules on CPAN. Some of them are probably better suited to your needs than this one.

The Minnesota Supercomputing Institute sponsored the development of this software.


File::NFSLock, Path::Class::File


Copyright 2007 by the Regents of the University of Minnesota. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.