package SQL::Translator;
# ----------------------------------------------------------------------
-# $Id: Translator.pm,v 1.14 2002-11-26 03:59:57 kycl4rk Exp $
+# $Id: Translator.pm,v 1.15 2003-01-27 17:04:43 dlc Exp $
# ----------------------------------------------------------------------
-# Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
-# darren chamberlain <darren@cpan.org>
+# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
+# darren chamberlain <darren@cpan.org>,
+# Chris Mungall <cjm@fruitfly.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
This module attempts to simplify the task of converting one database
create syntax to another through the use of Parsers (which understand
-the sourced format) and Producers (which understand the destination
+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 PostgreSQL-to-Oracle, you
-would use the PostgreSQL parser and the Oracle producer.
+the conversion process. So, if you wanted Postgres-to-Oracle, you
+would use the Postgres parser and the Oracle producer.
=cut
use base 'Class::Base';
$VERSION = '0.01';
-$REVISION = sprintf "%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/;
+$REVISION = sprintf "%d.%02d", q$Revision: 1.15 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
$ERROR = "";
=head1 METHODS
-# ----------------------------------------------------------------------
=head2 B<add_drop_table>
Toggles whether or not to add "DROP TABLE" statements just before the
}
-# ----------------------------------------------------------------------
=head2 B<custom_translate>
Allows the user to override default translation of fields. For example,
return $self->{'custom_translate'} || {};
}
-# ----------------------------------------------------------------------
=head2 B<no_comments>
Toggles whether to print comments in the output. Accepts a true or false
return $self->{'no_comments'} || 0;
}
-# ----------------------------------------------------------------------
=head2 B<producer>
The B<producer> method is an accessor/mutator, used to retrieve or
define what subroutine is called to produce the output. A subroutine
-defined as a producer will be invoked as a function (not a method) and
-passed 2 parameters: its container SQL::Translator instance and a
+defined as a producer will be invoked as a function (I<not a method>)
+and passed 2 parameters: its container SQL::Translator instance and a
data structure. It is expected that the function transform the data
structure to a string. The SQL::Transformer instance is provided for
informational purposes; for example, the type of the parser can be
$self->{'producer_args'};
}
-# ----------------------------------------------------------------------
=head2 B<parser>
The B<parser> method defines or retrieves a subroutine that will be
$self->{'parser_args'};
}
-# ----------------------------------------------------------------------
=head2 B<show_warnings>
Toggles whether to print warnings of name conflicts, identifier
return $self->{'show_warnings'} || 0;
}
-# ----------------------------------------------------------------------
=head2 B<translate>
The B<translate> method calls the subroutines referenced by the
=back
-# ----------------------------------------------------------------------
=head2 B<filename>, B<data>
Using the B<filename> method, the filename of the data to be parsed
return $self->{'data'};
}
-# ----------------------------------------------------------------------
=pod
=head2 B<trace>
}
# ----------------------------------------------------------------------
-sub isa { UNIVERSAL::isa($_[0], $_[1]) }
+sub isa($$) { UNIVERSAL::isa($_[0], $_[1]) }
1;
=head1 SEE ALSO
-L<perl>, L<Parse::RecDescent>
+L<perl>,
+L<SQL::Translator::Parser>,
+L<SQL::Translator::Producer>,
+L<Parse::RecDescent>
=cut
package SQL::Translator::Parser;
# ----------------------------------------------------------------------
-# $Id: Parser.pm,v 1.5 2002-11-22 03:03:40 kycl4rk Exp $
+# $Id: Parser.pm,v 1.6 2003-01-27 17:04:44 dlc Exp $
# ----------------------------------------------------------------------
-# Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
-# darren chamberlain <darren@cpan.org>
+# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
+# darren chamberlain <darren@cpan.org>,
+# Chris Mungall <cjm@fruitfly.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
use strict;
use vars qw( $VERSION );
-$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/;
sub parse { "" }
package SQL::Translator::Parser::MySQL;
# -------------------------------------------------------------------
-# $Id: MySQL.pm,v 1.8 2002-11-28 04:21:06 kycl4rk Exp $
+# $Id: MySQL.pm,v 1.9 2003-01-27 17:04:45 dlc Exp $
# -------------------------------------------------------------------
-# Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
-# darren chamberlain <darren@cpan.org>
+# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
+# darren chamberlain <darren@cpan.org>,
+# Chris Mungall <cjm@fruitfly.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
use strict;
use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 1 unless defined $DEBUG;
use Data::Dumper;
package SQL::Translator::Parser::Sybase;
# -------------------------------------------------------------------
-# $Id: Sybase.pm,v 1.3 2002-11-22 03:03:40 kycl4rk Exp $
+# $Id: Sybase.pm,v 1.4 2003-01-27 17:04:46 dlc Exp $
# -------------------------------------------------------------------
-# Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
-# darren chamberlain <darren@cpan.org>
+# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
+# darren chamberlain <darren@cpan.org>,
+# Chris Mungall <cjm@fruitfly.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
package SQL::Translator::Parser::xSV;
# -------------------------------------------------------------------
-# $Id: xSV.pm,v 1.3 2002-11-22 03:03:40 kycl4rk Exp $
+# $Id: xSV.pm,v 1.4 2003-01-27 17:04:46 dlc Exp $
# -------------------------------------------------------------------
-# Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
-# darren chamberlain <darren@cpan.org>
+# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
+# darren chamberlain <darren@cpan.org>,
+# Chris Mungall <cjm@fruitfly.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
use strict;
use vars qw($VERSION @EXPORT);
-$VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/;
use Exporter;
use Text::ParseWords qw(quotewords);
package SQL::Translator::Producer;
# -------------------------------------------------------------------
-# $Id: Producer.pm,v 1.4 2002-11-22 03:03:40 kycl4rk Exp $
+# $Id: Producer.pm,v 1.5 2003-01-27 17:04:45 dlc Exp $
# -------------------------------------------------------------------
-# Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
-# darren chamberlain <darren@cpan.org>
+# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
+# darren chamberlain <darren@cpan.org>,
+# Chris Mungall <cjm@fruitfly.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
use strict;
use vars qw($VERSION);
-$VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
sub produce { "" }
package SQL::Translator::Producer::MySQL;
# -------------------------------------------------------------------
-# $Id: MySQL.pm,v 1.4 2002-11-22 03:03:40 kycl4rk Exp $
+# $Id: MySQL.pm,v 1.5 2003-01-27 17:04:46 dlc Exp $
# -------------------------------------------------------------------
-# Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
-# darren chamberlain <darren@cpan.org>
+# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
+# darren chamberlain <darren@cpan.org>,
+# Chris Mungall <cjm@fruitfly.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
use strict;
use vars qw[ $VERSION $DEBUG ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 1 unless defined $DEBUG;
use Data::Dumper;
package SQL::Translator::Producer::Oracle;
# -------------------------------------------------------------------
-# $Id: Oracle.pm,v 1.8 2002-12-11 01:44:54 kycl4rk Exp $
+# $Id: Oracle.pm,v 1.9 2003-01-27 17:04:46 dlc Exp $
# -------------------------------------------------------------------
-# Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
-# darren chamberlain <darren@cpan.org>
+# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
+# darren chamberlain <darren@cpan.org>,
+# Chris Mungall <cjm@fruitfly.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
use strict;
use vars qw[ $VERSION $DEBUG $WARN ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
my %translate = (
package SQL::Translator::Producer::PostgreSQL;
# -------------------------------------------------------------------
-# $Id: PostgreSQL.pm,v 1.5 2003-01-02 17:47:59 kycl4rk Exp $
+# $Id: PostgreSQL.pm,v 1.6 2003-01-27 17:04:48 dlc Exp $
# -------------------------------------------------------------------
-# Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
-# darren chamberlain <darren@cpan.org>
+# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
+# darren chamberlain <darren@cpan.org>,
+# Chris Mungall <cjm@fruitfly.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
use strict;
use vars qw[ $DEBUG $WARN $VERSION ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 1 unless defined $DEBUG;
use Data::Dumper;
package SQL::Translator::Producer::XML;
# -------------------------------------------------------------------
-# $Id: XML.pm,v 1.4 2002-11-28 04:21:07 kycl4rk Exp $
+# $Id: XML.pm,v 1.5 2003-01-27 17:04:48 dlc Exp $
# -------------------------------------------------------------------
-# Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
-# darren chamberlain <darren@cpan.org>
+# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
+# darren chamberlain <darren@cpan.org>,
+# Chris Mungall <cjm@fruitfly.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
use strict;
use vars qw[ $VERSION $XML ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
# -------------------------------------------------------------------
sub produce {
package SQL::Translator::Validator;
# ----------------------------------------------------------------------
-# $Id: Validator.pm,v 1.6 2002-11-25 14:49:44 dlc Exp $
+# $Id: Validator.pm,v 1.7 2003-01-27 17:04:45 dlc Exp $
# ----------------------------------------------------------------------
-# Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
-# darren chamberlain <darren@cpan.org>
+# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
+# darren chamberlain <darren@cpan.org>,
+# Chris Mungall <cjm@fruitfly.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
use strict;
use vars qw($VERSION @EXPORT);
-$VERSION = sprintf "%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/;
use Exporter;
use base qw(Exporter);
=head1 SYNOPSIS
- print "1..1\n";
-
+ use Test::More plan tests => 1;
use SQL::Translator;
use SQL::Translator::Validator;
# Default producer passes the data structure through unchanged
my $parsed = $tr->translate($datafile);
- print "not " unless validate($parsed);
- print "ok 1 # data structure looks OK\n";
+ ok(validate($parsed), "data structure conformance to definition");
=head1 DESCRIPTION
or, potentially, even as a runtime assertion for producers you don't
trust:
- $tr->producer(\¶noid_producer);
+ $tr->producer(\¶noid_producer, real_producer => "MySQL");
sub paranoid_producer {
my ($tr, $data) = @_;
validate($data) or die "You gave me crap!"
# Load real producer, and execute it
- $tr->producer("MySQL");
+ $tr->producer($tr->producer_args->{'real_producer'});
return $tr->produce($data);
}