From: Mark Addison Date: Fri, 20 Aug 2004 00:58:35 +0000 (+0000) Subject: Doc tweaks X-Git-Tag: v0.06~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=466c88de259c91b372b3f069a71a044888307bf2;p=dbsrgits%2FSQL-Translator.git Doc tweaks --- diff --git a/lib/SQL/Translator/Manual.pod b/lib/SQL/Translator/Manual.pod index 14b5b22..90450b5 100644 --- a/lib/SQL/Translator/Manual.pod +++ b/lib/SQL/Translator/Manual.pod @@ -299,7 +299,7 @@ prints the name of each table and field that looks like this: [% END -%] [% END %] -And the process it like so: +And then process it like so: $ sqlt -f YAML -t TTSchema --template schema.tt foo.yaml @@ -424,7 +424,7 @@ map the concepts in the data to the Schema object. sub parser { my ( $tr, $data ) = @_; my $schema = $tr->schema; - + for my $line ( split( /\n/, $data ) ) { my ( $table_name, @fields ) = split( /:/, $line ); my $table = $schema->add_table( name => $table_name ) @@ -438,29 +438,29 @@ map the concepts in the data to the Schema object. ) or die $table->error; } } - + return 1; } And here is the output produced by this script: - -- + -- -- Created by SQL::Translator::Producer::Oracle -- Created on Wed Mar 31 15:43:30 2004 - -- + -- -- -- Table: foo -- - + CREATE TABLE foo ( foo_id number(11), foo_name varchar2(30) ); - + -- -- Table: bar -- - + CREATE TABLE bar ( bar_id number(11), bar_value varchar2(30) @@ -479,14 +479,14 @@ just for you! Instead of working like a normal producer it provides a base class so you can cheaply build new producer modules based on templates. It's simplest use is when we just want to put a single template in its own -module. So to create a Foo producer we create a F file as +module. So to create a Foo producer we create a F file as follows, putting our template in the __DATA__ section. package Custom::Foo.pm; use base qw/SQL::Translator::Producer::TT::Base/; # Use our new class as the producer sub produce { return __PACKAGE__->new( translator => shift )->run; }; - + __DATA__ [% FOREACH table IN schema.get_tables %] Table: [% table.name %] @@ -499,7 +499,7 @@ follows, putting our template in the __DATA__ section. For that we get a producer called Custom::Foo that we can now call like a normal producer (as long as the directory with F is in our @INC path): - + $ sqlt -f YAML -t Custom-Foo foo.yaml The template gets variables of C and C to use in building @@ -508,13 +508,13 @@ template generation. B Allows you to set the config options used by the Template object. The Template Toolkit provides a huge number of options which allow you to do all -sorts of magic (See L for details). This method +sorts of magic (See L for details). This method provides a hook into them by returning a hash of options for the Template. e.g. Say you want to use the INTERPOLATE option to save some typing in your template; sub tt_config { ( INTERPOLATE => 1 ); } -A common use for this is to add you own filters to the template: +Another common use for this is to add you own filters to the template: sub tt_config {( INTERPOLATE => 1, @@ -526,19 +526,19 @@ with B: sub tt_vars { ( foo => "bar" ); } -What about using template files instead of DATA sections? You can already! if +What about using template files instead of DATA sections? You can already - if you give a template on the command line your new producer will use that instead of reading the DATA section: $ sqlt -f YAML -t Custom-Foo --template foo.tt foo.yaml -This is usefull as you can set up a producer that adds a set of filters and +This is usefull as you can set up a producer that adds a set of filters and variables that you can then use in templates given on the command line. (There is also a tt_schema method to over ride if you need even finer control over the source of your template). Note that if you leave out the DATA section all together then your producer will require a template file name to be given. -See L for more details of what you can do. +See L for more details. =head1 AUTHOR diff --git a/lib/SQL/Translator/Producer/TT/Base.pm b/lib/SQL/Translator/Producer/TT/Base.pm index 90446aa..6f5740f 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.5 2004-08-19 19:55:36 grommit Exp $ +# $Id: Base.pm,v 1.6 2004-08-20 00:58:35 grommit Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -32,7 +32,7 @@ class. use strict; use vars qw[ $VERSION @EXPORT_OK ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/; use Template; use Data::Dumper; @@ -157,7 +157,7 @@ sub tt_vars { () }; =head1 SYNOPSIS -# Create a producer using a template in the __DATA__ section. + # Create a producer using a template in the __DATA__ section. package SQL::Translator::Producer::Foo; use base qw/SQL::Translator::Producer::TT::Base/; @@ -181,13 +181,12 @@ sub tt_vars { () }; =head1 DESCRIPTION -WARNING: This is currently WORK IN PROGRESS and so subject to change, -but it does work ;-) - A base class producer designed to be sub-classed to create new TT based producers cheaply - by simply giving the template to use and sprinkling in some extra template variables and config. +You can find an introduction to this module in L. + The 1st thing the module does is convert the produce sub routine call we get from SQL::Translator into a method call on an object, which we can then sub-class. This is done with the following code which needs to appear in B