Changes + Reverts for 0.11000, see Changes file for info
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer.pm
1 package SQL::Translator::Producer;
2
3 # -------------------------------------------------------------------
4 # Copyright (C) 2002-4 SQLFairy Authors
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.
9 #
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.
14 #
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;
22 use vars qw($VERSION);
23 $VERSION = '1.59';
24
25 sub produce { "" }
26
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 {
35   my (undef, $field_ref, $default, $exceptions) = @_;
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 {
53       $$field_ref .= " DEFAULT '$default'";
54   }
55
56 }
57
58 1;
59
60 # -------------------------------------------------------------------
61 # A burnt child loves the fire.
62 # Oscar Wilde
63 # -------------------------------------------------------------------
64
65 =pod
66
67 =head1 NAME
68
69 SQL::Translator::Producer - describes how to write a producer
70
71 =head1 DESCRIPTION
72
73 Producer modules designed to be used with SQL::Translator need to
74 implement a single function, called B<produce>.  B<produce> will be
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.
78
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
103 =back
104
105 =head1 AUTHORS
106
107 Darren Chamberlain E<lt>darren@cpan.orgE<gt>,
108 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
109
110 =head1 SEE ALSO
111
112 perl(1), SQL::Translator, SQL::Translator::Schema.
113
114 =cut