package SQL::Translator;
# ----------------------------------------------------------------------
-# $Id: Translator.pm,v 1.31 2003-06-16 20:58:10 kycl4rk Exp $
+# $Id: Translator.pm,v 1.37 2003-07-31 20:49:42 dlc Exp $
# ----------------------------------------------------------------------
# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
# darren chamberlain <darren@cpan.org>,
use vars qw( $VERSION $REVISION $DEFAULT_SUB $DEBUG $ERROR );
use base 'Class::Base';
+require 5.004;
+
$VERSION = '0.02';
-$REVISION = sprintf "%d.%02d", q$Revision: 1.31 $ =~ /(\d+)\.(\d+)/;
+$REVISION = sprintf "%d.%02d", q$Revision: 1.37 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
$ERROR = "";
use Carp qw(carp);
+use Class::Base;
use File::Spec::Functions qw(catfile);
use File::Basename qw(dirname);
use IO::Dir;
# SQL::Translator instance is the first value ($_[0]), and the stuff
# to be parsed is the second value ($_[1])
# ----------------------------------------------------------------------
-$DEFAULT_SUB = sub { $_[1] } unless defined $DEFAULT_SUB;
+$DEFAULT_SUB = sub { $_[0]->schema } unless defined $DEFAULT_SUB;
# ----------------------------------------------------------------------
# init([ARGS])
# ----------------------------------------------------------------------
sub init {
my ( $self, $config ) = @_;
-
#
# Set the parser and producer.
#
return $self->error($msg);
}
- if ( $self->validate ) {
+ if ($self->validate) {
my $schema = $self->schema;
return $self->error('Invalid schema') unless $schema->is_valid;
}
my $path = catfile "SQL", "Translator", $uctype;
for (@INC) {
my $dir = catfile $_, $path;
- $self->debug("_list_${type}s searching $dir");
+ $self->debug("_list_${type}s searching $dir\n");
next unless -d $dir;
my $dh = IO::Dir->new($dir);
# ----------------------------------------------------------------------
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;
+
+ if ( ref $_[0] eq 'CODE' ) {
+ $self->{'_format_pk_name'} = shift;
+ }
+
+ if ( @_ ) {
+ if ( defined $self->{'_format_pk_name'} ) {
+ return $self->{'_format_pk_name'}->( @_ );
+ }
+ else {
+ return '';
+ }
+ }
+
+ return $self->{'_format_pk_name'};
+# 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;
+
+ if ( ref $_[0] eq 'CODE' ) {
+ $self->{'_format_pk_name'} = shift;
+ }
+
+ if ( @_ ) {
+ if ( defined $self->{'_format_pk_name'} ) {
+ return $self->{'_format_pk_name'}->( @_ );
+ }
+ else {
+ return '';
+ }
+ }
+
+ return $self->{'_format_pk_name'};
}
# ----------------------------------------------------------------------
=head1 DESCRIPTION
-The SQLFairy project began with the idea of simplifying the task of
-converting one database create syntax to another through the use of
-Parsers (which understand the source format) and Producers (which
-understand the destination format). The idea is that any Parser can
-be used with any Producer in the conversion process, so, if you
-wanted Postgres-to-Oracle, you would use the Postgres parser and the
-Oracle producer. The project has since grown to include parsing
-structured data files like Excel spreadsheets and delimited text files
-and the production of various documentation aids, such as images,
-graphs, POD, and HTML descriptions of the schema, as well as automatic
-code generators through the use of Class::DBI. Presently only the
-definition parts of SQL are handled (CREATE, ALTER), not the
-manipulation of data (INSERT, UPDATE, DELETE).
+SQL::Translator is a group of Perl modules that converts
+vendor-specific SQL table definitions into other formats, such as
+other vendor-specific SQL, ER diagrams, documentation (POD and HTML),
+XML, and Class::DBI classes. The main focus of SQL::Translator is
+SQL, but parsers exist for other structured data formats, including
+Excel spreadsheets and arbitrarily delimited text files. Through the
+separation of the code into parsers and producers with an object model
+in between, it's possible to combine any parser with any producer, to
+plug in custom parsers or producers, or to manipulate the parsed data
+via the built-in object model. Presently only the definition parts of
+SQL are handled (CREATE, ALTER), not the manipulation of data (INSERT,
+UPDATE, DELETE).
=head1 CONSTRUCTOR