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