line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Starch::Store::Memory; |
2
|
13
|
|
|
13
|
|
6380
|
use 5.008001; |
|
13
|
|
|
|
|
50
|
|
3
|
13
|
|
|
13
|
|
83
|
use strictures 2; |
|
13
|
|
|
|
|
103
|
|
|
13
|
|
|
|
|
484
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Starch::Store::Memory - In-memory Starch store. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 DESCRIPTION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
This store provides an in-memory store using a hash ref to store the |
13
|
|
|
|
|
|
|
data. This store is mostly here as a proof of concept and for writing |
14
|
|
|
|
|
|
|
tests against. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
13
|
|
|
13
|
|
2885
|
use Types::Standard -types; |
|
13
|
|
|
|
|
40
|
|
|
13
|
|
|
|
|
240
|
|
19
|
13
|
|
|
13
|
|
62199
|
use Types::Common::Numeric -types; |
|
13
|
|
|
|
|
29
|
|
|
13
|
|
|
|
|
136
|
|
20
|
|
|
|
|
|
|
|
21
|
13
|
|
|
13
|
|
17658
|
use Moo; |
|
13
|
|
|
|
|
37
|
|
|
13
|
|
|
|
|
108
|
|
22
|
13
|
|
|
13
|
|
5992
|
use namespace::clean; |
|
13
|
|
|
|
|
42
|
|
|
13
|
|
|
|
|
139
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
with qw( |
25
|
|
|
|
|
|
|
Starch::Store |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 OPTIONAL ARGUMENTS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 global |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Set this to a true value to use a shared memory store for all instances |
33
|
|
|
|
|
|
|
of this class that enable this argument. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $global_memory = {}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has global => ( |
40
|
|
|
|
|
|
|
is => 'ro', |
41
|
|
|
|
|
|
|
isa => Bool, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 memory |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This is the hash ref which is used for storing states. |
47
|
|
|
|
|
|
|
Defaults to a global hash ref if L is set, or |
48
|
|
|
|
|
|
|
a new hash ref if not. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
has memory => ( |
53
|
|
|
|
|
|
|
is => 'lazy', |
54
|
|
|
|
|
|
|
isa => HashRef, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
sub _build_memory { |
57
|
33
|
|
|
33
|
|
407
|
my ($self) = @_; |
58
|
33
|
100
|
|
|
|
231
|
return $global_memory if $self->global(); |
59
|
29
|
|
|
|
|
487
|
return {}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 METHODS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 set |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Set L. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 get |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Set L. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 remove |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Set L. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub set { |
79
|
|
|
|
|
|
|
my ($self, $id, $namespace, $data) = @_; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$self->memory->{ |
82
|
|
|
|
|
|
|
$self->stringify_key( $id, $namespace ) |
83
|
|
|
|
|
|
|
} = $data; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub get { |
89
|
160
|
|
|
160
|
1
|
1478
|
my ($self, $id, $namespace) = @_; |
90
|
|
|
|
|
|
|
return $self->memory->{ |
91
|
160
|
|
|
|
|
2727
|
$self->stringify_key( $id, $namespace ) |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub remove { |
96
|
53
|
|
|
53
|
1
|
8355
|
my ($self, $id, $namespace) = @_; |
97
|
|
|
|
|
|
|
delete( $self->memory->{ |
98
|
53
|
|
|
|
|
947
|
$self->stringify_key( $id, $namespace ) |
99
|
|
|
|
|
|
|
} ); |
100
|
53
|
|
|
|
|
162
|
return; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
__END__ |