X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator.pm;h=08a129579e9888366429e1f081db088c3ef80d2f;hb=ede3a3eff20681c8b3dcdb34ec28a5381ef1e776;hp=809624ab4913cf460de1ad950e4df152b2a10c99;hpb=67e5ff532bf1c529ca7129aa058167bb51ea93f3;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator.pm b/lib/SQL/Translator.pm index 809624a..08a1295 100644 --- a/lib/SQL/Translator.pm +++ b/lib/SQL/Translator.pm @@ -1,7 +1,7 @@ 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 , # darren chamberlain , @@ -26,13 +26,16 @@ use strict; 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; @@ -43,7 +46,7 @@ use SQL::Translator::Schema; # 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]) @@ -60,7 +63,6 @@ $DEFAULT_SUB = sub { $_[1] } unless defined $DEFAULT_SUB; # ---------------------------------------------------------------------- sub init { my ( $self, $config ) = @_; - # # Set the parser and producer. # @@ -547,7 +549,7 @@ sub translate { return $self->error($msg); } - if ( $self->validate ) { + if ($self->validate) { my $schema = $self->schema; return $self->error('Invalid schema') unless $schema->is_valid; } @@ -644,7 +646,7 @@ sub _list { 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); @@ -698,21 +700,46 @@ sub format_package_name { # ---------------------------------------------------------------------- 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'}; } # ---------------------------------------------------------------------- @@ -786,19 +813,18 @@ SQL::Translator - manipulate structured data definitions (SQL and more) =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