line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hash::Storage::Driver::Memory; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
522
|
use v5.10; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
6
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
489
|
use File::Slurp; |
|
1
|
|
|
|
|
10094
|
|
|
1
|
|
|
|
|
77
|
|
10
|
1
|
|
|
1
|
|
733
|
use Storable qw/dclone/; |
|
1
|
|
|
|
|
2574
|
|
|
1
|
|
|
|
|
66
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use base 'Hash::Storage::Driver::Base'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
477
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub init { |
15
|
1
|
|
|
1
|
0
|
2
|
my ($self) = @_; |
16
|
1
|
|
|
|
|
5
|
$self->{data} = {}; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub get { |
20
|
7
|
|
|
7
|
0
|
7
|
my ( $self, $id ) = @_; |
21
|
7
|
|
|
|
|
11
|
my $hashes = $self->{data}; |
22
|
7
|
|
|
|
|
10
|
my $hash = $hashes->{$id}; |
23
|
|
|
|
|
|
|
|
24
|
7
|
100
|
|
|
|
18
|
return unless $hash; |
25
|
5
|
|
|
|
|
228
|
return dclone($hash); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub set { |
29
|
16
|
|
|
16
|
0
|
21
|
my ( $self, $id, $fields ) = @_; |
30
|
16
|
|
|
|
|
16
|
my $hashes = $self->{data}; |
31
|
|
|
|
|
|
|
|
32
|
16
|
|
|
|
|
37
|
@{ $hashes->{$id} }{ keys %$fields } = values %$fields; |
|
16
|
|
|
|
|
82
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub del { |
36
|
2
|
|
|
2
|
0
|
4
|
my ( $self, $id ) = @_; |
37
|
2
|
|
|
|
|
2
|
my $hashes = $self->{data}; |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
10
|
delete $hashes->{$id}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub list { |
43
|
10
|
|
|
10
|
0
|
18
|
my ( $self, @query ) = @_; |
44
|
10
|
|
|
|
|
13
|
my $hashes = $self->{data}; |
45
|
|
|
|
|
|
|
|
46
|
10
|
|
|
|
|
25
|
my @hashes = values %$hashes; |
47
|
10
|
|
|
|
|
39
|
my $filtered = $self->do_filtering(\@hashes, \@query); |
48
|
10
|
|
|
|
|
1104
|
return dclone $filtered; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub count { |
52
|
5
|
|
|
5
|
0
|
6
|
my ( $self, $filter ) = @_; |
53
|
5
|
|
|
|
|
8
|
my $hashes = $self->list(where => $filter); |
54
|
5
|
|
|
|
|
30
|
return scalar(@$hashes); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; # End of Hash::Storage |