X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FProducer%2FTT%2FBase.pm;h=4b03789e333c91e75b0467587015b8ccc7a7ec71;hb=b03926cdac036bdbcf69e478ca29e1121c814646;hp=4a00d1aab6b4be9f00a7f6317daf07bb86a9908a;hpb=bfd86e76517a132e6371afd8368d384448bf68bd;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Producer/TT/Base.pm b/lib/SQL/Translator/Producer/TT/Base.pm index 4a00d1a..4b03789 100644 --- a/lib/SQL/Translator/Producer/TT/Base.pm +++ b/lib/SQL/Translator/Producer/TT/Base.pm @@ -1,9 +1,7 @@ package SQL::Translator::Producer::TT::Base; # ------------------------------------------------------------------- -# $Id: Base.pm,v 1.4 2004-05-14 03:37:37 grommit Exp $ -# ------------------------------------------------------------------- -# Copyright (C) 2002-4 SQLFairy Authors +# Copyright (C) 2002-2009 SQLFairy Authors # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -32,7 +30,7 @@ class. use strict; use vars qw[ $VERSION @EXPORT_OK ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/; +$VERSION = '1.99'; use Template; use Data::Dumper; @@ -157,11 +155,12 @@ sub tt_vars { () }; =head1 SYNOPSIS + # Create a producer using a template in the __DATA__ section. package SQL::Translator::Producer::Foo; use base qw/SQL::Translator::Producer::TT::Base/; - # Convert produce call into an object of our new class + # Convert produce call into a method call on our new class sub produce { return __PACKAGE__->new( translator => shift )->run; }; # Configure the Template object. @@ -173,68 +172,60 @@ sub tt_vars { () }; # 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, -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, so we can sub-class it. -This is done with the following code which B appear in B sub -classes. +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 +sub classes. # Convert produce call into an object method call sub produce { return __PACKAGE__->new( translator => shift )->run; }; See L below for details. -The upshot of this is we can make new template producers by writing a template, -then creating a module that starts like this; - - package SQL::Translator::Producer::Foo; - - use base qw/SQL::Translator::Producer::TT::Base/; - - # Convert produce call into an object of our new class - sub produce { return __PACKAGE__->new( translator => shift )->run; }; - -And then over ride the hooks detailed below in L. +The upshot of this is we can make new template producers by sub classing this +base class, adding the above snippet and a template. +The module also provides a number of hooks into the templating process, +see L for details. See the L above for an example of creating a simple producer using a single template stored in the producers DATA section. =head1 SUB CLASS HOOKS -Sub-classes should override these methods to control the templating by giving +Sub-classes can override these methods to control the templating by giving the template source, adding variables and giving config to the Tempate object. =head2 tt_config sub tt_config { ( INTERPOLATE => 1 ); } -Return hash of Template config to add to the config given to the -C<< Template->new >> method. +Return hash of Template config to add to that given to the L