lib/Ubic/SingletonLock.pm

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