lib/SQL/Admin/Driver/Base/Producer.pm

filter: Statementstmt 66.9% 91 / 136 Branchbran 43.7% 14 / 32 Conditioncond 45.4% 5 / 11 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 60.9% 39 / 64 Podpod 0.0% 0 / 52 totaltotal 50.0% 151 / 302 CC 21 SCAR 15.1
CC
21
Cov
61%
alter_column
30.0
__process
20.0
produce
6.0
CRAP 4.5
« lib/SQL/Admin/Catalog/Object.pm ↑ Summary lib/SQL/Admin/Driver/Base/Parser.pm »
1  
2 package SQL::Admin::Driver::Base::Producer;
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = v0.5.0;
8  
9 ######################################################################
10  
11 2 ▶use SQL::Admin::Utils qw( refarray refhash );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 ######################################################################
14  
15 2 our $AUTOLOAD;
16 2 our $STATEMENT_SEPARATOR = ";\n\n";
17  
18 ######################################################################
19  
20 2 my %numbers = (
21 int2 => 1,
22 int4 => 1,
23 int8 => 1,
24 real => 1,
25 );
26  
27 ######################################################################
28 ######################################################################
29 1 ▶sub new { # ;
Subroutine new: called CC=2 SCAR=8.1
Pod undocumented
30 1 my ($class, %param) = @_;
31  
32 1 ▶ bless \ %param, ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
33 }
34  
35  
36 ######################################################################
37 ######################################################################
38 0 ▶sub produce { # ;
Subroutine produce: not called CC=2 SCAR=17.9
Pod undocumented
39 0 my $self = shift;
40 0 local $, = ' ';
41  
42 0 ▶ join '', (
Branch: 1 branch
BranchTrueFalseTotal
&refarray($_) ? : 0 0 0
43 map +($_, $STATEMENT_SEPARATOR),
44 map $self->__process ($_),
45 map refarray ($_) ? @$_ : $_,
46 @_
47 );
48 }
49  
50  
51 ######################################################################
52 ######################################################################
53 0 ▶sub __process { # ;
Subroutine __process: not called CC=4 SCAR=30.0
54 0 my ($self, $def) = @_;
55  
56 0 ▶ return $def
Branch: 1 branch
BranchTrueFalseTotal
unless ref $def 0 0 0
57 unless ref $def;
58  
59 0 ▶ return map $self->__apply (%$_), @$def
Branch: 1 branch
BranchTrueFalseTotal
if &refarray($def) 0 0 0
60 if refarray $def;
61  
62 0 ▶ return map $self->__call ($_, $def), keys %$def
Branch: 1 branch
BranchTrueFalseTotal
if &refhash($def) 0 0 0
63 if refhash $def;
64 }
65  
66  
67 ######################################################################
68 ######################################################################
69 61 ▶sub __apply { # ;
Subroutine __apply: called CC=2 SCAR=6.9
70 61 my ($self, $method, $def, @param) = @_;
71  
72 61 my $retval = join $,, do {
73 61 local $, = ' ';
74 61 local $_ = $def;
75 61 $self->$method ($def, @param)
76 };
77  
78 ##################################################################
79  
80 61 ▶ return $retval unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 16 45 61
81 45 grep length $_, $retval;
82 }
83  
84  
85 ######################################################################
86 ######################################################################
87 364 ▶sub __call { # ;
Subroutine __call: called CC=4 SCAR=13.9
88 364 my ($self, $method, $def, @param) = @_;
89  
90 364 ▶ return unless refhash $def;
Branch: 1 branch
BranchTrueFalseTotal
unless &refhash($def) 0 364 364
91 364 ▶ return unless exists $def->{$method};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $def->{$method} 115 249 364
92  
93 249 my $retval = join $,, do {
94 249 local $, = ' ';
95 249 local $_ = $def->{$method};
96 249 $self->$method ($def->{$method}, $def)
97 };
98  
99 ##################################################################
100  
101 249 ▶ return $retval unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 93 156 249
102 156 grep length $_, $retval;
103 }
104  
105  
106 ######################################################################
107 ######################################################################
108 0 ▶sub __values { # ;
Subroutine __values: not called CC=2 SCAR=17.9
109 0 my ($self, $def) = @_;
110  
111 0 ▶ join $,, sort $self->__process ($def || {});
Condition0%0/2
$def || {}
l!l
00
MC/DC0%0/1
$def || {}
$def
Truth table0%0/2
A
A= $def
Aresult
11
00
112 }
113  
114  
115 ######################################################################
116 ######################################################################
117  
118 0 ▶sub _escape_identifier { # ;
Subroutine _escape_identifier: not called CC=1 SCAR=6.9
119 0 $_[1];
120 }
121  
122  
123 ######################################################################
124 ######################################################################
125 124 ▶sub identifier { # ;
Subroutine identifier: called CC=1 SCAR=0.0
Pod undocumented
126 124 shift->_escape_identifier (@_);
127 }
128  
129  
130 ######################################################################
131 ######################################################################
132 5 ▶sub integer { # ;
Subroutine integer: called CC=1 SCAR=0.0
Pod undocumented
133 5 $_[1];
134 }
135  
136  
137 ######################################################################
138 ######################################################################
139 10 ▶sub numeric_constant { # ;
Subroutine numeric_constant: called CC=1 SCAR=0.0
Pod undocumented
140 10 $_[1];
141 }
142  
143  
144 ######################################################################
145 ######################################################################
146 2 ▶sub string { # ;
Subroutine string: called CC=1 SCAR=0.0
Pod undocumented
147 2 my ($self, $def) = @_;
148  
149 2 $def =~ s/(?=\')/\'/;
150 2 '\'' . $def . '\'';
151 }
152  
153  
154 ######################################################################
155 ######################################################################
156 26 ▶sub data_type { # ;
Subroutine data_type: called CC=4 SCAR=13.9
Pod undocumented
157 26 my ($self, $type, $parent) = @_;
158  
159 26 ▶ if (refhash $parent and $parent->{size}) {
Branch: 1 branch
BranchTrueFalseTotal
if (&refhash($parent) and $parent->{"size"}) 7 19 26
Condition100%3/3
&refhash($parent) and $parent->{"size"}
!ll&&!rl&&r
6137
MC/DC100%2/2
&refhash($parent) and $parent->{"size"}
&refhash($parent) $parent->{"size"}
Truth table100%3/3
A and B
A= &refhash($parent)B= $parent->{"size"}
ABresult
0X0
100
111
160 7 $type .= '(' . $parent->{size};
161 7 ▶ $type .= ',' . $parent->{scale} if defined $parent->{scale};
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent->{"scale"} 1 6 7
162 7 $type .= ')';
163 }
164  
165 26 $type;
166 }
167  
168  
169 ######################################################################
170 ######################################################################
171 57 ▶sub column_name { # ;
Subroutine column_name: called CC=1 SCAR=0.0
Pod undocumented
172 57 shift->identifier (@_);
173 }
174  
175  
176 ######################################################################
177 ######################################################################
178 12 ▶sub column_order { # ;
Subroutine column_order: called CC=1 SCAR=0.0
Pod undocumented
179 12 map uc, grep defined $_, $_[1];
180 }
181  
182  
183 ######################################################################
184 ######################################################################
185 24 ▶sub ordered_column_name { # ;
Subroutine ordered_column_name: called CC=1 SCAR=0.0
Pod undocumented
186 24 my ($self, $def) = @_;
187  
188 24 join ' ', grep $_, (
189 $self->__call (column_name => $def),
190 $self->__call (column_order => $def),
191 )
192 }
193  
194  
195 ######################################################################
196 ######################################################################
197 13 ▶sub ordered_column_names { # ;
Subroutine ordered_column_names: called CC=1 SCAR=0.0
Pod undocumented
198 13 my ($self, $def) = @_;
199  
200 13 join ', ', map $self->ordered_column_name ($_), @$def;
201 }
202  
203  
204 ######################################################################
205 ######################################################################
206 33 ▶sub schema_qualified_name { # ;
Subroutine schema_qualified_name: called CC=1 SCAR=0.0
Pod undocumented
207 33 my ($self, $def) = @_;
208  
209 join '.',
210 map $self->identifier ($_),
211 grep $_,
212 33 @$def{qw{ schema name }};
213 }
214  
215  
216 ######################################################################
217 ######################################################################
218 6 ▶sub index_name { # ; alias: schema_qualified_name
Subroutine index_name: called CC=1 SCAR=0.0
Pod undocumented
219 6 shift->schema_qualified_name (@_);
220 }
221  
222  
223 ######################################################################
224 ######################################################################
225 10 ▶sub sequence_name { # ; alias: schema_qualified_name
Subroutine sequence_name: called CC=1 SCAR=0.0
Pod undocumented
226 10 shift->schema_qualified_name (@_);
227 }
228  
229  
230 ######################################################################
231 ######################################################################
232 11 ▶sub table_name { # ; alias: schema_qualified_name
Subroutine table_name: called CC=1 SCAR=0.0
Pod undocumented
233 11 shift->schema_qualified_name (@_);
234 }
235  
236  
237 ######################################################################
238 ######################################################################
239 3 ▶sub view_name { # ; alias: schema_qualified_name
Subroutine view_name: called CC=1 SCAR=0.0
Pod undocumented
240 3 shift->schema_qualified_name (@_);
241 }
242  
243  
244 ######################################################################
245 ######################################################################
246  
247 2 ▶sub index_unique { # ;
Subroutine index_unique: called CC=1 SCAR=0.0
Pod undocumented
248 2 grep $_[1], 'UNIQUE';
249 }
250  
251  
252 ######################################################################
253 ######################################################################
254 8 ▶sub index_column_list { # ;
Subroutine index_column_list: called CC=1 SCAR=0.0
Pod undocumented
255 8 my ($self, $def) = @_;
256  
257 8 '(' . $self->__apply (ordered_column_names => $def) . ')';
258 }
259  
260 ######################################################################
261 ######################################################################
262 0 ▶sub index_options { # ;
Subroutine index_options: not called CC=1 SCAR=6.9
Pod undocumented
263 0 shift->__values (@_);
264 }
265  
266  
267 ######################################################################
268 ######################################################################
269  
270 9 ▶sub not_null { # ;
Subroutine not_null: called CC=1 SCAR=0.0
Pod undocumented
271 9 grep $_[1], ('NOT', 'NULL');
272 }
273  
274  
275 ######################################################################
276 ######################################################################
277 9 ▶sub column_not_null { # ; alias: not_null
Subroutine column_not_null: called CC=1 SCAR=0.0
Pod undocumented
278 9 shift->not_null (@_);
279 }
280  
281  
282 ######################################################################
283 ######################################################################
284 13 ▶sub column_definition { # ;
Subroutine column_definition: called CC=3 SCAR=11.0
Pod undocumented
285 13 my ($self, $def) = @_;
286  
287 13 my @retval = (
288 ' ',
289 (map $self->__call ($_ => $def, $def), (
290 'column_name',
291 'data_type',
292 'column_not_null',
293 'column_primary_key',
294 'column_unique',
295 'default_clause',
296 'autoincrement',
297 ))
298 );
299  
300 13 ▶ $retval[1] .= ' ' x (22 - length $retval[1]) if @retval > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @retval > 2 13 0 13
301 13 ▶ $retval[2] .= ' ' x (15 - length $retval[2]) if @retval > 3;
Branch: 1 branch
BranchTrueFalseTotal
if @retval > 3 9 4 13
302  
303 13 @retval;
304 }
305  
306  
307 ######################################################################
308 ######################################################################
309 0 ▶sub column_primary_key { # ;
Subroutine column_primary_key: not called CC=1 SCAR=6.9
Pod undocumented
310 0 grep $_[1], ('PRIMARY', 'KEY');
311 }
312  
313  
314 ######################################################################
315 ######################################################################
316 0 ▶sub column_unique { # ;
Subroutine column_unique: not called CC=1 SCAR=6.9
Pod undocumented
317 0 grep $_[1], ('UNIQUE');
318 }
319  
320  
321 ######################################################################
322 ######################################################################
323 1 ▶sub table_content { # ;
Subroutine table_content: called CC=1 SCAR=0.0
Pod undocumented
324 1 my ($self, $def) = @_;
325 1 my $key = 'column_definition';
326  
327 my $cols = join ",\n", map ' ' . $_, (
328 (map $self->__apply (%$_), grep exists $_->{$key}, @$def),
329 1 (map $self->__apply (%$_), grep !exists $_->{$key}, @$def),
330 );
331  
332 1 join "\n", '(', $cols, ')';
333 }
334  
335  
336 ######################################################################
337 ######################################################################
338 0 ▶sub table_options { # ;
Subroutine table_options: not called CC=1 SCAR=6.9
Pod undocumented
339 0 shift->__values (@_);
340 }
341  
342  
343 ######################################################################
344 ######################################################################
345 6 ▶sub add_constraint { # ;
Subroutine add_constraint: called CC=1 SCAR=0.0
Pod undocumented
346 6 my ($self, $def) = @_;
347  
348 6 "\n ",'ADD', $self->__apply (%$def);
349 }
350  
351  
352 ######################################################################
353 ######################################################################
354 0 ▶sub add_column { # ;
Subroutine add_column: not called CC=1 SCAR=6.9
Pod undocumented
355 0 my ($self, $def) = @_;
356  
357 0 'ADD', 'COLUMN', $self->__process ($def);
358 }
359  
360  
361 ######################################################################
362 ######################################################################
363 0 ▶sub alter_column { # ;
Subroutine alter_column: not called CC=5 SCAR=34.0
Pod undocumented
364 0 my ($self, $def) = @_;
365 0 my @action;
366  
367 0 ▶ if (exists $def->{default_clause}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $def->{'default_clause'}) { } 0 0 0
elsif (exists $def->{'not_null'}) { } 0 0 0
368 push @action,
369 defined $def->{default_clause}
370 0 ▶ ? ('SET', $self->__call (default_clause => $def, $def))
Branch: 1 branch
BranchTrueFalseTotal
defined $def->{'default_clause'} ? : 0 0 0
371 : ('DROP', 'DEFAULT')
372 ;
373 } elsif (exists $def->{not_null}) {
374 0 ▶ push @action, ($def->{not_null} ? 'SET' : 'DROP'), 'NOT', 'NULL';
Branch: 1 branch
BranchTrueFalseTotal
$def->{'not_null'} ? : 0 0 0
375 }
376  
377 ##################################################################
378  
379 0 'ALTER', 'COLUMN', $self->__call (column_name => $def, $def), @action;
380 }
381  
382  
383 ######################################################################
384 ######################################################################
385 6 ▶sub primary_key_constraint { # ;
Subroutine primary_key_constraint: called CC=1 SCAR=0.0
Pod undocumented
386 6 my ($self, $def) = @_;
387  
388 (
389 6 $self->__call (constraint_name => $def),
390 'PRIMARY',
391 'KEY',
392 $self->__call (column_list => $def),
393 );
394 }
395  
396  
397 ######################################################################
398 ######################################################################
399 1 ▶sub unique_constraint { # ;
Subroutine unique_constraint: called CC=1 SCAR=0.0
Pod undocumented
400 1 my ($self, $def) = @_;
401  
402 (
403 1 $self->__call (constraint_name => $def),
404 'UNIQUE',
405 $self->__call (column_list => $def),
406 );
407 }
408  
409  
410 ######################################################################
411 ######################################################################
412 1 ▶sub foreign_key_constraint { # ;
Subroutine foreign_key_constraint: called CC=1 SCAR=0.0
Pod undocumented
413 1 my ($self, $def) = @_;
414  
415 (
416 1 $self->__call (constraint_name => $def),
417 'FOREIGN', 'KEY',
418 $self->__call (referencing_column_list => $def),
419 "\n ", 'REFERENCES',
420 $self->__call (referenced_table => $def),
421 $self->__call (referenced_column_list => $def),
422 $self->__call (delete_rule => $def),
423 $self->__call (update_rule => $def),
424 );
425 }
426  
427  
428 ######################################################################
429 ######################################################################
430 7 ▶sub constraint_name { # ;
Subroutine constraint_name: called CC=1 SCAR=0.0
Pod undocumented
431 7 my ($self, $def) = @_;
432  
433 7 'CONSTRAINT', $self->identifier ($def), "\n ";
434 }
435  
436  
437 ######################################################################
438 ######################################################################
439 13 ▶sub column_list { # ;
Subroutine column_list: called CC=1 SCAR=0.0
Pod undocumented
440 13 my ($self, $def) = @_;
441  
442 13 '(' . join (', ', map $self->column_name ($_), @$def) . ')';
443 }
444  
445 ######################################################################
446 ######################################################################
447 1 ▶sub referencing_column_list { # ; alias: column_list
Subroutine referencing_column_list: called CC=1 SCAR=0.0
Pod undocumented
448 1 shift->column_list (@_);
449 }
450  
451  
452 ######################################################################
453 ######################################################################
454 1 ▶sub referenced_column_list { # ; alias: column_list
Subroutine referenced_column_list: called CC=1 SCAR=0.0
Pod undocumented
455 1 shift->column_list (@_);
456 }
457  
458  
459 ######################################################################
460 ######################################################################
461 1 ▶sub referenced_table { # ; alias: table_name
Subroutine referenced_table: called CC=1 SCAR=0.0
Pod undocumented
462 1 shift->table_name (@_);
463 }
464  
465  
466 ######################################################################
467 ######################################################################
468  
469 3 ▶sub statement_insert { # ;
Subroutine statement_insert: called CC=2 SCAR=8.1
Pod undocumented
470 3 my ($self, $def) = @_;
471  
472 3 ▶ join ' ', (
Condition33%1/3
$self->__call('insert_value_list', $def) || $self->__call('statement_select', $def)
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->__call('insert_value_list', $def) || $self->__call('statement_select', $def)
$self->__call('insert_value_list', $def) $self->__call('statement_select', $def)
Truth table33%1/3
A || B
A= $self->__call('insert_value_list', $def)B= $self->__call('statement_select', $def)
ABresult
1X1
011
000
473 'INSERT',
474 'INTO',
475 $self->__call (table_name => $def),
476 $self->__call (column_list => $def),
477 (
478 $self->__call (insert_value_list => $def)
479 || $self->__call (statement_select => $def)
480 )
481 );
482 }
483  
484  
485 ######################################################################
486 ######################################################################
487 3 ▶sub insert_value_list { # ;
Subroutine insert_value_list: called CC=1 SCAR=0.0
Pod undocumented
488 3 my ($self, $def) = @_;
489  
490 (
491 3 'VALUES', '(',
492 join ("),\n (", (
493 map join (', ', map $self->__apply (%$_), @$_), @$def
494 )),
495 ')',
496 )
497 }
498  
499  
500 ######################################################################
501 ######################################################################
502 0 ▶sub insert_values { # ;
Subroutine insert_values: not called CC=1 SCAR=0.0
Pod undocumented
503 }
504  
505 0 ▶sub statement_select { # ;
Subroutine statement_select: not called CC=1 SCAR=6.9
Pod undocumented
506 0 my ($self, $def) = @_;
507  
508 (
509 0 $self->__call ('select_what', $def),
510 $self->__call ('select_from', $def),
511 $self->__call ('select_where', $def),
512 );
513 }
514  
515  
516 ######################################################################
517 ######################################################################
518 0 ▶sub select_what { # ;
Subroutine select_what: not called CC=1 SCAR=6.9
Pod undocumented
519 0 my ($self, $def) = @_;
520  
521 0 'SELECT', join ', ', $self->__process ($def);
522 }
523  
524  
525 ######################################################################
526 ######################################################################
527 0 ▶sub select_from { # ;
Subroutine select_from: not called CC=1 SCAR=6.9
Pod undocumented
528 0 my ($self, $def) = @_;
529  
530 0 'FROM', join ', ', $self->__process ($def);
531 }
532  
533  
534 ######################################################################
535 ######################################################################
536 0 ▶sub select_where { # ;
Subroutine select_where: not called CC=1 SCAR=6.9
Pod undocumented
537 0 my ($self, $def) = @_;
538  
539 0 'WHERE', join ', ', $self->__apply (%$def);
540 }
541  
542  
543 ######################################################################
544 ######################################################################
545 0 ▶sub subselect { # ;
Subroutine subselect: not called CC=1 SCAR=6.9
Pod undocumented
546 0 my ($self, $def) = @_;
547  
548 0 '(', (
549 $self->statement_select ($def),
550 ), ')', $self->__call ('select_name', $def);
551 }
552  
553  
554 ######################################################################
555 ######################################################################
556 0 ▶sub select_name { # ; alias: identifier
Subroutine select_name: not called CC=1 SCAR=6.9
Pod undocumented
557 0 shift->identifier (@_);
558 }
559  
560  
561 ######################################################################
562 ######################################################################
563 0 ▶sub _unary_operator { # ;
Subroutine _unary_operator: not called CC=1 SCAR=6.9
564 0 my ($self, $name, $def) = @_;
565  
566 0 $name, $self->__process ($def);
567 }
568  
569  
570 ######################################################################
571 ######################################################################
572 0 ▶sub _binary_operator { # ;
Subroutine _binary_operator: not called CC=1 SCAR=6.9
573 0 my ($self, $name, $def) = @_;
574  
575 0 my @retval = map +($name, $self->__process ($_)), @$def;
576 0 $retval[0] = '(';
577  
578 0 @retval, ')';
579 }
580  
581  
582 ######################################################################
583 ######################################################################
584 0 ▶sub operator_not { # ;
Subroutine operator_not: not called CC=1 SCAR=6.9
Pod undocumented
585 0 shift->_unary_operator ('NOT', @_);
586 }
587  
588  
589 ######################################################################
590 ######################################################################
591 0 ▶sub operator_exists { # ;
Subroutine operator_exists: not called CC=1 SCAR=6.9
Pod undocumented
592 0 shift->_unary_operator ('EXISTS', @_);
593 }
594  
595 ######################################################################
596 ######################################################################
597 0 ▶sub operator_and { # ;
Subroutine operator_and: not called CC=1 SCAR=6.9
Pod undocumented
598 0 shift->_binary_operator ('AND', @_);
599 }
600  
601  
602 ######################################################################
603 ######################################################################
604 0 ▶sub operator_equal { # ;
Subroutine operator_equal: not called CC=1 SCAR=6.9
Pod undocumented
605 0 shift->_binary_operator ('=', @_);
606 }
607  
608  
609 ######################################################################
610 ######################################################################
611  
612 1 ▶sub null { # ;
Subroutine null: called CC=1 SCAR=0.0
Pod undocumented
613 1 'NULL';
614 }
615  
616  
617 ######################################################################
618 ######################################################################
619 1 ▶sub default { # ;
Subroutine default: called CC=1 SCAR=0.0
Pod undocumented
620 1 'DEFAULT';
621 }
622  
623  
624 ######################################################################
625 ######################################################################
626  
627 0 ▶sub DESTROY { # ;
Subroutine DESTROY: not called CC=1 SCAR=0.0
628 }
629  
630  
631 ######################################################################
632 ######################################################################
633 0 ▶sub AUTOLOAD { # ;
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
634 0 warn $AUTOLOAD;
635 0 ();
636 }
637  
638  
639 ######################################################################
640 ######################################################################
641  
642 package SQL::Admin::Driver::Base::Producer;
643  
644 2 1;
645  
646 __END__
« lib/SQL/Admin/Catalog/Object.pm ↑ Summary lib/SQL/Admin/Driver/Base/Parser.pm »