| 1 | package Model::Envoy::Storage::Memory; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | our $VERSION = '0.1.1'; | |||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Scalar::Util 'blessed'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use MooseX::ClassAttribute; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | 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 | 1 | ▶ | default => sub { {} }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | ); | |||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | 5 | ▶ | sub fetch { | ||||||||
|
Subroutine
fetch: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||
| 24 | 5 | my $self = shift; | |||||||||
| 25 | 5 | my $model_class = shift; | |||||||||
| 26 | 5 | my %params; | |||||||||
| 27 | |||||||||||
| 28 | 5 | ▶ | return undef unless @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | |||||||||||
| 30 | 5 | ▶ | if ( @_ == 1 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | |||||||||||
| 32 | 5 | my ( $id ) = @_; | |||||||||
| 33 | |||||||||||
| 34 | 5 | $params{id} = $id; | |||||||||
| 35 | } | ||||||||||
| 36 | else { | ||||||||||
| 37 | 0 | %params = @_; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 5 | my $id = $params{id}; | |||||||||
| 41 | |||||||||||
| 42 | 5 | ▶ | return undef unless $id; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | |||||||||||
| 44 | 5 | ▶ | return exists $self->store->{$id} ? $model_class->build( $self->store->{$id} ) : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | sub list { | ||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 48 | |||||||||||
| 49 | 0 | return (); | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 6 | ▶ | sub save { | ||||||||
|
Subroutine
save: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 53 | 6 | my ( $self ) = @_; | |||||||||
| 54 | |||||||||||
| 55 | 6 | $self->store->{ $self->model->id } = $self->model->dump; | |||||||||
| 56 | |||||||||||
| 57 | 6 | return $self; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 3 | ▶ | sub delete { | ||||||||
|
Subroutine
delete: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 61 | 3 | my ( $self ) = @_; | |||||||||
| 62 | |||||||||||
| 63 | 3 | delete $self->store->{ $self->model->id }; | |||||||||
| 64 | |||||||||||
| 65 | 3 | return; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 11 | ▶ | sub in_storage { | ||||||||
|
Subroutine
in_storage: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 69 | 11 | my ( $self ) = @_; | |||||||||
| 70 | |||||||||||
| 71 | 11 | return exists $self->store->{ $self->model->id }; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 1 | 1; | |||||||||