BatchSystem::SBS::Common - Common tools Simple Batch System


BatchSystem-SBS documentation Contained in the BatchSystem-SBS distribution.

Index


Code Index:

NAME

Top

BatchSystem::SBS::Common - Common tools Simple Batch System

DESCRIPTION

Top

SYNOPSIS

Top

EXPORT

Top

FUNCTIONS

Top

lockFile($file)

call a locker on the file (File::Flock or Lockfile::Simple)

unlockFile($file)

AUTHOR

Top

Alexandre Masselot, <alexandre.masselot@genebio.com>

BUGS

Top

Please report any bugs or feature requests to bug-batchsystem-sbs@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=BatchSystem-SBS. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


BatchSystem-SBS documentation Contained in the BatchSystem-SBS distribution.

package BatchSystem::SBS::Common;
use warnings;
use strict;
require Exporter;
use English;

our @ISA=qw(Exporter);
our @EXPORT_OK=qw(&lockFile &unlockFile);

our $simpleLocker;

eval{
  require File::Flock;
};
if($@){
  require LockFile::Simple;
  warn "$@\nUsing LockFile::Simple";
  $simpleLocker=LockFile::Simple->make(-format => '%f.lck',
				       -max => 20,
				       -delay => 1,
				       -nfs => 1,
				       -autoclean => 1
				      );
}

sub lockFile{
  my $f=shift or CORE::die  "must pass an argument to lockFile";
  if($simpleLocker){
    return $simpleLocker->trylock($f) or CORE::die  "cannot lock [$f]: $!";
  }else{
    File::Flock::lock("$f.flck", (($OSNAME=~/win/i)?'shared':'')) or CORE::die  "cannot lock ($f): $!";
  }
}

sub unlockFile{
  my $f=shift or CORE::die  "must pass an argument to lockFile";
  if($simpleLocker){
    return $simpleLocker->unlock($f) or CORE::die  "cannot lock [$f]: $!";
  }else{
    File::Flock::unlock("$f.flck") or CORE::die  "cannot lock ($f): $!";
  }
}

1; # End of BatchSystem::SBS