blib/lib/SQL/Translator/Generator/Role/DDL.pm

filter: Statementstmt 97.9% 47 / 48 Branchbran 88.8% 16 / 18 Conditioncond 100% 15 / 15 MC/DCmcdc 100% 9 / 9 Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 11 totaltotal 87.8% 101 / 115 SCAR 27.1
CC
15
Cov
96%
field_default
8.0
field_type_size
3.0
table_comments
2.1
CRAP 15.0
« blib/lib/SQL/Translator/Parser/Access.pm ↑ Summary blib/lib/SQL/Translator/Filter/Globals.pm »
1 package SQL::Translator::Generator::Role::DDL;
2  
3 =head1 NAME
4  
5 SQL::Translator::Generator::Role::DDL - Role implementing common parts of
6 DDL generation.
7  
8 =head1 DESCRIPTION
9  
10 I<documentation volunteers needed>
11  
12 =cut
13  
14 10 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 10 ▶use SQL::Translator::Utils qw(header_comment);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 10 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 10 requires '_build_type_map';
19 10 requires '_build_numeric_types';
20 10 requires '_build_unquoted_defaults';
21 10 requires '_build_sizeless_types';
22 10 requires 'quote';
23 10 requires 'quote_string';
24  
25 10 has type_map => (
26 is => 'lazy',
27 );
28  
29 10 has numeric_types => (
30 is => 'lazy',
31 );
32  
33 10 has sizeless_types => (
34 is => 'lazy',
35 );
36  
37 10 has unquoted_defaults => (
38 is => 'lazy',
39 );
40  
41 10 has add_comments => (
42 is => 'ro',
43 );
44  
45 10 has add_drop_table => (
46 is => 'ro',
47 );
48  
49 # would also be handy to have a required size set if there is such a thing
50  
51 139 ▶sub field_name { $_[0]->quote($_[1]->name) }
Subroutine field_name: called CC=1 SCAR=0.0
Pod undocumented
52  
53 sub field_comments {
54 108 ▶ ( $_[1]->comments ? ('-- ' . $_[1]->comments . "\n ") : () )
Subroutine field_comments: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->comments ? : 4 104 108
55 }
56  
57 sub table_comments {
58 9 ▶ my ($self, $table) = @_;
Subroutine table_comments: called CC=2 SCAR=7.6
Pod undocumented
59 9 ▶ if ($self->add_comments) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->add_comments) { } 0 9 9
60 return (
61 0 "",
62 "--",
63 "-- Table: " . $self->quote($table->name) . "",
64 "--",
65 map "-- $_", $table->comments
66 )
67 } else {
68 return ()
69 9 }
70 }
71  
72 139 ▶sub field_nullable { ($_[1]->is_nullable ? $_[0]->nullable : 'NOT NULL' ) }
Subroutine field_nullable: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->is_nullable ? : 92 47 139
73  
74 sub field_default {
75 139 ▶ my ($self, $field, $exceptions) = @_;
Subroutine field_default: called CC=8 SCAR=20.8
Pod undocumented
76  
77 139 my $default = $field->default_value;
78 139 ▶ return () if !defined $default;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $default 80 59 139
79  
80 $default = \"$default"
81 59 ▶ if $exceptions and !ref $default and $exceptions->{$default};
Branch: 1 branch
BranchTrueFalseTotal
if $exceptions and not ref $default and $exceptions->{$default} 7 52 59
Condition100%6/6
$exceptions and not ref $default and $exceptions->{$default}
!ll&&!rl&&r
15377
$exceptions and not ref $default
!ll&&!rl&&r
14144
MC/DC100%3/3
$exceptions and not ref $default and $exceptions->{$default}
$exceptions not ref $default $exceptions->{$default}
Truth table100%4/4
A and not(B) and C
A= $exceptionsB= not ref $defaultC= $exceptions->{$default}
ABCresult
0XX0
10X0
1100
1111
82 59 ▶ if (ref $default) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $default) { } 8 51 59
elsif (not $self->numeric_types->{lc $field->data_type} && &Scalar::Util::looks_like_number($default)) { } 32 19 51
83 8 $default = $$default;
84 ▶ } elsif (!($self->numeric_types->{lc($field->data_type)} && Scalar::Util::looks_like_number ($default))) {
Condition100%3/3
$self->numeric_types->{lc $field->data_type} && &Scalar::Util::looks_like_number($default)
!ll&&!rl&&r
31119
MC/DC100%2/2
$self->numeric_types->{lc $field->data_type} && &Scalar::Util::looks_like_number($default)
$self->numeric_types->{lc $field->data_type} &Scalar::Util::looks_like_number($default)
Truth table100%3/3
A && B
A= $self->numeric_types->{lc $field->data_type}B= &Scalar::Util::looks_like_number($default)
ABresult
0X0
100
111
85 32 $default = $self->quote_string($default);
86 }
87 59 return ( "DEFAULT $default" )
88 }
89  
90 sub field_type {
91 121 ▶ my ($self, $field) = @_;
Subroutine field_type: called CC=2 SCAR=6.9
Pod undocumented
92  
93 121 my $field_type = $field->data_type;
94 121 ▶ ($self->type_map->{$field_type} || $field_type).$self->field_type_size($field)
Condition100%3/3
$self->type_map->{$field_type} || $field_type
l!l&&r!l&&!r
21172
MC/DC100%2/2
$self->type_map->{$field_type} || $field_type
$self->type_map->{$field_type} $field_type
Truth table100%3/3
A || B
A= $self->type_map->{$field_type}B= $field_type
ABresult
1X1
011
000
95 }
96  
97 sub field_type_size {
98 121 ▶ my ($self, $field) = @_;
Subroutine field_type_size: called CC=3 SCAR=11.0
Pod undocumented
99  
100 121 ▶ ($field->size && !$self->sizeless_types->{$field->data_type}
Branch: 1 branch
BranchTrueFalseTotal
$field->size && !$self->sizeless_types->{$field->data_type} ? : 69 52 121
Condition100%3/3
$field->size and not $self->sizeless_types->{$field->data_type}
!ll&&!rl&&r
44869
MC/DC100%2/2
$field->size and not $self->sizeless_types->{$field->data_type}
$field->size not $self->sizeless_types->{$field->data_type}
Truth table100%3/3
A and not(B)
A= $field->sizeB= not $self->sizeless_types->{$field->data_type}
ABresult
0X0
100
111
101 ? '(' . $field->size . ')'
102 : ''
103 )
104 }
105  
106 sub fields {
107 9 ▶ my ($self, $table) = @_;
Subroutine fields: called CC=1 SCAR=0.0
Pod undocumented
108 9 ( map $self->field($_), $table->get_fields )
109 }
110  
111 sub indices {
112 9 ▶ my ($self, $table) = @_;
Subroutine indices: called CC=1 SCAR=0.0
Pod undocumented
113 9 (map $self->index($_), $table->get_indices)
114 }
115  
116 21 ▶sub nullable { 'NULL' }
Subroutine nullable: called CC=1 SCAR=0.0
Pod undocumented
117  
118 2 ▶sub header_comments { header_comment() . "\n" if $_[0]->add_comments }
Subroutine header_comments: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->add_comments 0 2 2
119  
120 10 1;
121  
122 =head1 AUTHORS
123  
124 See the included AUTHORS file:
125 L<http://search.cpan.org/dist/SQL-Translator/AUTHORS>
126  
127 =head1 COPYRIGHT
128  
129 Copyright (c) 2012 the SQL::Translator L</AUTHORS> as listed above.
130  
131 =head1 LICENSE
132  
133 This code is free software and may be distributed under the same terms as Perl
134 itself.
135  
136 =cut
« blib/lib/SQL/Translator/Parser/Access.pm ↑ Summary blib/lib/SQL/Translator/Filter/Globals.pm »