turnkey commit).
modified TTschema to accept 'ttargs' in addition to already present 'ttfile'
so arbitrary template args can be interpolated.
added Schema::Graph unit test (!). minimal.
introduced Log::Log4perl dependency.
modified Schema to have translator() slot to hold parent ref. needed to
get at producer_args(), parser_args(), and _format_name() from Graph.pm
-# $Id: Build.PL,v 1.1 2004-07-30 15:27:36 kycl4rk Exp $
+# $Id: Build.PL,v 1.2 2004-10-15 03:52:50 allenday Exp $
use strict;
use Module::Build;
requires => {
'Class::Base' => 0,
'IO::Dir' => 0,
+ 'Log::Log4perl' => 0,
'Template' => 2.10,
'Parse::RecDescent' => 1.94,
'Pod::Usage' => 0,
package SQL::Translator;
# ----------------------------------------------------------------------
-# $Id: Translator.pm,v 1.58 2004-10-15 02:23:29 allenday Exp $
+# $Id: Translator.pm,v 1.59 2004-10-15 03:52:50 allenday Exp $
# ----------------------------------------------------------------------
# Copyright (C) 2002-4 The SQLFairy Authors
#
require 5.004;
$VERSION = '0.06';
-$REVISION = sprintf "%d.%02d", q$Revision: 1.58 $ =~ /(\d+)\.(\d+)/;
+$REVISION = sprintf "%d.%02d", q$Revision: 1.59 $ =~ /(\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 up callbacks for formatting of pk,fk,table,package names in producer
+ # MOVED TO PRODUCER ARGS
+ #
+ #$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
unless ( defined $self->{'schema'} ) {
$self->{'schema'} = SQL::Translator::Schema->new(
- parser_args => $self->parser_args,
- producer_args => $self->producer_args,
+ translator => $self,
);
}
package SQL::Translator::Producer::TTSchema;
# -------------------------------------------------------------------
-# $Id: TTSchema.pm,v 1.4 2004-02-09 23:02:17 kycl4rk Exp $
+# $Id: TTSchema.pm,v 1.5 2004-10-15 03:52:50 allenday Exp $
# -------------------------------------------------------------------
# Copyright (C) 2002-4 SQLFairy Authors
#
filename => 'foo_schema.sql',
to => 'TTSchema',
producer_args => {
+ ttargs => {},
ttfile => 'foo_template.tt',
},
);
to => 'TT',
producer_args => {
ttfile => 'foo_template.tt',
+ ttargs => {},
INCLUDE_PATH => '/foo/templates/tt',
INTERPOLATE => 1,
},
use strict;
use vars qw[ $DEBUG $VERSION @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
use Template;
%$args, # Allow any TT opts to be passed in the producer_args
) || die "Failed to initialize Template object: ".Template->error;
- $tt->process( $file, { schema => $scma }, \$out )
+ $tt->process( $file, { schema => $scma , %{ $args->{ttargs} } }, \$out )
or die "Error processing template '$file': ".$tt->error;
return $out;
package SQL::Translator::Schema;
# ----------------------------------------------------------------------
-# $Id: Schema.pm,v 1.17 2004-10-15 02:23:30 allenday Exp $
+# $Id: Schema.pm,v 1.18 2004-10-15 03:52:50 allenday Exp $
# ----------------------------------------------------------------------
# Copyright (C) 2002-4 SQLFairy Authors
#
use base 'Class::Base';
use vars qw[ $VERSION $TABLE_ORDER $VIEW_ORDER $TRIGGER_ORDER $PROC_ORDER ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.17 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.18 $ =~ /(\d+)\.(\d+)/;
# ----------------------------------------------------------------------
sub init {
=cut
my ( $self, $config ) = @_;
- $self->params( $config, qw[ name database parser_args producer_args ] )
+ $self->params( $config, qw[ name database translator ] )
|| return undef;
return $self;
}
+sub as_graph {
+ my($self) = @_;
+ return SQL::Translator::Schema::Graph->new(translator => $self->translator);
+}
+
# ----------------------------------------------------------------------
sub add_table {
return $self->{'name'} || '';
}
-=head2 parser_args
-
-=cut
-
-sub parser_args {
- my $self = shift;
- return $self->{'parser_args'};
-}
+=head2 translator
-=head2 producer_args
+get the SQL::Translator instance that instatiated me
=cut
-sub producer_args {
+sub translator {
my $self = shift;
- return $self->{'producer_args'};
+ $self->{'translator'} = shift if @_;
+ return $self->{'translator'};
}
# ----------------------------------------------------------------------
use Data::Dumper;
$Data::Dumper::Maxdepth = 3;
+use Log::Log4perl qw(:easy);
+Log::Log4perl->easy_init($ERROR);
use SQL::Translator::Schema::Graph::Node;
use SQL::Translator::Schema::Graph::Edge;
use SQL::Translator::Schema::Graph::Port;
object => [
'translator' => {class => 'SQL::Translator'},
],
- 'hash' => [ qw( node ) ],
+ 'hash' => [ qw( node translator) ],
'number --counter' => [ qw( order ) ],
);
sub init {
my $self = shift;
+
#
# build package objects
#
$that->edgecount($node->name, $that->edgecount($node->name)+1);
- #warn "\t" . $node->name . "\t" . $node->edgecount($that->name);
+ #warn "\t" . $node->name . "\t" . $node->edgecount($that->name);
$node->push_edges( $edge );
$that->push_edges( $edge->flip );
}
}
+=head2 translator
+
+get the SQL::Translator instance that instatiated me
+
+=cut
+
+sub translator {
+ my $self = shift;
+ $self->{'translator'} = shift if @_;
+ return $self->{'translator'};
+}
+
1;
$| = 1;
use strict;
-use Test::More tests => 202;
+use Test::More tests => 206;
use SQL::Translator::Schema::Constants;
+require_ok( 'SQL::Translator' );
require_ok( 'SQL::Translator::Schema' );
{
my @views = $schema->get_views;
is( scalar @views, 2, 'Found 1 view' );
+
+}
+
+#
+# Graph
+#
+{
+ my $tr = SQL::Translator->new(
+ parser => "PostgreSQL",
+ );
+
+ ok( $tr->translate('t/data/pgsql/wiki.sql'), 'Translate PG' );
+ ok( my $schema = $tr->schema, 'Got Schema' );
+ ok( my $graph = $schema->as_graph, 'Graph made');
}
#