App-Highlander
view release on metacpan or search on metacpan
lib/App/Highlander.pm view on Meta::CPAN
sub _create_if_not_exists {
my ($dir) = @_;
return if -e $dir;
mkdir $dir, 0755
or die "Unable to make directory '$dir': $OS_ERROR";
return;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
App::Highlander - Module that provides simple named locks
=head1 VERSION
version 0.003
=head1 SYNOPSIS
use App::Highlander;
App::Highlander::get_lock();
# ...
App::Highlander::release_lock();
or
use App::Highlander;
my $has_lock = App::Highlander::get_lock('lockstring');
while ( ! $has_lock ) {
sleep 10;
$has_lock = App::Highlander::get_lock('lockstring');
}
# ... code ...
App::Highlander::release_lock('lockstring');
or
use App::Highlander LOCKDIR => "$ENV{HOME}/.locks";
...
=head1 DESCRIPTION
Simple module that provides a named locking mechanism based on flock. Application code requests a lock, then executes, then releases the lock. Lockfiles are stored in a temporary directory created by File::Temp::tempdir( CLEANUP => 1 ) by default. Yo...
App::Highlander does *not* currently (and may never) handle errors, this means that if your application dies under Highlander then it will not have released the lock. Application code will need to capture the error with eval or a sugary module like T...
=head1 NAME
App::Highlander
=head1 METHODS
=over 4
=item C<get_lock>
Attempts to get a lock on the supplied lock string. If no lock string is supplied then $PROGRAM_NAME will be used. Locks are written to a temporary directory or LOCKDIR if one was specified
Returns the name of the lock file that was created.
=item C<release_lock>
Attempts to release a lock on the suppplied lock string. If no lock string is supplied then $PROGRAM_NAME will be used. Releasing the lock will close the open filehandle is that was used for flock and delete the lockfile
Returns the name of the lock file that was destroyed.
=back
=head1 ISSUES
Issues (bugs or feature requests) should be created on the github repo: https://github.com/mcmillhj/App-Highlander/issues
=head1 AUTHOR
Hunter McMillen <mcmillhj@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by Hunter McMillen.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
( run in 1.691 second using v1.01-cache-2.11-cpan-39bf76dae61 )