1 package SQL::Translator::Producer;
3 # -------------------------------------------------------------------
4 # $Id: Producer.pm,v 1.8 2006-06-07 16:28:59 schiffbruechige Exp $
5 # -------------------------------------------------------------------
6 # Copyright (C) 2002-4 SQLFairy Authors
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; version 2.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # -------------------------------------------------------------------
24 use vars qw($VERSION);
25 $VERSION = sprintf "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/;
29 # Do not rely on this if you are not bundled with SQL::Translator.
31 ## $exceptions contains an arrayref of paired values
32 ## Each pair contains a pattern match or string, and a value to be used as
33 ## the default if matched.
34 ## They are special per Producer, and provide support for the old 'now()'
35 ## default value exceptions
36 sub _apply_default_value {
37 my (undef, $field_ref, $default, $exceptions) = @_;
39 if ($exceptions and ! ref $default) {
40 for (my $i = 0; $i < @$exceptions; $i += 2) {
41 my ($pat, $val) = @$exceptions[ $i, $i + 1 ];
42 if (ref $pat and $default =~ $pat) {
45 } elsif (lc $default eq lc $pat) {
53 $$field_ref .= " DEFAULT $$default";
55 $$field_ref .= " DEFAULT '$default'";
62 # -------------------------------------------------------------------
63 # A burnt child loves the fire.
65 # -------------------------------------------------------------------
71 SQL::Translator::Producer - describes how to write a producer
75 Producer modules designed to be used with SQL::Translator need to
76 implement a single function, called B<produce>. B<produce> will be
77 called with the SQL::Translator object from which it is expected to
78 retrieve the SQL::Translator::Schema object which has been populated
79 by the parser. It is expected to return a string.
87 =item create_table($table)
89 =item create_field($field)
91 =item create_view($view)
93 =item create_index($index)
95 =item create_constraint($constraint)
97 =item create_trigger($trigger)
99 =item alter_field($from_field, $to_field)
101 =item add_field($table, $new_field)
103 =item drop_field($table, $old_field)
107 Darren Chamberlain E<lt>darren@cpan.orgE<gt>,
108 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
112 perl(1), SQL::Translator, SQL::Translator::Schema.