NoSQL/ClassScaffold.pm

filter: Statementstmt 97.5% 80 / 82 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 95.4% 21 / 22 Podpod 16.6% 1 / 6 totaltotal 92.8% 104 / 112 CC 4 SCAR 3.1
CC
4
Cov
98%
deploy
3.0
__ANON__
2.0
_build_version
2.0
CRAP 1.4
« NoSQL/Stash.pm ↑ Summary NoSQLite.pm »
1 package DBIx::NoSQL::ClassScaffold;
2 # Scaffold
3  
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 my $__serial__ = -1;
8 our $serial = sub {
9 29 ▶ return $__serial__ += 1;
Subroutine __ANON__: called CC=1 SCAR=0.0
10 9 };
11  
12 9 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 9 has package => qw/ is ro lazy_build 1 /;
15 sub _build_package {
16 29 ▶ return 'DBIx::NoSQL::__Anonymous__::Class' . $serial->();
Subroutine _build_package: called CC=1 SCAR=0.0
17 }
18  
19 9 has package_meta => qw/ is ro lazy_build 1 /;
20 sub _build_package_meta {
21 11 ▶ my $self = shift;
Subroutine _build_package_meta: called CC=1 SCAR=0.0
22 11 return any_moose( 'Meta::Class' )->create( $self->package );
23 }
24  
25 sub push_ISA {
26 19 ▶ my $self = shift;
Subroutine push_ISA: called CC=1 SCAR=0.0
Pod undocumented
27 19 my $target = shift;
28  
29 19 my $package = $self->package;
30 19 eval "push \@${package}::ISA, '$target'";
31 19 return $self;
32 }
33  
34 sub become_Schema {
35 10 ▶ my $self = shift;
Subroutine become_Schema: called CC=1 SCAR=0.0
Pod undocumented
36  
37 10 require DBIx::Class::Schema;
38 10 $self->package_meta->superclasses( 'DBIx::NoSQL::ClassScaffold::Schema' );
39 10 return $self;
40 }
41  
42 sub become_ResultClass {
43 19 ▶ my $self = shift;
Subroutine become_ResultClass: called CC=1 SCAR=0.0
Pod undocumented
44  
45 19 require DBIx::Class::Core;
46 19 $self->push_ISA( 'DBIx::NoSQL::ClassScaffold::ResultClass' );
47 19 return $self;
48 }
49  
50 sub become_ResultClass_Store {
51 10 ▶ my $self = shift;
Subroutine become_ResultClass_Store: called CC=1 SCAR=0.0
Pod undocumented
52  
53 10 $self->become_ResultClass;
54 10 my $package = $self->package;
55  
56 10 $package->table( '__Store__' );
57 10 $package->add_columns(
58 __model__ => {
59 data_type => 'text',
60 },
61 __key__ => {
62 data_type => 'text',
63 },
64 __value__ => {
65 data_type => 'text',
66 default_value => '{}',
67 },
68 );
69 10 $package->set_primary_key(qw/ __model__ __key__ /);
70 10 return $self;
71 }
72  
73 package DBIx::NoSQL::ClassScaffold::Schema;
74  
75 9 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
76  
77 9 extends qw/ DBIx::Class::Schema /;
78  
79 9 ▶use JSON; our $json = JSON->new->pretty;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 9 ▶use Digest::SHA qw/ sha1_hex /;
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82 9 has store => qw/ is rw weak_ref 1 /;
83  
84 9 has deployment_statements => qw/ accessor _deployment_statements lazy_build 1 /;
85 sub _build_deployment_statements {
86 8 ▶ return shift->build_deployment_statements;
Subroutine _build_deployment_statements: called CC=1 SCAR=0.0
87 }
88  
89 sub build_deployment_statements {
90 23 ▶ my $self = shift;
Subroutine build_deployment_statements: called CC=1 SCAR=0.0
Pod undocumented
91 23 my $sql = $self->deployment_statements( undef, undef, undef, { add_drop_table => 1 } );
92 23 $sql =~ s/^--[^\n]*$//gsm;
93 23 return $sql;
94 }
95  
96 around deployment_statements => sub {
97 31 ▶ my $inner = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
98 31 my $self = shift;
99 31 ▶ return $inner->( $self, @_ ) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 23 8 31
100 8 return $self->_deployment_statements;
101 9 };
102  
103 9 has version => qw/ is ro lazy_build 1 /;
104 sub _build_version {
105 0 ▶ my $self = shift;
Subroutine _build_version: not called CC=1 SCAR=6.9
106 0 return sha1_hex( $self->sql );
107 }
108  
109 sub deploy {
110 8 ▶ my $self = shift;
Subroutine deploy: called CC=3 SCAR=11.0
Pod documented
111  
112 8 my $deployment_statements = $self->deployment_statements;
113 8 s/^\s*//, s/\s*$// for $deployment_statements;
114 8 my @deployment_statements = split m/;\n\s*/, $deployment_statements;
115  
116 8 $self->store->storage->do( $_ ) for @deployment_statements;
117 }
118  
119 package DBIx::NoSQL::ClassScaffold::ResultClass;
120  
121 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
123  
124 9 ▶use base qw/ DBIx::Class::Core /;
Subroutine BEGIN: called CC=1 SCAR=0.0
125  
126 sub register {
127 10 ▶ my $class = shift;
Subroutine register: called CC=1 SCAR=0.0
128 10 my $schema_class = shift;
129 10 my $moniker = shift;
130  
131 10 $schema_class->register_class( $moniker => $class );
132 }
133  
134 9 1;
135  
« NoSQL/Stash.pm ↑ Summary NoSQLite.pm »