line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::SharedObject; |
2
|
56
|
|
|
56
|
|
2490619
|
use 5.008001; |
|
56
|
|
|
|
|
174
|
|
|
56
|
|
|
|
|
1775
|
|
3
|
56
|
|
|
56
|
|
230
|
use strict; |
|
56
|
|
|
|
|
58
|
|
|
56
|
|
|
|
|
1320
|
|
4
|
56
|
|
|
56
|
|
181
|
use warnings; |
|
56
|
|
|
|
|
58
|
|
|
56
|
|
|
|
|
2121
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
7
|
|
|
|
|
|
|
|
8
|
56
|
|
|
56
|
|
725
|
use Storable qw/store_fd fd_retrieve/; |
|
56
|
|
|
|
|
2775
|
|
|
56
|
|
|
|
|
3270
|
|
9
|
56
|
|
|
56
|
|
1166
|
use File::Temp qw/tempfile/; |
|
56
|
|
|
|
|
14921
|
|
|
56
|
|
|
|
|
3514
|
|
10
|
56
|
|
|
56
|
|
17097
|
use Test::SharedObject::Lock; |
|
56
|
|
|
|
|
114
|
|
|
56
|
|
|
|
|
17511
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
55
|
|
|
55
|
1
|
746
|
my ($class, $data) = @_; |
14
|
|
|
|
|
|
|
|
15
|
55
|
|
|
|
|
379
|
my ($fh, $file) = tempfile(EXLOCK => 0); |
16
|
55
|
|
|
|
|
344975
|
my $self = bless { |
17
|
|
|
|
|
|
|
file => $file, |
18
|
|
|
|
|
|
|
ppid => $$, |
19
|
|
|
|
|
|
|
} => $class; |
20
|
|
|
|
|
|
|
|
21
|
55
|
|
|
|
|
228
|
seek $fh, 0, 0; |
22
|
55
|
|
|
|
|
1291
|
truncate $fh, 0; |
23
|
55
|
|
|
|
|
387
|
store_fd \$data, $fh; |
24
|
55
|
|
|
|
|
5346
|
close $fh; |
25
|
|
|
|
|
|
|
|
26
|
55
|
|
|
|
|
287
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub txn { |
30
|
124
|
|
|
124
|
1
|
582
|
my ($self, $code) = @_; |
31
|
124
|
|
|
|
|
2231
|
my $lock = Test::SharedObject::Lock->new($self); |
32
|
|
|
|
|
|
|
|
33
|
124
|
|
|
|
|
810
|
my $fh = $lock->fh; |
34
|
124
|
|
|
|
|
1361
|
my $ref = fd_retrieve $fh; |
35
|
124
|
|
|
|
|
8687
|
my $data = $code->($$ref); |
36
|
|
|
|
|
|
|
|
37
|
124
|
|
|
|
|
635
|
seek $fh, 0, 0; |
38
|
124
|
|
|
|
|
6678
|
truncate $fh, 0; |
39
|
124
|
|
|
|
|
1372
|
store_fd \$data, $fh; |
40
|
|
|
|
|
|
|
|
41
|
124
|
|
|
|
|
10475
|
return $data; ## unlock |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub set { |
45
|
2
|
|
|
2
|
1
|
4
|
my ($self, $data) = @_; |
46
|
2
|
|
|
2
|
|
12
|
return $self->txn(sub { $data }); |
|
2
|
|
|
|
|
4
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
66
|
|
|
66
|
|
176
|
sub _identity { $_[0] } |
50
|
|
|
|
|
|
|
sub get { |
51
|
66
|
|
|
66
|
1
|
308
|
my $self = shift; |
52
|
66
|
|
|
|
|
266
|
return $self->txn(\&_identity); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub DESTROY { |
56
|
55
|
|
|
55
|
|
4730
|
my $self = shift; |
57
|
55
|
100
|
|
|
|
9894
|
unlink $self->{file} if $$ == $self->{ppid}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
__END__ |