needed to tighten up regex added in last commit
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer.pm
CommitLineData
16dc9970 1package SQL::Translator::Producer;
2
49e1eb70 3# -------------------------------------------------------------------
0e1ec14f 4# $Id: Producer.pm,v 1.8 2006-06-07 16:28:59 schiffbruechige Exp $
49e1eb70 5# -------------------------------------------------------------------
977651a5 6# Copyright (C) 2002-4 SQLFairy Authors
077ebf34 7#
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.
16dc9970 11#
077ebf34 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.
16dc9970 16#
077ebf34 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
20# 02111-1307 USA
21# -------------------------------------------------------------------
22
23use strict;
24use vars qw($VERSION);
0e1ec14f 25$VERSION = sprintf "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/;
16dc9970 26
077ebf34 27sub produce { "" }
16dc9970 28
bc8e2aa1 29# Do not rely on this if you are not bundled with SQL::Translator.
30# -- rjbs, 2008-09-30
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
36sub _apply_default_value {
5c1ffcdc 37 my (undef, $field_ref, $default, $exceptions, $noquote) = @_;
38
39 my @noquote = (defined $noquote)?@$noquote:();
bc8e2aa1 40
41 if ($exceptions and ! ref $default) {
42 for (my $i = 0; $i < @$exceptions; $i += 2) {
43 my ($pat, $val) = @$exceptions[ $i, $i + 1 ];
44 if (ref $pat and $default =~ $pat) {
45 $default = $val;
46 last;
47 } elsif (lc $default eq lc $pat) {
48 $default = $val;
49 last
50 }
51 }
52 }
53
ed53eb28 54 my $qc = (grep m/^$default$/, @noquote)?"":"'";
bc8e2aa1 55 if (ref $default) {
56 $$field_ref .= " DEFAULT $$default";
57 } else {
5c1ffcdc 58 $$field_ref .= " DEFAULT $qc$default$qc";
bc8e2aa1 59 }
60
61}
62
16dc9970 631;
64
49e1eb70 65# -------------------------------------------------------------------
16dc9970 66# A burnt child loves the fire.
67# Oscar Wilde
49e1eb70 68# -------------------------------------------------------------------
69
70=pod
16dc9970 71
72=head1 NAME
73
56435d6f 74SQL::Translator::Producer - describes how to write a producer
16dc9970 75
16dc9970 76=head1 DESCRIPTION
77
077ebf34 78Producer modules designed to be used with SQL::Translator need to
79implement a single function, called B<produce>. B<produce> will be
56435d6f 80called with the SQL::Translator object from which it is expected to
81retrieve the SQL::Translator::Schema object which has been populated
82by the parser. It is expected to return a string.
16dc9970 83
0e1ec14f 84=head1 METHODS
85
86=over 4
87
88=item produce
89
90=item create_table($table)
91
92=item create_field($field)
93
94=item create_view($view)
95
96=item create_index($index)
97
98=item create_constraint($constraint)
99
100=item create_trigger($trigger)
101
102=item alter_field($from_field, $to_field)
103
104=item add_field($table, $new_field)
105
106=item drop_field($table, $old_field)
107
56435d6f 108=head1 AUTHORS
16dc9970 109
56435d6f 110Darren Chamberlain E<lt>darren@cpan.orgE<gt>,
111Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
16dc9970 112
113=head1 SEE ALSO
114
56435d6f 115perl(1), SQL::Translator, SQL::Translator::Schema.
16dc9970 116
117=cut