blib/lib/SQL/Translator/Producer.pm

filter: Statementstmt 90.9% 30 / 33 Branchbran 92.8% 13 / 14 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 81.1% 56 / 69 SCAR 24.3
CC
11
Cov
86%
_apply_default_value
11.6
produce
2.0
BEGIN
1.0
CRAP 11.4
« blib/lib/SQL/Translator/Parser/DBI/MySQL.pm ↑ Summary blib/lib/SQL/Translator/Filter/Names.pm »
1 package SQL::Translator::Producer;
2  
3 71 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 71 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 71 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 71 our $VERSION = '1.63';
7  
8 0 ▶sub produce { "" }
Subroutine produce: not called CC=1 SCAR=6.9
Pod documented
9  
10 # Do not rely on this if you are not bundled with SQL::Translator.
11 # -- rjbs, 2008-09-30
12 ## $exceptions contains an arrayref of paired values
13 ## Each pair contains a pattern match or string, and a value to be used as
14 ## the default if matched.
15 ## They are special per Producer, and provide support for the old 'now()'
16 ## default value exceptions
17 sub _apply_default_value {
18 413 ▶ my ($self, $field, $field_ref, $exceptions) = @_;
Subroutine _apply_default_value: called CC=11 SCAR=24.5
19 413 my $default = $field->default_value;
20 413 ▶ return if !defined $default;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $default 292 121 413
21  
22 121 ▶ if ($exceptions and ! ref $default) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exceptions and not ref $default) 113 8 121
Condition66%2/3
$exceptions and not ref $default
!ll&&!rl&&r
08113
MC/DC50%1/2
$exceptions and not ref $default
$exceptions not ref $default
Truth table66%2/3
A and not(B)
A= $exceptionsB= not ref $default
ABresult
0X0
100
111
23 113 ▶ for (my $i = 0; $i < @$exceptions; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$exceptions) 191 112 303
24 191 my ($pat, $val) = @$exceptions[ $i, $i + 1 ];
25 191 ▶ if (ref $pat and $default =~ $pat) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $pat and $default =~ /$pat/) { } 0 191 191
elsif (lc $default eq lc $pat) { } 1 190 191
Condition33%1/3
ref $pat and $default =~ /$pat/
!ll&&!rl&&r
19100
MC/DC0%0/2
ref $pat and $default =~ /$pat/
ref $pat $default =~ /$pat/
Truth table33%1/3
A and B
A= ref $patB= $default =~ /$pat/
ABresult
0X0
100
111
26 0 $default = $val;
27 0 last;
28 } elsif (lc $default eq lc $pat) {
29 1 $default = $val;
30 last
31 1 }
32 }
33 }
34  
35 121 my $type = lc $field->data_type;
36 121 my $is_numeric_datatype = ($type =~ /^(?:(?:big|medium|small|tiny)?int(?:eger)?|decimal|double|float|num(?:ber|eric)?|real)$/);
37  
38 121 ▶ if (ref $default) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $default) { } 9 112 121
elsif ($is_numeric_datatype and &Scalar::Util::looks_like_number($default)) { } 42 70 112
39 9 $$field_ref .= " DEFAULT $$default";
40 ▶ } elsif ($is_numeric_datatype && Scalar::Util::looks_like_number ($default) ) {
Condition66%2/3
$is_numeric_datatype and &Scalar::Util::looks_like_number($default)
!ll&&!rl&&r
70042
MC/DC50%1/2
$is_numeric_datatype and &Scalar::Util::looks_like_number($default)
$is_numeric_datatype &Scalar::Util::looks_like_number($default)
Truth table66%2/3
A and B
A= $is_numeric_datatypeB= &Scalar::Util::looks_like_number($default)
ABresult
0X0
100
111
41 # we need to check the data itself in addition to the datatype, for basic safety
42 42 $$field_ref .= " DEFAULT $default";
43 } else {
44 70 $default = $self->_quote_string($default);
45 70 $$field_ref .= " DEFAULT $default";
46 }
47  
48 }
49  
50 sub _quote_string {
51 132 ▶ my ($self, $string) = @_;
Subroutine _quote_string: called CC=1 SCAR=0.0
52 132 $string =~ s/'/''/g;
53 132 return qq{'$string'};
54 }
55  
56 71 1;
57  
58 # -------------------------------------------------------------------
59 # A burnt child loves the fire.
60 # Oscar Wilde
61 # -------------------------------------------------------------------
62  
63 =pod
64  
65 =head1 NAME
66  
67 SQL::Translator::Producer - describes how to write a producer
68  
69 =head1 DESCRIPTION
70  
71 Producer modules designed to be used with SQL::Translator need to
72 implement a single function, called B<produce>. B<produce> will be
73 called with the SQL::Translator object from which it is expected to
74 retrieve the SQL::Translator::Schema object which has been populated
75 by the parser. It is expected to return a string.
76  
77 =head1 METHODS
78  
79 =over 4
80  
81 =item produce
82  
83 =item create_table($table)
84  
85 =item create_field($field)
86  
87 =item create_view($view)
88  
89 =item create_index($index)
90  
91 =item create_constraint($constraint)
92  
93 =item create_trigger($trigger)
94  
95 =item alter_field($from_field, $to_field)
96  
97 =item add_field($table, $new_field)
98  
99 =item drop_field($table, $old_field)
100  
101 =back
102  
103 =head1 AUTHORS
104  
105 Darren Chamberlain E<lt>darren@cpan.orgE<gt>,
106 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
107  
108 =head1 SEE ALSO
109  
110 perl(1), SQL::Translator, SQL::Translator::Schema.
111  
112 =cut
« blib/lib/SQL/Translator/Parser/DBI/MySQL.pm ↑ Summary blib/lib/SQL/Translator/Filter/Names.pm »