Commit | Line | Data |
16dc9970 |
1 | package SQL::Translator::Producer; |
2 | |
49e1eb70 |
3 | # ------------------------------------------------------------------- |
11ad2df9 |
4 | # Copyright (C) 2002-4 SQLFairy Authors |
077ebf34 |
5 | # |
6 | # This program is free software; you can redistribute it and/or |
7 | # modify it under the terms of the GNU General Public License as |
8 | # published by the Free Software Foundation; version 2. |
16dc9970 |
9 | # |
077ebf34 |
10 | # This program is distributed in the hope that it will be useful, but |
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | # General Public License for more details. |
16dc9970 |
14 | # |
077ebf34 |
15 | # You should have received a copy of the GNU General Public License |
16 | # along with this program; if not, write to the Free Software |
17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
18 | # 02111-1307 USA |
19 | # ------------------------------------------------------------------- |
20 | |
21 | use strict; |
da06ac74 |
22 | use vars qw($VERSION); |
11ad2df9 |
23 | $VERSION = '1.59'; |
16dc9970 |
24 | |
077ebf34 |
25 | sub produce { "" } |
16dc9970 |
26 | |
bc8e2aa1 |
27 | # Do not rely on this if you are not bundled with SQL::Translator. |
28 | # -- rjbs, 2008-09-30 |
29 | ## $exceptions contains an arrayref of paired values |
30 | ## Each pair contains a pattern match or string, and a value to be used as |
31 | ## the default if matched. |
32 | ## They are special per Producer, and provide support for the old 'now()' |
33 | ## default value exceptions |
34 | sub _apply_default_value { |
0f4c1a5b |
35 | my (undef, $field_ref, $default, $exceptions) = @_; |
bc8e2aa1 |
36 | |
37 | if ($exceptions and ! ref $default) { |
38 | for (my $i = 0; $i < @$exceptions; $i += 2) { |
39 | my ($pat, $val) = @$exceptions[ $i, $i + 1 ]; |
40 | if (ref $pat and $default =~ $pat) { |
41 | $default = $val; |
42 | last; |
43 | } elsif (lc $default eq lc $pat) { |
44 | $default = $val; |
45 | last |
46 | } |
47 | } |
48 | } |
49 | |
50 | if (ref $default) { |
51 | $$field_ref .= " DEFAULT $$default"; |
52 | } else { |
0f4c1a5b |
53 | $$field_ref .= " DEFAULT '$default'"; |
bc8e2aa1 |
54 | } |
55 | |
56 | } |
57 | |
16dc9970 |
58 | 1; |
59 | |
49e1eb70 |
60 | # ------------------------------------------------------------------- |
16dc9970 |
61 | # A burnt child loves the fire. |
62 | # Oscar Wilde |
49e1eb70 |
63 | # ------------------------------------------------------------------- |
64 | |
65 | =pod |
16dc9970 |
66 | |
67 | =head1 NAME |
68 | |
56435d6f |
69 | SQL::Translator::Producer - describes how to write a producer |
16dc9970 |
70 | |
16dc9970 |
71 | =head1 DESCRIPTION |
72 | |
077ebf34 |
73 | Producer modules designed to be used with SQL::Translator need to |
74 | implement a single function, called B<produce>. B<produce> will be |
56435d6f |
75 | called with the SQL::Translator object from which it is expected to |
76 | retrieve the SQL::Translator::Schema object which has been populated |
77 | by the parser. It is expected to return a string. |
16dc9970 |
78 | |
0e1ec14f |
79 | =head1 METHODS |
80 | |
81 | =over 4 |
82 | |
83 | =item produce |
84 | |
85 | =item create_table($table) |
86 | |
87 | =item create_field($field) |
88 | |
89 | =item create_view($view) |
90 | |
91 | =item create_index($index) |
92 | |
93 | =item create_constraint($constraint) |
94 | |
95 | =item create_trigger($trigger) |
96 | |
97 | =item alter_field($from_field, $to_field) |
98 | |
99 | =item add_field($table, $new_field) |
100 | |
101 | =item drop_field($table, $old_field) |
102 | |
0e42fda6 |
103 | =back |
104 | |
56435d6f |
105 | =head1 AUTHORS |
16dc9970 |
106 | |
56435d6f |
107 | Darren Chamberlain E<lt>darren@cpan.orgE<gt>, |
11ad2df9 |
108 | Ken Y. Clark E<lt>kclark@cpan.orgE<gt>. |
16dc9970 |
109 | |
110 | =head1 SEE ALSO |
111 | |
56435d6f |
112 | perl(1), SQL::Translator, SQL::Translator::Schema. |
16dc9970 |
113 | |
114 | =cut |