line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Starch::Store::Memory; |
2
|
13
|
|
|
13
|
|
6472
|
use 5.008001; |
|
13
|
|
|
|
|
53
|
|
3
|
13
|
|
|
13
|
|
78
|
use strictures 2; |
|
13
|
|
|
|
|
147
|
|
|
13
|
|
|
|
|
505
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
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
|
|
3014
|
use Types::Standard -types; |
|
13
|
|
|
|
|
29
|
|
|
13
|
|
|
|
|
175
|
|
19
|
13
|
|
|
13
|
|
61271
|
use Types::Common::Numeric -types; |
|
13
|
|
|
|
|
31
|
|
|
13
|
|
|
|
|
129
|
|
20
|
|
|
|
|
|
|
|
21
|
13
|
|
|
13
|
|
17309
|
use Moo; |
|
13
|
|
|
|
|
29
|
|
|
13
|
|
|
|
|
104
|
|
22
|
13
|
|
|
13
|
|
5582
|
use namespace::clean; |
|
13
|
|
|
|
|
33
|
|
|
13
|
|
|
|
|
100
|
|
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
|
|
398
|
my ($self) = @_; |
58
|
33
|
100
|
|
|
|
231
|
return $global_memory if $self->global(); |
59
|
29
|
|
|
|
|
462
|
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
|
1452
|
my ($self, $id, $namespace) = @_; |
90
|
|
|
|
|
|
|
return $self->memory->{ |
91
|
160
|
|
|
|
|
2593
|
$self->stringify_key( $id, $namespace ) |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub remove { |
96
|
53
|
|
|
53
|
1
|
765
|
my ($self, $id, $namespace) = @_; |
97
|
|
|
|
|
|
|
delete( $self->memory->{ |
98
|
53
|
|
|
|
|
931
|
$self->stringify_key( $id, $namespace ) |
99
|
|
|
|
|
|
|
} ); |
100
|
53
|
|
|
|
|
150
|
return; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
__END__ |