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

filter: Statementstmt 95.4% 21 / 22 Branchbran 100% 8 / 8 Conditioncond 65.2% 15 / 23 MC/DCmcdc 50.0% 5 / 10 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 4 totaltotal 75.6% 59 / 78 SCAR 25.4
CC
12
Cov
83%
_ipk
7.0
field_autoinc
5.1
field
3.0
CRAP 12.7
« blib/lib/SQL/Translator/Producer/TT/Base.pm ↑ Summary blib/lib/SQL/Translator/Producer/TTSchema.pm »
1 package SQL::Translator::Generator::DDL::SQLite;
2  
3 =head1 NAME
4  
5 SQL::Translator::Generator::DDL::SQLite - A Moo based SQLite DDL generation
6 engine.
7  
8 =head1 DESCRIPTION
9  
10 I<documentation volunteers needed>
11  
12 =cut
13  
14 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 ▶has quote_chars => (is=>'ro', default=>sub { +[qw(" ")] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
17  
18 9 with 'SQL::Translator::Generator::Role::Quote';
19 9 with 'SQL::Translator::Generator::Role::DDL';
20  
21 179 ▶sub name_sep { q(.) }
Subroutine name_sep: called CC=1 SCAR=0.0
Pod undocumented
22  
23 sub _build_type_map {
24 +{
25 8 ▶ set => 'varchar',
Subroutine _build_type_map: called CC=1 SCAR=0.0
26 bytea => 'blob',
27 }
28 }
29  
30 sub _build_sizeless_types {
31 +{
32 8 ▶ text => 1,
Subroutine _build_sizeless_types: called CC=1 SCAR=0.0
33 blob => 1,
34 }
35 }
36 sub _build_numeric_types {
37 +{
38 5 ▶ int => 1,
Subroutine _build_numeric_types: called CC=1 SCAR=0.0
39 integer => 1,
40 tinyint => 1,
41 smallint => 1,
42 mediumint => 1,
43 bigint => 1,
44 'unsigned big int' => 1,
45 int2 => 1,
46 int8 => 1,
47 numeric => 1,
48 decimal => 1,
49 boolean => 1,
50 real => 1,
51 double => 1,
52 'double precision' => 1,
53 float => 1,
54 }
55 }
56  
57 sub _build_unquoted_defaults {
58 +{
59 0 ▶ NULL => 1,
Subroutine _build_unquoted_defaults: not called CC=1 SCAR=6.9
60 'now()' => 1,
61 CURRENT_TIMESTAMP => 1,
62 }
63 }
64  
65 71 ▶sub nullable { () }
Subroutine nullable: called CC=1 SCAR=0.0
Pod undocumented
66  
67 sub _ipk {
68 109 ▶ my ($self, $field) = @_;
Subroutine _ipk: called CC=6 SCAR=19.4
69  
70 109 my $pk = $field->table->primary_key;
71 109 ▶ my @pk_fields = $pk ? $pk->fields : ();
Branch: 1 branch
BranchTrueFalseTotal
$pk ? : 95 14 109
72  
73 109 ▶ $field->is_primary_key && scalar @pk_fields == 1 &&
Branch: 1 branch
BranchTrueFalseTotal
$field->is_primary_key and scalar @pk_fields == 1 and $field->data_type =~ /int(eger)?$/i || $field->data_type =~ /^number?$/i && !($field->size =~ /,/) 19 90 109
Condition50%6/12
$field->is_primary_key && scalar @pk_fields == 1 && ($field->data_type =~ /int(eger)?$/i || $field->data_type =~ /^number?$/i && !($field->size =~ /,/))
!ll&&!rl&&r
90019
$field->is_primary_key and scalar @pk_fields == 1
!ll&&!rl&&r
85519
$field->data_type =~ /int(eger)?$/i or $field->data_type =~ /^number?$/i and not $field->size =~ /,/
l!l&&r!l&&!r
1900
$field->data_type =~ /^number?$/i and not $field->size =~ /,/
!ll&&!rl&&r
000
MC/DC40%2/5
$field->is_primary_key && scalar @pk_fields == 1 && ($field->data_type =~ /int(eger)?$/i || $field->data_type =~ /^number?$/i && !($field->size =~ /,/))
$field->is_primary_key scalar @pk_fields == 1 $field->data_type =~ /int(eger)?$/i $field->data_type =~ /^number?$/i not $field->size =~ /,/
Truth table50%3/6
A and B && C or D and not(E)
A= $field->is_primary_keyB= scalar @pk_fields == 1C= $field->data_type =~ /int(eger)?$/iD= $field->data_type =~ /^number?$/iE= not $field->size =~ /,/
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
74 ( $field->data_type =~ /int(eger)?$/i
75 ||
76 ( $field->data_type =~ /^number?$/i && $field->size !~ /,/ ) )
77 }
78  
79 sub field_autoinc {
80 108 ▶ my ($self, $field) = @_;
Subroutine field_autoinc: called CC=5 SCAR=16.3
Pod undocumented
81  
82 return (
83 (
84 108 ▶ ($field->extra->{auto_increment_type}||'') eq 'monotonic'
Branch: 1 branch
BranchTrueFalseTotal
($field->extra->{'auto_increment_type'} || '') eq 'monotonic' && $self->_ipk($field) && $field->is_auto_increment ? : 1 107 108
Condition75%6/8
($field->extra->{"auto_increment_type"} || "") eq "monotonic" and $self->_ipk($field) and $field->is_auto_increment
!ll&&!rl&&r
10701
($field->extra->{"auto_increment_type"} || "") eq "monotonic" and $self->_ipk($field)
!ll&&!rl&&r
10701
$field->extra->{'auto_increment_type'} || ''
l!l
1107
MC/DC33%1/3
($field->extra->{"auto_increment_type"} || "") eq "monotonic" and $self->_ipk($field) and $field->is_auto_increment
$field->extra->{'auto_increment_type'} $self->_ipk($field) $field->is_auto_increment
Truth table50%2/4
A and B and C
A= $field->extra->{'auto_increment_type'}B= $self->_ipk($field)C= $field->is_auto_increment
ABCresult
0XX0
10X0
1100
1111
85 and
86 $self->_ipk($field)
87 and
88 $field->is_auto_increment
89 )
90 ? 'AUTOINCREMENT'
91 : ''
92 );
93 }
94  
95 sub field {
96 108 ▶ my ($self, $field) = @_;
Subroutine field: called CC=3 SCAR=11.0
Pod undocumented
97  
98  
99 108 ▶ return join ' ',
Branch: 1 branch
BranchTrueFalseTotal
$self->_ipk($field) ? : 18 90 108
Condition100%3/3
$self->field_autoinc($field) || ()
l!l&&r!l&&!r
11052
MC/DC100%2/2
$self->field_autoinc($field) || ()
$self->field_autoinc($field) ()
Truth table100%3/3
A || B
A= $self->field_autoinc($field)B= ()
ABresult
1X1
011
000
100 $self->field_comments($field),
101 $self->field_name($field),
102 ( $self->_ipk($field)
103 ? ( 'INTEGER PRIMARY KEY' )
104 : ( $self->field_type($field) )
105 ),
106 ( $self->field_autoinc($field) || () ),
107 $self->field_nullable($field),
108 $self->field_default($field, {
109 NULL => 1,
110 'now()' => 1,
111 'CURRENT_TIMESTAMP' => 1,
112 }),
113 }
114  
115 9 1;
116  
117 =head1 AUTHORS
118  
119 See the included AUTHORS file:
120 L<http://search.cpan.org/dist/SQL-Translator/AUTHORS>
121  
122 =head1 COPYRIGHT
123  
124 Copyright (c) 2012 the SQL::Translator L</AUTHORS> as listed above.
125  
126 =head1 LICENSE
127  
128 This code is free software and may be distributed under the same terms as Perl
129 itself.
130  
131 =cut
« blib/lib/SQL/Translator/Producer/TT/Base.pm ↑ Summary blib/lib/SQL/Translator/Producer/TTSchema.pm »