« blib/lib/SQL/Translator/Producer/JSON.pm
↑ Summary
blib/lib/SQL/Translator/Producer/XML/SQLFairy.pm »
| 1 | package SQL::Translator::Producer; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 72 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 72 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 72 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 72 | our $VERSION = '1.66'; | |||||||||||||||||||||||||||||||
| 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 | 413 | ▶ | sub _apply_default_value { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_default_value: called CC=11 SCAR=24.5
| |||||||||||||||||||||||||||||||||
| 18 | 413 | my ($self, $field, $field_ref, $exceptions) = @_; | |||||||||||||||||||||||||||||||
| 19 | 413 | my $default = $field->default_value; | |||||||||||||||||||||||||||||||
| 20 | 413 | ▶ | return if !defined $default; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 121 | ▶ | if ($exceptions and !ref $default) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$exceptions and not ref $default
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
| |||||||||||||||||||||||||||||||||
| 23 | 113 | ▶ | for (my $i = 0; $i < @$exceptions; $i += 2) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 24 | 191 | my ($pat, $val) = @$exceptions[ $i, $i + 1 ]; | |||||||||||||||||||||||||||||||
| 25 | 191 | ▶ | if (ref $pat and $default =~ $pat) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
ref $pat and $default =~ /$pat/
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/
| |||||||||||||||||||||||||||||||||
| 26 | 0 | $default = $val; | |||||||||||||||||||||||||||||||
| 27 | 0 | last; | |||||||||||||||||||||||||||||||
| 28 | } elsif (lc $default eq lc $pat) { | ||||||||||||||||||||||||||||||||
| 29 | 1 | $default = $val; | |||||||||||||||||||||||||||||||
| 30 | 1 | last; | |||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 121 | my $type = lc $field->data_type; | |||||||||||||||||||||||||||||||
| 36 | 121 | my $is_numeric_datatype | |||||||||||||||||||||||||||||||
| 37 | = ($type =~ /^(?:(?:big|medium|small|tiny)?int(?:eger)?|decimal|double|float|num(?:ber|eric)?|real)$/); | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 121 | ▶ | if (ref $default) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 40 | 9 | $$field_ref .= " DEFAULT $$default"; | |||||||||||||||||||||||||||||||
| 41 | ▶ | } elsif ($is_numeric_datatype && Scalar::Util::looks_like_number($default)) { | |||||||||||||||||||||||||||||||
|
Condition66%2/3
$is_numeric_datatype and &Scalar::Util::looks_like_number($default)
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)
| |||||||||||||||||||||||||||||||||
| 42 | # we need to check the data itself in addition to the datatype, for basic safety | ||||||||||||||||||||||||||||||||
| 43 | 42 | $$field_ref .= " DEFAULT $default"; | |||||||||||||||||||||||||||||||
| 44 | } else { | ||||||||||||||||||||||||||||||||
| 45 | 70 | $default = $self->_quote_string($default); | |||||||||||||||||||||||||||||||
| 46 | 70 | $$field_ref .= " DEFAULT $default"; | |||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 132 | ▶ | sub _quote_string { | ||||||||||||||||||||||||||||||
|
Subroutine
_quote_string: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 52 | 132 | my ($self, $string) = @_; | |||||||||||||||||||||||||||||||
| 53 | 132 | $string =~ s/'/''/g; | |||||||||||||||||||||||||||||||
| 54 | 132 | return qq{'$string'}; | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 72 | 1; | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 60 | # A burnt child loves the fire. | ||||||||||||||||||||||||||||||||
| 61 | # Oscar Wilde | ||||||||||||||||||||||||||||||||
| 62 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | =pod | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | SQL::Translator::Producer - describes how to write a producer | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | Producer modules designed to be used with SQL::Translator need to | ||||||||||||||||||||||||||||||||
| 73 | implement a single function, called B<produce>. B<produce> will be | ||||||||||||||||||||||||||||||||
| 74 | called with the SQL::Translator object from which it is expected to | ||||||||||||||||||||||||||||||||
| 75 | retrieve the SQL::Translator::Schema object which has been populated | ||||||||||||||||||||||||||||||||
| 76 | by the parser. It is expected to return a string. | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | =over 4 | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | =item produce | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | =item create_table($table) | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | =item create_field($field) | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | =item create_view($view) | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | =item create_index($index) | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | =item create_constraint($constraint) | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | =item create_trigger($trigger) | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | =item alter_field($from_field, $to_field) | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | =item add_field($table, $new_field) | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | =item drop_field($table, $old_field) | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | =back | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | Darren Chamberlain E<lt>darren@cpan.orgE<gt>, | ||||||||||||||||||||||||||||||||
| 107 | Ken Y. Clark E<lt>kclark@cpan.orgE<gt>. | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | perl(1), SQL::Translator, SQL::Translator::Schema. | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||||||||||||||