blib/lib/IPC/ConcurrencyLimit/Lock/NFS.pm

filter: Statementstmt 96.2% 51 / 53 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 84.6% 11 / 13 Podpod 100% 3 / 3 totaltotal 92.4% 73 / 79 CC 7 SCAR 8.6
CC
7
Cov
94%
new
4.0
_get_lock
4.0
lock_file
2.0
CRAP 2.4
↑ Summary
1 package IPC::ConcurrencyLimit::Lock::NFS;
2 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.01';
7  
8 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use File::Path qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Fcntl qw(:DEFAULT :flock);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use File::SharedNFSLock;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use IPC::ConcurrencyLimit::Lock;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 our @ISA = qw(IPC::ConcurrencyLimit::Lock);
16  
17 31 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
18 31 my $class = shift;
19 31 my $opt = shift;
20  
21 my $max_procs = $opt->{max_procs}
22 31 ▶ or croak("Need a 'max_procs' parameter");
Branch: 1 branch
BranchTrueFalseTotal
my $max_procs = $opt->{"max_procs"} or croak("Need a 'max_procs' parameter") 31 0 31
23 my $path = $opt->{path}
24 31 ▶ or croak("Need a 'path' parameter");
Branch: 1 branch
BranchTrueFalseTotal
my $path = $opt->{"path"} or croak("Need a 'path' parameter") 31 0 31
25  
26 31 my $h = {};
27 31 my $self = bless {
28 max_procs => $max_procs,
29 path => $path,
30 the_lock => undef,
31 lock_file => undef,
32 id => undef,
33 unique => "$h",
34 unique_s => $h,
35 } => $class;
36 31 $self->{unique} =~ s/[^A-Za-z0-9.-_]+//g;
37 31 $self->{unique} =~ s/HASH//;
38  
39 31 ▶ $self->_get_lock() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_get_lock or return undef 27 4 31
40  
41 27 return $self;
42 }
43  
44 31 ▶sub _get_lock {
Subroutine _get_lock: called CC=4 SCAR=13.9
45 31 my $self = shift;
46  
47 31 File::Path::mkpath($self->{path});
48  
49 31 for my $worker (1 .. $self->{max_procs}) {
50 244 my $lock_file = File::Spec->catfile($self->{path}, $worker);
51  
52 my $lock = File::SharedNFSLock->new(
53 file => $lock_file,
54 timeout_acquire => 0,
55 timeout_stale => 0,
56 unique_token => $self->{unique},
57 244 );
58  
59 244 ▶ if ($lock->lock()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lock->lock) 27 217 244
60 27 $self->{the_lock} = $lock;
61 27 $self->{id} = $worker;
62 27 $self->{lock_file} = $lock_file;
63 27 last;
64 }
65 }
66  
67 31 ▶ return undef if not $self->{id};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"id"} 4 27 31
68 27 return 1;
69 }
70  
71 0 ▶sub lock_file { $_[0]->{lock_file} }
Subroutine lock_file: not called CC=1 SCAR=6.9
Pod documented
72 0 ▶sub path { $_[0]->{path} }
Subroutine path: not called CC=1 SCAR=6.9
Pod documented
73  
74 # Normally needs implementing to release the lock,
75 # but in this case, we just hold on to the file handle that's flocked.
76 # Thus, it will be released as soon as this object is freed.
77 #sub DESTROY {}
78  
79 2 1;
80  
81 __END__
↑ Summary