| 1 | package DBIx::NoSQL::Store::Manager::Model; | ||||||||||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||||||||||||||||
| 3 | #ABSTRACT: Role for classes to be handled by DBIx::NoSQL::Store::Manager | ||||||||||||||||||||||||||||
| 4 | 2 | $DBIx::NoSQL::Store::Manager::Model::VERSION = '1.0.0'; | |||||||||||||||||||||||||||
| 5 | 2 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use MooseX::ClassAttribute; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use MooseX::Storage 0.31; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use MooseX::SetOnce; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Scalar::Util qw/ refaddr /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | with Storage; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use DBIx::NoSQL::Store::Manager::StoreKey; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use DBIx::NoSQL::Store::Manager::StoreIndex; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use DBIx::NoSQL::Store::Manager::StoreModel; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use experimental 'signatures'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # TODO: ad-hoc model registration | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | has store_db => ( | |||||||||||||||||||||||||||
| 31 | traits => [ 'DoNotSerialize', 'SetOnce' ], | ||||||||||||||||||||||||||||
| 32 | is => 'rw', | ||||||||||||||||||||||||||||
| 33 | predicate => 'has_store_db', | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 3 | ▶ | around store_db => sub ( $orig, $self, @rest ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||
| 37 | 3 | ▶ | if ( @rest and $self->has_store_db ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@rest and $self->has_store_db
MC/DC0%0/2
@rest and $self->has_store_db
@rest
$self->has_store_db
Truth table66%2/3
A and B
A= @restB= $self->has_store_db
| |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | shift @rest if refaddr $self->store_db == refaddr $rest[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 3 | return $orig->($self,@rest); | |||||||||||||||||||||||||||
| 42 | 2 | }; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | class_has store_model => ( | ||||||||||||||||||||||||||||
| 46 | isa => 'Str', | ||||||||||||||||||||||||||||
| 47 | is => 'rw', | ||||||||||||||||||||||||||||
| 48 | 1 | ▶ | default => sub ($self) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | # TODO probably over-complicated | ||||||||||||||||||||||||||||
| 50 | 1 | my( $class ) = $self->class_precedence_list; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1 | $class =~ s/^.*::Model:://; | |||||||||||||||||||||||||||
| 53 | 1 | $class =~ s/::/_/g; | |||||||||||||||||||||||||||
| 54 | 1 | return $class; | |||||||||||||||||||||||||||
| 55 | }, | ||||||||||||||||||||||||||||
| 56 | 2 | ); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | has store_key => ( | ||||||||||||||||||||||||||||
| 60 | traits => [ 'DoNotSerialize' ], | ||||||||||||||||||||||||||||
| 61 | is => 'ro', | ||||||||||||||||||||||||||||
| 62 | lazy => 1, | ||||||||||||||||||||||||||||
| 63 | 2 | ▶ | default => sub($self) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 4 | return join( '-', map { $self->$_ } sort map { | |||||||||||||||||||||||||||
| 66 | 4 | $_->get_read_method | |||||||||||||||||||||||||||
| 67 | 2 | ▶ | } grep { $_->does('DBIx::NoSQL::Store::Manager::StoreKey') } | ||||||||||||||||||||||||||
|
Condition50%1/2
join("-", map({$self->$_;} sort(map({$_->get_read_method;} grep({$_->does("DBIx::NoSQL::Store::Manager::StoreKey");} $self->meta->get_all_attributes))))) // die("no store key set for $self")
MC/DC0%0/1
join("-", map({$self->$_;} sort(map({$_->get_read_method;} grep({$_->does("DBIx::NoSQL::Store::Manager::StoreKey");} $self->meta->get_all_attributes))))) // die("no store key set for $self")
join("-", map({$self->$_;} sort(map({$_->get_read_method;} grep({$_->does("DBIx::NoSQL::Store::Manager::StoreKey");} $self->meta->get_all_attributes)))))
Truth table50%1/2
A
A= join("-", map({$self->$_;} sort(map({$_->get_read_method;} grep({$_->does("DBIx::NoSQL::Store::Manager::StoreKey");} $self->meta->get_all_attributes)))))
| |||||||||||||||||||||||||||||
| 68 | $self->meta->get_all_attributes ) | ||||||||||||||||||||||||||||
| 69 | // die "no store key set for $self"; | ||||||||||||||||||||||||||||
| 70 | }, | ||||||||||||||||||||||||||||
| 71 | 2 | ); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub store($self) { | ||||||||||||||||||||||||||
|
Subroutine
store: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | # TODO put deprecation notice | ||||||||||||||||||||||||||||
| 76 | 0 | $self->save; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub delete($self) { | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 0 | $self->store_db->delete( $self->store_model => $self->store_key ); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub _entity($self) { | ||||||||||||||||||||||||||
|
Subroutine
_entity: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 85 | 0 | return $self->pack; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 2 | ▶ | around pack => sub($orig,$self) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 89 | 2 | local $DBIx::NoSQL::Store::Manager::Model::INNER_PACKING = $DBIx::NoSQL::Store::Manager::Model::INNER_PACKING; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 2 | ▶ | return $DBIx::NoSQL::Store::Manager::Model::INNER_PACKING++ ? $self->store_key : $orig->($self); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 2 | }; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 1 | ▶ | sub indexes($self) { | ||||||||||||||||||||||||||
|
Subroutine
indexes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 95 | 2 | return map { [ $_->name, ( isa => $_->store_isa ) x $_->has_store_isa ] } | |||||||||||||||||||||||||||
| 96 | 1 | grep { $_->does('DBIx::NoSQL::Store::Manager::StoreIndex') } | |||||||||||||||||||||||||||
| 97 | $self->meta->get_all_attributes; | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 1 | ▶ | sub save($self,$store=undef) { | ||||||||||||||||||||||||||
|
Subroutine
save: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | 1 | ▶ | $self->store_db( $store ) if $store; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 1 | $self->store_db->set($self); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 2 | 1; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||||||||||