line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hash::Storage::Driver::Base; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
36
|
use v5.10; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
147
|
|
6
|
3
|
|
|
3
|
|
13
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
98
|
|
7
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
100
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
11
|
use Carp qw/croak/; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
132
|
|
10
|
3
|
|
|
3
|
|
14
|
use File::Spec; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
127
|
|
11
|
3
|
|
|
3
|
|
15
|
use Fcntl qw/:flock/; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
428
|
|
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
1507
|
use Data::Serializer::Raw; |
|
3
|
|
|
|
|
2316
|
|
|
3
|
|
|
|
|
94
|
|
14
|
3
|
|
|
3
|
|
1371
|
use Query::Abstract; |
|
3
|
|
|
|
|
24806
|
|
|
3
|
|
|
|
|
1663
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
3
|
|
|
3
|
0
|
6
|
my $class = shift; |
18
|
3
|
|
|
|
|
6
|
my %args = @_; |
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
|
|
5
|
my $serializer = $args{serializer}; |
21
|
3
|
50
|
|
|
|
13
|
croak "Wrong serializer" unless $serializer; |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
8
|
my $self = bless \%args, $class; |
24
|
|
|
|
|
|
|
|
25
|
3
|
50
|
0
|
|
|
11
|
if (! ref $serializer ) { |
|
|
0
|
|
|
|
|
|
26
|
3
|
100
|
|
|
|
10
|
if ($serializer ne 'Dummy') { |
27
|
2
|
|
|
|
|
14
|
$self->{serializer} = Data::Serializer::Raw->new(serializer => $serializer); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} elsif ( $serializer->can('serialize') && $serializer->can('deserialize') ) { |
30
|
0
|
|
|
|
|
0
|
$self->{serializer} = $serializer; |
31
|
|
|
|
|
|
|
} else { |
32
|
0
|
|
|
|
|
0
|
croak "Wrong serializer [$serializer]"; |
33
|
|
|
|
|
|
|
} |
34
|
3
|
|
|
|
|
2002
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub init { |
38
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
39
|
0
|
|
0
|
|
|
0
|
my $class = ref $self || $self; |
40
|
0
|
|
|
|
|
0
|
croak "Method [init] is not implemented in class [$class]"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub get { |
44
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $id ) = @_; |
45
|
0
|
|
0
|
|
|
0
|
my $class = ref $self || $self; |
46
|
0
|
|
|
|
|
0
|
croak "Method [get] is not implemented in class [$class]"; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub set { |
50
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $id, $fields ) = @_; |
51
|
0
|
|
0
|
|
|
0
|
my $class = ref $self || $self; |
52
|
0
|
|
|
|
|
0
|
croak "Method [set] is not implemented in class [$class]"; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub del { |
56
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $id ) = @_; |
57
|
0
|
|
0
|
|
|
0
|
my $class = ref $self || $self; |
58
|
0
|
|
|
|
|
0
|
croak "Method [del] is not implemented in class [$class]"; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub list { |
62
|
0
|
|
|
0
|
0
|
0
|
my ( $self, @query ) = @_; |
63
|
0
|
|
0
|
|
|
0
|
my $class = ref $self || $self; |
64
|
0
|
|
|
|
|
0
|
croak "Method [list] is not implemented in class [$class]"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub count { |
68
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $filter ) = @_; |
69
|
0
|
|
0
|
|
|
0
|
my $class = ref $self || $self; |
70
|
0
|
|
|
|
|
0
|
croak "Method [count] is not implemented in class [$class]"; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub do_filtering { |
74
|
30
|
|
|
30
|
0
|
42
|
my ( $self, $hashes, $query ) = @_; |
75
|
30
|
|
|
|
|
152
|
my $qa = Query::Abstract->new( driver => ['ArrayOfHashes'] ); |
76
|
30
|
|
|
|
|
10215
|
my $filter_sub = $qa->convert_query(@$query); |
77
|
30
|
|
|
|
|
2377
|
return $filter_sub->($hashes); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub do_exclusively { |
81
|
36
|
|
|
36
|
0
|
40
|
my ($self, $cb) = @_; |
82
|
36
|
50
|
|
|
|
100
|
croak "Subroutine reference required" unless ref($cb) eq 'CODE'; |
83
|
|
|
|
|
|
|
|
84
|
36
|
|
|
|
|
76
|
state $semophore = File::Spec->tmpdir() . '/hash_storage.semaphore'; |
85
|
36
|
50
|
|
|
|
1967
|
open( my $fh, '>', $semophore ) or die "Cannot open semaphore [$semophore] $!"; |
86
|
|
|
|
|
|
|
|
87
|
36
|
50
|
|
|
|
188
|
flock( $fh, LOCK_EX ) or die "Cannot lock semaphore [$semophore] $!"; |
88
|
36
|
|
|
|
|
97
|
$cb->(); |
89
|
36
|
50
|
|
|
|
9112
|
flock( $fh, LOCK_UN ) or die "Cannot unlock semaphore [$semophore] $!"; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; # End of Hash::Storage |