lib/SQL/Admin/Catalog.pm

filter: Statementstmt 67.9% 55 / 81 Branchbran 37.5% 9 / 24 Conditioncond 32.0% 8 / 25 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 60.8% 14 / 23 Podpod 0.0% 0 / 9 totaltotal 48.5% 86 / 177 CC 23 SCAR 20.9
CC
23
Cov
55%
exists
30.0
load
12.0
save
12.0
CRAP 8.1
« lib/SQL/Admin/Driver/Pg/Producer.pm ↑ Summary lib/SQL/Admin/Catalog/Table/Column.pm »
1  
2 package SQL::Admin::Catalog;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = v0.5.0;
8  
9 ######################################################################
10  
11 1 ▶use SQL::Admin::Catalog::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use SQL::Admin::Catalog::Sequence;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use SQL::Admin::Catalog::Index;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use SQL::Admin::Catalog::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use SQL::Admin::Catalog::Table::Column;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use SQL::Admin::Catalog::Table::PrimaryKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use SQL::Admin::Catalog::Table::Unique;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use SQL::Admin::Catalog::Table::ForeignKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 ######################################################################
21  
22 1 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 our $NAME_TRANSFORM = {
25 0 ▶ NAME => sub { $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 0 ▶ NAME_lc => sub { lc $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 ▶ NAME_uc => sub { uc $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 1 };
29  
30 ######################################################################
31  
32 1 my $class_map = {
33 schema => 'SQL::Admin::Catalog::Schema',
34 sequence => 'SQL::Admin::Catalog::Sequence',
35 table => 'SQL::Admin::Catalog::Table',
36 index => 'SQL::Admin::Catalog::Index',
37 column => 'SQL::Admin::Catalog::Table::Column',
38 primary_key => 'SQL::Admin::Catalog::Table::PrimaryKey',
39 unique => 'SQL::Admin::Catalog::Table::Unique',
40 foreign_key => 'SQL::Admin::Catalog::Table::ForeignKey',
41 };
42  
43 ######################################################################
44 ######################################################################
45 8 ▶sub new { # ;
Subroutine new: called CC=4 SCAR=15.6
Pod undocumented
46 8 my ($class, %param) = @_;
47  
48 $param{FetchHashKeyName} = 'NAME_uc'
49 8 ▶ unless $param{FetchHashKeyName};
Branch: 1 branch
BranchTrueFalseTotal
unless $param{"FetchHashKeyName"} 8 0 8
50  
51 $param{FetchHashKeyName} = 'NAME'
52 8 ▶ unless exists $NAME_TRANSFORM->{ $param{FetchHashKeyName} };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$SQL::Admin::Catalog::NAME_TRANSFORM{$param{"FetchHashKeyName"}} 0 8 8
53  
54 ##################################################################
55  
56 bless {
57 name_transform => $NAME_TRANSFORM->{ $param{FetchHashKeyName} },
58 8 ▶ allow_redeclare => 1,
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
080
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
59  
60 (map +($_ => {}), keys %$class_map),
61 }, ref $class || $class;
62 }
63  
64  
65 ######################################################################
66 ######################################################################
67 0 ▶sub catalog { # ;
Subroutine catalog: not called CC=1 SCAR=6.9
Pod undocumented
68 0 $_[0];
69 }
70  
71  
72 ######################################################################
73 ######################################################################
74 20 ▶sub add { # ;
Subroutine add: called CC=8 SCAR=21.8
Pod undocumented
75 20 my ($self, $type, %param) = @_;
76  
77 20 ▶ return unless exists $class_map->{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $class_map->{$type} 0 20 20
78  
79 20 ▶ my $typemap = $self->{$type} ||= {};
Condition50%1/2
$self->{$type} ||= {}
l!l
200
MC/DC0%0/1
$self->{$type} ||= {}
$self->{$type}
Truth table50%1/2
A
A= $self->{$type}
Aresult
11
00
80  
81 ##################################################################
82  
83 $param{schema} = $self->{default_schema}
84 20 ▶ if ! $param{schema} and $self->{default_schema};
Branch: 1 branch
BranchTrueFalseTotal
if not $param{"schema"} and $self->{"default_schema"} 0 20 20
Condition66%2/3
not $param{"schema"} and $self->{"default_schema"}
!ll&&!rl&&r
1190
MC/DC0%0/2
not $param{"schema"} and $self->{"default_schema"}
not $param{"schema"} $self->{"default_schema"}
Truth table66%2/3
not(A) and B
A= not $param{"schema"}B= $self->{"default_schema"}
ABresult
0X0
100
111
85  
86 20 my $obj = $self->get ($type, %param, catalog => $self);
87  
88 ##################################################################
89  
90 20 ▶ if (my $schema = $obj->schema) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $schema = $obj->schema) 11 9 20
91 11 ▶ $self->{schema}{$schema} ||= $class_map->{schema}->new (name => $schema);
Condition66%2/3
$self->{"schema"}{$schema} ||= $class_map->{"schema"}->new("name", $schema)
l!l&&r!l&&!r
380
MC/DC0%0/2
$self->{"schema"}{$schema} ||= $class_map->{"schema"}->new("name", $schema)
$self->{"schema"}{$schema} $class_map->{"schema"}->new("name", $schema)
Truth table66%2/3
A ||= B
A= $self->{"schema"}{$schema}B= $class_map->{"schema"}->new("name", $schema)
ABresult
1X1
011
000
92 }
93  
94 ##################################################################
95  
96 20 ▶ $typemap->{ $obj->fullname } ||= $obj;
Condition66%2/3
$$typemap{$obj->fullname} ||= $obj
l!l&&r!l&&!r
1190
MC/DC0%0/2
$$typemap{$obj->fullname} ||= $obj
$$typemap{$obj->fullname} $obj
Truth table66%2/3
A ||= B
A= $$typemap{$obj->fullname}B= $obj
ABresult
1X1
011
000
97 }
98  
99  
100 ######################################################################
101 ######################################################################
102 23 ▶sub get { # ;
Subroutine get: called CC=3 SCAR=11.0
Pod undocumented
103 23 my ($self, $type, %param) = @_;
104  
105 return
106 23 ▶ unless exists $class_map->{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $class_map->{$type} 0 23 23
107  
108 ##################################################################
109  
110 # my $obj = $class_map->{$type}->new (%param, catalog => $self);
111 23 my $obj = $class_map->{$type}->new (%param);
112 23 my $key = $obj->fullname;
113  
114 $obj = $self->{$type}{ $key }
115 23 ▶ if exists $self->{$type}{ $key };
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{$type}{$key} 1 22 23
116  
117 ##################################################################
118  
119 23 return $obj;
120 }
121  
122  
123 ######################################################################
124 ######################################################################
125 0 ▶sub exists { # ;
Subroutine exists: not called CC=5 SCAR=34.0
Pod undocumented
126 0 my ($self, $type, @list) = @_;
127  
128 return
129 0 ▶ unless exists $class_map->{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $class_map->{$type} 0 0 0
130  
131 0 my $key;
132 0 ▶ $key = 1 == @list ? $list[0] : $class_map->{$type}->new (@list);
Branch: 1 branch
BranchTrueFalseTotal
1 == @list ? : 0 0 0
133 0 ▶ $key = $key->fullname if ref $key;
Branch: 1 branch
BranchTrueFalseTotal
if ref $key 0 0 0
134  
135 0 ▶ return exists $self->{$type}{ $key } && $key;
Condition0%0/3
exists $self->{$type}{$key} && $key
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{$type}{$key} && $key
exists $self->{$type}{$key} $key
Truth table0%0/3
A && B
A= exists $self->{$type}{$key}B= $key
ABresult
0X0
100
111
136 }
137  
138  
139 ######################################################################
140 ######################################################################
141 0 ▶sub list { # ;
Subroutine list: not called CC=2 SCAR=17.9
Pod undocumented
142 0 my ($self, $type) = @_;
143  
144 0 ▶ +{ %{ $self->{$type} || {} } };
Condition0%0/2
$self->{$type} || {}
l!l
00
MC/DC0%0/1
$self->{$type} || {}
$self->{$type}
Truth table0%0/2
A
A= $self->{$type}
Aresult
11
00
145 }
146  
147  
148 ######################################################################
149 ######################################################################
150 0 ▶sub add_statement { # ;
Subroutine add_statement: not called CC=2 SCAR=17.9
Pod undocumented
151 0 my $self = shift;
152 0 ▶ my $list = $self->{statements} ||= [];
Condition0%0/2
$self->{"statements"} ||= []
l!l
00
MC/DC0%0/1
$self->{"statements"} ||= []
$self->{"statements"}
Truth table0%0/2
A
A= $self->{"statements"}
Aresult
11
00
153  
154 0 push @$list, @_;
155 }
156  
157  
158 ######################################################################
159 ######################################################################
160 0 ▶sub load { # ;
Subroutine load: not called CC=3 SCAR=24.8
Pod undocumented
161 0 my ($self, $driver, @params) = @_;
162  
163 0 ▶ $driver = SQL::Admin->get_driver ($driver, @{ shift @params || [] } )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $driver 0 0 0
Condition0%0/2
shift @params || []
l!l
00
MC/DC0%0/1
shift @params || []
shift @params
Truth table0%0/2
A
A= shift @params
Aresult
11
00
164 unless ref $driver;
165  
166 0 $driver->load ($self, @params);
167  
168 0 $self;
169 }
170  
171  
172 ######################################################################
173 ######################################################################
174 0 ▶sub save { # ;
Subroutine save: not called CC=3 SCAR=24.8
Pod undocumented
175 0 my ($self, $driver, @params) = @_;
176  
177 0 ▶ $driver = SQL::Admin->get_driver ($driver, @{ shift @params || [] } )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $driver 0 0 0
Condition0%0/2
shift @params || []
l!l
00
MC/DC0%0/1
shift @params || []
shift @params
Truth table0%0/2
A
A= shift @params
Aresult
11
00
178 unless ref $driver;
179  
180 0 $driver->save ($self, @params);
181  
182 0 $self;
183 }
184  
185  
186 ######################################################################
187 ######################################################################
188  
189 package SQL::Admin::Catalog;
190  
191 1 1;
192  
193 __END__
« lib/SQL/Admin/Driver/Pg/Producer.pm ↑ Summary lib/SQL/Admin/Catalog/Table/Column.pm »