blib/lib/Ubic/SingletonLock.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 40 SCAR 17.9
CC
2
Cov
0%
new
6.0
DESTROY
2.0
BEGIN
2.0
CRAP 6.0
1 package Ubic::SingletonLock;
2 $Ubic::SingletonLock::VERSION = '1.59';
3 use strict;
4 use warnings;
5  
6 # ABSTRACT: lock which can be safely created several times from the same process without deadlocking
7  
8  
9 use Params::Validate;
10 use Scalar::Util qw(weaken);
11  
12 use Ubic::Lockf;
13  
14 our %LOCKS;
15  
16 sub new {
17 my ($class, $file, $options) = validate_pos(@_, 1, 1, 0);
18  
19 if ($LOCKS{$file}) {
20 return $LOCKS{$file};
21 }
22 my $lock = lockf($file, $options);
23 my $self = bless { file => $file, lock => $lock } => $class;
24  
25 $LOCKS{$file} = $self;
26 weaken $LOCKS{$file};
27 return $self;
28 }
29  
30 sub DESTROY {
31 my $self = shift;
32 local $@;
33 delete $LOCKS{ $self->{file} };
34 }
35  
36  
37 1;
38  
39 __END__