NAME

XAS::Lib::Mixin::Locking - A mixin to provide discretionary locking.

SYNOPSIS

use LockFile::Simple;

use XAS::Class
   version  => '0.01',
   base     => 'XAS::Base',
   accessor => 'lockmgr',
   mixins   => 'XAS::Lib::Mixin::Locking'
;

sub init {
   my $class = shift;

   my $self = $class->SUPER::init(@_);

   $self->{lockmgr} = LockFile::Simple->make(
       -format => '%f.lck',
       -max    => 20,
       -delay  => 1,
       -nfs    => 1,
       -stale  => 1,
       -hold   => 900,
       -wfunc  => sub { my $msg = shift; $self->log('warn', $msg); },
       -efunc  => sub { my $msg = shift; $self->log('error', $msg); }
   );

   return $self;
 
}

sub main {

   if ($self->lock_directories($source, $destination)) {

       $self->unlock_directories($source, $destination);

   }

}

DESCRIPTION

This module provides discretionary directory locking. This is to coordinate access to directories by multiple processes. These locks are advisory. It is implemented as a mixin. This module also needs an accessor named 'lockmgr' initilaized by LockFile::Simple.

METHODS

lock_directory($directory)

This method will lock a single directory. It takes these parameters:

$directory

The directory to use when locking.

unlock_directory($directory)

This method will unlock a single directory. It takes these parameters:

$directory

The directory to use when unlocking.

lock_directories($source, $destination)

This method will attempt to lock the source and destination directories. It takes these parameters:

$source

The source directory.

$destination

The destination directory.

unlock_directories($source, $destination)

This method will unlock the source and destination directories. It takes these parameters:

$source

The source directory.

$destination

The destination directory.

lock_file_name($directory)

This method returns the locks filename. It can be overridden if needed. The default name is 'locked'. It takes the following parameters:

$directory

The directory the lock file resides in.

SEE ALSO

XAS

AUTHOR

Kevin L. Esteb, <kevin@kesteb.us>

COPYRIGHT AND LICENSE

Copyright (C) 2013 by Kevin L. Esteb

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.