line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Lockfile; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
72820
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1061
|
use version; our $VERSION = qv('1.0.5'); |
|
1
|
|
|
|
|
2378
|
|
|
1
|
|
|
|
|
7
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Class::Data::Inheritable; |
9
|
1
|
|
|
1
|
|
124
|
use base qw(Class::Data::Inheritable); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
917
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata(qw/lockfile/); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
1
|
|
|
1
|
1
|
764
|
my ($class, $filename, $dir) = @_; |
15
|
1
|
|
|
|
|
10
|
$class->lockfile(join("/", $dir, $filename)); |
16
|
1
|
|
|
|
|
12
|
return bless {}, $class; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub write { |
20
|
1
|
|
|
1
|
1
|
262
|
my $fh; |
21
|
1
|
50
|
|
|
|
7
|
open $fh, '>', __PACKAGE__->lockfile or die("Can't write lockfile: ".__PACKAGE__->lockfile.": $!"); |
22
|
1
|
|
|
|
|
103
|
print $fh $$; |
23
|
1
|
|
|
|
|
55
|
close $fh; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub remove { |
27
|
1
|
|
|
1
|
1
|
272
|
unlink __PACKAGE__->lockfile; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub check { |
31
|
3
|
|
|
3
|
1
|
512
|
my ($class, $lockfile) = @_; |
32
|
|
|
|
|
|
|
|
33
|
3
|
50
|
|
|
|
17
|
$lockfile = __PACKAGE__->lockfile unless $lockfile; |
34
|
|
|
|
|
|
|
|
35
|
3
|
100
|
|
|
|
87
|
if ( -s $lockfile ) { |
36
|
1
|
|
|
|
|
2
|
my $fh; |
37
|
1
|
50
|
|
|
|
40
|
open $fh, '<', $lockfile or die("Can't open lockfile for reading: ".__PACKAGE->lockfile.": $!"); |
38
|
1
|
|
|
|
|
13
|
my $pid = <$fh>; |
39
|
1
|
|
|
|
|
16
|
my $running = kill 0, $pid; |
40
|
1
|
50
|
|
|
|
15
|
return $pid if $running; |
41
|
|
|
|
|
|
|
} |
42
|
2
|
|
|
|
|
6
|
return undef; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |