Manager.pm

filter: Statementstmt 93.6% 59 / 63 Branchbran 60.0% 6 / 10 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 94.1% 16 / 17 Podpod 66.6% 2 / 3 totaltotal 87.5% 84 / 96 CC 9 SCAR 8.1
CC
9
Cov
88%
_register_models
5.1
__ANON__
3.1
__ANON__
2.0
CRAP 2.2
« Manager/StoreModel.pm ↑ Summary Manager/Model.pm »
1 package DBIx::NoSQL::Store::Manager;
2 4 our $AUTHORITY = 'cpan:YANICK';
3 #ABSTRACT: DBIx::NoSQL as a Moose object store
4 4 $DBIx::NoSQL::Store::Manager::VERSION = '1.0.0';
5 4 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # TODO type tiny
13 4 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶use DBIx::NoSQL 0.0020;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Module::Pluggable require => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 extends 'DBIx::NoSQL::Store';
19  
20 4 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 4 subtype Model
24 => as 'ArrayRef[Str]';
25  
26 coerce Model
27 => from 'Str'
28 0 ▶ => via { [ $_ ] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
29  
30 has models => (
31 traits => [ 'Array' ],
32 is => 'ro',
33 isa => 'Model',
34 4 ▶ default => sub($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
35 4 [ join "::", ($self->meta->class_precedence_list)[0], 'Model', '' ];
36 },
37 4 handles => {
38 arg_models => 'elements',
39 },
40 );
41  
42  
43 4 has _models => (
44 traits => [ 'Hash' ],
45 is => 'ro',
46 isa => 'HashRef',
47 handles => {
48 model_names => 'keys',
49 model_classes => 'values',
50 model_class => 'get',
51 _set_model => 'set',
52 },
53 );
54  
55 4 ▶sub _register_models( $self, @models ) {
Subroutine _register_models: called CC=5 SCAR=16.2
56 # expand namespaces into their plugins
57 @models = map {
58 4 ▶ s/::$// ? do {
Branch: 1 branch
BranchTrueFalseTotal
s/::$//u ? : 4 0 4
59 4 $self->search_path( new => $_ );
60 4 $self->plugins } : $_
61 } @models;
62  
63  
64 4 for my $model ( @models ) {
65 1 ▶ eval "use $model; 1" or die "couldn't load '$_': $@\n";
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval "use $model; 1" or die "couldn't load '${_}': $@\n" 1 0 1
66 1 $self->_set_model( $model->store_model => $model );
67  
68 1 my $store_model = $self->model($model->store_model);
69  
70  
71 1 ▶ $store_model->_wrap( sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
72 1 my $ref = shift;
73 1 ▶ $ref = $ref->[0] if ref($ref) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref eq "ARRAY" 0 1 1
74 1 $model->unpack($ref, inject => { store_db => $self } );
75 1 });
76  
77 1 $store_model->index(@$_) for $model->indexes;
78 }
79 }
80  
81 4 ▶sub BUILD($self,$args) {
Subroutine BUILD: called CC=2 SCAR=7.1
Pod undocumented
82 $args->{models} ||= [
83 4 ▶ join "::", ($self->meta->class_precedence_list)[0], 'Model', ''
Condition50%1/2
$args->{"models"} ||= [join("::", ($self->meta->class_precedence_list)[0], "Model", "")]
l!l
04
MC/DC0%0/1
$args->{"models"} ||= [join("::", ($self->meta->class_precedence_list)[0], "Model", "")]
$args->{"models"}
Truth table50%1/2
A
A= $args->{"models"}
Aresult
11
00
84 ];
85  
86 4 $self->_register_models( @{ $args->{models} } );
87 };
88  
89  
90  
91 1 ▶sub new_model_object($self,$model,@args) {
Subroutine new_model_object: called CC=1 SCAR=0.0
Pod documented
92 1 $self->model_class($model)->new( store_db => $self, @args);
93 }
94  
95  
96 1 ▶sub create ( $self, $model, @args ) {
Subroutine create: called CC=1 SCAR=2.6
Pod documented
97 1 my $object = $self->new_model_object( $model => @args );
98 0 $object->save;
99 0 return $object;
100 }
101  
102 # $store->set( $model, $key, $hashref )
103 # $store->set( $object )
104 2 ▶around set => sub($orig,$self,@rest) {
Subroutine __ANON__: called CC=3 SCAR=11.2
105  
106 2 ▶ if( @rest == 1 ) { # object call
Branch: 1 branch
BranchTrueFalseTotal
if (@rest == 1) 2 0 2
107 2 my $object = shift @rest;
108 2 ▶ $object->store_db($self) unless $object->has_store_db;
Branch: 1 branch
BranchTrueFalseTotal
unless $object->has_store_db 1 1 2
109
110 2 return $orig->( $self, map { $object->$_ } qw/ store_model store_key pack / );
111 }
112 0 $orig->($self, @rest );
113 4 };
114  
115 4 1;
116  
117 __END__
« Manager/StoreModel.pm ↑ Summary Manager/Model.pm »