line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Model::Envoy::Storage::Memory; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.1.1'; |
4
|
1
|
|
|
1
|
|
630
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
5
|
1
|
|
|
1
|
|
6808
|
use Scalar::Util 'blessed'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
60
|
|
6
|
1
|
|
|
1
|
|
7
|
use MooseX::ClassAttribute; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'Model::Envoy::Storage'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 Model::Envoy::Storage::Memory |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
A trivial example in-memory storage plugin. It should not be used in production. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
class_has 'store' => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
isa => 'DBIx::Class::Schema', |
19
|
|
|
|
|
|
|
default => sub { {} }, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub fetch { |
24
|
5
|
|
|
5
|
1
|
14
|
my $self = shift; |
25
|
5
|
|
|
|
|
16
|
my $model_class = shift; |
26
|
5
|
|
|
|
|
7
|
my %params; |
27
|
|
|
|
|
|
|
|
28
|
5
|
50
|
|
|
|
24
|
return undef unless @_; |
29
|
|
|
|
|
|
|
|
30
|
5
|
50
|
|
|
|
17
|
if ( @_ == 1 ) { |
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
|
|
11
|
my ( $id ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
5
|
|
|
|
|
14
|
$params{id} = $id; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
0
|
|
|
|
|
0
|
%params = @_; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
5
|
|
|
|
|
10
|
my $id = $params{id}; |
41
|
|
|
|
|
|
|
|
42
|
5
|
50
|
|
|
|
11
|
return undef unless $id; |
43
|
|
|
|
|
|
|
|
44
|
5
|
100
|
|
|
|
166
|
return exists $self->store->{$id} ? $model_class->build( $self->store->{$id} ) : undef; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub list { |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
0
|
1
|
0
|
return (); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub save { |
53
|
6
|
|
|
6
|
1
|
15
|
my ( $self ) = @_; |
54
|
|
|
|
|
|
|
|
55
|
6
|
|
|
|
|
157
|
$self->store->{ $self->model->id } = $self->model->dump; |
56
|
|
|
|
|
|
|
|
57
|
6
|
|
|
|
|
78
|
return $self; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub delete { |
61
|
3
|
|
|
3
|
1
|
10
|
my ( $self ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
3
|
|
|
|
|
91
|
delete $self->store->{ $self->model->id }; |
64
|
|
|
|
|
|
|
|
65
|
3
|
|
|
|
|
28
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub in_storage { |
69
|
11
|
|
|
11
|
0
|
25
|
my ( $self ) = @_; |
70
|
|
|
|
|
|
|
|
71
|
11
|
|
|
|
|
315
|
return exists $self->store->{ $self->model->id }; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |