From: Mark Addison Date: Fri, 14 May 2004 03:37:37 +0000 (+0000) Subject: Added experimental pre_process_schema method. X-Git-Tag: v0.06~52 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bfd86e76517a132e6371afd8368d384448bf68bd;p=dbsrgits%2FSQL-Translator.git Added experimental pre_process_schema method. --- diff --git a/lib/SQL/Translator/Producer/TT/Base.pm b/lib/SQL/Translator/Producer/TT/Base.pm index e2dbc0b..4a00d1a 100644 --- a/lib/SQL/Translator/Producer/TT/Base.pm +++ b/lib/SQL/Translator/Producer/TT/Base.pm @@ -1,7 +1,7 @@ package SQL::Translator::Producer::TT::Base; # ------------------------------------------------------------------- -# $Id: Base.pm,v 1.3 2004-05-14 00:46:32 grommit Exp $ +# $Id: Base.pm,v 1.4 2004-05-14 03:37:37 grommit Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -32,10 +32,11 @@ class. use strict; use vars qw[ $VERSION @EXPORT_OK ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/; use Template; use Data::Dumper; +use IO::Handle; use Exporter; use base qw(Exporter); @EXPORT_OK = qw(produce); @@ -119,16 +120,33 @@ sub run { sub tt_config { () }; -sub tt_schema { shift->args("ttfile") }; +sub tt_schema { + my $me = shift; + my $class = ref $me; + + my $file = $me->args("ttfile"); + return $file if $file; + + no strict 'refs'; + my $ref = *{"$class\:\:DATA"}{IO}; + if ( $ref->opened ) { + local $/ = undef; # Slurp mode + return \<$ref>; + } + + undef; +}; sub tt_default_vars { my $me = shift; return ( translator => $me->translator, - schema => $me->translator->schema, + schema => $me->pre_process_schema($me->translator->schema), ); } +sub pre_process_schema { $_[1] } + sub tt_vars { () }; 1; @@ -146,15 +164,20 @@ sub tt_vars { () }; # Convert produce call into an object of our new class sub produce { return __PACKAGE__->new( translator => shift )->run; }; - # Return file name or template source - sub tt_schema { local $/ = undef; \; } - # Configure the Template object. sub tt_config { ( INTERPOLATE => 1 ); } # Extra vars to add to the template sub tt_vars { ( foo => "bar" ); } + # Put template in DATA section (or use file with ttfile producer arg) + __DATA__ + Schema + + Database: [% schema.database %] + Foo: $foo + ... + =head1 DESCRIPTION WARNING: This is currently WORK IN PROGRESS and so subject to change, @@ -211,7 +234,9 @@ an L. See L