package SQL::Translator;
# ----------------------------------------------------------------------
-# $Id: Translator.pm,v 1.21 2003-04-17 13:40:47 dlc Exp $
+# $Id: Translator.pm,v 1.22 2003-04-17 23:16:28 allenday Exp $
# ----------------------------------------------------------------------
# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
# darren chamberlain <darren@cpan.org>,
use base 'Class::Base';
$VERSION = '0.01';
-$REVISION = sprintf "%d.%02d", q$Revision: 1.21 $ =~ /(\d+)\.(\d+)/;
+$REVISION = sprintf "%d.%02d", q$Revision: 1.22 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
$ERROR = "";
$self->parser ($config->{'parser'} || $config->{'from'} || $DEFAULT_SUB);
$self->producer($config->{'producer'} || $config->{'to'} || $DEFAULT_SUB);
+ #
+ # Set up callbacks for formatting of pk,fk,table,package names in producer
+ #
+ $self->format_table_name($config->{'format_table_name'});
+ $self->format_package_name($config->{'format_package_name'});
+ $self->format_fk_name($config->{'format_fk_name'});
+ $self->format_pk_name($config->{'format_pk_name'});
+
#
# Set the parser_args and producer_args
#
return 1;
}
+sub format_table_name {
+ my $self = shift;
+ my $sub = shift;
+ $self->{_format_table_name} = $sub if ref($sub) eq 'CODE';
+ return $self->{_format_table_name}->($sub,@_) if defined($self->{_format_table_name});
+ return($sub);
+}
+
+sub format_package_name {
+ my $self = shift;
+ my $sub = shift;
+ $self->{_format_package_name} = $sub if ref($sub) eq 'CODE';
+ return $self->{_format_package_name}->($sub,@_) if defined($self->{_format_package_name});
+ return($sub);
+}
+
+sub format_fk_name {
+ my $self = shift;
+ my $sub = shift;
+ $self->{_format_fk_name} = $sub if ref($sub) eq 'CODE';
+ return $self->{_format_fk_name}->($sub,@_) if defined($self->{_format_fk_name});
+ return($sub);
+}
+
+sub format_pk_name {
+ my $self = shift;
+ my $sub = shift;
+ $self->{_format_pk_name} = $sub if ref($sub) eq 'CODE';
+ return $self->{_format_pk_name}->($sub,@_) if defined($self->{_format_pk_name});
+ return($sub);
+}
+
# ----------------------------------------------------------------------
# isa($ref, $type)
#
no_comments => 0, # Don't include comments in output
show_warnings => 0, # Print name mutations, conflicts
add_drop_table => 1, # Add "drop table" statements
+
+ #make all table names CAPS in producers which support this option
+ format_table_name => sub {my $tablename = shift; return uc($tablename)},
+ #null-op formatting, only here for documentation's sake
+ format_package_name => sub {return shift},
+ format_fk_name => sub {return shift},
+ format_pk_name => sub {return shift},
);
my $output = $translator->translate(
package SQL::Translator::Parser::PostgreSQL;
# -------------------------------------------------------------------
-# $Id: PostgreSQL.pm,v 1.11 2003-04-17 19:42:33 allenday Exp $
+# $Id: PostgreSQL.pm,v 1.12 2003-04-17 23:16:29 allenday Exp $
# -------------------------------------------------------------------
# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
# Allen Day <allenday@users.sourceforge.net>,
use strict;
use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.11 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.12 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
use Data::Dumper;
for my $constraint ( @{ $definition->{'constraints'} || [] } ) {
$constraint->{'fields'} = [ $field_name ];
- push @{ $tables{ $table_name }{'constraints'} },
+ push @{ $tables{ $table_name }{'constraints'} },
$constraint;
}
}