blib/lib/DB/Introspector/CommonRDB/Introspector.pm

filter: Statementstmt 19.4% 40 / 206 Branchbran 0.0% 0 / 50 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 25.0% 13 / 52 Podpod 0.0% 0 / 6 totaltotal 16.2% 53 / 327 CC 30 SCAR 18.8
CC
30
Cov
15%
columns
20.0
_lookup_indexes
20.0
primary_key
12.0
CRAP 6.6
« blib/lib/DB/Introspector/MappedPath.pm ↑ Summary test_lib/DB/IntrospectorBaseTest.pm »
1 package DB::Introspector::CommonRDB::Introspector;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use base qw( DB::Introspector );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use constant TABLE_NAME_COL => 'TABLE_NAME';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use constant OWNER_NAME_COL => 'OWNER_NAME';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 ## ABSTRACT METHODS
12  
13 0 ▶sub get_single_table_lookup_statement {
Subroutine get_single_table_lookup_statement: not called CC=1 SCAR=6.9
Pod undocumented
14 0 die("get_table_lookup_statement not defined");
15 }
16  
17 0 ▶sub get_all_tables_lookup_statement {
Subroutine get_all_tables_lookup_statement: not called CC=1 SCAR=6.9
Pod undocumented
18 0 die("get_all_tables_lookup_statement not defined");
19 }
20  
21 0 ▶sub get_table_class {
Subroutine get_table_class: not called CC=1 SCAR=6.9
Pod undocumented
22 0 die("get_table_class not defined");
23 }
24  
25  
26 ## DEFINED METHODS
27  
28 0 ▶sub lookup_table {
Subroutine lookup_table: not called CC=2 SCAR=17.9
Pod undocumented
29 0 my $self = shift;
30 0 my $table_name = shift;
31  
32 0 my $sth = $self->get_single_table_lookup_statement($table_name);
33 0 my $row = $sth->fetchrow_hashref('NAME_uc');
34 0 $sth->finish();
35 0 ▶ return undef unless( defined $row );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $row 0 0 0
36  
37 return $self->get_table_instance($row->{TABLE_NAME_COL()},
38 0 $row->{OWNER_NAME_COL()});
39 }
40  
41 0 ▶sub lookup_all_tables {
Subroutine lookup_all_tables: not called CC=2 SCAR=17.9
Pod undocumented
42 0 my $self = shift;
43 0 my $table_name = shift;
44  
45 0 my $sth = $self->get_all_tables_lookup_statement();
46  
47 # TODO: use cache
48 0 my @results;
49 0 ▶ while( my $row = $sth->fetchrow_hashref('NAME_uc') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref("NAME_uc")) 0 0 0
50 my $table = $self->get_table_instance($row->{TABLE_NAME_COL()},
51 0 $row->{OWNER_NAME_COL});
52 0 push(@results, $table);
53 }
54 0 $sth->finish();
55  
56 0 return @results;
57 }
58  
59 0 ▶sub get_table_instance {
Subroutine get_table_instance: not called CC=1 SCAR=6.9
Pod undocumented
60 0 my $self = shift;
61 0 my $table_name = shift;
62 0 my $owner_name = shift;
63  
64 0 return $self->get_table_class->new($table_name, $owner_name, $self);
65 }
66  
67  
68 package DB::Introspector::CommonRDB::Table;
69  
70 1 ▶use base qw( DB::Introspector::Base::Table );
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74  
75 1 ▶use constant COLUMN_NAME_COL => 'COLUMN_NAME';
Subroutine BEGIN: called CC=1 SCAR=0.0
76  
77  
78 ## ABSTRACT METHODS
79  
80 0 ▶sub get_column_lookup_statement {
Subroutine get_column_lookup_statement: not called CC=1 SCAR=6.9
81 0 die("get_column_lookup_statement not defined");
82 }
83  
84 0 ▶sub get_indexes_lookup_statement {
Subroutine get_indexes_lookup_statement: not called CC=1 SCAR=6.9
85 0 die("get_indexes_lookup_statement not defined");
86 }
87  
88 0 ▶sub get_foreign_keys_lookup_statement {
Subroutine get_foreign_keys_lookup_statement: not called CC=1 SCAR=6.9
89 0 die("get_foreign_keys_lookup_statement not defined");
90 }
91  
92 0 ▶sub get_dependencies_lookup_statement {
Subroutine get_dependencies_lookup_statement: not called CC=1 SCAR=6.9
93 0 die("get_dependencies_lookup_statement not defined");
94 }
95  
96 0 ▶sub get_functional_index_class {
Subroutine get_functional_index_class: not called CC=1 SCAR=6.9
97 0 my $self = shift;
98 0 return $self->get_index_class(@_);
99 }
100  
101 0 ▶sub get_column_instance {
Subroutine get_column_instance: not called CC=1 SCAR=6.9
102 0 my $self = shift;
103 0 my $name = shift;
104 0 my $type = shift;
105 0 die("get_column_instance not defined");
106 }
107  
108 0 ▶sub get_foreign_key_class {
Subroutine get_foreign_key_class: not called CC=1 SCAR=6.9
109 0 die("get_foreign_key_class not defined");
110 }
111  
112 0 ▶sub get_dependency_class {
Subroutine get_dependency_class: not called CC=1 SCAR=6.9
113 0 die("get_dependency_class not defined");
114 }
115  
116 0 ▶sub get_primary_key_column_ids {
Subroutine get_primary_key_column_ids: not called CC=1 SCAR=6.9
117 0 die("get_primary_key_column_ids not defined");
118 }
119  
120 ## DEFINED METHODS
121  
122 0 ▶sub primary_key {
Subroutine primary_key: not called CC=3 SCAR=24.8
123 0 my $self = shift;
124
125 0 ▶ unless(defined $self->{_primary_key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_primary_key"}) 0 0 0
126 0 my @primary_key;
127 0 my @column_ids = $self->get_primary_key_column_ids;
128 0 my @columns = $self->columns;
129  
130 0 foreach my $column_id (@column_ids) {
131 0 push(@primary_key, $columns[$column_id]);
132 }
133 0 $self->{_primary_key} = \@primary_key;
134 }
135 0 return @{$self->{_primary_key}};
136 }
137  
138 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
139 0 my $class = shift;
140 0 my $self = $class->SUPER::new(@_);
141 0 my $introspector = $_[2];
142  
143 0 ▶ unless( UNIVERSAL::isa($introspector, 'DB::Introspector') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($introspector, "DB::Introspector")) 0 0 0
144 0 die("$class constructor requires introspector");
145 }
146  
147 0 $self->{_introspector} = $introspector;
148 0 $self;
149 }
150  
151 0 ▶sub _introspector {
Subroutine _introspector: not called CC=1 SCAR=6.9
152 0 my $self = shift;
153 0 return $self->{_introspector};
154 }
155  
156 1 ▶use DB::Introspector::Base::SpecialColumn;
Subroutine BEGIN: called CC=1 SCAR=0.0
157 0 ▶sub columns {
Subroutine columns: not called CC=4 SCAR=30.0
158 0 my $self = shift;
159  
160 0 ▶ unless( defined $self->{'columns'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"columns"}) 0 0 0
161 0 my $sth = $self->get_column_lookup_statement();
162  
163 0 my @columns;
164 0 ▶ while( my $row = $sth->fetchrow_hashref('NAME_uc') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref("NAME_uc")) 0 0 0
165 my $column = $self->get_column_instance(
166 $row->{NAME}, $row->{TYPE}, $row)
167 || DB::Introspector::Base::SpecialColumn
168 0 ▶ ->new($row->{NAME}, $row->{TYPE});
Condition0%0/3
$self->get_column_instance($row->{'NAME'}, $row->{'TYPE'}, $row) || 'DB::Introspector::Base::SpecialColumn'->new($row->{'NAME'}, $row->{'TYPE'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_column_instance($row->{'NAME'}, $row->{'TYPE'}, $row) || 'DB::Introspector::Base::SpecialColumn'->new($row->{'NAME'}, $row->{'TYPE'})
$self->get_column_instance($row->{'NAME'}, $row->{'TYPE'}, $row) 'DB::Introspector::Base::SpecialColumn'->new($row->{'NAME'}, $row->{'TYPE'})
Truth table0%0/3
A || B
A= $self->get_column_instance($row->{'NAME'}, $row->{'TYPE'}, $row)B= 'DB::Introspector::Base::SpecialColumn'->new($row->{'NAME'}, $row->{'TYPE'})
ABresult
1X1
011
000
169
170 0 push(@columns, $column);
171 }
172 0 $sth->finish();
173  
174 0 $self->{'columns'} = \@columns;
175 }
176  
177 0 return @{$self->{'columns'}};
178 }
179  
180 0 ▶sub foreign_keys {
Subroutine foreign_keys: not called CC=2 SCAR=17.9
181 0 my $self = shift;
182  
183 0 ▶ unless( defined $self->{'foreign_keys'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"foreign_keys"}) 0 0 0
184 0 $self->{'foreign_keys'} = $self->_lookup_foreign_keys;
185 }
186  
187 0 return @{$self->{'foreign_keys'}};
188 }
189  
190 0 ▶sub indexes {
Subroutine indexes: not called CC=2 SCAR=17.9
191 0 my $self = shift;
192  
193 0 ▶ unless( defined $self->{'indexes'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"indexes"}) 0 0 0
194 0 $self->{'indexes'} = $self->_lookup_indexes;
195 }
196  
197 0 return @{$self->{'indexes'}};
198 }
199  
200 0 ▶sub dependencies {
Subroutine dependencies: not called CC=2 SCAR=17.9
201 0 my $self = shift;
202  
203 0 ▶ unless( defined $self->{'dependencies'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dependencies"}) 0 0 0
204 0 $self->{'dependencies'} = $self->_lookup_dependencies;
205 }
206  
207 0 return @{$self->{'dependencies'}};
208 }
209  
210 0 ▶sub _lookup_foreign_keys {
Subroutine _lookup_foreign_keys: not called CC=2 SCAR=17.9
211 0 my $self = shift;
212 0 my $sth = $self->get_foreign_keys_lookup_statement();
213  
214 0 my @foreign_keys;
215 0 ▶ while( my $row = $sth->fetchrow_hashref('NAME_uc') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref("NAME_uc")) 0 0 0
216 0 my $foreign_key = $self->get_foreign_key_class()->new($self,0, %$row);
217 0 push(@foreign_keys, $foreign_key);
218 }
219 0 $sth->finish();
220  
221 0 return \@foreign_keys;
222 }
223  
224 1 ▶use constant FUNCTIONAL => 'FUNCTIONAL';
Subroutine BEGIN: called CC=1 SCAR=0.0
225 0 ▶sub _lookup_indexes {
Subroutine _lookup_indexes: not called CC=4 SCAR=30.0
226 0 my $self = shift;
227 0 my $sth = $self->get_indexes_lookup_statement();
228  
229 0 my @indexes;
230 0 ▶ while( my $row = $sth->fetchrow_hashref('NAME_uc') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref("NAME_uc")) 0 0 0
231 0 ▶ if(defined($row->{INDEX_TYPE}) && $row->{INDEX_TYPE} eq FUNCTIONAL()) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $row->{'INDEX_TYPE'} and $row->{'INDEX_TYPE'} eq 'FUNCTIONAL') { } 0 0 0
Condition0%0/3
defined $row->{"INDEX_TYPE"} and $row->{"INDEX_TYPE"} eq "FUNCTIONAL"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $row->{"INDEX_TYPE"} and $row->{"INDEX_TYPE"} eq "FUNCTIONAL"
defined $row->{"INDEX_TYPE"} $row->{"INDEX_TYPE"} eq "FUNCTIONAL"
Truth table0%0/3
A and B
A= defined $row->{"INDEX_TYPE"}B= $row->{"INDEX_TYPE"} eq "FUNCTIONAL"
ABresult
0X0
100
111
232 0 push(@indexes,$self->get_functional_index_class()->new($self, %$row));
233 } else {
234 0 push(@indexes, $self->get_index_class()->new($self, %$row));
235 }
236 }
237 0 $sth->finish();
238  
239 0 return \@indexes;
240 }
241  
242 0 ▶sub _lookup_dependencies {
Subroutine _lookup_dependencies: not called CC=3 SCAR=24.8
243 0 my $self = shift;
244 0 my $sth = $self->get_dependencies_lookup_statement();
245  
246 0 my @dependencies;
247 0 ▶ while( my $row = $sth->fetchrow_hashref('NAME_uc') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref("NAME_uc")) 0 0 0
248 my $local_table =
249 $self->_introspector->find_table( $row->{CHILD_TABLE_NAME} )
250 0 ▶ || die("no child table found for dependency");
Condition0%0/2
$self->_introspector->find_table($row->{'CHILD_TABLE_NAME'}) || die('no child table found for dependency')
l!l
00
MC/DC0%0/1
$self->_introspector->find_table($row->{'CHILD_TABLE_NAME'}) || die('no child table found for dependency')
$self->_introspector->find_table($row->{'CHILD_TABLE_NAME'})
Truth table0%0/2
A
A= $self->_introspector->find_table($row->{'CHILD_TABLE_NAME'})
Aresult
11
00
251 0 my $dependency = $self->get_foreign_key_class()->new($local_table, 1,
252 %$row);
253 0 push(@dependencies, $dependency);
254 }
255 0 $sth->finish();
256  
257 0 return \@dependencies;
258 }
259  
260  
261 package DB::Introspector::CommonRDB::ForeignKey;
262  
263 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
264  
265 1 ▶use base qw( DB::Introspector::Base::ForeignKey );
Subroutine BEGIN: called CC=1 SCAR=0.0
266  
267  
268 ## ABSTRACT METHODS
269  
270 0 ▶sub get_local_column_name_lookup_statement {
Subroutine get_local_column_name_lookup_statement: not called CC=1 SCAR=6.9
271 0 die("get_local_column_name_lookup_statement not defined");
272 }
273  
274 0 ▶sub get_foreign_column_name_lookup_statement {
Subroutine get_foreign_column_name_lookup_statement: not called CC=1 SCAR=6.9
275 0 die("get_foreign_column_name_lookup_statement not defined");
276 }
277  
278 0 ▶sub get_foreign_table_name_lookup_statement {
Subroutine get_foreign_table_name_lookup_statement: not called CC=1 SCAR=6.9
279 0 die("get_foreign_table_name_lookup_statement not defined");
280 }
281  
282  
283 ## DEFINED METHODS
284  
285 0 ▶sub local_column_names {
Subroutine local_column_names: not called CC=3 SCAR=24.8
286 0 my $self = shift;
287  
288 0 ▶ unless( defined $self->{'local_column_names'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"local_column_names"}) 0 0 0
289 0 my $sth = $self->get_local_column_name_lookup_statement();
290  
291 0 my @local_column_names;
292 0 ▶ while( my $row = $sth->fetchrow_hashref('NAME_uc') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref("NAME_uc")) 0 0 0
293 0 push(@local_column_names, $row->{NAME});
294 }
295 0 $sth->finish();
296  
297 0 $self->{'local_column_names'} = \@local_column_names;
298 }
299  
300 0 return @{$self->{'local_column_names'}};
301 }
302  
303 0 ▶sub foreign_column_names {
Subroutine foreign_column_names: not called CC=2 SCAR=17.9
304 0 my $self = shift;
305  
306 0 ▶ unless( defined $self->{'foreign_column_names'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"foreign_column_names"}) 0 0 0
307 0 $self->{'foreign_column_names'} = $self->_populate_foreign_column_names;
308 }
309  
310 0 return @{$self->{'foreign_column_names'}};
311 }
312  
313 0 ▶sub _populate_foreign_column_names {
Subroutine _populate_foreign_column_names: not called CC=2 SCAR=17.9
314 0 my $self = shift;
315  
316 0 my $sth = $self->get_foreign_column_name_lookup_statement();
317  
318 0 my @foreign_column_names;
319 0 ▶ while( my $row = $sth->fetchrow_hashref('NAME_uc') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref("NAME_uc")) 0 0 0
320 0 push(@foreign_column_names, $row->{NAME});
321 }
322 0 $sth->finish();
323  
324 0 return \@foreign_column_names;
325 }
326  
327 0 ▶sub set_foreign_column_names {
Subroutine set_foreign_column_names: not called CC=2 SCAR=17.9
328 0 my $self = shift;
329 0 ▶ return unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
330  
331 0 $self->{foreign_column_names} = shift;
332 }
333  
334 0 ▶sub set_local_column_names {
Subroutine set_local_column_names: not called CC=2 SCAR=17.9
335 0 my $self = shift;
336 0 ▶ return unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
337  
338 0 $self->{local_column_names} = shift;
339 }
340  
341 0 ▶sub set_foreign_table_name {
Subroutine set_foreign_table_name: not called CC=2 SCAR=17.9
342 0 my $self = shift;
343 0 ▶ return unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
344  
345 0 $self->{foreign_table_name} = shift;
346 }
347  
348 0 ▶sub foreign_table_name {
Subroutine foreign_table_name: not called CC=2 SCAR=17.9
349 0 my $self = shift;
350  
351 0 ▶ unless( defined $self->{'foreign_table_name'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"foreign_table_name"}) 0 0 0
352 0 my $sth = $self->get_foreign_table_name_lookup_statement();
353  
354 0 my $row = $sth->fetchrow_hashref('NAME_uc');
355 0 $sth->finish();
356  
357 0 $self->set_foreign_table_name($row->{NAME});
358 }
359  
360 0 return $self->{'foreign_table_name'};
361 }
362  
363 0 ▶sub foreign_table {
Subroutine foreign_table: not called CC=2 SCAR=17.9
364 0 my $self = shift;
365  
366 0 ▶ unless( defined $self->{'foreign_table'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"foreign_table"}) 0 0 0
367 0 $self->{'foreign_table'} = $self->local_table
368 ->_introspector
369 ->find_table($self->foreign_table_name);
370 }
371 0 return $self->{'foreign_table'};
372 }
373  
374  
375  
376 package DB::Introspector::CommonRDB::Index;
377  
378 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
379  
380 1 ▶use base qw( DB::Introspector::Base::Index );
Subroutine BEGIN: called CC=1 SCAR=0.0
381  
382  
383 0 ▶sub get_column_name_lookup_statement {
Subroutine get_column_name_lookup_statement: not called CC=1 SCAR=6.9
384 0 die("get_column_name_lookup_statement not defined");
385 }
386  
387 ## DEFINED METHODS
388  
389 0 ▶sub column_names {
Subroutine column_names: not called CC=3 SCAR=24.8
390 0 my $self = shift;
391  
392 0 ▶ unless( defined $self->{'column_names'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"column_names"}) 0 0 0
393 0 my $sth = $self->get_column_name_lookup_statement();
394  
395 0 my @column_names;
396 0 ▶ while( my $row = $sth->fetchrow_hashref('NAME_uc') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref("NAME_uc")) 0 0 0
397 0 push(@column_names, $row->{NAME});
398 }
399 0 $sth->finish();
400  
401 0 $self->{'column_names'} = \@column_names;
402 }
403  
404 0 return @{$self->{'column_names'}};
405 }
406  
407 0 ▶sub set_column_names {
Subroutine set_column_names: not called CC=2 SCAR=17.9
408 0 my $self = shift;
409 0 ▶ return unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
410  
411 0 $self->{column_names} = shift;
412 }
413  
414  
415 1 1;
« blib/lib/DB/Introspector/MappedPath.pm ↑ Summary test_lib/DB/IntrospectorBaseTest.pm »