From 3282be229999dc36c197b264d63063a18d136331 Mon Sep 17 00:00:00 2001 From: Andreas Brachold Date: Sun, 11 Nov 2007 06:55:13 +0000 Subject: * Update installation list with required modules * Remove unused/doubled provided external perl moduls --- lib/Template/Base.pm | 314 -- lib/Template/Config.pm | 467 -- lib/Template/Constants.pm | 287 -- lib/Template/Context.pm | 1570 ------- lib/Template/Directive.pm | 1004 ----- lib/Template/Document.pm | 492 --- lib/Template/Exception.pm | 254 -- lib/Template/FAQ.pod | 329 -- lib/Template/Filters.pm | 1448 ------- lib/Template/Grammar.pm | 6179 --------------------------- lib/Template/Iterator.pm | 456 -- lib/Template/Library/HTML.pod | 316 -- lib/Template/Library/PostScript.pod | 78 - lib/Template/Library/Splash.pod | 1030 ----- lib/Template/Manual.pod | 180 - lib/Template/Manual/Config.pod | 2122 --------- lib/Template/Manual/Credits.pod | 188 - lib/Template/Manual/Directives.pod | 2179 ---------- lib/Template/Manual/Filters.pod | 529 --- lib/Template/Manual/Internals.pod | 556 --- lib/Template/Manual/Intro.pod | 295 -- lib/Template/Manual/Plugins.pod | 552 --- lib/Template/Manual/Refs.pod | 171 - lib/Template/Manual/Syntax.pod | 306 -- lib/Template/Manual/VMethods.pod | 529 --- lib/Template/Manual/Variables.pod | 868 ---- lib/Template/Manual/Views.pod | 642 --- lib/Template/Modules.pod | 448 -- lib/Template/Namespace/Constants.pm | 205 - lib/Template/Parser.pm | 1446 ------- lib/Template/Plugin.pm | 409 -- lib/Template/Plugin/Autoformat.pm | 242 -- lib/Template/Plugin/CGI.pm | 168 - lib/Template/Plugin/DBI.pm | 947 ---- lib/Template/Plugin/Datafile.pm | 198 - lib/Template/Plugin/Date.pm | 361 -- lib/Template/Plugin/Directory.pm | 410 -- lib/Template/Plugin/Dumper.pm | 179 - lib/Template/Plugin/File.pm | 416 -- lib/Template/Plugin/Filter.pm | 436 -- lib/Template/Plugin/Format.pm | 124 - lib/Template/Plugin/GD/Constants.pm | 138 - lib/Template/Plugin/GD/Graph/area.pm | 148 - lib/Template/Plugin/GD/Graph/bars.pm | 191 - lib/Template/Plugin/GD/Graph/bars3d.pm | 166 - lib/Template/Plugin/GD/Graph/lines.pm | 178 - lib/Template/Plugin/GD/Graph/lines3d.pm | 166 - lib/Template/Plugin/GD/Graph/linespoints.pm | 158 - lib/Template/Plugin/GD/Graph/mixed.pm | 176 - lib/Template/Plugin/GD/Graph/pie.pm | 141 - lib/Template/Plugin/GD/Graph/pie3d.pm | 145 - lib/Template/Plugin/GD/Graph/points.pm | 155 - lib/Template/Plugin/GD/Image.pm | 184 - lib/Template/Plugin/GD/Polygon.pm | 155 - lib/Template/Plugin/GD/Text.pm | 140 - lib/Template/Plugin/GD/Text/Align.pm | 147 - lib/Template/Plugin/GD/Text/Wrap.pm | 183 - lib/Template/Plugin/HTML.pm | 197 - lib/Template/Plugin/Image.pm | 425 -- lib/Template/Plugin/Iterator.pm | 118 - lib/Template/Plugin/Pod.pm | 116 - lib/Template/Plugin/Procedural.pm | 170 - lib/Template/Plugin/String.pm | 796 ---- lib/Template/Plugin/Table.pm | 464 -- lib/Template/Plugin/URL.pm | 236 - lib/Template/Plugin/View.pm | 127 - lib/Template/Plugin/Wrap.pm | 162 - lib/Template/Plugin/XML/DOM.pm | 841 ---- lib/Template/Plugin/XML/RSS.pm | 194 - lib/Template/Plugin/XML/Simple.pm | 124 - lib/Template/Plugin/XML/Style.pm | 357 -- lib/Template/Plugin/XML/XPath.pm | 284 -- lib/Template/Plugins.pm | 1041 ----- lib/Template/Provider.pm | 1449 ------- lib/Template/Service.pm | 775 ---- lib/Template/Stash.pm | 1040 ----- lib/Template/Stash/Context.pm | 791 ---- lib/Template/Stash/XS.pm | 176 - lib/Template/Test.pm | 711 --- lib/Template/Tools/tpage.pod | 76 - lib/Template/Tools/ttree.pod | 332 -- lib/Template/Tutorial.pod | 109 - lib/Template/Tutorial/Datafile.pod | 461 -- lib/Template/Tutorial/Web.pod | 801 ---- lib/Template/View.pm | 752 ---- 85 files changed, 45026 deletions(-) delete mode 100644 lib/Template/Base.pm delete mode 100644 lib/Template/Config.pm delete mode 100644 lib/Template/Constants.pm delete mode 100644 lib/Template/Context.pm delete mode 100644 lib/Template/Directive.pm delete mode 100644 lib/Template/Document.pm delete mode 100644 lib/Template/Exception.pm delete mode 100644 lib/Template/FAQ.pod delete mode 100644 lib/Template/Filters.pm delete mode 100644 lib/Template/Grammar.pm delete mode 100644 lib/Template/Iterator.pm delete mode 100644 lib/Template/Library/HTML.pod delete mode 100644 lib/Template/Library/PostScript.pod delete mode 100644 lib/Template/Library/Splash.pod delete mode 100644 lib/Template/Manual.pod delete mode 100644 lib/Template/Manual/Config.pod delete mode 100644 lib/Template/Manual/Credits.pod delete mode 100644 lib/Template/Manual/Directives.pod delete mode 100644 lib/Template/Manual/Filters.pod delete mode 100644 lib/Template/Manual/Internals.pod delete mode 100644 lib/Template/Manual/Intro.pod delete mode 100644 lib/Template/Manual/Plugins.pod delete mode 100644 lib/Template/Manual/Refs.pod delete mode 100644 lib/Template/Manual/Syntax.pod delete mode 100644 lib/Template/Manual/VMethods.pod delete mode 100644 lib/Template/Manual/Variables.pod delete mode 100644 lib/Template/Manual/Views.pod delete mode 100644 lib/Template/Modules.pod delete mode 100644 lib/Template/Namespace/Constants.pm delete mode 100644 lib/Template/Parser.pm delete mode 100644 lib/Template/Plugin.pm delete mode 100644 lib/Template/Plugin/Autoformat.pm delete mode 100644 lib/Template/Plugin/CGI.pm delete mode 100644 lib/Template/Plugin/DBI.pm delete mode 100644 lib/Template/Plugin/Datafile.pm delete mode 100644 lib/Template/Plugin/Date.pm delete mode 100644 lib/Template/Plugin/Directory.pm delete mode 100644 lib/Template/Plugin/Dumper.pm delete mode 100644 lib/Template/Plugin/File.pm delete mode 100644 lib/Template/Plugin/Filter.pm delete mode 100644 lib/Template/Plugin/Format.pm delete mode 100644 lib/Template/Plugin/GD/Constants.pm delete mode 100644 lib/Template/Plugin/GD/Graph/area.pm delete mode 100644 lib/Template/Plugin/GD/Graph/bars.pm delete mode 100644 lib/Template/Plugin/GD/Graph/bars3d.pm delete mode 100644 lib/Template/Plugin/GD/Graph/lines.pm delete mode 100644 lib/Template/Plugin/GD/Graph/lines3d.pm delete mode 100644 lib/Template/Plugin/GD/Graph/linespoints.pm delete mode 100644 lib/Template/Plugin/GD/Graph/mixed.pm delete mode 100644 lib/Template/Plugin/GD/Graph/pie.pm delete mode 100644 lib/Template/Plugin/GD/Graph/pie3d.pm delete mode 100644 lib/Template/Plugin/GD/Graph/points.pm delete mode 100644 lib/Template/Plugin/GD/Image.pm delete mode 100644 lib/Template/Plugin/GD/Polygon.pm delete mode 100644 lib/Template/Plugin/GD/Text.pm delete mode 100644 lib/Template/Plugin/GD/Text/Align.pm delete mode 100644 lib/Template/Plugin/GD/Text/Wrap.pm delete mode 100644 lib/Template/Plugin/HTML.pm delete mode 100644 lib/Template/Plugin/Image.pm delete mode 100644 lib/Template/Plugin/Iterator.pm delete mode 100644 lib/Template/Plugin/Pod.pm delete mode 100644 lib/Template/Plugin/Procedural.pm delete mode 100644 lib/Template/Plugin/String.pm delete mode 100644 lib/Template/Plugin/Table.pm delete mode 100644 lib/Template/Plugin/URL.pm delete mode 100644 lib/Template/Plugin/View.pm delete mode 100644 lib/Template/Plugin/Wrap.pm delete mode 100644 lib/Template/Plugin/XML/DOM.pm delete mode 100644 lib/Template/Plugin/XML/RSS.pm delete mode 100644 lib/Template/Plugin/XML/Simple.pm delete mode 100644 lib/Template/Plugin/XML/Style.pm delete mode 100644 lib/Template/Plugin/XML/XPath.pm delete mode 100644 lib/Template/Plugins.pm delete mode 100644 lib/Template/Provider.pm delete mode 100644 lib/Template/Service.pm delete mode 100644 lib/Template/Stash.pm delete mode 100644 lib/Template/Stash/Context.pm delete mode 100644 lib/Template/Stash/XS.pm delete mode 100644 lib/Template/Test.pm delete mode 100644 lib/Template/Tools/tpage.pod delete mode 100644 lib/Template/Tools/ttree.pod delete mode 100644 lib/Template/Tutorial.pod delete mode 100644 lib/Template/Tutorial/Datafile.pod delete mode 100644 lib/Template/Tutorial/Web.pod delete mode 100644 lib/Template/View.pm (limited to 'lib/Template') diff --git a/lib/Template/Base.pm b/lib/Template/Base.pm deleted file mode 100644 index 5f19d78..0000000 --- a/lib/Template/Base.pm +++ /dev/null @@ -1,314 +0,0 @@ -#============================================================= -*-perl-*- -# -# Template::Base -# -# DESCRIPTION -# Base class module implementing common functionality for various other -# Template Toolkit modules. -# -# AUTHOR -# Andy Wardley -# -# COPYRIGHT -# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -#------------------------------------------------------------------------ -# -# $Id: Base.pm,v 2.69 2004/01/13 16:19:09 abw Exp $ -# -#======================================================================== - -package Template::Base; - -require 5.004; - -use strict; -use vars qw( $VERSION ); -use Template::Constants; - -$VERSION = sprintf("%d.%02d", q$Revision: 2.69 $ =~ /(\d+)\.(\d+)/); - - -#------------------------------------------------------------------------ -# new(\%params) -# -# General purpose constructor method which expects a hash reference of -# configuration parameters, or a list of name => value pairs which are -# folded into a hash. Blesses a hash into an object and calls its -# _init() method, passing the parameter hash reference. Returns a new -# object derived from Template::Base, or undef on error. -#------------------------------------------------------------------------ - -sub new { - my $class = shift; - my ($argnames, @args, $arg, $cfg); -# $class->error(''); # always clear package $ERROR var? - - { no strict qw( refs ); - $argnames = \@{"$class\::BASEARGS"} || [ ]; - } - - # shift off all mandatory args, returning error if undefined or null - foreach $arg (@$argnames) { - return $class->error("no $arg specified") - unless ($cfg = shift); - push(@args, $cfg); - } - - # fold all remaining args into a hash, or use provided hash ref -# local $" = ', '; -# print STDERR "args: [@_]\n"; - $cfg = defined $_[0] && UNIVERSAL::isa($_[0], 'HASH') ? shift : { @_ }; - - my $self = bless { - map { ($_ => shift @args) } @$argnames, - _ERROR => '', - DEBUG => 0, - }, $class; - - return $self->_init($cfg) ? $self : $class->error($self->error); -} - - -#------------------------------------------------------------------------ -# error() -# error($msg, ...) -# -# May be called as a class or object method to set or retrieve the -# package variable $ERROR (class method) or internal member -# $self->{ _ERROR } (object method). The presence of parameters indicates -# that the error value should be set. Undef is then returned. In the -# abscence of parameters, the current error value is returned. -#------------------------------------------------------------------------ - -sub error { - my $self = shift; - my $errvar; - - { - no strict qw( refs ); - $errvar = ref $self ? \$self->{ _ERROR } : \${"$self\::ERROR"}; - } - if (@_) { - $$errvar = ref($_[0]) ? shift : join('', @_); - return undef; - } - else { - return $$errvar; - } -} - - -#------------------------------------------------------------------------ -# _init() -# -# Initialisation method called by the new() constructor and passing a -# reference to a hash array containing any configuration items specified -# as constructor arguments. Should return $self on success or undef on -# error, via a call to the error() method to set the error message. -#------------------------------------------------------------------------ - -sub _init { - my ($self, $config) = @_; - return $self; -} - - -sub DEBUG { - my $self = shift; - print STDERR "DEBUG: ", @_; -} - -sub debug { - my $self = shift; - my $msg = join('', @_); - my ($pkg, $file, $line) = caller(); - - unless ($msg =~ /\n$/) { - $msg .= ($self->{ DEBUG } & Template::Constants::DEBUG_CALLER) - ? " at $file line $line\n" - : "\n"; - } - - print STDERR "[$pkg] $msg"; -} - - -#------------------------------------------------------------------------ -# module_version() -# -# Returns the current version number. -#------------------------------------------------------------------------ - -sub module_version { - my $self = shift; - my $class = ref $self || $self; - no strict 'refs'; - return ${"${class}::VERSION"}; -} - - -1; - -__END__ - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Base - Base class module implementing common functionality - -=head1 SYNOPSIS - - package My::Module; - use base qw( Template::Base ); - - sub _init { - my ($self, $config) = @_; - $self->{ doodah } = $config->{ doodah } - || return $self->error("No 'doodah' specified"); - return $self; - } - - package main; - - my $object = My::Module->new({ doodah => 'foobar' }) - || die My::Module->error(); - -=head1 DESCRIPTION - -Base class module which implements a constructor and error reporting -functionality for various Template Toolkit modules. - -=head1 PUBLIC METHODS - -=head2 new(\%config) - -Constructor method which accepts a reference to a hash array or a list -of C value> parameters which are folded into a hash. The -_init() method is then called, passing the configuration hash and should -return true/false to indicate success or failure. A new object reference -is returned, or undef on error. Any error message raised can be examined -via the error() class method or directly via the package variable ERROR -in the derived class. - - my $module = My::Module->new({ ... }) - || die My::Module->error(), "\n"; - - my $module = My::Module->new({ ... }) - || die "constructor error: $My::Module::ERROR\n"; - -=head2 error($msg, ...) - -May be called as an object method to get/set the internal _ERROR member -or as a class method to get/set the $ERROR variable in the derived class's -package. - - my $module = My::Module->new({ ... }) - || die My::Module->error(), "\n"; - - $module->do_something() - || die $module->error(), "\n"; - -When called with parameters (multiple params are concatenated), this -method will set the relevant variable and return undef. This is most -often used within object methods to report errors to the caller. - - package My::Module; - - sub foobar { - my $self = shift; - - # some other code... - - return $self->error('some kind of error...') - if $some_condition; - } - -=head2 debug($msg, ...) - -Generates a debugging message by concatenating all arguments -passed into a string and printing it to STDERR. A prefix is -added to indicate the module of the caller. - - package My::Module; - - sub foobar { - my $self = shift; - - $self->debug('called foobar()'); - - # some other code... - } - -When the foobar() method is called, the following message -is sent to STDERR: - - [My::Module] called foobar() - -Objects can set an internal DEBUG value which the debug() -method will examine. If this value sets the relevant bits -to indicate DEBUG_CALLER then the file and line number of -the caller will be appened to the message. - - use Template::Constants qw( :debug ); - - my $module = My::Module->new({ - DEBUG => DEBUG_SERVICE | DEBUG_CONTEXT | DEBUG_CALLER, - }); - - $module->foobar(); - -This generates an error message such as: - - [My::Module] called foobar() at My/Module.pm line 6 - -=head1 AUTHOR - -Andy Wardley Eabw@andywardley.comE - -L - - - - -=head1 VERSION - -2.69, distributed as part of the -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -=head1 SEE ALSO - -L - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Config.pm b/lib/Template/Config.pm deleted file mode 100644 index 9a3f378..0000000 --- a/lib/Template/Config.pm +++ /dev/null @@ -1,467 +0,0 @@ -#============================================================= -*-perl-*- -# -# Template::Config -# -# DESCRIPTION -# Template Toolkit configuration module. -# -# AUTHOR -# Andy Wardley -# -# COPYRIGHT -# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -#------------------------------------------------------------------------ -# -# $Id: Config.pm,v 2.67 2004/01/13 16:19:10 abw Exp $ -# -#======================================================================== - -package Template::Config; - -require 5.004; - -use strict; -use base qw( Template::Base ); -use vars qw( $VERSION $DEBUG $ERROR $INSTDIR - $PARSER $PROVIDER $PLUGINS $FILTERS $ITERATOR - $LATEX_PATH $PDFLATEX_PATH $DVIPS_PATH - $STASH $SERVICE $CONTEXT $CONSTANTS @PRELOAD ); - -$VERSION = sprintf("%d.%02d", q$Revision: 2.67 $ =~ /(\d+)\.(\d+)/); -$DEBUG = 0 unless defined $DEBUG; -$ERROR = ''; -$CONTEXT = 'Template::Context'; -$FILTERS = 'Template::Filters'; -$ITERATOR = 'Template::Iterator'; -$PARSER = 'Template::Parser'; -$PLUGINS = 'Template::Plugins'; -$PROVIDER = 'Template::Provider'; -$SERVICE = 'Template::Service'; -$STASH = 'Template::Stash'; -$CONSTANTS = 'Template::Namespace::Constants'; - -@PRELOAD = ( $CONTEXT, $FILTERS, $ITERATOR, $PARSER, - $PLUGINS, $PROVIDER, $SERVICE, $STASH ); - -# the following is set at installation time by the Makefile.PL -$INSTDIR = ''; - -# LaTeX executable paths set at installation time by the Makefile.PL -# Empty strings cause the latex(pdf|dvi|ps) filters to throw an error. -$LATEX_PATH = ''; -$PDFLATEX_PATH = ''; -$DVIPS_PATH = ''; - -#======================================================================== -# --- CLASS METHODS --- -#======================================================================== - -#------------------------------------------------------------------------ -# preload($module, $module, ...) -# -# Preloads all the standard TT modules that are likely to be used, along -# with any other passed as arguments. -#------------------------------------------------------------------------ - -sub preload { - my $class = shift; - - foreach my $module (@PRELOAD, @_) { - $class->load($module) || return; - }; - return 1; -} - - -#------------------------------------------------------------------------ -# load($module) -# -# Load a module via require(). Any occurences of '::' in the module name -# are be converted to '/' and '.pm' is appended. Returns 1 on success -# or undef on error. Use $class->error() to examine the error string. -#------------------------------------------------------------------------ - -sub load { - my ($class, $module) = @_; - $module =~ s[::][/]g; - $module .= '.pm'; -# print STDERR "loading $module\n" -# if $DEBUG; - eval { - require $module; - }; - return $@ ? $class->error("failed to load $module: $@") : 1; -} - - -#------------------------------------------------------------------------ -# parser(\%params) -# -# Instantiate a new parser object of the class whose name is denoted by -# the package variable $PARSER (default: Template::Parser). Returns -# a reference to a newly instantiated parser object or undef on error. -# The class error() method can be called without arguments to examine -# the error message generated by this failure. -#------------------------------------------------------------------------ - -sub parser { - my $class = shift; - my $params = defined($_[0]) && UNIVERSAL::isa($_[0], 'HASH') - ? shift : { @_ }; - - return undef unless $class->load($PARSER); - return $PARSER->new($params) - || $class->error("failed to create parser: ", $PARSER->error); -} - - -#------------------------------------------------------------------------ -# provider(\%params) -# -# Instantiate a new template provider object (default: Template::Provider). -# Returns an object reference or undef on error, as above. -#------------------------------------------------------------------------ - -sub provider { - my $class = shift; - my $params = defined($_[0]) && UNIVERSAL::isa($_[0], 'HASH') - ? shift : { @_ }; - - return undef unless $class->load($PROVIDER); - return $PROVIDER->new($params) - || $class->error("failed to create template provider: ", - $PROVIDER->error); -} - - -#------------------------------------------------------------------------ -# plugins(\%params) -# -# Instantiate a new plugins provider object (default: Template::Plugins). -# Returns an object reference or undef on error, as above. -#------------------------------------------------------------------------ - -sub plugins { - my $class = shift; - my $params = defined($_[0]) && UNIVERSAL::isa($_[0], 'HASH') - ? shift : { @_ }; - - return undef unless $class->load($PLUGINS); - return $PLUGINS->new($params) - || $class->error("failed to create plugin provider: ", - $PLUGINS->error); -} - - -#------------------------------------------------------------------------ -# filters(\%params) -# -# Instantiate a new filters provider object (default: Template::Filters). -# Returns an object reference or undef on error, as above. -#------------------------------------------------------------------------ - -sub filters { - my $class = shift; - my $params = defined($_[0]) && UNIVERSAL::isa($_[0], 'HASH') - ? shift : { @_ }; - - return undef unless $class->load($FILTERS); - return $FILTERS->new($params) - || $class->error("failed to create filter provider: ", - $FILTERS->error); -} - - -#------------------------------------------------------------------------ -# iterator(\@list) -# -# Instantiate a new Template::Iterator object (default: Template::Iterator). -# Returns an object reference or undef on error, as above. -#------------------------------------------------------------------------ - -sub iterator { - my $class = shift; - my $list = shift; - - return undef unless $class->load($ITERATOR); - return $ITERATOR->new($list, @_) - || $class->error("failed to create iterator: ", $ITERATOR->error); -} - - -#------------------------------------------------------------------------ -# stash(\%vars) -# -# Instantiate a new template variable stash object (default: -# Template::Stash). Returns object or undef, as above. -#------------------------------------------------------------------------ - -sub stash { - my $class = shift; - my $params = defined($_[0]) && UNIVERSAL::isa($_[0], 'HASH') - ? shift : { @_ }; - - return undef unless $class->load($STASH); - return $STASH->new($params) - || $class->error("failed to create stash: ", $STASH->error); -} - - -#------------------------------------------------------------------------ -# context(\%params) -# -# Instantiate a new template context object (default: Template::Context). -# Returns object or undef, as above. -#------------------------------------------------------------------------ - -sub context { - my $class = shift; - my $params = defined($_[0]) && UNIVERSAL::isa($_[0], 'HASH') - ? shift : { @_ }; - - return undef unless $class->load($CONTEXT); - return $CONTEXT->new($params) - || $class->error("failed to create context: ", $CONTEXT->error); -} - - -#------------------------------------------------------------------------ -# service(\%params) -# -# Instantiate a new template context object (default: Template::Service). -# Returns object or undef, as above. -#------------------------------------------------------------------------ - -sub service { - my $class = shift; - my $params = defined($_[0]) && UNIVERSAL::isa($_[0], 'HASH') - ? shift : { @_ }; - - return undef unless $class->load($SERVICE); - return $SERVICE->new($params) - || $class->error("failed to create context: ", $SERVICE->error); -} - - -#------------------------------------------------------------------------ -# constants(\%params) -# -# Instantiate a new namespace handler for compile time constant folding -# (default: Template::Namespace::Constants). -# Returns object or undef, as above. -#------------------------------------------------------------------------ - -sub constants { - my $class = shift; - my $params = defined($_[0]) && UNIVERSAL::isa($_[0], 'HASH') - ? shift : { @_ }; - - return undef unless $class->load($CONSTANTS); - return $CONSTANTS->new($params) - || $class->error("failed to create constants namespace: ", - $CONSTANTS->error); -} - - -#------------------------------------------------------------------------ -# instdir($dir) -# -# Returns the root installation directory appended with any local -# component directory passed as an argument. -#------------------------------------------------------------------------ - -sub instdir { - my ($class, $dir) = @_; - my $inst = $INSTDIR - || return $class->error("no installation directory"); - $inst =~ s[/$][]g; - $inst .= "/$dir" if $dir; - return $inst; -} - -#------------------------------------------------------------------------ -# latexpaths() -# -# Returns a reference to a three element array: -# [latex_path, pdf2latex_path, dvips_path] -# These values are determined by Makefile.PL at installation time -# and are used by the latex(pdf|dvi|ps) filters. -#------------------------------------------------------------------------ - -sub latexpaths { - return [$LATEX_PATH, $PDFLATEX_PATH, $DVIPS_PATH]; -} - -#======================================================================== -# This should probably be moved somewhere else in the long term, but for -# now it ensures that Template::TieString is available even if the -# Template::Directive module hasn't been loaded, as is the case when -# using compiled templates and Template::Parser hasn't yet been loaded -# on demand. -#======================================================================== - -#------------------------------------------------------------------------ -# simple package for tying $output variable to STDOUT, used by perl() -#------------------------------------------------------------------------ - -package Template::TieString; - -sub TIEHANDLE { - my ($class, $textref) = @_; - bless $textref, $class; -} -sub PRINT { - my $self = shift; - $$self .= join('', @_); -} - - - -1; - -__END__ - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Config - Factory module for instantiating other TT2 modules - -=head1 SYNOPSIS - - use Template::Config; - -=head1 DESCRIPTION - -This module implements various methods for loading and instantiating -other modules that comprise the Template Toolkit. It provides a consistent -way to create toolkit components and allows custom modules to be used in -place of the regular ones. - -Package variables such as $STASH, $SERVICE, $CONTEXT, etc., contain -the default module/package name for each component (Template::Stash, -Template::Service and Template::Context, respectively) and are used by -the various factory methods (stash(), service() and context()) to load -the appropriate module. Changing these package variables will cause -subsequent calls to the relevant factory method to load and instantiate -an object from the new class. - -=head1 PUBLIC METHODS - -=head2 load($module) - -Load a module via require(). Any occurences of '::' in the module name -are be converted to '/' and '.pm' is appended. Returns 1 on success -or undef on error. Use $class-Eerror() to examine the error string. - -=head2 preload() - -This method preloads all the other Template::* modules that are likely -to be used. It is called by the Template module when running under -mod_perl ($ENV{MOD_PERL} is set). - -=head2 parser(\%config) - -Instantiate a new parser object of the class whose name is denoted by -the package variable $PARSER (default: Template::Parser). Returns -a reference to a newly instantiated parser object or undef on error. - -=head2 provider(\%config) - -Instantiate a new template provider object (default: Template::Provider). -Returns an object reference or undef on error, as above. - -=head2 plugins(\%config) - -Instantiate a new plugins provider object (default: Template::Plugins). -Returns an object reference or undef on error, as above. - -=head2 filters(\%config) - -Instantiate a new filter provider object (default: Template::Filters). -Returns an object reference or undef on error, as above. - -=head2 stash(\%vars) - -Instantiate a new stash object (Template::Stash or Template::Stash::XS -depending on the default set at installation time) using the contents -of the optional hash array passed by parameter as initial variable -definitions. Returns an object reference or undef on error, as above. - -=head2 context(\%config) - -Instantiate a new template context object (default: Template::Context). -Returns an object reference or undef on error, as above. - -=head2 service(\%config) - -Instantiate a new template service object (default: Template::Service). -Returns an object reference or undef on error, as above. - -=head2 instdir($dir) - -Returns the root directory of the Template Toolkit installation under -which optional components are installed. Any relative directory specified -as an argument will be appended to the returned directory. - - # e.g. returns '/usr/local/tt2' - my $ttroot = Template::Config->instdir() - || die "$Template::Config::ERROR\n"; - - # e.g. returns '/usr/local/tt2/templates' - my $template = Template::Config->instdir('templates') - || die "$Template::Config::ERROR\n"; - -Returns undef and sets $Template::Config::ERROR appropriately if the -optional components of the Template Toolkit have not been installed. - -=head1 AUTHOR - -Andy Wardley Eabw@andywardley.comE - -L - - - - -=head1 VERSION - -2.67, distributed as part of the -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -=head1 SEE ALSO - -L - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Constants.pm b/lib/Template/Constants.pm deleted file mode 100644 index b227467..0000000 --- a/lib/Template/Constants.pm +++ /dev/null @@ -1,287 +0,0 @@ -#============================================================= -*-Perl-*- -# -# Template::Constants.pm -# -# DESCRIPTION -# Definition of constants for the Template Toolkit. -# -# AUTHOR -# Andy Wardley -# -# COPYRIGHT -# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -#---------------------------------------------------------------------------- -# -# $Id: Constants.pm,v 2.67 2004/01/13 16:19:10 abw Exp $ -# -#============================================================================ - -package Template::Constants; - -require 5.004; -require Exporter; - -use strict; -use vars qw( $VERSION @ISA @EXPORT_OK %EXPORT_TAGS ); -use vars qw( $DEBUG_OPTIONS @STATUS @ERROR @CHOMP @DEBUG); - -@ISA = qw( Exporter ); -$VERSION = sprintf("%d.%02d", q$Revision: 2.67 $ =~ /(\d+)\.(\d+)/); - - -#======================================================================== -# ----- EXPORTER ----- -#======================================================================== - -# STATUS constants returned by directives -use constant STATUS_OK => 0; # ok -use constant STATUS_RETURN => 1; # ok, block ended by RETURN -use constant STATUS_STOP => 2; # ok, stoppped by STOP -use constant STATUS_DONE => 3; # ok, iterator done -use constant STATUS_DECLINED => 4; # ok, declined to service request -use constant STATUS_ERROR => 255; # error condition - -# ERROR constants for indicating exception types -use constant ERROR_RETURN => 'return'; # return a status code -use constant ERROR_FILE => 'file'; # file error: I/O, parse, recursion -use constant ERROR_VIEW => 'view'; # view error -use constant ERROR_UNDEF => 'undef'; # undefined variable value used -use constant ERROR_PERL => 'perl'; # error in [% PERL %] block -use constant ERROR_FILTER => 'filter'; # filter error -use constant ERROR_PLUGIN => 'plugin'; # plugin error - -# CHOMP constants for PRE_CHOMP and POST_CHOMP -use constant CHOMP_NONE => 0; # do not remove whitespace -use constant CHOMP_ALL => 1; # remove whitespace -use constant CHOMP_COLLAPSE => 2; # collapse whitespace to a single space - -# DEBUG constants to enable various debugging options -use constant DEBUG_OFF => 0; # do nothing -use constant DEBUG_ON => 1; # basic debugging flag -use constant DEBUG_UNDEF => 2; # throw undef on undefined variables -use constant DEBUG_VARS => 4; # general variable debugging -use constant DEBUG_DIRS => 8; # directive debugging -use constant DEBUG_STASH => 16; # general stash debugging -use constant DEBUG_CONTEXT => 32; # context debugging -use constant DEBUG_PARSER => 64; # parser debugging -use constant DEBUG_PROVIDER => 128; # provider debugging -use constant DEBUG_PLUGINS => 256; # plugins debugging -use constant DEBUG_FILTERS => 512; # filters debugging -use constant DEBUG_SERVICE => 1024; # context debugging -use constant DEBUG_ALL => 2047; # everything - -# extra debugging flags -use constant DEBUG_CALLER => 4096; # add caller file/line -use constant DEBUG_FLAGS => 4096; # bitmask to extraxt flags - -$DEBUG_OPTIONS = { - &DEBUG_OFF => off => off => &DEBUG_OFF, - &DEBUG_ON => on => on => &DEBUG_ON, - &DEBUG_UNDEF => undef => undef => &DEBUG_UNDEF, - &DEBUG_VARS => vars => vars => &DEBUG_VARS, - &DEBUG_DIRS => dirs => dirs => &DEBUG_DIRS, - &DEBUG_STASH => stash => stash => &DEBUG_STASH, - &DEBUG_CONTEXT => context => context => &DEBUG_CONTEXT, - &DEBUG_PARSER => parser => parser => &DEBUG_PARSER, - &DEBUG_PROVIDER => provider => provider => &DEBUG_PROVIDER, - &DEBUG_PLUGINS => plugins => plugins => &DEBUG_PLUGINS, - &DEBUG_FILTERS => filters => filters => &DEBUG_FILTERS, - &DEBUG_SERVICE => service => service => &DEBUG_SERVICE, - &DEBUG_ALL => all => all => &DEBUG_ALL, - &DEBUG_CALLER => caller => caller => &DEBUG_CALLER, -}; - -@STATUS = qw( STATUS_OK STATUS_RETURN STATUS_STOP STATUS_DONE - STATUS_DECLINED STATUS_ERROR ); -@ERROR = qw( ERROR_FILE ERROR_VIEW ERROR_UNDEF ERROR_PERL - ERROR_RETURN ERROR_FILTER ERROR_PLUGIN ); -@CHOMP = qw( CHOMP_NONE CHOMP_ALL CHOMP_COLLAPSE ); -@DEBUG = qw( DEBUG_OFF DEBUG_ON DEBUG_UNDEF DEBUG_VARS - DEBUG_DIRS DEBUG_STASH DEBUG_CONTEXT DEBUG_PARSER - DEBUG_PROVIDER DEBUG_PLUGINS DEBUG_FILTERS DEBUG_SERVICE - DEBUG_ALL DEBUG_CALLER DEBUG_FLAGS ); - -@EXPORT_OK = ( @STATUS, @ERROR, @CHOMP, @DEBUG ); -%EXPORT_TAGS = ( - 'all' => [ @EXPORT_OK ], - 'status' => [ @STATUS ], - 'error' => [ @ERROR ], - 'chomp' => [ @CHOMP ], - 'debug' => [ @DEBUG ], -); - - -sub debug_flags { - my ($self, $debug) = @_; - my (@flags, $flag, $value); - $debug = $self unless defined($debug) || ref($self); - - if ($debug =~ /^\d+$/) { - foreach $flag (@DEBUG) { - next if $flag =~ /^DEBUG_(OFF|ALL|FLAGS)$/; - - # don't trash the original - my $copy = $flag; - $flag =~ s/^DEBUG_//; - $flag = lc $flag; - return $self->error("no value for flag: $flag") - unless defined($value = $DEBUG_OPTIONS->{ $flag }); - $flag = $value; - - if ($debug & $flag) { - $value = $DEBUG_OPTIONS->{ $flag }; - return $self->error("no value for flag: $flag") unless defined $value; - push(@flags, $value); - } - } - return wantarray ? @flags : join(', ', @flags); - } - else { - @flags = split(/\W+/, $debug); - $debug = 0; - foreach $flag (@flags) { - $value = $DEBUG_OPTIONS->{ $flag }; - return $self->error("unknown debug flag: $flag") unless defined $value; - $debug |= $value; - } - return $debug; - } -} - - -1; - -__END__ - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Constants - Defines constants for the Template Toolkit - -=head1 SYNOPSIS - - use Template::Constants qw( :status :error :all ); - -=head1 DESCRIPTION - -The Template::Constants modules defines, and optionally exports into the -caller's namespace, a number of constants used by the Template package. - -Constants may be used by specifying the Template::Constants package -explicitly: - - use Template::Constants; - - print Template::Constants::STATUS_DECLINED; - -Constants may be imported into the caller's namespace by naming them as -options to the C statement: - - use Template::Constants qw( STATUS_DECLINED ); - - print STATUS_DECLINED; - -Alternatively, one of the following tagset identifiers may be specified -to import sets of constants; :status, :error, :all. - - use Template::Constants qw( :status ); - - print STATUS_DECLINED; - -See L for more information on exporting variables. - -=head1 EXPORTABLE TAG SETS - -The following tag sets and associated constants are defined: - - :status - STATUS_OK # no problem, continue - STATUS_RETURN # ended current block then continue (ok) - STATUS_STOP # controlled stop (ok) - STATUS_DONE # iterator is all done (ok) - STATUS_DECLINED # provider declined to service request (ok) - STATUS_ERROR # general error condition (not ok) - - :error - ERROR_RETURN # return a status code (e.g. 'stop') - ERROR_FILE # file error: I/O, parse, recursion - ERROR_UNDEF # undefined variable value used - ERROR_PERL # error in [% PERL %] block - ERROR_FILTER # filter error - ERROR_PLUGIN # plugin error - - :chomp # for PRE_CHOMP and POST_CHOMP - CHOMP_NONE # do not remove whitespace - CHOMP_ALL # remove whitespace - CHOMP_COLLAPSE # collapse whitespace to a single space - - :debug - DEBUG_OFF # do nothing - DEBUG_ON # basic debugging flag - DEBUG_UNDEF # throw undef on undefined variables - DEBUG_VARS # general variable debugging - DEBUG_DIRS # directive debugging - DEBUG_STASH # general stash debugging - DEBUG_CONTEXT # context debugging - DEBUG_PARSER # parser debugging - DEBUG_PROVIDER # provider debugging - DEBUG_PLUGINS # plugins debugging - DEBUG_FILTERS # filters debugging - DEBUG_SERVICE # context debugging - DEBUG_ALL # everything - DEBUG_CALLER # add caller file/line info - DEBUG_FLAGS # bitmap used internally - - :all All the above constants. - -=head1 AUTHOR - -Andy Wardley Eabw@andywardley.comE - -L - - - - -=head1 VERSION - -2.67, distributed as part of the -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -=head1 SEE ALSO - -L, L - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Context.pm b/lib/Template/Context.pm deleted file mode 100644 index cdc699e..0000000 --- a/lib/Template/Context.pm +++ /dev/null @@ -1,1570 +0,0 @@ -#============================================================= -*-Perl-*- -# -# Template::Context -# -# DESCRIPTION -# Module defining a context in which a template document is processed. -# This is the runtime processing interface through which templates -# can access the functionality of the Template Toolkit. -# -# AUTHOR -# Andy Wardley -# -# COPYRIGHT -# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -# REVISION -# $Id: Context.pm,v 2.89 2004/01/30 18:37:47 abw Exp $ -# -#============================================================================ - -package Template::Context; - -require 5.004; - -use strict; -use vars qw( $VERSION $DEBUG $AUTOLOAD $DEBUG_FORMAT ); -use base qw( Template::Base ); - -use Template::Base; -use Template::Config; -use Template::Constants; -use Template::Exception; - -$VERSION = sprintf("%d.%02d", q$Revision: 2.89 $ =~ /(\d+)\.(\d+)/); -$DEBUG_FORMAT = "\n## \$file line \$line : [% \$text %] ##\n"; - - -#======================================================================== -# ----- PUBLIC METHODS ----- -#======================================================================== - -#------------------------------------------------------------------------ -# template($name) -# -# General purpose method to fetch a template and return it in compiled -# form. In the usual case, the $name parameter will be a simple string -# containing the name of a template (e.g. 'header'). It may also be -# a reference to Template::Document object (or sub-class) or a Perl -# sub-routine. These are considered to be compiled templates and are -# returned intact. Finally, it may be a reference to any other kind -# of valid input source accepted by Template::Provider (e.g. scalar -# ref, glob, IO handle, etc). -# -# Templates may be cached at one of 3 different levels. The internal -# BLOCKS member is a local cache which holds references to all -# template blocks used or imported via PROCESS since the context's -# reset() method was last called. This is checked first and if the -# template is not found, the method then walks down the BLOCKSTACK -# list. This contains references to the block definition tables in -# any enclosing Template::Documents that we're visiting (e.g. we've -# been called via an INCLUDE and we want to access a BLOCK defined in -# the template that INCLUDE'd us). If nothing is defined, then we -# iterate through the LOAD_TEMPLATES providers list as a 'chain of -# responsibility' (see Design Patterns) asking each object to fetch() -# the template if it can. -# -# Returns the compiled template. On error, undef is returned and -# the internal ERROR value (read via error()) is set to contain an -# error message of the form "$name: $error". -#------------------------------------------------------------------------ - -sub template { - my ($self, $name) = @_; - my ($prefix, $blocks, $defblocks, $provider, $template, $error); - my ($shortname, $blockname, $providers); - - $self->debug("template($name)") if $self->{ DEBUG }; - - # references to Template::Document (or sub-class) objects objects, or - # CODE references are assumed to be pre-compiled templates and are - # returned intact - return $name - if UNIVERSAL::isa($name, 'Template::Document') - || ref($name) eq 'CODE'; - - $shortname = $name; - - unless (ref $name) { - - $self->debug("looking for block [$name]") if $self->{ DEBUG }; - - # we first look in the BLOCKS hash for a BLOCK that may have - # been imported from a template (via PROCESS) - return $template - if ($template = $self->{ BLOCKS }->{ $name }); - - # then we iterate through the BLKSTACK list to see if any of the - # Template::Documents we're visiting define this BLOCK - foreach $blocks (@{ $self->{ BLKSTACK } }) { - return $template - if $blocks && ($template = $blocks->{ $name }); - } - - # now it's time to ask the providers, so we look to see if any - # prefix is specified to indicate the desired provider set. - if ($^O eq 'MSWin32') { - # let C:/foo through - $prefix = $1 if $shortname =~ s/^(\w{2,})://o; - } - else { - $prefix = $1 if $shortname =~ s/^(\w+)://; - } - - if (defined $prefix) { - $providers = $self->{ PREFIX_MAP }->{ $prefix } - || return $self->throw( Template::Constants::ERROR_FILE, - "no providers for template prefix '$prefix'"); - } - } - $providers = $self->{ PREFIX_MAP }->{ default } - || $self->{ LOAD_TEMPLATES } - unless $providers; - - - # Finally we try the regular template providers which will - # handle references to files, text, etc., as well as templates - # reference by name. If - - $blockname = ''; - while ($shortname) { - $self->debug("asking providers for [$shortname] [$blockname]") - if $self->{ DEBUG }; - - foreach my $provider (@$providers) { - ($template, $error) = $provider->fetch($shortname, $prefix); - if ($error) { - if ($error == Template::Constants::STATUS_ERROR) { - # $template contains exception object - if (UNIVERSAL::isa($template, 'Template::Exception') - && $template->type() eq Template::Constants::ERROR_FILE) { - $self->throw($template); - } - else { - $self->throw( Template::Constants::ERROR_FILE, $template ); - } - } - # DECLINE is ok, carry on - } - elsif (length $blockname) { - return $template - if $template = $template->blocks->{ $blockname }; - } - else { - return $template; - } - } - - last if ref $shortname || ! $self->{ EXPOSE_BLOCKS }; - $shortname =~ s{/([^/]+)$}{} || last; - $blockname = length $blockname ? "$1/$blockname" : $1; - } - - $self->throw(Template::Constants::ERROR_FILE, "$name: not found"); -} - - -#------------------------------------------------------------------------ -# plugin($name, \@args) -# -# Calls on each of the LOAD_PLUGINS providers in turn to fetch() (i.e. load -# and instantiate) a plugin of the specified name. Additional parameters -# passed are propagated to the new() constructor for the plugin. -# Returns a reference to a new plugin object or other reference. On -# error, undef is returned and the appropriate error message is set for -# subsequent retrieval via error(). -#------------------------------------------------------------------------ - -sub plugin { - my ($self, $name, $args) = @_; - my ($provider, $plugin, $error); - - $self->debug("plugin($name, ", defined $args ? @$args : '[ ]', ')') - if $self->{ DEBUG }; - - # request the named plugin from each of the LOAD_PLUGINS providers in turn - foreach my $provider (@{ $self->{ LOAD_PLUGINS } }) { - ($plugin, $error) = $provider->fetch($name, $args, $self); - return $plugin unless $error; - if ($error == Template::Constants::STATUS_ERROR) { - $self->throw($plugin) if ref $plugin; - $self->throw(Template::Constants::ERROR_PLUGIN, $plugin); - } - } - - $self->throw(Template::Constants::ERROR_PLUGIN, "$name: plugin not found"); -} - - -#------------------------------------------------------------------------ -# filter($name, \@args, $alias) -# -# Similar to plugin() above, but querying the LOAD_FILTERS providers to -# return filter instances. An alias may be provided which is used to -# save the returned filter in a local cache. -#------------------------------------------------------------------------ - -sub filter { - my ($self, $name, $args, $alias) = @_; - my ($provider, $filter, $error); - - $self->debug("filter($name, ", - defined $args ? @$args : '[ ]', - defined $alias ? $alias : '', ')') - if $self->{ DEBUG }; - - # use any cached version of the filter if no params provided - return $filter - if ! $args && ! ref $name - && ($filter = $self->{ FILTER_CACHE }->{ $name }); - - # request the named filter from each of the FILTERS providers in turn - foreach my $provider (@{ $self->{ LOAD_FILTERS } }) { - ($filter, $error) = $provider->fetch($name, $args, $self); - last unless $error; - if ($error == Template::Constants::STATUS_ERROR) { - $self->throw($filter) if ref $filter; - $self->throw(Template::Constants::ERROR_FILTER, $filter); - } - # return $self->error($filter) - # if $error == &Template::Constants::STATUS_ERROR; - } - - return $self->error("$name: filter not found") - unless $filter; - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # commented out by abw on 19 Nov 2001 to fix problem with xmlstyle - # plugin which may re-define a filter by calling define_filter() - # multiple times. With the automatic aliasing/caching below, any - # new filter definition isn't seen. Don't think this will cause - # any problems as filters explicitly supplied with aliases will - # still work as expected. - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # alias defaults to name if undefined - # $alias = $name - # unless defined($alias) or ref($name) or $args; - - # cache FILTER if alias is valid - $self->{ FILTER_CACHE }->{ $alias } = $filter - if $alias; - - return $filter; -} - - -#------------------------------------------------------------------------ -# view(\%config) -# -# Create a new Template::View bound to this context. -#------------------------------------------------------------------------ - -sub view { - my $self = shift; - require Template::View; - return Template::View->new($self, @_) - || $self->throw(&Template::Constants::ERROR_VIEW, - $Template::View::ERROR); -} - - -#------------------------------------------------------------------------ -# process($template, \%params) [% PROCESS template var=val ... %] -# process($template, \%params, $local) [% INCLUDE template var=val ... %] -# -# Processes the template named or referenced by the first parameter. -# The optional second parameter may reference a hash array of variable -# definitions. These are set before the template is processed by -# calling update() on the stash. Note that, unless the third parameter -# is true, the context is not localised and these, and any other -# variables set in the template will retain their new values after this -# method returns. The third parameter is in place so that this method -# can handle INCLUDE calls: the stash will be localized. -# -# Returns the output of processing the template. Errors are thrown -# as Template::Exception objects via die(). -#------------------------------------------------------------------------ - -sub process { - my ($self, $template, $params, $localize) = @_; - my ($trim, $blocks) = @$self{ qw( TRIM BLOCKS ) }; - my (@compiled, $name, $compiled); - my ($stash, $component, $tblocks, $error, $tmpout); - my $output = ''; - - $template = [ $template ] unless ref $template eq 'ARRAY'; - - $self->debug("process([ ", join(', '), @$template, ' ], ', - defined $params ? $params : '', ', ', - $localize ? '' : '', ')') - if $self->{ DEBUG }; - - # fetch compiled template for each name specified - foreach $name (@$template) { - push(@compiled, $self->template($name)); - } - - if ($localize) { - # localise the variable stash with any parameters passed - $stash = $self->{ STASH } = $self->{ STASH }->clone($params); - } else { - # update stash with any new parameters passed - $self->{ STASH }->update($params); - $stash = $self->{ STASH }; - } - - eval { - # save current component - eval { $component = $stash->get('component') }; - - foreach $name (@$template) { - $compiled = shift @compiled; - my $element = ref $compiled eq 'CODE' - ? { (name => (ref $name ? '' : $name), modtime => time()) } - : $compiled; - - if (UNIVERSAL::isa($component, 'Template::Document')) { - $element->{ caller } = $component->{ name }; - $element->{ callers } = $component->{ callers } || []; - push(@{$element->{ callers }}, $element->{ caller }); - } - - $stash->set('component', $element); - - unless ($localize) { - # merge any local blocks defined in the Template::Document - # into our local BLOCKS cache - @$blocks{ keys %$tblocks } = values %$tblocks - if UNIVERSAL::isa($compiled, 'Template::Document') - && ($tblocks = $compiled->blocks()); - } - - if (ref $compiled eq 'CODE') { - $tmpout = &$compiled($self); - } - elsif (ref $compiled) { - $tmpout = $compiled->process($self); - } - else { - $self->throw('file', - "invalid template reference: $compiled"); - } - - if ($trim) { - for ($tmpout) { - s/^\s+//; - s/\s+$//; - } - } - $output .= $tmpout; - } - $stash->set('component', $component); - }; - $error = $@; - - if ($localize) { - # ensure stash is delocalised before dying - $self->{ STASH } = $self->{ STASH }->declone(); - } - - $self->throw(ref $error - ? $error : (Template::Constants::ERROR_FILE, $error)) - if $error; - - return $output; -} - - -#------------------------------------------------------------------------ -# include($template, \%params) [% INCLUDE template var = val, ... %] -# -# Similar to process() above but processing the template in a local -# context. Any variables passed by reference to a hash as the second -# parameter will be set before the template is processed and then -# revert to their original values before the method returns. Similarly, -# any changes made to non-global variables within the template will -# persist only until the template is processed. -# -# Returns the output of processing the template. Errors are thrown -# as Template::Exception objects via die(). -#------------------------------------------------------------------------ - -sub include { - my ($self, $template, $params) = @_; - return $self->process($template, $params, 'localize me!'); -} - -#------------------------------------------------------------------------ -# insert($file) -# -# Insert the contents of a file without parsing. -#------------------------------------------------------------------------ - -sub insert { - my ($self, $file) = @_; - my ($prefix, $providers, $text, $error); - my $output = ''; - - my $files = ref $file eq 'ARRAY' ? $file : [ $file ]; - - $self->debug("insert([ ", join(', '), @$files, " ])") - if $self->{ DEBUG }; - - - FILE: foreach $file (@$files) { - my $name = $file; - - if ($^O eq 'MSWin32') { - # let C:/foo through - $prefix = $1 if $name =~ s/^(\w{2,})://o; - } - else { - $prefix = $1 if $name =~ s/^(\w+)://; - } - - if (defined $prefix) { - $providers = $self->{ PREFIX_MAP }->{ $prefix } - || return $self->throw(Template::Constants::ERROR_FILE, - "no providers for file prefix '$prefix'"); - } - else { - $providers = $self->{ PREFIX_MAP }->{ default } - || $self->{ LOAD_TEMPLATES }; - } - - foreach my $provider (@$providers) { - ($text, $error) = $provider->load($name, $prefix); - next FILE unless $error; - if ($error == Template::Constants::STATUS_ERROR) { - $self->throw($text) if ref $text; - $self->throw(Template::Constants::ERROR_FILE, $text); - } - } - $self->throw(Template::Constants::ERROR_FILE, "$file: not found"); - } - continue { - $output .= $text; - } - return $output; -} - - -#------------------------------------------------------------------------ -# throw($type, $info, \$output) [% THROW errtype "Error info" %] -# -# Throws a Template::Exception object by calling die(). This method -# may be passed a reference to an existing Template::Exception object; -# a single value containing an error message which is used to -# instantiate a Template::Exception of type 'undef'; or a pair of -# values representing the exception type and info from which a -# Template::Exception object is instantiated. e.g. -# -# $context->throw($exception); -# $context->throw("I'm sorry Dave, I can't do that"); -# $context->throw('denied', "I'm sorry Dave, I can't do that"); -# -# An optional third parameter can be supplied in the last case which -# is a reference to the current output buffer containing the results -# of processing the template up to the point at which the exception -# was thrown. The RETURN and STOP directives, for example, use this -# to propagate output back to the user, but it can safely be ignored -# in most cases. -# -# This method rides on a one-way ticket to die() oblivion. It does not -# return in any real sense of the word, but should get caught by a -# surrounding eval { } block (e.g. a BLOCK or TRY) and handled -# accordingly, or returned to the caller as an uncaught exception. -#------------------------------------------------------------------------ - -sub throw { - my ($self, $error, $info, $output) = @_; - local $" = ', '; - - # die! die! die! - if (UNIVERSAL::isa($error, 'Template::Exception')) { - die $error; - } - elsif (defined $info) { - die (Template::Exception->new($error, $info, $output)); - } - else { - $error ||= ''; - die (Template::Exception->new('undef', $error, $output)); - } - - # not reached -} - - -#------------------------------------------------------------------------ -# catch($error, \$output) -# -# Called by various directives after catching an error thrown via die() -# from within an eval { } block. The first parameter contains the errror -# which may be a sanitized reference to a Template::Exception object -# (such as that raised by the throw() method above, a plugin object, -# and so on) or an error message thrown via die from somewhere in user -# code. The latter are coerced into 'undef' Template::Exception objects. -# Like throw() above, a reference to a scalar may be passed as an -# additional parameter to represent the current output buffer -# localised within the eval block. As exceptions are thrown upwards -# and outwards from nested blocks, the catch() method reconstructs the -# correct output buffer from these fragments, storing it in the -# exception object for passing further onwards and upwards. -# -# Returns a reference to a Template::Exception object.. -#------------------------------------------------------------------------ - -sub catch { - my ($self, $error, $output) = @_; - - if (UNIVERSAL::isa($error, 'Template::Exception')) { - $error->text($output) if $output; - return $error; - } - else { - return Template::Exception->new('undef', $error, $output); - } -} - - -#------------------------------------------------------------------------ -# localise(\%params) -# delocalise() -# -# The localise() method creates a local copy of the current stash, -# allowing the existing state of variables to be saved and later -# restored via delocalise(). -# -# A reference to a hash array may be passed containing local variable -# definitions which should be added to the cloned namespace. These -# values persist until delocalisation. -#------------------------------------------------------------------------ - -sub localise { - my $self = shift; - $self->{ STASH } = $self->{ STASH }->clone(@_); -} - -sub delocalise { - my $self = shift; - $self->{ STASH } = $self->{ STASH }->declone(); -} - - -#------------------------------------------------------------------------ -# visit($document, $blocks) -# -# Each Template::Document calls the visit() method on the context -# before processing itself. It passes a reference to the hash array -# of named BLOCKs defined within the document, allowing them to be -# added to the internal BLKSTACK list which is subsequently used by -# template() to resolve templates. -# from a provider. -#------------------------------------------------------------------------ - -sub visit { - my ($self, $document, $blocks) = @_; - unshift(@{ $self->{ BLKSTACK } }, $blocks) -} - - -#------------------------------------------------------------------------ -# leave() -# -# The leave() method is called when the document has finished -# processing itself. This removes the entry from the BLKSTACK list -# that was added visit() above. For persistance of BLOCK definitions, -# the process() method (i.e. the PROCESS directive) does some extra -# magic to copy BLOCKs into a shared hash. -#------------------------------------------------------------------------ - -sub leave { - my $self = shift; - shift(@{ $self->{ BLKSTACK } }); -} - - -#------------------------------------------------------------------------ -# define_block($name, $block) -# -# Adds a new BLOCK definition to the local BLOCKS cache. $block may -# be specified as a reference to a sub-routine or Template::Document -# object or as text which is compiled into a template. Returns a true -# value (the $block reference or compiled block reference) if -# succesful or undef on failure. Call error() to retrieve the -# relevent error message (i.e. compilation failure). -#------------------------------------------------------------------------ - -sub define_block { - my ($self, $name, $block) = @_; - $block = $self->template(\$block) - || return undef - unless ref $block; - $self->{ BLOCKS }->{ $name } = $block; -} - - -#------------------------------------------------------------------------ -# define_filter($name, $filter, $is_dynamic) -# -# Adds a new FILTER definition to the local FILTER_CACHE. -#------------------------------------------------------------------------ - -sub define_filter { - my ($self, $name, $filter, $is_dynamic) = @_; - my ($result, $error); - $filter = [ $filter, 1 ] if $is_dynamic; - - foreach my $provider (@{ $self->{ LOAD_FILTERS } }) { - ($result, $error) = $provider->store($name, $filter); - return 1 unless $error; - $self->throw(&Template::Constants::ERROR_FILTER, $result) - if $error == &Template::Constants::STATUS_ERROR; - } - $self->throw(&Template::Constants::ERROR_FILTER, - "FILTER providers declined to store filter $name"); -} - - -#------------------------------------------------------------------------ -# reset() -# -# Reset the state of the internal BLOCKS hash to clear any BLOCK -# definitions imported via the PROCESS directive. Any original -# BLOCKS definitions passed to the constructor will be restored. -#------------------------------------------------------------------------ - -sub reset { - my ($self, $blocks) = @_; - $self->{ BLKSTACK } = [ ]; - $self->{ BLOCKS } = { %{ $self->{ INIT_BLOCKS } } }; -} - - -#------------------------------------------------------------------------ -# stash() -# -# Simple accessor methods to return the STASH values. This is likely -# to be called quite often so we provide a direct method rather than -# relying on the slower AUTOLOAD. -#------------------------------------------------------------------------ - -sub stash { - return $_[0]->{ STASH }; -} - - -#------------------------------------------------------------------------ -# define_vmethod($type, $name, \&sub) -# -# Passes $type, $name, and &sub on to stash->define_vmethod(). -#------------------------------------------------------------------------ -sub define_vmethod { - my $self = shift; - $self->stash->define_vmethod(@_); -} - - -#------------------------------------------------------------------------ -# debugging($command, @args, \%params) -# -# Method for controlling the debugging status of the context. The first -# argument can be 'on' or 'off' to enable/disable debugging, 'format' -# to define the format of the debug message, or 'msg' to generate a -# debugging message reporting the file, line, message text, etc., -# according to the current debug format. -#------------------------------------------------------------------------ - -sub debugging { - my $self = shift; - my $hash = ref $_[-1] eq 'HASH' ? pop : { }; - my @args = @_; - -# print "*** debug(@args)\n"; - if (@args) { - if ($args[0] =~ /^on|1$/i) { - $self->{ DEBUG_DIRS } = 1; - shift(@args); - } - elsif ($args[0] =~ /^off|0$/i) { - $self->{ DEBUG_DIRS } = 0; - shift(@args); - } - } - - if (@args) { - if ($args[0] =~ /^msg$/i) { - return unless $self->{ DEBUG_DIRS }; - my $format = $self->{ DEBUG_FORMAT }; - $format = $DEBUG_FORMAT unless defined $format; - $format =~ s/\$(\w+)/$hash->{ $1 }/ge; - return $format; - } - elsif ($args[0] =~ /^format$/i) { - $self->{ DEBUG_FORMAT } = $args[1]; - } - # else ignore - } - - return ''; -} - - -#------------------------------------------------------------------------ -# AUTOLOAD -# -# Provides pseudo-methods for read-only access to various internal -# members. For example, templates(), plugins(), filters(), -# eval_perl(), load_perl(), etc. These aren't called very often, or -# may never be called at all. -#------------------------------------------------------------------------ - -sub AUTOLOAD { - my $self = shift; - my $method = $AUTOLOAD; - my $result; - - $method =~ s/.*:://; - return if $method eq 'DESTROY'; - - warn "no such context method/member: $method\n" - unless defined ($result = $self->{ uc $method }); - - return $result; -} - - -#------------------------------------------------------------------------ -# DESTROY -# -# Stash may contain references back to the Context via macro closures, -# etc. This breaks the circular references. -#------------------------------------------------------------------------ - -sub DESTROY { - my $self = shift; - undef $self->{ STASH }; -} - - - -#======================================================================== -# -- PRIVATE METHODS -- -#======================================================================== - -#------------------------------------------------------------------------ -# _init(\%config) -# -# Initialisation method called by Template::Base::new() -#------------------------------------------------------------------------ - -sub _init { - my ($self, $config) = @_; - my ($name, $item, $method, $block, $blocks); - my @itemlut = ( - LOAD_TEMPLATES => 'provider', - LOAD_PLUGINS => 'plugins', - LOAD_FILTERS => 'filters' - ); - - # LOAD_TEMPLATE, LOAD_PLUGINS, LOAD_FILTERS - lists of providers - while (($name, $method) = splice(@itemlut, 0, 2)) { - $item = $config->{ $name } - || Template::Config->$method($config) - || return $self->error($Template::Config::ERROR); - $self->{ $name } = ref $item eq 'ARRAY' ? $item : [ $item ]; - } - - my $providers = $self->{ LOAD_TEMPLATES }; - my $prefix_map = $self->{ PREFIX_MAP } = $config->{ PREFIX_MAP } || { }; - while (my ($key, $val) = each %$prefix_map) { - $prefix_map->{ $key } = [ ref $val ? $val : - map { $providers->[$_] } - split(/\D+/, $val) ] - unless ref $val eq 'ARRAY'; -# print(STDERR "prefix $key => $val => [", -# join(', ', @{ $prefix_map->{ $key } }), "]\n"); - } - - # STASH - $self->{ STASH } = $config->{ STASH } || do { - my $predefs = $config->{ VARIABLES } - || $config->{ PRE_DEFINE } - || { }; - - # hack to get stash to know about debug mode - $predefs->{ _DEBUG } = ( ($config->{ DEBUG } || 0) - & &Template::Constants::DEBUG_UNDEF ) ? 1 : 0 - unless defined $predefs->{ _DEBUG }; - - Template::Config->stash($predefs) - || return $self->error($Template::Config::ERROR); - }; - - # compile any template BLOCKS specified as text - $blocks = $config->{ BLOCKS } || { }; - $self->{ INIT_BLOCKS } = $self->{ BLOCKS } = { - map { - $block = $blocks->{ $_ }; - $block = $self->template(\$block) - || return undef - unless ref $block; - ($_ => $block); - } - keys %$blocks - }; - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # RECURSION - flag indicating is recursion into templates is supported - # EVAL_PERL - flag indicating if PERL blocks should be processed - # TRIM - flag to remove leading and trailing whitespace from output - # BLKSTACK - list of hashes of BLOCKs defined in current template(s) - # CONFIG - original configuration hash - # EXPOSE_BLOCKS - make blocks visible as pseudo-files - # DEBUG_FORMAT - format for generating template runtime debugging messages - # DEBUG - format for generating template runtime debugging messages - - $self->{ RECURSION } = $config->{ RECURSION } || 0; - $self->{ EVAL_PERL } = $config->{ EVAL_PERL } || 0; - $self->{ TRIM } = $config->{ TRIM } || 0; - $self->{ BLKSTACK } = [ ]; - $self->{ CONFIG } = $config; - $self->{ EXPOSE_BLOCKS } = defined $config->{ EXPOSE_BLOCKS } - ? $config->{ EXPOSE_BLOCKS } - : 0; - - $self->{ DEBUG_FORMAT } = $config->{ DEBUG_FORMAT }; - $self->{ DEBUG_DIRS } = ($config->{ DEBUG } || 0) - & Template::Constants::DEBUG_DIRS; - $self->{ DEBUG } = defined $config->{ DEBUG } - ? $config->{ DEBUG } & ( Template::Constants::DEBUG_CONTEXT - | Template::Constants::DEBUG_FLAGS ) - : $DEBUG; - - return $self; -} - - -#------------------------------------------------------------------------ -# _dump() -# -# Debug method which returns a string representing the internal state -# of the context object. -#------------------------------------------------------------------------ - -sub _dump { - my $self = shift; - my $output = "[Template::Context] {\n"; - my $format = " %-16s => %s\n"; - my $key; - - foreach $key (qw( RECURSION EVAL_PERL TRIM )) { - $output .= sprintf($format, $key, $self->{ $key }); - } - foreach my $pname (qw( LOAD_TEMPLATES LOAD_PLUGINS LOAD_FILTERS )) { - my $provtext = "[\n"; - foreach my $prov (@{ $self->{ $pname } }) { - $provtext .= $prov->_dump(); -# $provtext .= ",\n"; - } - $provtext =~ s/\n/\n /g; - $provtext =~ s/\s+$//; - $provtext .= ",\n ]"; - $output .= sprintf($format, $pname, $provtext); - } - $output .= sprintf($format, STASH => $self->{ STASH }->_dump()); - $output .= '}'; - return $output; -} - - -1; - -__END__ - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Context - Runtime context in which templates are processed - -=head1 SYNOPSIS - - use Template::Context; - - # constructor - $context = Template::Context->new(\%config) - || die $Template::Context::ERROR; - - # fetch (load and compile) a template - $template = $context->template($template_name); - - # fetch (load and instantiate) a plugin object - $plugin = $context->plugin($name, \@args); - - # fetch (return or create) a filter subroutine - $filter = $context->filter($name, \@args, $alias); - - # process/include a template, errors are thrown via die() - $output = $context->process($template, \%vars); - $output = $context->include($template, \%vars); - - # raise an exception via die() - $context->throw($error_type, $error_message, \$output_buffer); - - # catch an exception, clean it up and fix output buffer - $exception = $context->catch($exception, \$output_buffer); - - # save/restore the stash to effect variable localisation - $new_stash = $context->localise(\%vars); - $old_stash = $context->delocalise(); - - # add new BLOCK or FILTER definitions - $context->define_block($name, $block); - $context->define_filter($name, \&filtersub, $is_dynamic); - - # reset context, clearing any imported BLOCK definitions - $context->reset(); - - # methods for accessing internal items - $stash = $context->stash(); - $tflag = $context->trim(); - $epflag = $context->eval_perl(); - $providers = $context->templates(); - $providers = $context->plugins(); - $providers = $context->filters(); - ... - -=head1 DESCRIPTION - -The Template::Context module defines an object class for representing -a runtime context in which templates are processed. It provides an -interface to the fundamental operations of the Template Toolkit -processing engine through which compiled templates (i.e. Perl code -constructed from the template source) can process templates, load -plugins and filters, raise exceptions and so on. - -A default Template::Context object is created by the Template module. -Any Template::Context options may be passed to the Template new() -constructor method and will be forwarded to the Template::Context -constructor. - - use Template; - - my $template = Template->new({ - TRIM => 1, - EVAL_PERL => 1, - BLOCKS => { - header => 'This is the header', - footer => 'This is the footer', - }, - }); - -Similarly, the Template::Context constructor will forward all configuration -parameters onto other default objects (e.g. Template::Provider, Template::Plugins, -Template::Filters, etc.) that it may need to instantiate. - - $context = Template::Context->new({ - INCLUDE_PATH => '/home/abw/templates', # provider option - TAG_STYLE => 'html', # parser option - }); - -A Template::Context object (or subclass/derivative) can be explicitly -instantiated and passed to the Template new() constructor method as -the CONTEXT item. - - use Template; - use Template::Context; - - my $context = Template::Context->new({ TRIM => 1 }); - my $template = Template->new({ CONTEXT => $context }); - -The Template module uses the Template::Config context() factory method -to create a default context object when required. The -$Template::Config::CONTEXT package variable may be set to specify an -alternate context module. This will be loaded automatically and its -new() constructor method called by the context() factory method when -a default context object is required. - - use Template; - - $Template::Config::CONTEXT = 'MyOrg::Template::Context'; - - my $template = Template->new({ - EVAL_PERL => 1, - EXTRA_MAGIC => 'red hot', # your extra config items - ... - }); - -=head1 METHODS - -=head2 new(\%params) - -The new() constructor method is called to instantiate a Template::Context -object. Configuration parameters may be specified as a HASH reference or -as a list of (name =E value) pairs. - - my $context = Template::Context->new({ - INCLUDE_PATH => 'header', - POST_PROCESS => 'footer', - }); - - my $context = Template::Context->new( EVAL_PERL => 1 ); - -The new() method returns a Template::Context object (or sub-class) or -undef on error. In the latter case, a relevant error message can be -retrieved by the error() class method or directly from the -$Template::Context::ERROR package variable. - - my $context = Template::Context->new(\%config) - || die Template::Context->error(); - - my $context = Template::Context->new(\%config) - || die $Template::Context::ERROR; - -The following configuration items may be specified. - -=over 4 - - -=item VARIABLES, PRE_DEFINE - -The VARIABLES option (or PRE_DEFINE - they're equivalent) can be used -to specify a hash array of template variables that should be used to -pre-initialise the stash when it is created. These items are ignored -if the STASH item is defined. - - my $context = Template::Context->new({ - VARIABLES => { - title => 'A Demo Page', - author => 'Joe Random Hacker', - version => 3.14, - }, - }; - -or - - my $context = Template::Context->new({ - PRE_DEFINE => { - title => 'A Demo Page', - author => 'Joe Random Hacker', - version => 3.14, - }, - }; - - - - - -=item BLOCKS - -The BLOCKS option can be used to pre-define a default set of template -blocks. These should be specified as a reference to a hash array -mapping template names to template text, subroutines or Template::Document -objects. - - my $context = Template::Context->new({ - BLOCKS => { - header => 'The Header. [% title %]', - footer => sub { return $some_output_text }, - another => Template::Document->new({ ... }), - }, - }); - - - - - -=item TRIM - -The TRIM option can be set to have any leading and trailing whitespace -automatically removed from the output of all template files and BLOCKs. - -By example, the following BLOCK definition - - [% BLOCK foo %] - Line 1 of foo - [% END %] - -will be processed is as "\nLine 1 of foo\n". When INCLUDEd, the surrounding -newlines will also be introduced. - - before - [% INCLUDE foo %] - after - -output: - before - - Line 1 of foo - - after - -With the TRIM option set to any true value, the leading and trailing -newlines (which count as whitespace) will be removed from the output -of the BLOCK. - - before - Line 1 of foo - after - -The TRIM option is disabled (0) by default. - - - - - - -=item EVAL_PERL - -This flag is used to indicate if PERL and/or RAWPERL blocks should be -evaluated. By default, it is disabled and any PERL or RAWPERL blocks -encountered will raise exceptions of type 'perl' with the message -'EVAL_PERL not set'. Note however that any RAWPERL blocks should -always contain valid Perl code, regardless of the EVAL_PERL flag. The -parser will fail to compile templates that contain invalid Perl code -in RAWPERL blocks and will throw a 'file' exception. - -When using compiled templates (see -L and -L), -the EVAL_PERL has an affect when the template is compiled, and again -when the templates is subsequently processed, possibly in a different -context to the one that compiled it. - -If the EVAL_PERL is set when a template is compiled, then all PERL and -RAWPERL blocks will be included in the compiled template. If the -EVAL_PERL option isn't set, then Perl code will be generated which -B throws a 'perl' exception with the message 'EVAL_PERL not -set' B the compiled template code is run. - -Thus, you must have EVAL_PERL set if you want your compiled templates -to include PERL and RAWPERL blocks. - -At some point in the future, using a different invocation of the -Template Toolkit, you may come to process such a pre-compiled -template. Assuming the EVAL_PERL option was set at the time the -template was compiled, then the output of any RAWPERL blocks will be -included in the compiled template and will get executed when the -template is processed. This will happen regardless of the runtime -EVAL_PERL status. - -Regular PERL blocks are a little more cautious, however. If the -EVAL_PERL flag isn't set for the I context, that is, the -one which is trying to process it, then it will throw the familiar 'perl' -exception with the message, 'EVAL_PERL not set'. - -Thus you can compile templates to include PERL blocks, but optionally -disable them when you process them later. Note however that it is -possible for a PERL block to contain a Perl "BEGIN { # some code }" -block which will always get run regardless of the runtime EVAL_PERL -status. Thus, if you set EVAL_PERL when compiling templates, it is -assumed that you trust the templates to Do The Right Thing. Otherwise -you must accept the fact that there's no bulletproof way to prevent -any included code from trampling around in the living room of the -runtime environment, making a real nuisance of itself if it really -wants to. If you don't like the idea of such uninvited guests causing -a bother, then you can accept the default and keep EVAL_PERL disabled. - - - - - - - -=item RECURSION - -The template processor will raise a file exception if it detects -direct or indirect recursion into a template. Setting this option to -any true value will allow templates to include each other recursively. - - - -=item LOAD_TEMPLATES - -The LOAD_TEMPLATE option can be used to provide a reference to a list -of Template::Provider objects or sub-classes thereof which will take -responsibility for loading and compiling templates. - - my $context = Template::Context->new({ - LOAD_TEMPLATES => [ - MyOrg::Template::Provider->new({ ... }), - Template::Provider->new({ ... }), - ], - }); - -When a PROCESS, INCLUDE or WRAPPER directive is encountered, the named -template may refer to a locally defined BLOCK or a file relative to -the INCLUDE_PATH (or an absolute or relative path if the appropriate -ABSOLUTE or RELATIVE options are set). If a BLOCK definition can't be -found (see the Template::Context template() method for a discussion of -BLOCK locality) then each of the LOAD_TEMPLATES provider objects is -queried in turn via the fetch() method to see if it can supply the -required template. Each provider can return a compiled template, an -error, or decline to service the request in which case the -responsibility is passed to the next provider. If none of the -providers can service the request then a 'not found' error is -returned. The same basic provider mechanism is also used for the -INSERT directive but it bypasses any BLOCK definitions and doesn't -attempt is to parse or process the contents of the template file. - -This is an implementation of the 'Chain of Responsibility' -design pattern as described in -"Design Patterns", Erich Gamma, Richard Helm, Ralph Johnson, John -Vlissides), Addision-Wesley, ISBN 0-201-63361-2, page 223 -. - -If LOAD_TEMPLATES is undefined, a single default provider will be -instantiated using the current configuration parameters. For example, -the Template::Provider INCLUDE_PATH option can be specified in the Template::Context configuration and will be correctly passed to the provider's -constructor method. - - my $context = Template::Context->new({ - INCLUDE_PATH => '/here:/there', - }); - - - - - -=item LOAD_PLUGINS - -The LOAD_PLUGINS options can be used to specify a list of provider -objects (i.e. they implement the fetch() method) which are responsible -for loading and instantiating template plugin objects. The -Template::Content plugin() method queries each provider in turn in a -"Chain of Responsibility" as per the template() and filter() methods. - - my $context = Template::Context->new({ - LOAD_PLUGINS => [ - MyOrg::Template::Plugins->new({ ... }), - Template::Plugins->new({ ... }), - ], - }); - -By default, a single Template::Plugins object is created using the -current configuration hash. Configuration items destined for the -Template::Plugins constructor may be added to the Template::Context -constructor. - - my $context = Template::Context->new({ - PLUGIN_BASE => 'MyOrg::Template::Plugins', - LOAD_PERL => 1, - }); - - - - - -=item LOAD_FILTERS - -The LOAD_FILTERS option can be used to specify a list of provider -objects (i.e. they implement the fetch() method) which are responsible -for returning and/or creating filter subroutines. The -Template::Context filter() method queries each provider in turn in a -"Chain of Responsibility" as per the template() and plugin() methods. - - my $context = Template::Context->new({ - LOAD_FILTERS => [ - MyTemplate::Filters->new(), - Template::Filters->new(), - ], - }); - -By default, a single Template::Filters object is created for the -LOAD_FILTERS list. - - - -=item STASH - -A reference to a Template::Stash object or sub-class which will take -responsibility for managing template variables. - - my $stash = MyOrg::Template::Stash->new({ ... }); - my $context = Template::Context->new({ - STASH => $stash, - }); - -If unspecified, a default stash object is created using the VARIABLES -configuration item to initialise the stash variables. These may also -be specified as the PRE_DEFINE option for backwards compatibility with -version 1. - - my $context = Template::Context->new({ - VARIABLES => { - id => 'abw', - name => 'Andy Wardley', - }, - }; - - - -=item DEBUG - -The DEBUG option can be used to enable various debugging features -of the Template::Context module. - - use Template::Constants qw( :debug ); - - my $template = Template->new({ - DEBUG => DEBUG_CONTEXT | DEBUG_DIRS, - }); - -The DEBUG value can include any of the following. Multiple values -should be combined using the logical OR operator, '|'. - -=over 4 - -=item DEBUG_CONTEXT - -Enables general debugging messages for the -L module. - -=item DEBUG_DIRS - -This option causes the Template Toolkit to generate comments -indicating the source file, line and original text of each directive -in the template. These comments are embedded in the template output -using the format defined in the DEBUG_FORMAT configuration item, or a -simple default format if unspecified. - -For example, the following template fragment: - - - Hello World - -would generate this output: - - ## input text line 1 : ## - Hello - ## input text line 2 : World ## - World - - -=back - - - - - -=back - -=head2 template($name) - -Returns a compiled template by querying each of the LOAD_TEMPLATES providers -(instances of Template::Provider, or sub-class) in turn. - - $template = $context->template('header'); - -On error, a Template::Exception object of type 'file' is thrown via -die(). This can be caught by enclosing the call to template() in an -eval block and examining $@. - - eval { - $template = $context->template('header'); - }; - if ($@) { - print "failed to fetch template: $@\n"; - } - -=head2 plugin($name, \@args) - -Instantiates a plugin object by querying each of the LOAD_PLUGINS -providers. The default LOAD_PLUGINS provider is a Template::Plugins -object which attempts to load plugin modules, according the various -configuration items such as PLUGIN_BASE, LOAD_PERL, etc., and then -instantiate an object via new(). A reference to a list of constructor -arguments may be passed as the second parameter. These are forwarded -to the plugin constructor. - -Returns a reference to a plugin (which is generally an object, but -doesn't have to be). Errors are thrown as Template::Exception objects -of type 'plugin'. - - $plugin = $context->plugin('DBI', 'dbi:msql:mydbname'); - -=head2 filter($name, \@args, $alias) - -Instantiates a filter subroutine by querying the LOAD_FILTERS providers. -The default LOAD_FILTERS providers is a Template::Filters object. -Additional arguments may be passed by list reference along with an -optional alias under which the filter will be cached for subsequent -use. The filter is cached under its own $name if $alias is undefined. -Subsequent calls to filter($name) will return the cached entry, if -defined. Specifying arguments bypasses the caching mechanism and -always creates a new filter. Errors are thrown as Template::Exception -objects of typre 'filter'. - - # static filter (no args) - $filter = $context->filter('html'); - - # dynamic filter (args) aliased to 'padright' - $filter = $context->filter('format', '%60s', 'padright'); - - # retrieve previous filter via 'padright' alias - $filter = $context->filter('padright'); - -=head2 process($template, \%vars) - -Processes a template named or referenced by the first parameter and returns -the output generated. An optional reference to a hash array may be passed -as the second parameter, containing variable definitions which will be set -before the template is processed. The template is processed in the current -context, with no localisation of variables performed. Errors are thrown -as Template::Exception objects via die(). - - $output = $context->process('header', { title => 'Hello World' }); - -=head2 include($template, \%vars) - -Similar to process() above, but using localised variables. Changes made to -any variables will only persist until the include() method completes. - - $output = $context->include('header', { title => 'Hello World' }); - -=head2 throw($error_type, $error_message, \$output) - -Raises an exception in the form of a Template::Exception object by -calling die(). This method may be passed a reference to an existing -Template::Exception object; a single value containing an error message -which is used to instantiate a Template::Exception of type 'undef'; or -a pair of values representing the exception type and info from which a -Template::Exception object is instantiated. e.g. - - $context->throw($exception); - $context->throw("I'm sorry Dave, I can't do that"); - $context->throw('denied', "I'm sorry Dave, I can't do that"); - -The optional third parameter may be a reference to the current output -buffer. This is then stored in the exception object when created, -allowing the catcher to examine and use the output up to the point at -which the exception was raised. - - $output .= 'blah blah blah'; - $output .= 'more rhubarb'; - $context->throw('yack', 'Too much yacking', \$output); - -=head2 catch($exception, \$output) - -Catches an exception thrown, either as a reference to a -Template::Exception object or some other value. In the latter case, -the error string is promoted to a Template::Exception object of -'undef' type. This method also accepts a reference to the current -output buffer which is passed to the Template::Exception constructor, -or is appended to the output buffer stored in an existing -Template::Exception object, if unique (i.e. not the same reference). -By this process, the correct state of the output buffer can be -reconstructed for simple or nested throws. - -=head2 define_block($name, $block) - -Adds a new block definition to the internal BLOCKS cache. The first -argument should contain the name of the block and the second a reference -to a Template::Document object or template sub-routine, or template text -which is automatically compiled into a template sub-routine. Returns -a true value (the sub-routine or Template::Document reference) on -success or undef on failure. The relevant error message can be -retrieved by calling the error() method. - -=head2 define_filter($name, \&filter, $is_dynamic) - -Adds a new filter definition by calling the store() method on each of -the LOAD_FILTERS providers until accepted (in the usual case, this is -accepted straight away by the one and only Template::Filters -provider). The first argument should contain the name of the filter -and the second a reference to a filter subroutine. The optional -third argument can be set to any true value to indicate that the -subroutine is a dynamic filter factory. Returns a true value or -throws a 'filter' exception on error. - -=head2 localise(\%vars) - -Clones the stash to create a context with localised variables. Returns a -reference to the newly cloned stash object which is also stored -internally. - - $stash = $context->localise(); - -=head2 delocalise() - -Restore the stash to its state prior to localisation. - - $stash = $context->delocalise(); - -=head2 visit(\%blocks) - -This method is called by Template::Document objects immediately before -they process their content. It is called to register any local BLOCK -definitions with the context object so that they may be subsequently -delivered on request. - -=head2 leave() - -Compliment to visit(), above. Called by Template::Document objects -immediately after they process their content. - -=head2 reset() - -Clears the local BLOCKS cache of any BLOCK definitions. Any initial set of -BLOCKS specified as a configuration item to the constructor will be reinstated. - -=head2 AUTOLOAD - -An AUTOLOAD method provides access to context configuration items. - - $stash = $context->stash(); - $tflag = $context->trim(); - $epflag = $context->eval_perl(); - ... - -=head1 AUTHOR - -Andy Wardley Eabw@andywardley.comE - -L - - - - -=head1 VERSION - -2.89, distributed as part of the -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -=head1 SEE ALSO - -L, L, L, L, L, L, L, L - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Directive.pm b/lib/Template/Directive.pm deleted file mode 100644 index c3f86a9..0000000 --- a/lib/Template/Directive.pm +++ /dev/null @@ -1,1004 +0,0 @@ -#================================================================= -*-Perl-*- -# -# Template::Directive -# -# DESCRIPTION -# Factory module for constructing templates from Perl code. -# -# AUTHOR -# Andy Wardley -# -# WARNING -# Much of this module is hairy, even furry in places. It needs -# a lot of tidying up and may even be moved into a different place -# altogether. The generator code is often inefficient, particulary in -# being very anal about pretty-printing the Perl code all neatly, but -# at the moment, that's still high priority for the sake of easier -# debugging. -# -# COPYRIGHT -# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -#---------------------------------------------------------------------------- -# -# $Id: Directive.pm,v 2.18 2003/10/08 09:34:41 abw Exp $ -# -#============================================================================ - -package Template::Directive; - -require 5.004; - -use strict; -use Template::Base; -use Template::Constants; -use Template::Exception; - -use base qw( Template::Base ); -use vars qw( $VERSION $DEBUG $PRETTY $WHILE_MAX $OUTPUT ); - -$VERSION = sprintf("%d.%02d", q$Revision: 2.18 $ =~ /(\d+)\.(\d+)/); - -$WHILE_MAX = 1000 unless defined $WHILE_MAX; -$PRETTY = 0 unless defined $PRETTY; -$OUTPUT = '$output .= '; - - -sub _init { - my ($self, $config) = @_; - $self->{ NAMESPACE } = $config->{ NAMESPACE }; - return $self; -} - - -sub pad { - my ($text, $pad) = @_; - $pad = ' ' x ($pad * 4); - $text =~ s/^(?!#line)/$pad/gm; - $text; -} - -#======================================================================== -# FACTORY METHODS -# -# These methods are called by the parser to construct directive instances. -#======================================================================== - -#------------------------------------------------------------------------ -# template($block) -#------------------------------------------------------------------------ - -sub template { - my ($class, $block) = @_; - $block = pad($block, 2) if $PRETTY; - - return "sub { return '' }" unless $block =~ /\S/; - - return <stash; - my \$output = ''; - my \$error; - - eval { BLOCK: { -$block - } }; - if (\$@) { - \$error = \$context->catch(\$@, \\\$output); - die \$error unless \$error->type eq 'return'; - } - - return \$output; -} -EOF -} - - -#------------------------------------------------------------------------ -# anon_block($block) [% BLOCK %] ... [% END %] -#------------------------------------------------------------------------ - -sub anon_block { - my ($class, $block) = @_; - $block = pad($block, 2) if $PRETTY; - - return <catch(\$@, \\\$output); - die \$error unless \$error->type eq 'return'; - } - - \$output; -}; -EOF -} - - -#------------------------------------------------------------------------ -# block($blocktext) -#------------------------------------------------------------------------ - -sub block { - my ($class, $block) = @_; - return join("\n", @{ $block || [] }); -} - - -#------------------------------------------------------------------------ -# textblock($text) -#------------------------------------------------------------------------ - -sub textblock { - my ($class, $text) = @_; - return "$OUTPUT " . &text($class, $text) . ';'; -} - - -#------------------------------------------------------------------------ -# text($text) -#------------------------------------------------------------------------ - -sub text { - my ($class, $text) = @_; - for ($text) { - s/(["\$\@\\])/\\$1/g; - s/\n/\\n/g; - } - return '"' . $text . '"'; -} - - -#------------------------------------------------------------------------ -# quoted(\@items) "foo$bar" -#------------------------------------------------------------------------ - -sub quoted { - my ($class, $items) = @_; - return '' unless @$items; - return ("('' . " . $items->[0] . ')') if scalar @$items == 1; - return '(' . join(' . ', @$items) . ')'; -# my $r = '(' . join(' . ', @$items) . ' . "")'; -# print STDERR "[$r]\n"; -# return $r; -} - - -#------------------------------------------------------------------------ -# ident(\@ident) foo.bar(baz) -#------------------------------------------------------------------------ - -sub ident { - my ($class, $ident) = @_; - return "''" unless @$ident; - my $ns; - - # does the first element of the identifier have a NAMESPACE - # handler defined? - if (ref $class && @$ident > 2 && ($ns = $class->{ NAMESPACE })) { - my $key = $ident->[0]; - $key =~ s/^'(.+)'$/$1/s; - if ($ns = $ns->{ $key }) { - return $ns->ident($ident); - } - } - - if (scalar @$ident <= 2 && ! $ident->[1]) { - $ident = $ident->[0]; - } - else { - $ident = '[' . join(', ', @$ident) . ']'; - } - return "\$stash->get($ident)"; -} - -#------------------------------------------------------------------------ -# identref(\@ident) \foo.bar(baz) -#------------------------------------------------------------------------ - -sub identref { - my ($class, $ident) = @_; - return "''" unless @$ident; - if (scalar @$ident <= 2 && ! $ident->[1]) { - $ident = $ident->[0]; - } - else { - $ident = '[' . join(', ', @$ident) . ']'; - } - return "\$stash->getref($ident)"; -} - - -#------------------------------------------------------------------------ -# assign(\@ident, $value, $default) foo = bar -#------------------------------------------------------------------------ - -sub assign { - my ($class, $var, $val, $default) = @_; - - if (ref $var) { - if (scalar @$var == 2 && ! $var->[1]) { - $var = $var->[0]; - } - else { - $var = '[' . join(', ', @$var) . ']'; - } - } - $val .= ', 1' if $default; - return "\$stash->set($var, $val)"; -} - - -#------------------------------------------------------------------------ -# args(\@args) foo, bar, baz = qux -#------------------------------------------------------------------------ - -sub args { - my ($class, $args) = @_; - my $hash = shift @$args; - push(@$args, '{ ' . join(', ', @$hash) . ' }') - if @$hash; - - return '0' unless @$args; - return '[ ' . join(', ', @$args) . ' ]'; -} - -#------------------------------------------------------------------------ -# filenames(\@names) -#------------------------------------------------------------------------ - -sub filenames { - my ($class, $names) = @_; - if (@$names > 1) { - $names = '[ ' . join(', ', @$names) . ' ]'; - } - else { - $names = shift @$names; - } - return $names; -} - - -#------------------------------------------------------------------------ -# get($expr) [% foo %] -#------------------------------------------------------------------------ - -sub get { - my ($class, $expr) = @_; - return "$OUTPUT $expr;"; -} - - -#------------------------------------------------------------------------ -# call($expr) [% CALL bar %] -#------------------------------------------------------------------------ - -sub call { - my ($class, $expr) = @_; - $expr .= ';'; - return $expr; -} - - -#------------------------------------------------------------------------ -# set(\@setlist) [% foo = bar, baz = qux %] -#------------------------------------------------------------------------ - -sub set { - my ($class, $setlist) = @_; - my $output; - while (my ($var, $val) = splice(@$setlist, 0, 2)) { - $output .= &assign($class, $var, $val) . ";\n"; - } - chomp $output; - return $output; -} - - -#------------------------------------------------------------------------ -# default(\@setlist) [% DEFAULT foo = bar, baz = qux %] -#------------------------------------------------------------------------ - -sub default { - my ($class, $setlist) = @_; - my $output; - while (my ($var, $val) = splice(@$setlist, 0, 2)) { - $output .= &assign($class, $var, $val, 1) . ";\n"; - } - chomp $output; - return $output; -} - - -#------------------------------------------------------------------------ -# insert(\@nameargs) [% INSERT file %] -# # => [ [ $file, ... ], \@args ] -#------------------------------------------------------------------------ - -sub insert { - my ($class, $nameargs) = @_; - my ($file, $args) = @$nameargs; - $file = $class->filenames($file); - return "$OUTPUT \$context->insert($file);"; -} - - -#------------------------------------------------------------------------ -# include(\@nameargs) [% INCLUDE template foo = bar %] -# # => [ [ $file, ... ], \@args ] -#------------------------------------------------------------------------ - -sub include { - my ($class, $nameargs) = @_; - my ($file, $args) = @$nameargs; - my $hash = shift @$args; - $file = $class->filenames($file); - $file .= @$hash ? ', { ' . join(', ', @$hash) . ' }' : ''; - return "$OUTPUT \$context->include($file);"; -} - - -#------------------------------------------------------------------------ -# process(\@nameargs) [% PROCESS template foo = bar %] -# # => [ [ $file, ... ], \@args ] -#------------------------------------------------------------------------ - -sub process { - my ($class, $nameargs) = @_; - my ($file, $args) = @$nameargs; - my $hash = shift @$args; - $file = $class->filenames($file); - $file .= @$hash ? ', { ' . join(', ', @$hash) . ' }' : ''; - return "$OUTPUT \$context->process($file);"; -} - - -#------------------------------------------------------------------------ -# if($expr, $block, $else) [% IF foo < bar %] -# ... -# [% ELSE %] -# ... -# [% END %] -#------------------------------------------------------------------------ - -sub if { - my ($class, $expr, $block, $else) = @_; - my @else = $else ? @$else : (); - $else = pop @else; - $block = pad($block, 1) if $PRETTY; - - my $output = "if ($expr) {\n$block\n}\n"; - - foreach my $elsif (@else) { - ($expr, $block) = @$elsif; - $block = pad($block, 1) if $PRETTY; - $output .= "elsif ($expr) {\n$block\n}\n"; - } - if (defined $else) { - $else = pad($else, 1) if $PRETTY; - $output .= "else {\n$else\n}\n"; - } - - return $output; -} - - -#------------------------------------------------------------------------ -# foreach($target, $list, $args, $block) [% FOREACH x = [ foo bar ] %] -# ... -# [% END %] -#------------------------------------------------------------------------ - -sub foreach { - my ($class, $target, $list, $args, $block) = @_; - $args = shift @$args; - $args = @$args ? ', { ' . join(', ', @$args) . ' }' : ''; - - my ($loop_save, $loop_set, $loop_restore, $setiter); - if ($target) { - $loop_save = 'eval { $oldloop = ' . &ident($class, ["'loop'"]) . ' }'; - $loop_set = "\$stash->{'$target'} = \$value"; - $loop_restore = "\$stash->set('loop', \$oldloop)"; - } - else { - $loop_save = '$stash = $context->localise()'; -# $loop_set = "\$stash->set('import', \$value) " -# . "if ref \$value eq 'HASH'"; - $loop_set = "\$stash->get(['import', [\$value]]) " - . "if ref \$value eq 'HASH'"; - $loop_restore = '$stash = $context->delocalise()'; - } - $block = pad($block, 3) if $PRETTY; - - return <iterator(\$list) - || die \$Template::Config::ERROR, "\\n"; - } - - (\$value, \$error) = \$list->get_first(); - $loop_save; - \$stash->set('loop', \$list); - eval { -LOOP: while (! \$error) { - $loop_set; -$block; - (\$value, \$error) = \$list->get_next(); - } - }; - $loop_restore; - die \$@ if \$@; - \$error = 0 if \$error && \$error eq Template::Constants::STATUS_DONE; - die \$error if \$error; -}; -EOF -} - -#------------------------------------------------------------------------ -# next() [% NEXT %] -# -# Next iteration of a FOREACH loop (experimental) -#------------------------------------------------------------------------ - -sub next { - return <get_next(); -next LOOP; -EOF -} - - -#------------------------------------------------------------------------ -# wrapper(\@nameargs, $block) [% WRAPPER template foo = bar %] -# # => [ [$file,...], \@args ] -#------------------------------------------------------------------------ - -sub wrapper { - my ($class, $nameargs, $block) = @_; - my ($file, $args) = @$nameargs; - my $hash = shift @$args; - - local $" = ', '; -# print STDERR "wrapper([@$file], { @$hash })\n"; - - return $class->multi_wrapper($file, $hash, $block) - if @$file > 1; - $file = shift @$file; - - $block = pad($block, 1) if $PRETTY; - push(@$hash, "'content'", '$output'); - $file .= @$hash ? ', { ' . join(', ', @$hash) . ' }' : ''; - - return <include($file); -}; -EOF -} - - -sub multi_wrapper { - my ($class, $file, $hash, $block) = @_; - $block = pad($block, 1) if $PRETTY; - - push(@$hash, "'content'", '$output'); - $hash = @$hash ? ', { ' . join(', ', @$hash) . ' }' : ''; - - $file = join(', ', reverse @$file); -# print STDERR "multi wrapper: $file\n"; - - return <include(\$_$hash); - } - \$output; -}; -EOF -} - - -#------------------------------------------------------------------------ -# while($expr, $block) [% WHILE x < 10 %] -# ... -# [% END %] -#------------------------------------------------------------------------ - -sub while { - my ($class, $expr, $block) = @_; - $block = pad($block, 2) if $PRETTY; - - return < $WHILE_MAX iterations)\\n" - unless \$failsafe; -}; -EOF -} - - -#------------------------------------------------------------------------ -# switch($expr, \@case) [% SWITCH %] -# [% CASE foo %] -# ... -# [% END %] -#------------------------------------------------------------------------ - -sub switch { - my ($class, $expr, $case) = @_; - my @case = @$case; - my ($match, $block, $default); - my $caseblock = ''; - - $default = pop @case; - - foreach $case (@case) { - $match = $case->[0]; - $block = $case->[1]; - $block = pad($block, 1) if $PRETTY; - $caseblock .= <[0] || do { - $default ||= $catch->[1]; - next; - }; - $mblock = $catch->[1]; - $mblock = pad($mblock, 1) if $PRETTY; - push(@$handlers, "'$match'"); - $catchblock .= $n++ - ? "elsif (\$handler eq '$match') {\n$mblock\n}\n" - : "if (\$handler eq '$match') {\n$mblock\n}\n"; - } - $catchblock .= "\$error = 0;"; - $catchblock = pad($catchblock, 3) if $PRETTY; - if ($default) { - $default = pad($default, 1) if $PRETTY; - $default = "else {\n # DEFAULT\n$default\n \$error = '';\n}"; - } - else { - $default = '# NO DEFAULT'; - } - $default = pad($default, 2) if $PRETTY; - - $handlers = join(', ', @$handlers); -return <catch(\$@, \\\$output); - die \$error if \$error->type =~ /^return|stop\$/; - \$stash->set('error', \$error); - \$stash->set('e', \$error); - if (defined (\$handler = \$error->select_handler($handlers))) { -$catchblock - } -$default - } -$final -}; -EOF -} - - -#------------------------------------------------------------------------ -# throw(\@nameargs) [% THROW foo "bar error" %] -# # => [ [$type], \@args ] -#------------------------------------------------------------------------ - -sub throw { - my ($class, $nameargs) = @_; - my ($type, $args) = @$nameargs; - my $hash = shift(@$args); - my $info = shift(@$args); - $type = shift @$type; # uses same parser production as INCLUDE - # etc., which allow multiple names - # e.g. INCLUDE foo+bar+baz - - if (! $info) { - $args = "$type, undef"; - } - elsif (@$hash || @$args) { - local $" = ', '; - my $i = 0; - $args = "$type, { args => [ " - . join(', ', $info, @$args) - . ' ], ' - . join(', ', - (map { "'" . $i++ . "' => $_" } ($info, @$args)), - @$hash) - . ' }'; - } - else { - $args = "$type, $info"; - } - - return "\$context->throw($args, \\\$output);"; -} - - -#------------------------------------------------------------------------ -# clear() [% CLEAR %] -# -# NOTE: this is redundant, being hard-coded (for now) into Parser.yp -#------------------------------------------------------------------------ - -sub clear { - return "\$output = '';"; -} - -#------------------------------------------------------------------------ -# break() [% BREAK %] -# -# NOTE: this is redundant, being hard-coded (for now) into Parser.yp -#------------------------------------------------------------------------ - -sub break { - return 'last LOOP;'; -} - -#------------------------------------------------------------------------ -# return() [% RETURN %] -#------------------------------------------------------------------------ - -sub return { - return "\$context->throw('return', '', \\\$output);"; -} - -#------------------------------------------------------------------------ -# stop() [% STOP %] -#------------------------------------------------------------------------ - -sub stop { - return "\$context->throw('stop', '', \\\$output);"; -} - - -#------------------------------------------------------------------------ -# use(\@lnameargs) [% USE alias = plugin(args) %] -# # => [ [$file, ...], \@args, $alias ] -#------------------------------------------------------------------------ - -sub use { - my ($class, $lnameargs) = @_; - my ($file, $args, $alias) = @$lnameargs; - $file = shift @$file; # same production rule as INCLUDE - $alias ||= $file; - $args = &args($class, $args); - $file .= ", $args" if $args; -# my $set = &assign($class, $alias, '$plugin'); - return "# USE\n" - . "\$stash->set($alias,\n" - . " \$context->plugin($file));"; -} - -#------------------------------------------------------------------------ -# view(\@nameargs, $block) [% VIEW name args %] -# # => [ [$file, ... ], \@args ] -#------------------------------------------------------------------------ - -sub view { - my ($class, $nameargs, $block, $defblocks) = @_; - my ($name, $args) = @$nameargs; - my $hash = shift @$args; - $name = shift @$name; # same production rule as INCLUDE - $block = pad($block, 1) if $PRETTY; - - if (%$defblocks) { - $defblocks = join(",\n", map { "'$_' => $defblocks->{ $_ }" } - keys %$defblocks); - $defblocks = pad($defblocks, 1) if $PRETTY; - $defblocks = "{\n$defblocks\n}"; - push(@$hash, "'blocks'", $defblocks); - } - $hash = @$hash ? '{ ' . join(', ', @$hash) . ' }' : ''; - - return <get('view'); - my \$view = \$context->view($hash); - \$stash->set($name, \$view); - \$stash->set('view', \$view); - -$block - - \$stash->set('view', \$oldv); - \$view->seal(); - \$output; -}; -EOF -} - - -#------------------------------------------------------------------------ -# perl($block) -#------------------------------------------------------------------------ - -sub perl { - my ($class, $block) = @_; - $block = pad($block, 1) if $PRETTY; - - return <throw('perl', 'EVAL_PERL not set') - unless \$context->eval_perl(); - -$OUTPUT do { - my \$output = "package Template::Perl;\\n"; - -$block - - local(\$Template::Perl::context) = \$context; - local(\$Template::Perl::stash) = \$stash; - - my \$result = ''; - tie *Template::Perl::PERLOUT, 'Template::TieString', \\\$result; - my \$save_stdout = select *Template::Perl::PERLOUT; - - eval \$output; - select \$save_stdout; - \$context->throw(\$@) if \$@; - \$result; -}; -EOF -} - - -#------------------------------------------------------------------------ -# no_perl() -#------------------------------------------------------------------------ - -sub no_perl { - my $class = shift; - return "\$context->throw('perl', 'EVAL_PERL not set');"; -} - - -#------------------------------------------------------------------------ -# rawperl($block) -# -# NOTE: perhaps test context EVAL_PERL switch at compile time rather than -# runtime? -#------------------------------------------------------------------------ - -sub rawperl { - my ($class, $block, $line) = @_; - for ($block) { - s/^\n+//; - s/\n+$//; - } - $block = pad($block, 1) if $PRETTY; - $line = $line ? " (starting line $line)" : ''; - - return <filter($name) - || \$context->throw(\$context->error); - -$block - - &\$filter(\$output); -}; -EOF -} - - -#------------------------------------------------------------------------ -# capture($name, $block) -#------------------------------------------------------------------------ - -sub capture { - my ($class, $name, $block) = @_; - - if (ref $name) { - if (scalar @$name == 2 && ! $name->[1]) { - $name = $name->[0]; - } - else { - $name = '[' . join(', ', @$name) . ']'; - } - } - $block = pad($block, 1) if $PRETTY; - - return <set($name, do { - my \$output = ''; -$block - \$output; -}); -EOF - -} - - -#------------------------------------------------------------------------ -# macro($name, $block, \@args) -#------------------------------------------------------------------------ - -sub macro { - my ($class, $ident, $block, $args) = @_; - $block = pad($block, 2) if $PRETTY; - - if ($args) { - my $nargs = scalar @$args; - $args = join(', ', map { "'$_'" } @$args); - $args = $nargs > 1 - ? "\@args{ $args } = splice(\@_, 0, $nargs)" - : "\$args{ $args } = shift"; - - return <set('$ident', sub { - my \$output = ''; - my (%args, \$params); - $args; - \$params = shift; - \$params = { } unless ref(\$params) eq 'HASH'; - \$params = { \%args, %\$params }; - - my \$stash = \$context->localise(\$params); - eval { -$block - }; - \$stash = \$context->delocalise(); - die \$@ if \$@; - return \$output; -}); -EOF - - } - else { - return <set('$ident', sub { - my \$params = \$_[0] if ref(\$_[0]) eq 'HASH'; - my \$output = ''; - - my \$stash = \$context->localise(\$params); - eval { -$block - }; - \$stash = \$context->delocalise(); - die \$@ if \$@; - return \$output; -}); -EOF - } -} - - -sub debug { - my ($class, $nameargs) = @_; - my ($file, $args) = @$nameargs; - my $hash = shift @$args; - $args = join(', ', @$file, @$args); - $args .= @$hash ? ', { ' . join(', ', @$hash) . ' }' : ''; - return "$OUTPUT \$context->debugging($args); ## DEBUG ##"; -} - - -1; - -__END__ - diff --git a/lib/Template/Document.pm b/lib/Template/Document.pm deleted file mode 100644 index ce3beb2..0000000 --- a/lib/Template/Document.pm +++ /dev/null @@ -1,492 +0,0 @@ -##============================================================= -*-Perl-*- -# -# Template::Document -# -# DESCRIPTION -# Module defining a class of objects which encapsulate compiled -# templates, storing additional block definitions and metadata -# as well as the compiled Perl sub-routine representing the main -# template content. -# -# AUTHOR -# Andy Wardley -# -# COPYRIGHT -# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -#---------------------------------------------------------------------------- -# -# $Id: Document.pm,v 2.71 2004/01/13 16:19:10 abw Exp $ -# -#============================================================================ - -package Template::Document; - -require 5.004; - -use strict; -use vars qw( $VERSION $ERROR $COMPERR $DEBUG $AUTOLOAD ); -use base qw( Template::Base ); -use Template::Constants; - -$VERSION = sprintf("%d.%02d", q$Revision: 2.71 $ =~ /(\d+)\.(\d+)/); - - -#======================================================================== -# ----- PUBLIC METHODS ----- -#======================================================================== - -#------------------------------------------------------------------------ -# new(\%document) -# -# Creates a new self-contained Template::Document object which -# encapsulates a compiled Perl sub-routine, $block, any additional -# BLOCKs defined within the document ($defblocks, also Perl sub-routines) -# and additional $metadata about the document. -#------------------------------------------------------------------------ - -sub new { - my ($class, $doc) = @_; - my ($block, $defblocks, $metadata) = @$doc{ qw( BLOCK DEFBLOCKS METADATA ) }; - $defblocks ||= { }; - $metadata ||= { }; - - # evaluate Perl code in $block to create sub-routine reference if necessary - unless (ref $block) { - local $SIG{__WARN__} = \&catch_warnings; - $COMPERR = ''; - - # DON'T LOOK NOW! - blindly untainting can make you go blind! - $block =~ /(.*)/s; - $block = $1; - - $block = eval $block; - return $class->error($@) - unless defined $block; - } - - # same for any additional BLOCK definitions - @$defblocks{ keys %$defblocks } = - # MORE BLIND UNTAINTING - turn away if you're squeamish - map { - ref($_) - ? $_ - : ( /(.*)/s && eval($1) or return $class->error($@) ) - } values %$defblocks; - - bless { - %$metadata, - _BLOCK => $block, - _DEFBLOCKS => $defblocks, - _HOT => 0, - }, $class; -} - - -#------------------------------------------------------------------------ -# block() -# -# Returns a reference to the internal sub-routine reference, _BLOCK, -# that constitutes the main document template. -#------------------------------------------------------------------------ - -sub block { - return $_[0]->{ _BLOCK }; -} - - -#------------------------------------------------------------------------ -# blocks() -# -# Returns a reference to a hash array containing any BLOCK definitions -# from the template. The hash keys are the BLOCK nameand the values -# are references to Template::Document objects. Returns 0 (# an empty hash) -# if no blocks are defined. -#------------------------------------------------------------------------ - -sub blocks { - return $_[0]->{ _DEFBLOCKS }; -} - - -#------------------------------------------------------------------------ -# process($context) -# -# Process the document in a particular context. Checks for recursion, -# registers the document with the context via visit(), processes itself, -# and then unwinds with a large gin and tonic. -#------------------------------------------------------------------------ - -sub process { - my ($self, $context) = @_; - my $defblocks = $self->{ _DEFBLOCKS }; - my $output; - - - # check we're not already visiting this template - return $context->throw(Template::Constants::ERROR_FILE, - "recursion into '$self->{ name }'") - if $self->{ _HOT } && ! $context->{ RECURSION }; ## RETURN ## - - $context->visit($self, $defblocks); - - $self->{ _HOT } = 1; - eval { - my $block = $self->{ _BLOCK }; - $output = &$block($context); - }; - $self->{ _HOT } = 0; - - $context->leave(); - - die $context->catch($@) - if $@; - - return $output; -} - - -#------------------------------------------------------------------------ -# AUTOLOAD -# -# Provides pseudo-methods for read-only access to various internal -# members. -#------------------------------------------------------------------------ - -sub AUTOLOAD { - my $self = shift; - my $method = $AUTOLOAD; - - $method =~ s/.*:://; - return if $method eq 'DESTROY'; -# my ($pkg, $file, $line) = caller(); -# print STDERR "called $self->AUTOLOAD($method) from $file line $line\n"; - return $self->{ $method }; -} - - -#======================================================================== -# ----- PRIVATE METHODS ----- -#======================================================================== - - -#------------------------------------------------------------------------ -# _dump() -# -# Debug method which returns a string representing the internal state -# of the object. -#------------------------------------------------------------------------ - -sub _dump { - my $self = shift; - my $dblks; - my $output = "$self : $self->{ name }\n"; - - $output .= "BLOCK: $self->{ _BLOCK }\nDEFBLOCKS:\n"; - - if ($dblks = $self->{ _DEFBLOCKS }) { - foreach my $b (keys %$dblks) { - $output .= " $b: $dblks->{ $b }\n"; - } - } - - return $output; -} - - -#======================================================================== -# ----- CLASS METHODS ----- -#======================================================================== - -#------------------------------------------------------------------------ -# as_perl($content) -# -# This method expects a reference to a hash passed as the first argument -# containing 3 items: -# METADATA # a hash of template metadata -# BLOCK # string containing Perl sub definition for main block -# DEFBLOCKS # hash containing further subs for addional BLOCK defs -# It returns a string containing Perl code which, when evaluated and -# executed, will instantiate a new Template::Document object with the -# above data. On error, it returns undef with an appropriate error -# message set in $ERROR. -#------------------------------------------------------------------------ - -sub as_perl { - my ($class, $content) = @_; - my ($block, $defblocks, $metadata) = @$content{ qw( BLOCK DEFBLOCKS METADATA ) }; - - $block =~ s/\n/\n /g; - $block =~ s/\s+$//; - - $defblocks = join('', map { - my $code = $defblocks->{ $_ }; - $code =~ s/\n/\n /g; - $code =~ s/\s*$//; - " '$_' => $code,\n"; - } keys %$defblocks); - $defblocks =~ s/\s+$//; - - $metadata = join('', map { - my $x = $metadata->{ $_ }; - $x =~ s/(['\\])/\\$1/g; - " '$_' => '$x',\n"; - } keys %$metadata); - $metadata =~ s/\s+$//; - - return <new({ - METADATA => { -$metadata - }, - BLOCK => $block, - DEFBLOCKS => { -$defblocks - }, -}); -EOF -} - - -#------------------------------------------------------------------------ -# write_perl_file($filename, \%content) -# -# This method calls as_perl() to generate the Perl code to represent a -# compiled template with the content passed as the second argument. -# It then writes this to the file denoted by the first argument. -# -# Returns 1 on success. On error, sets the $ERROR package variable -# to contain an error message and returns undef. -#------------------------------------------------------------------------ - -sub write_perl_file { - my ($class, $file, $content) = @_; - my ($fh, $tmpfile); - - return $class->error("invalid filename: $file") - unless $file =~ /^(.+)$/s; - - eval { - require File::Temp; - require File::Basename; - ($fh, $tmpfile) = File::Temp::tempfile( - DIR => File::Basename::dirname($file) - ); - print $fh $class->as_perl($content) || die $!; - close($fh); - }; - return $class->error($@) if $@; - return rename($tmpfile, $file) - || $class->error($!); -} - - -#------------------------------------------------------------------------ -# catch_warnings($msg) -# -# Installed as -#------------------------------------------------------------------------ - -sub catch_warnings { - $COMPERR .= join('', @_); -} - - -1; - -__END__ - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Document - Compiled template document object - -=head1 SYNOPSIS - - use Template::Document; - - $doc = Template::Document->new({ - BLOCK => sub { # some perl code; return $some_text }, - DEFBLOCKS => { - header => sub { # more perl code; return $some_text }, - footer => sub { # blah blah blah; return $some_text }, - }, - METADATA => { - author => 'Andy Wardley', - version => 3.14, - } - }) || die $Template::Document::ERROR; - - print $doc->process($context); - -=head1 DESCRIPTION - -This module defines an object class whose instances represent compiled -template documents. The Template::Parser module creates a -Template::Document instance to encapsulate a template as it is compiled -into Perl code. - -The constructor method, new(), expects a reference to a hash array -containing the BLOCK, DEFBLOCKS and METADATA items. The BLOCK item -should contain a reference to a Perl subroutine or a textual -representation of Perl code, as generated by the Template::Parser -module, which is then evaluated into a subroutine reference using -eval(). The DEFLOCKS item should reference a hash array containing -further named BLOCKs which may be defined in the template. The keys -represent BLOCK names and the values should be subroutine references -or text strings of Perl code as per the main BLOCK item. The METADATA -item should reference a hash array of metadata items relevant to the -document. - -The process() method can then be called on the instantiated -Template::Document object, passing a reference to a Template::Content -object as the first parameter. This will install any locally defined -blocks (DEFBLOCKS) in the the contexts() BLOCKS cache (via a call to -visit()) so that they may be subsequently resolved by the context. The -main BLOCK subroutine is then executed, passing the context reference -on as a parameter. The text returned from the template subroutine is -then returned by the process() method, after calling the context leave() -method to permit cleanup and de-registration of named BLOCKS previously -installed. - -An AUTOLOAD method provides access to the METADATA items for the document. -The Template::Service module installs a reference to the main -Template::Document object in the stash as the 'template' variable. -This allows metadata items to be accessed from within templates, -including PRE_PROCESS templates. - -header: - - - - [% template.title %] - </head> - ... - -Template::Document objects are usually created by the Template::Parser -but can be manually instantiated or sub-classed to provide custom -template components. - -=head1 METHODS - -=head2 new(\%config) - -Constructor method which accept a reference to a hash array containing the -structure as shown in this example: - - $doc = Template::Document->new({ - BLOCK => sub { # some perl code; return $some_text }, - DEFBLOCKS => { - header => sub { # more perl code; return $some_text }, - footer => sub { # blah blah blah; return $some_text }, - }, - METADATA => { - author => 'Andy Wardley', - version => 3.14, - } - }) || die $Template::Document::ERROR; - -BLOCK and DEFBLOCKS items may be expressed as references to Perl subroutines -or as text strings containing Perl subroutine definitions, as is generated -by the Template::Parser module. These are evaluated into subroutine references -using eval(). - -Returns a new Template::Document object or undef on error. The error() class -method can be called, or the $ERROR package variable inspected to retrieve -the relevant error message. - -=head2 process($context) - -Main processing routine for the compiled template document. A reference to -a Template::Context object should be passed as the first parameter. The -method installs any locally defined blocks via a call to the context -visit() method, processes it's own template, passing the context reference -by parameter and then calls leave() in the context to allow cleanup. - - print $doc->process($context); - -Returns a text string representing the generated output for the template. -Errors are thrown via die(). - -=head2 block() - -Returns a reference to the main BLOCK subroutine. - -=head2 blocks() - -Returns a reference to the hash array of named DEFBLOCKS subroutines. - -=head2 AUTOLOAD - -An autoload method returns METADATA items. - - print $doc->author(); - -=head1 PACKAGE SUB-ROUTINES - -=head2 write_perl_file(\%config) - -This package subroutine is provided to effect persistance of compiled -templates. If the COMPILE_EXT option (to indicate a file extension -for saving compiled templates) then the Template::Parser module calls -this subroutine before calling the new() constructor. At this stage, -the parser has a representation of the template as text strings -containing Perl code. We can write that to a file, enclosed in a -small wrapper which will allow us to susequently require() the file -and have Perl parse and compile it into a Template::Document. Thus we -have persistance of compiled templates. - -=head1 AUTHOR - -Andy Wardley E<lt>abw@andywardley.comE<gt> - -L<http://www.andywardley.com/|http://www.andywardley.com/> - - - - -=head1 VERSION - -2.71, distributed as part of the -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -=head1 SEE ALSO - -L<Template|Template>, L<Template::Parser|Template::Parser> - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Exception.pm b/lib/Template/Exception.pm deleted file mode 100644 index 9a95af7..0000000 --- a/lib/Template/Exception.pm +++ /dev/null @@ -1,254 +0,0 @@ -#============================================================= -*-Perl-*- -# -# Template::Exception -# -# DESCRIPTION -# Module implementing a generic exception class used for error handling -# in the Template Toolkit. -# -# AUTHOR -# Andy Wardley <abw@kfs.org> -# -# COPYRIGHT -# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -#------------------------------------------------------------------------ -# -# $Id: Exception.pm,v 2.64 2004/01/13 16:19:10 abw Exp $ -# -#======================================================================== - - -package Template::Exception; - -require 5.005; - -use strict; -use vars qw( $VERSION ); - -use constant TYPE => 0; -use constant INFO => 1; -use constant TEXT => 2; -use overload q|""| => "as_string", fallback => 1; - - -$VERSION = sprintf("%d.%02d", q$Revision: 2.64 $ =~ /(\d+)\.(\d+)/); - - -#------------------------------------------------------------------------ -# new($type, $info, \$text) -# -# Constructor method used to instantiate a new Template::Exception -# object. The first parameter should contain the exception type. This -# can be any arbitrary string of the caller's choice to represent a -# specific exception. The second parameter should contain any -# information (i.e. error message or data reference) relevant to the -# specific exception event. The third optional parameter may be a -# reference to a scalar containing output text from the template -# block up to the point where the exception was thrown. -#------------------------------------------------------------------------ - -sub new { - my ($class, $type, $info, $textref) = @_; - bless [ $type, $info, $textref ], $class; -} - - -#------------------------------------------------------------------------ -# type() -# info() -# type_info() -# -# Accessor methods to return the internal TYPE and INFO fields. -#------------------------------------------------------------------------ - -sub type { - $_[0]->[ TYPE ]; -} - -sub info { - $_[0]->[ INFO ]; -} - -sub type_info { - my $self = shift; - @$self[ TYPE, INFO ]; -} - -#------------------------------------------------------------------------ -# text() -# text(\$pretext) -# -# Method to return the text referenced by the TEXT member. A text -# reference may be passed as a parameter to supercede the existing -# member. The existing text is added to the *end* of the new text -# before being stored. This facility is provided for template blocks -# to gracefully de-nest when an exception occurs and allows them to -# reconstruct their output in the correct order. -#------------------------------------------------------------------------ - -sub text { - my ($self, $newtextref) = @_; - my $textref = $self->[ TEXT ]; - - if ($newtextref) { - $$newtextref .= $$textref if $textref && $textref ne $newtextref; - $self->[ TEXT ] = $newtextref; - return ''; - - } - elsif ($textref) { - return $$textref; - } - else { - return ''; - } -} - - -#------------------------------------------------------------------------ -# as_string() -# -# Accessor method to return a string indicating the exception type and -# information. -#------------------------------------------------------------------------ - -sub as_string { - my $self = shift; - return $self->[ TYPE ] . ' error - ' . $self->[ INFO ]; -} - - -#------------------------------------------------------------------------ -# select_handler(@types) -# -# Selects the most appropriate handler for the exception TYPE, from -# the list of types passed in as parameters. The method returns the -# item which is an exact match for TYPE or the closest, more -# generic handler (e.g. foo being more generic than foo.bar, etc.) -#------------------------------------------------------------------------ - -sub select_handler { - my ($self, @options) = @_; - my $type = $self->[ TYPE ]; - my %hlut; - @hlut{ @options } = (1) x @options; - - while ($type) { - return $type if $hlut{ $type }; - - # strip .element from the end of the exception type to find a - # more generic handler - $type =~ s/\.?[^\.]*$//; - } - return undef; -} - -1; - -__END__ - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Exception - Exception handling class module - -=head1 SYNOPSIS - - use Template::Exception; - - my $exception = Template::Exception->new($type, $info); - $type = $exception->type; - $info = $exception->info; - ($type, $info) = $exception->type_info; - - print $exception->as_string(); - - $handler = $exception->select_handler(\@candidates); - -=head1 DESCRIPTION - -The Template::Exception module defines an object class for -representing exceptions within the template processing life cycle. -Exceptions can be raised by modules within the Template Toolkit, or -can be generated and returned by user code bound to template -variables. - - -Exceptions can be raised in a template using the THROW directive, - - [% THROW user.login 'no user id: please login' %] - -or by calling the throw() method on the current Template::Context object, - - $context->throw('user.passwd', 'Incorrect Password'); - $context->throw('Incorrect Password'); # type 'undef' - -or from Perl code by calling die() with a Template::Exception object, - - die (Template::Exception->new('user.denied', 'Invalid User ID')); - -or by simply calling die() with an error string. This is -automagically caught and converted to an exception of 'undef' -type which can then be handled in the usual way. - - die "I'm sorry Dave, I can't do that"; - - - -Each exception is defined by its type and a information component -(e.g. error message). The type can be any identifying string and may -contain dotted components (e.g. 'foo', 'foo.bar', 'foo.bar.baz'). -Exception types are considered to be hierarchical such that 'foo.bar' -would be a specific type of the more general 'foo' type. - -=head1 AUTHOR - -Andy Wardley E<lt>abw@andywardley.comE<gt> - -L<http://www.andywardley.com/|http://www.andywardley.com/> - - - - -=head1 VERSION - -2.64, distributed as part of the -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -=head1 SEE ALSO - -L<Template|Template>, L<Template::Context|Template::Context> - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/FAQ.pod b/lib/Template/FAQ.pod deleted file mode 100644 index 0807ace..0000000 --- a/lib/Template/FAQ.pod +++ /dev/null @@ -1,329 +0,0 @@ -#============================================================= -*-perl-*- -# -# Template::FAQ -# -# DESCRIPTION -# This is the Frequently Asked Questions list for the Template -# Toolkit. More accurately, it's a very thin placeholder for where -# the FAQ will soon be. -# -# AUTHOR -# Andy Wardley <abw@andywardley.com> -# -# COPYRIGHT -# Copyright (C) 1996-2001 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2001 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -# REVISION -# 2.69 -# -#======================================================================== - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::FAQ - Frequently Asked Questions about the Template Toolkit - -=head1 DESCRIPTION - -This is the Frequently Asked Questions list for the Template Toolkit. -More accurately, it's a very thin placeholder for where the FAQ will -soon be. - - -=head1 Template Toolkit Language - -=head2 Why doesn't [% a = b IF c %] work as expected? - -Because the parser interprets it as - - [% a = (b IF c) %] - -Do this instead: - - [% SET a = b IF c %] - -=head2 If I'm using TT to write out a TT template, is there a good way to escape [% and %]? - -You can do this: - - [% stag = "[\%" - etag = "%\]" - %] - -and then: - - [% stag; 'hello'; etag %] - -Or something like: - - [% TAGS [- -] %] - [- INCLUDE foo -] # is a directive - [% INCLUDE foo %] # not a directive, just plain text, passed through - -=head2 How do I iterate over a hash? - -This is covered in the L<Template::Manual::VMethods|VMethods> section -of the manual page. A list of all the keys that are in the hash can -be obtained with the 'keys' virtual method. You can then iterate -over that list and by looking up each key in turn get the value. - - [% FOREACH key = product.keys %] - [% key %] => [% product.$key %] - [% END %] - -=head1 Plugins - -=head2 How do I get the Table plugin to order data across rather than down? - -Order the data into rows: - - Steve Karen Jeff - Brooklyn Nantucket Fairfax - NY MA VA - - [% USE table(data, rows=3) %] - -Then ask for each column - - [% FOREACH column = table.cols %] - -And then print each item in the column going across the output rows - - [% FOREACH item = column %] - <td>[% item %]</td> - [% END %] - -=head2 Accessing Cookies - -Jeff Boes E<lt>jboes@nexcerpt.comE<gt> asks: - - Does anyone have a quick-n-dirty approach to accessing - cookies from templates? - -Jonas Liljegren answers: - - [% USE CGI %] - - <p>The value is [% CGI.cookie('cookie_name') | html %] - - -=head1 Extending the Template Toolkit - -=head2 Can I serve templates from a database? - -Short answer: yes, Chris Nandor has done this for Slash. You need to -subclass Template::Provider. See the mailing list archives for further -info. - -=head2 Can I fetch templates via http? - -To do the job properly, you should sublcass Template::Provider to -Template::Provider::HTTP and use a PREFIX_MAP option to bind the -'http' template prefix to that particular provider (you may want to -go digging around in the F<Changes> file around version 2.01 for -more info on PREFIX_MAP - it may not be properly documented anywhere -else...yet!). e.g. (untested due to lack of existing HTTP Provider -- patches welcome!). - - use Template::Provider::HTTP; - - my $file = Template::Provider( INCLUDE_PATH => [...] ); - my $http = Template::Provider::HTTP->new(...); - my $tt2 = Template->new({ - LOAD_TEMPLATES => [ $file, $http ], - PREFIX_MAP => { - file => '0', # file:foo.html - http => '1', # http:foo.html - default => '0', # foo.html => file:foo.html - } - }); - -Now a template specified as: - - [% INCLUDE foo %] - -will be served by the 'file' provider (the default). Otherwise you -can explicitly add a prefix: - - [% INCLUDE file:foo.html %] - [% INCLUDE http:foo.html %] - [% INCLUDE http://www.xyz.com/tt2/header.tt2 %] - -This same principal can be used to create a DBI template provider. e.g. - - [% INCLUDE dbi:foo.html %] - -But similarly, alas, we don't yet have a DBI provider as part of the -Template Toolkit. There has been some talk on the mailing list about -efforts to develop DBI and/or HTTP providers but as yet no-one has -stepped forward to take up the challenge... - -In the mean time, Craig's post from the mailing list has some useful -pointers on how to acheive this using existing modules: - - To: Adam Theo <adamtheo@theoretic.com> - From: Craig Barratt <craig@arraycomm.com> - Date: Fri, 18 May 2001 17:06:59 -0700 - - > i was wondering if there is anyway to fetch a file using http:// or - > ftp:// and include that? - - Here's one way. Set the LOAD_PERL option: - - use Template; - - my $template = Template->new({ - LOAD_PERL => 1 - }); - $template->process("example.tt", { stdout => *STDOUT }) - || die $template->error(); - - and then use LWP::UserAgent and HTTP::Request: - - [% - USE ua = LWP.UserAgent; - ua.proxy("http", "http://your_proxy/"); - USE req = HTTP.Request("GET", "http://www.cpan.org"); - ua.request(req).content; - -%] - - For FTP use Net::FTP: - - [% - USE ftp = Net.FTP("ftp.cpan.org"); - x = ftp.login("anonymous", "me@here.there"); - x = ftp.cwd("/"); - x = ftp.get("welcome.msg", stdout); - x = ftp.quit; - -%] - - Normally ftp.get would write the file into the current directory. - Instead we pass stdout as a second argument so that it is written - to stdout. We set stdout to STDOUT in the variables we pass to - process. - - Craig - -=head1 Miscellaneous - -=head2 How can I configure variables on a per-request basis? - -One easy way to acheive this is to define a single PRE_PROCESS template which -loads in other configuration files based on variables defined or other -conditions. - -For example, my setup usually looks something like this: - - PRE_PROCESS => 'config/main' - -config/main: - - [% DEFAULT style = 'text' - section = template.section or 'home'; - - PROCESS config/site - + config/urls - + config/macros - + "config/style/$style" - + "config/section/$section" - + ... - %] - -This allows me to set a single 'style' variable to control which config -file gets pre-processed to set my various style options (colours, img paths, -etc). For example: - -config/style/basic: - - [% style = { - name = style # save existing 'style' var as 'style.name' - - # define various other style variables.... - col = { - back => '#ffffff' - text => '#000000' - # ...etc... - } - - logo = { - # ...etc... - } - - # ...etc... - } - %] - -Each source template can declare which section it's in via a META -directive: - - [% META - title = 'General Information' - section = 'info' - %] - - ... - -This controls which section configuration file gets loaded to set various -other variables for defining the section title, menu, etc. - -config/section/info: - - [% section = { - name = section # save 'section' var as 'section.name' - title = 'Information' - menu = [ ... ] - # ...etc... - } - %] - -This illustrates the basic principal but you can extend it to perform -pretty much any kind of per-document initialisation that you require. - -=head1 AUTHOR - -Andy Wardley E<lt>abw@andywardley.comE<gt> - -L<http://www.andywardley.com/|http://www.andywardley.com/> - - - - -=head1 VERSION - -2.69, distributed as part of the -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - - - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Filters.pm b/lib/Template/Filters.pm deleted file mode 100644 index a9c4846..0000000 --- a/lib/Template/Filters.pm +++ /dev/null @@ -1,1448 +0,0 @@ -#============================================================= -*-Perl-*- -# -# Template::Filters -# -# DESCRIPTION -# Defines filter plugins as used by the FILTER directive. -# -# AUTHORS -# Andy Wardley <abw@kfs.org>, with a number of filters contributed -# by Leslie Michael Orchard <deus_x@nijacode.com> -# -# COPYRIGHT -# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -#---------------------------------------------------------------------------- -# -# $Id: Filters.pm,v 2.77 2004/01/13 16:19:10 abw Exp $ -# -#============================================================================ - -package Template::Filters; - -require 5.004; - -use strict; -use base qw( Template::Base ); -use vars qw( $VERSION $DEBUG $FILTERS $URI_ESCAPES $PLUGIN_FILTER ); -use Template::Constants; - -$VERSION = sprintf("%d.%02d", q$Revision: 2.77 $ =~ /(\d+)\.(\d+)/); - - -#------------------------------------------------------------------------ -# standard filters, defined in one of the following forms: -# name => \&static_filter -# name => [ \&subref, $is_dynamic ] -# If the $is_dynamic flag is set then the sub-routine reference -# is called to create a new filter each time it is requested; if -# not set, then it is a single, static sub-routine which is returned -# for every filter request for that name. -#------------------------------------------------------------------------ - -$FILTERS = { - # static filters - 'html' => \&html_filter, - 'html_para' => \&html_paragraph, - 'html_break' => \&html_para_break, - 'html_para_break' => \&html_para_break, - 'html_line_break' => \&html_line_break, - 'uri' => \&uri_filter, - 'upper' => sub { uc $_[0] }, - 'lower' => sub { lc $_[0] }, - 'ucfirst' => sub { ucfirst $_[0] }, - 'lcfirst' => sub { lcfirst $_[0] }, - 'stderr' => sub { print STDERR @_; return '' }, - 'trim' => sub { for ($_[0]) { s/^\s+//; s/\s+$// }; $_[0] }, - 'null' => sub { return '' }, - 'collapse' => sub { for ($_[0]) { s/^\s+//; s/\s+$//; s/\s+/ /g }; - $_[0] }, - - # dynamic filters - 'html_entity' => [ \&html_entity_filter_factory, 1 ], - 'indent' => [ \&indent_filter_factory, 1 ], - 'format' => [ \&format_filter_factory, 1 ], - 'truncate' => [ \&truncate_filter_factory, 1 ], - 'repeat' => [ \&repeat_filter_factory, 1 ], - 'replace' => [ \&replace_filter_factory, 1 ], - 'remove' => [ \&remove_filter_factory, 1 ], - 'eval' => [ \&eval_filter_factory, 1 ], - 'evaltt' => [ \&eval_filter_factory, 1 ], # alias - 'perl' => [ \&perl_filter_factory, 1 ], - 'evalperl' => [ \&perl_filter_factory, 1 ], # alias - 'redirect' => [ \&redirect_filter_factory, 1 ], - 'file' => [ \&redirect_filter_factory, 1 ], # alias - 'stdout' => [ \&stdout_filter_factory, 1 ], - 'latex' => [ \&latex_filter_factory, 1 ], -}; - -# name of module implementing plugin filters -$PLUGIN_FILTER = 'Template::Plugin::Filter'; - - -#======================================================================== -# -- PUBLIC METHODS -- -#======================================================================== - -#------------------------------------------------------------------------ -# fetch($name, \@args, $context) -# -# Attempts to instantiate or return a reference to a filter sub-routine -# named by the first parameter, $name, with additional constructor -# arguments passed by reference to a list as the second parameter, -# $args. A reference to the calling Template::Context object is -# passed as the third paramter. -# -# Returns a reference to a filter sub-routine or a pair of values -# (undef, STATUS_DECLINED) or ($error, STATUS_ERROR) to decline to -# deliver the filter or to indicate an error. -#------------------------------------------------------------------------ - -sub fetch { - my ($self, $name, $args, $context) = @_; - my ($factory, $is_dynamic, $filter, $error); - - $self->debug("fetch($name, ", - defined $args ? ('[ ', join(', ', @$args), ' ]') : '<no args>', ', ', - defined $context ? $context : '<no context>', - ')') if $self->{ DEBUG }; - - # allow $name to be specified as a reference to - # a plugin filter object; any other ref is - # assumed to be a coderef and hence already a filter; - # non-refs are assumed to be regular name lookups - - if (ref $name) { - if (UNIVERSAL::isa($name, $PLUGIN_FILTER)) { - $factory = $name->factory() - || return $self->error($name->error()); - } - else { - return $name; - } - } - else { - return (undef, Template::Constants::STATUS_DECLINED) - unless ($factory = $self->{ FILTERS }->{ $name } - || $FILTERS->{ $name }); - } - - # factory can be an [ $code, $dynamic ] or just $code - if (ref $factory eq 'ARRAY') { - ($factory, $is_dynamic) = @$factory; - } - else { - $is_dynamic = 0; - } - - if (ref $factory eq 'CODE') { - if ($is_dynamic) { - # if the dynamic flag is set then the sub-routine is a - # factory which should be called to create the actual - # filter... - eval { - ($filter, $error) = &$factory($context, $args ? @$args : ()); - }; - $error ||= $@; - $error = "invalid FILTER for '$name' (not a CODE ref)" - unless $error || ref($filter) eq 'CODE'; - } - else { - # ...otherwise, it's a static filter sub-routine - $filter = $factory; - } - } - else { - $error = "invalid FILTER entry for '$name' (not a CODE ref)"; - } - - if ($error) { - return $self->{ TOLERANT } - ? (undef, Template::Constants::STATUS_DECLINED) - : ($error, Template::Constants::STATUS_ERROR) ; - } - else { - return $filter; - } -} - - -#------------------------------------------------------------------------ -# store($name, \&filter) -# -# Stores a new filter in the internal FILTERS hash. The first parameter -# is the filter name, the second a reference to a subroutine or -# array, as per the standard $FILTERS entries. -#------------------------------------------------------------------------ - -sub store { - my ($self, $name, $filter) = @_; - - $self->debug("store($name, $filter)") if $self->{ DEBUG }; - - $self->{ FILTERS }->{ $name } = $filter; - return 1; -} - - -#======================================================================== -# -- PRIVATE METHODS -- -#======================================================================== - -#------------------------------------------------------------------------ -# _init(\%config) -# -# Private initialisation method. -#------------------------------------------------------------------------ - -sub _init { - my ($self, $params) = @_; - - $self->{ FILTERS } = $params->{ FILTERS } || { }; - $self->{ TOLERANT } = $params->{ TOLERANT } || 0; - $self->{ DEBUG } = ( $params->{ DEBUG } || 0 ) - & Template::Constants::DEBUG_FILTERS; - - - return $self; -} - - - -#------------------------------------------------------------------------ -# _dump() -# -# Debug method -#------------------------------------------------------------------------ - -sub _dump { - my $self = shift; - my $output = "[Template::Filters] {\n"; - my $format = " %-16s => %s\n"; - my $key; - - foreach $key (qw( TOLERANT )) { - my $val = $self->{ $key }; - $val = '<undef>' unless defined $val; - $output .= sprintf($format, $key, $val); - } - - my $filters = $self->{ FILTERS }; - $filters = join('', map { - sprintf(" $format", $_, $filters->{ $_ }); - } keys %$filters); - $filters = "{\n$filters }"; - - $output .= sprintf($format, 'FILTERS (local)' => $filters); - - $filters = $FILTERS; - $filters = join('', map { - my $f = $filters->{ $_ }; - my ($ref, $dynamic) = ref $f eq 'ARRAY' ? @$f : ($f, 0); - sprintf(" $format", $_, $dynamic ? 'dynamic' : 'static'); - } sort keys %$filters); - $filters = "{\n$filters }"; - - $output .= sprintf($format, 'FILTERS (global)' => $filters); - - $output .= '}'; - return $output; -} - - -#======================================================================== -# -- STATIC FILTER SUBS -- -#======================================================================== - -#------------------------------------------------------------------------ -# uri_filter() [% FILTER uri %] -# -# URI escape a string. This code is borrowed from Gisle Aas' URI::Escape -# module. For something so simple, I can't see any validation in making -# the user install the URI modules just for this, so we cut and paste. -# -# URI::Escape is Copyright 1995-2000 Gisle Aas. -#------------------------------------------------------------------------ - -sub uri_filter { - my $text = shift; - - # construct and cache a lookup table for escapes (faster than - # doing a sprintf() for every character in every string each - # time) - $URI_ESCAPES ||= { - map { ( chr($_), sprintf("%%%02X", $_) ) } (0..255), - }; - - $text =~ s/([^;\/?:@&=+\$,A-Za-z0-9\-_.!~*'()])/$URI_ESCAPES->{$1}/g; - $text; -} - - -#------------------------------------------------------------------------ -# html_filter() [% FILTER html %] -# -# Convert any '<', '>' or '&' characters to the HTML equivalents, '<', -# '>' and '&', respectively. -#------------------------------------------------------------------------ - -sub html_filter { - my $text = shift; - for ($text) { - s/&/&/g; - s/</</g; - s/>/>/g; - s/"/"/g; - } - return $text; -} - - -#------------------------------------------------------------------------ -# html_paragraph() [% FILTER html_para %] -# -# Wrap each paragraph of text (delimited by two or more newlines) in the -# <p>...</p> HTML tags. -#------------------------------------------------------------------------ - -sub html_paragraph { - my $text = shift; - return "<p>\n" - . join("\n</p>\n\n<p>\n", split(/(?:\r?\n){2,}/, $text)) - . "</p>\n"; -} - - -#------------------------------------------------------------------------ -# html_para_break() [% FILTER html_para_break %] -# -# Join each paragraph of text (delimited by two or more newlines) with -# <br><br> HTML tags. -#------------------------------------------------------------------------ - -sub html_para_break { - my $text = shift; - $text =~ s|(\r?\n){2,}|$1<br />$1<br />$1|g; - return $text; -} - -#------------------------------------------------------------------------ -# html_line_break() [% FILTER html_line_break %] -# -# replaces any newlines with <br> HTML tags. -#------------------------------------------------------------------------ - -sub html_line_break { - my $text = shift; - $text =~ s|(\r?\n)|<br />$1|g; - return $text; -} - -#======================================================================== -# -- DYNAMIC FILTER FACTORIES -- -#======================================================================== - -#------------------------------------------------------------------------ -# html_entity_filter_factory(\%options) [% FILTER html %] -# -# Dynamic version of the static html filter which attempts to locate the -# Apache::Util or HTML::Entities modules to perform full entity encoding -# of the text passed. Returns an exception if one or other of the -# modules can't be located. -#------------------------------------------------------------------------ - -sub html_entity_filter_factory { - my $context = shift; - - # if Apache::Util is installed then we use it - eval { - require Apache::Util; - Apache::Util::escape_html(''); - }; - return \&Apache::Util::escape_html - unless $@; - - # otherwise if HTML::Entities is installed then we use that - eval { - require HTML::Entities; - }; - return \&HTML::Entities::encode_entities - unless $@; - - return (undef, Template::Exception->new( html_entity => - 'cannot locate Apache::Util or HTML::Entities' )); - -} - - -#------------------------------------------------------------------------ -# indent_filter_factory($pad) [% FILTER indent(pad) %] -# -# Create a filter to indent text by a fixed pad string or when $pad is -# numerical, a number of space. -#------------------------------------------------------------------------ - -sub indent_filter_factory { - my ($context, $pad) = @_; - $pad = 4 unless defined $pad; - $pad = ' ' x $pad if $pad =~ /^\d+$/; - - return sub { - my $text = shift; - $text = '' unless defined $text; - $text =~ s/^/$pad/mg; - return $text; - } -} - -#------------------------------------------------------------------------ -# format_filter_factory() [% FILTER format(format) %] -# -# Create a filter to format text according to a printf()-like format -# string. -#------------------------------------------------------------------------ - -sub format_filter_factory { - my ($context, $format) = @_; - $format = '%s' unless defined $format; - - return sub { - my $text = shift; - $text = '' unless defined $text; - return join("\n", map{ sprintf($format, $_) } split(/\n/, $text)); - } -} - - -#------------------------------------------------------------------------ -# repeat_filter_factory($n) [% FILTER repeat(n) %] -# -# Create a filter to repeat text n times. -#------------------------------------------------------------------------ - -sub repeat_filter_factory { - my ($context, $iter) = @_; - $iter = 1 unless defined $iter and length $iter; - - return sub { - my $text = shift; - $text = '' unless defined $text; - return join('\n', $text) x $iter; - } -} - - -#------------------------------------------------------------------------ -# replace_filter_factory($s, $r) [% FILTER replace(search, replace) %] -# -# Create a filter to replace 'search' text with 'replace' -#------------------------------------------------------------------------ - -sub replace_filter_factory { - my ($context, $search, $replace) = @_; - $search = '' unless defined $search; - $replace = '' unless defined $replace; - - return sub { - my $text = shift; - $text = '' unless defined $text; - $text =~ s/$search/$replace/g; - return $text; - } -} - - -#------------------------------------------------------------------------ -# remove_filter_factory($text) [% FILTER remove(text) %] -# -# Create a filter to remove 'search' string from the input text. -#------------------------------------------------------------------------ - -sub remove_filter_factory { - my ($context, $search) = @_; - - return sub { - my $text = shift; - $text = '' unless defined $text; - $text =~ s/$search//g; - return $text; - } -} - - -#------------------------------------------------------------------------ -# truncate_filter_factory($n) [% FILTER truncate(n) %] -# -# Create a filter to truncate text after n characters. -#------------------------------------------------------------------------ - -sub truncate_filter_factory { - my ($context, $len) = @_; - $len = 32 unless defined $len; - - return sub { - my $text = shift; - return $text if length $text < $len; - return substr($text, 0, $len - 3) . "..."; - } -} - - -#------------------------------------------------------------------------ -# eval_filter_factory [% FILTER eval %] -# -# Create a filter to evaluate template text. -#------------------------------------------------------------------------ - -sub eval_filter_factory { - my $context = shift; - - return sub { - my $text = shift; - $context->process(\$text); - } -} - - -#------------------------------------------------------------------------ -# perl_filter_factory [% FILTER perl %] -# -# Create a filter to process Perl text iff the context EVAL_PERL flag -# is set. -#------------------------------------------------------------------------ - -sub perl_filter_factory { - my $context = shift; - my $stash = $context->stash; - - return (undef, Template::Exception->new('perl', 'EVAL_PERL is not set')) - unless $context->eval_perl(); - - return sub { - my $text = shift; - local($Template::Perl::context) = $context; - local($Template::Perl::stash) = $stash; - my $out = eval <<EOF; -package Template::Perl; -\$stash = \$context->stash(); -$text -EOF - $context->throw($@) if $@; - return $out; - } -} - - -#------------------------------------------------------------------------ -# redirect_filter_factory($context, $file) [% FILTER redirect(file) %] -# -# Create a filter to redirect the block text to a file. -#------------------------------------------------------------------------ - -sub redirect_filter_factory { - my ($context, $file, $options) = @_; - my $outpath = $context->config->{ OUTPUT_PATH }; - - return (undef, Template::Exception->new('redirect', - 'OUTPUT_PATH is not set')) - unless $outpath; - - $options = { binmode => $options } unless ref $options; - - sub { - my $text = shift; - my $outpath = $context->config->{ OUTPUT_PATH } - || return ''; - $outpath .= "/$file"; - my $error = Template::_output($outpath, \$text, $options); - die Template::Exception->new('redirect', $error) - if $error; - return ''; - } -} - - -#------------------------------------------------------------------------ -# stdout_filter_factory($context, $binmode) [% FILTER stdout(binmode) %] -# -# Create a filter to print a block to stdout, with an optional binmode. -#------------------------------------------------------------------------ - -sub stdout_filter_factory { - my ($context, $options) = @_; - - $options = { binmode => $options } unless ref $options; - - sub { - my $text = shift; - binmode(STDOUT) if $options->{ binmode }; - print STDOUT $text; - return ''; - } -} - - -#------------------------------------------------------------------------ -# latex_filter_factory($context, $outputType) [% FILTER latex(outputType) %] -# -# Return a filter sub that converts a (hopefully) complete LaTeX source -# file to either "ps", "dvi", or "pdf". Output type should be "ps", "dvi" -# or "pdf" (pdf is default). -# -# Creates a temporary directory below File::Spec->tmpdir() (often /tmp) -# and writes the text into doc.tex. It then runs either pdflatex or -# latex and optionally dvips. Based on the exit status either returns -# the entire doc.(pdf|ps|dvi) output or throws an error with a summary -# of the error messages from doc.log. -# -# Written by Craig Barratt, Apr 28 2001. -# Win32 additions by Richard Tietjen. -#------------------------------------------------------------------------ -use File::Path; -use File::Spec; -use Cwd; - -sub latex_filter_factory -{ - my($context, $output) = @_; - - $output = lc($output); - my $fName = "latex"; - my($LaTeXPath, $PdfLaTeXPath, $DviPSPath) - = @{Template::Config->latexpaths()}; - if ( $output eq "ps" || $output eq "dvi" ) { - $context->throw($fName, - "latex not installed (see Template::Config::LATEX_PATH)") - if ( $LaTeXPath eq "" ); - } else { - $output = "pdf"; - $LaTeXPath = $PdfLaTeXPath; - $context->throw($fName, - "pdflatex not installed (see Template::Config::PDFLATEX_PATH)") - if ( $LaTeXPath eq "" ); - } - if ( $output eq "ps" && $DviPSPath eq "" ) { - $context->throw($fName, - "dvips not installed (see Template::Config::DVIPS_PATH)"); - } - if ( $^O !~ /^(MacOS|os2|VMS)$/i ) { - return sub { - local(*FH); - my $text = shift; - my $tmpRootDir = File::Spec->tmpdir(); - my $cnt = 0; - my($tmpDir, $fileName, $devnull); - my $texDoc = 'doc'; - - do { - $tmpDir = File::Spec->catdir($tmpRootDir, - "tt2latex$$" . "_$cnt"); - $cnt++; - } while ( -e $tmpDir ); - mkpath($tmpDir, 0, 0700); - $context->throw($fName, "can't create temp dir $tmpDir") - if ( !-d $tmpDir ); - $fileName = File::Spec->catfile($tmpDir, "$texDoc.tex"); - $devnull = File::Spec->devnull(); - if ( !open(FH, ">$fileName") ) { - rmtree($tmpDir); - $context->throw($fName, "can't open $fileName for output"); - } - print(FH $text); - close(FH); - - # latex must run in tmpDir directory - my $currDir = cwd(); - if ( !chdir($tmpDir) ) { - rmtree($tmpDir); - $context->throw($fName, "can't chdir $tmpDir"); - } - # - # We don't need to quote the backslashes on windows, but we - # do on other OSs - # - my $LaTeX_arg = "\\nonstopmode\\input{$texDoc}"; - $LaTeX_arg = "'$LaTeX_arg'" if ( $^O ne 'MSWin32' ); - if ( system("$LaTeXPath $LaTeX_arg" - . " 1>$devnull 2>$devnull 0<$devnull") ) { - my $texErrs = ""; - $fileName = File::Spec->catfile($tmpDir, "$texDoc.log"); - if ( open(FH, "<$fileName") ) { - my $state = 0; - # - # Try to extract just the interesting errors from - # the verbose log file - # - while ( <FH> ) { - # - # TeX errors seems to start with a "!" at the - # start of the line, and are followed several - # lines later by a line designator of the - # form "l.nnn" where nnn is the line number. - # We make sure we pick up every /^!/ line, and - # the first /^l.\d/ line after each /^!/ line. - # - if ( /^(!.*)/ ) { - $texErrs .= $1 . "\n"; - $state = 1; - } - if ( $state == 1 && /^(l\.\d.*)/ ) { - $texErrs .= $1 . "\n"; - $state = 0; - } - } - close(FH); - } else { - $texErrs = "Unable to open $fileName\n"; - } - my $ok = chdir($currDir); - rmtree($tmpDir); - $context->throw($fName, "can't chdir $currDir") if ( !$ok ); - $context->throw($fName, "latex exited with errors:\n$texErrs"); - } - if ( $output eq "ps" ) { - $fileName = File::Spec->catfile($tmpDir, "$texDoc.dvi"); - if ( system("$DviPSPath $texDoc -o" - . " 1>$devnull 2>$devnull 0<$devnull") ) { - my $ok = chdir($currDir); - rmtree($tmpDir); - $context->throw($fName, "can't chdir $currDir") if ( !$ok ); - $context->throw($fName, "can't run $DviPSPath $fileName"); - } - } - if ( !chdir($currDir) ) { - rmtree($tmpDir); - $context->throw($fName, "can't chdir $currDir"); - } - - my $retStr; - $fileName = File::Spec->catfile($tmpDir, "$texDoc.$output"); - if ( open(FH, $fileName) ) { - local $/ = undef; # slurp file in one go - binmode(FH); - $retStr = <FH>; - close(FH); - } else { - rmtree($tmpDir); - $context->throw($fName, "Can't open output file $fileName"); - } - rmtree($tmpDir); - return $retStr; - } - } else { - $context->throw("$fName not yet supported on $^O OS." - . " Please contribute code!!"); - } -} - -1; - -__END__ - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Filters - Post-processing filters for template blocks - -=head1 SYNOPSIS - - use Template::Filters; - - $filters = Template::Filters->new(\%config); - - ($filter, $error) = $filters->fetch($name, \@args, $context); - -=head1 DESCRIPTION - -The Template::Filters module implements a provider for creating and/or -returning subroutines that implement the standard filters. Additional -custom filters may be provided via the FILTERS options. - -=head1 METHODS - -=head2 new(\%params) - -Constructor method which instantiates and returns a reference to a -Template::Filters object. A reference to a hash array of configuration -items may be passed as a parameter. These are described below. - - my $filters = Template::Filters->new({ - FILTERS => { ... }, - }); - - my $template = Template->new({ - LOAD_FILTERS => [ $filters ], - }); - -A default Template::Filters module is created by the Template.pm module -if the LOAD_FILTERS option isn't specified. All configuration parameters -are forwarded to the constructor. - - $template = Template->new({ - FILTERS => { ... }, - }); - -=head2 fetch($name, \@args, $context) - -Called to request that a filter of a given name be provided. The name -of the filter should be specified as the first parameter. This should -be one of the standard filters or one specified in the FILTERS -configuration hash. The second argument should be a reference to an -array containing configuration parameters for the filter. This may be -specified as 0, or undef where no parameters are provided. The third -argument should be a reference to the current Template::Context -object. - -The method returns a reference to a filter sub-routine on success. It -may also return (undef, STATUS_DECLINE) to decline the request, to allow -delegation onto other filter providers in the LOAD_FILTERS chain of -responsibility. On error, ($error, STATUS_ERROR) is returned where $error -is an error message or Template::Exception object indicating the error -that occurred. - -When the TOLERANT option is set, errors are automatically downgraded to -a STATUS_DECLINE response. - - -=head1 CONFIGURATION OPTIONS - -The following list details the configuration options that can be provided -to the Template::Filters new() constructor. - -=over 4 - - - - -=item FILTERS - -The FILTERS option can be used to specify custom filters which can -then be used with the FILTER directive like any other. These are -added to the standard filters which are available by default. Filters -specified via this option will mask any standard filters of the same -name. - -The FILTERS option should be specified as a reference to a hash array -in which each key represents the name of a filter. The corresponding -value should contain a reference to an array containing a subroutine -reference and a flag which indicates if the filter is static (0) or -dynamic (1). A filter may also be specified as a solitary subroutine -reference and is assumed to be static. - - $filters = Template::Filters->new({ - FILTERS => { - 'sfilt1' => \&static_filter, # static - 'sfilt2' => [ \&static_filter, 0 ], # same as above - 'dfilt1' => [ \&dyanamic_filter_factory, 1 ], - }, - }); - -Additional filters can be specified at any time by calling the -define_filter() method on the current Template::Context object. -The method accepts a filter name, a reference to a filter -subroutine and an optional flag to indicate if the filter is -dynamic. - - my $context = $template->context(); - $context->define_filter('new_html', \&new_html); - $context->define_filter('new_repeat', \&new_repeat, 1); - -Static filters are those where a single subroutine reference is used -for all invocations of a particular filter. Filters that don't accept -any configuration parameters (e.g. 'html') can be implemented -statically. The subroutine reference is simply returned when that -particular filter is requested. The subroutine is called to filter -the output of a template block which is passed as the only argument. -The subroutine should return the modified text. - - sub static_filter { - my $text = shift; - # do something to modify $text... - return $text; - } - -The following template fragment: - - [% FILTER sfilt1 %] - Blah blah blah. - [% END %] - -is approximately equivalent to: - - &static_filter("\nBlah blah blah.\n"); - -Filters that can accept parameters (e.g. 'truncate') should be -implemented dynamically. In this case, the subroutine is taken to be -a filter 'factory' that is called to create a unique filter subroutine -each time one is requested. A reference to the current -Template::Context object is passed as the first parameter, followed by -any additional parameters specified. The subroutine should return -another subroutine reference (usually a closure) which implements the -filter. - - sub dynamic_filter_factory { - my ($context, @args) = @_; - - return sub { - my $text = shift; - # do something to modify $text... - return $text; - } - } - -The following template fragment: - - [% FILTER dfilt1(123, 456) %] - Blah blah blah - [% END %] - -is approximately equivalent to: - - my $filter = &dynamic_filter_factory($context, 123, 456); - &$filter("\nBlah blah blah.\n"); - -See the FILTER directive for further examples. - - - - -=item TOLERANT - -The TOLERANT flag is used by the various Template Toolkit provider -modules (Template::Provider, Template::Plugins, Template::Filters) to -control their behaviour when errors are encountered. By default, any -errors are reported as such, with the request for the particular -resource (template, plugin, filter) being denied and an exception -raised. When the TOLERANT flag is set to any true values, errors will -be silently ignored and the provider will instead return -STATUS_DECLINED. This allows a subsequent provider to take -responsibility for providing the resource, rather than failing the -request outright. If all providers decline to service the request, -either through tolerated failure or a genuine disinclination to -comply, then a 'E<lt>resourceE<gt> not found' exception is raised. - - - - -=item DEBUG - -The DEBUG option can be used to enable debugging messages from the -Template::Filters module by setting it to include the DEBUG_FILTERS -value. - - use Template::Constants qw( :debug ); - - my $template = Template->new({ - DEBUG => DEBUG_FILTERS | DEBUG_PLUGINS, - }); - - - - -=back - -=head1 TEMPLATE TOOLKIT FILTERS - -The following standard filters are distributed with the Template Toolkit. - - - -=head2 format(format) - -The 'format' filter takes a format string as a parameter (as per -printf()) and formats each line of text accordingly. - - [% FILTER format('<!-- %-40s -->') %] - This is a block of text filtered - through the above format. - [% END %] - -output: - - <!-- This is a block of text filtered --> - <!-- through the above format. --> - -=head2 upper - -Folds the input to UPPER CASE. - - [% "hello world" FILTER upper %] - -output: - - HELLO WORLD - -=head2 lower - -Folds the input to lower case. - - [% "Hello World" FILTER lower %] - -output: - - hello world - -=head2 ucfirst - -Folds the first character of the input to UPPER CASE. - - [% "hello" FILTER ucfirst %] - -output: - - Hello - -=head2 lcfirst - -Folds the first character of the input to lower case. - - [% "HELLO" FILTER lcfirst %] - -output: - - hELLO - -=head2 trim - -Trims any leading or trailing whitespace from the input text. Particularly -useful in conjunction with INCLUDE, PROCESS, etc., having the same effect -as the TRIM configuration option. - - [% INCLUDE myfile | trim %] - -=head2 collapse - -Collapse any whitespace sequences in the input text into a single space. -Leading and trailing whitespace (which would be reduced to a single space) -is removed, as per trim. - - [% FILTER collapse %] - - The cat - - sat on - - the mat - - [% END %] - -output: - - The cat sat on the mat - -=head2 html - -Converts the characters 'E<lt>', 'E<gt>' and '&' to '<', '>' and -'&', respectively, protecting them from being interpreted as -representing HTML tags or entities. - - [% FILTER html %] - Binary "<=>" returns -1, 0, or 1 depending on... - [% END %] - -output: - - Binary "<=>" returns -1, 0, or 1 depending on... - -=head2 html_entity - -The html filter is fast and simple but it doesn't encode the full -range of HTML entities that your text may contain. The html_entity -filter uses either the Apache::Util module (which is written in C and -is therefore faster) or the HTML::Entities module (written in Perl but -equally as comprehensive) to perform the encoding. If one or other of -these modules are installed on your system then the text will be -encoded (via the escape_html() or encode_entities() subroutines -respectively) to convert all extended characters into their -appropriate HTML entities (e.g. converting 'é' to 'é'). If -neither module is available on your system then an 'html_entity' exception -will be thrown reporting an appropriate message. - -For further information on HTML entity encoding, see -http://www.w3.org/TR/REC-html40/sgml/entities.html. - -=head2 html_para - -This filter formats a block of text into HTML paragraphs. A sequence of -two or more newlines is used as the delimiter for paragraphs which are -then wrapped in HTML E<lt>pE<gt>...E<lt>/pE<gt> tags. - - [% FILTER html_para %] - The cat sat on the mat. - - Mary had a little lamb. - [% END %] - -output: - - <p> - The cat sat on the mat. - </p> - - <p> - Mary had a little lamb. - </p> - -=head2 html_break / html_para_break - -Similar to the html_para filter described above, but uses the HTML tag -sequence E<lt>brE<gt>E<lt>brE<gt> to join paragraphs. - - [% FILTER html_break %] - The cat sat on the mat. - - Mary had a little lamb. - [% END %] - -output: - - The cat sat on the mat. - <br> - <br> - Mary had a little lamb. - -=head2 html_line_break - -This filter replaces any newlines with E<lt>brE<gt> HTML tags, -thus preserving the line breaks of the original text in the -HTML output. - - [% FILTER html_line_break %] - The cat sat on the mat. - Mary had a little lamb. - [% END %] - -output: - - The cat sat on the mat.<br> - Mary had a little lamb.<br> - -=head2 uri - -This filter URI escapes the input text, converting any characters -outside of the permitted URI character set (as defined by RFC 2396) -into a C<%nn> hex escape. - - [% 'my file.html' | uri %] - -output: - - my%20file.html - -Note that URI escaping isn't always enough when generating hyperlinks in -an HTML document. The C<&> character, for example, is valid in a URI and -will not be escaped by the URI filter. In this case you should also filter -the text through the 'html' filter. - - <a href="[% filename | uri | html %]">click here</a> - -=head2 indent(pad) - -Indents the text block by a fixed pad string or width. The 'pad' argument -can be specified as a string, or as a numerical value to indicate a pad -width (spaces). Defaults to 4 spaces if unspecified. - - [% FILTER indent('ME> ') %] - blah blah blah - cabbages, rhubard, onions - [% END %] - -output: - - ME> blah blah blah - ME> cabbages, rhubard, onions - -=head2 truncate(length) - -Truncates the text block to the length specified, or a default length of -32. Truncated text will be terminated with '...' (i.e. the '...' falls -inside the required length, rather than appending to it). - - [% FILTER truncate(21) %] - I have much to say on this matter that has previously - been said on more than one occasion. - [% END %] - -output: - - I have much to say... - -=head2 repeat(iterations) - -Repeats the text block for as many iterations as are specified (default: 1). - - [% FILTER repeat(3) %] - We want more beer and we want more beer, - [% END %] - We are the more beer wanters! - -output: - - We want more beer and we want more beer, - We want more beer and we want more beer, - We want more beer and we want more beer, - We are the more beer wanters! - -=head2 remove(string) - -Searches the input text for any occurrences of the specified string and -removes them. A Perl regular expression may be specified as the search -string. - - [% "The cat sat on the mat" FILTER remove('\s+') %] - -output: - - Thecatsatonthemat - -=head2 replace(search, replace) - -Similar to the remove filter described above, but taking a second parameter -which is used as a replacement string for instances of the search string. - - [% "The cat sat on the mat" | replace('\s+', '_') %] - -output: - - The_cat_sat_on_the_mat - -=head2 redirect(file, options) - -The 'redirect' filter redirects the output of the block into a separate -file, specified relative to the OUTPUT_PATH configuration item. - - [% FOREACH user = myorg.userlist %] - [% FILTER redirect("users/${user.id}.html") %] - [% INCLUDE userinfo %] - [% END %] - [% END %] - -or more succinctly, using side-effect notation: - - [% INCLUDE userinfo - FILTER redirect("users/${user.id}.html") - FOREACH user = myorg.userlist - %] - -A 'file' exception will be thrown if the OUTPUT_PATH option is undefined. - -An optional 'binmode' argument can follow the filename to explicitly set -the output file to binary mode. - - [% PROCESS my/png/generator - FILTER redirect("images/logo.png", binmode=1) %] - -For backwards compatibility with earlier versions, a single true/false -value can be used to set binary mode. - - [% PROCESS my/png/generator - FILTER redirect("images/logo.png", 1) %] - -For the sake of future compatibility and clarity, if nothing else, we -would strongly recommend you explicitly use the named 'binmode' option -as shown in the first example. - -=head2 eval / evaltt - -The 'eval' filter evaluates the block as template text, processing -any directives embedded within it. This allows template variables to -contain template fragments, or for some method to be provided for -returning template fragments from an external source such as a -database, which can then be processed in the template as required. - - my $vars = { - fragment => "The cat sat on the [% place %]", - }; - $template->process($file, $vars); - -The following example: - - [% fragment | eval %] - -is therefore equivalent to - - The cat sat on the [% place %] - -The 'evaltt' filter is provided as an alias for 'eval'. - -=head2 perl / evalperl - -The 'perl' filter evaluates the block as Perl code. The EVAL_PERL -option must be set to a true value or a 'perl' exception will be -thrown. - - [% my_perl_code | perl %] - -In most cases, the [% PERL %] ... [% END %] block should suffice for -evaluating Perl code, given that template directives are processed -before being evaluate as Perl. Thus, the previous example could have -been written in the more verbose form: - - [% PERL %] - [% my_perl_code %] - [% END %] - -as well as - - [% FILTER perl %] - [% my_perl_code %] - [% END %] - -The 'evalperl' filter is provided as an alias for 'perl' for backwards -compatibility. - -=head2 stdout(options) - -The stdout filter prints the output generated by the enclosing block to -STDOUT. The 'binmode' option can be passed as either a named parameter -or a single argument to set STDOUT to binary mode (see the -binmode perl function). - - [% PROCESS something/cool - FILTER stdout(binmode=1) # recommended %] - - [% PROCESS something/cool - FILTER stdout(1) # alternate %] - -The stdout filter can be used to force binmode on STDOUT, or also inside -redirect, null or stderr blocks to make sure that particular output goes -to stdout. See the null filter below for an example. - -=head2 stderr - -The stderr filter prints the output generated by the enclosing block to -STDERR. - -=head2 null - -The null filter prints nothing. This is useful for plugins whose -methods return values that you don't want to appear in the output. -Rather than assigning every plugin method call to a dummy variable -to silence it, you can wrap the block in a null filter: - - [% FILTER null; - USE im = GD.Image(100,100); - black = im.colorAllocate(0, 0, 0); - red = im.colorAllocate(255,0, 0); - blue = im.colorAllocate(0, 0, 255); - im.arc(50,50,95,75,0,360,blue); - im.fill(50,50,red); - im.png | stdout(1); - END; - -%] - -Notice the use of the stdout filter to ensure that a particular expression -generates output to stdout (in this case in binary mode). - -=head2 latex(outputType) - -Passes the text block to LaTeX and produces either PDF, DVI or -PostScript output. The 'outputType' argument determines the output -format and it should be set to one of the strings: "pdf" (default), -"dvi", or "ps". - -The text block should be a complete LaTeX source file. - - [% FILTER latex("pdf") -%] - \documentclass{article} - - \begin{document} - - \title{A Sample TT2 \LaTeX\ Source File} - \author{Craig Barratt} - \maketitle - - \section{Introduction} - This is some text. - - \end{document} - [% END -%] - -The output will be a PDF file. You should be careful not to prepend or -append any extraneous characters or text outside the FILTER block, -since this text will wrap the (binary) output of the latex filter. -Notice the END directive uses '-%]' for the END_TAG to remove the -trailing new line. - -One example where you might prepend text is in a CGI script where -you might include the Content-Type before the latex output, eg: - - Content-Type: application/pdf - - [% FILTER latex("pdf") -%] - \documentclass{article} - \begin{document} - ... - \end{document} - [% END -%] - -In other cases you might use the redirect filter to put the output -into a file, rather than delivering it to stdout. This might be -suitable for batch scripts: - - [% output = FILTER latex("pdf") -%] - \documentclass{article} - \begin{document} - ... - \end{document} - [% END; output | redirect("document.pdf", 1) -%] - -(Notice the second argument to redirect to force binary mode.) - -Note that the latex filter runs one or two external programs, so it -isn't very fast. But for modest documents the performance is adequate, -even for interactive applications. - -A error of type 'latex' will be thrown if there is an error reported -by latex, pdflatex or dvips. - -=head1 AUTHOR - -Andy Wardley E<lt>abw@andywardley.comE<gt> - -L<http://www.andywardley.com/|http://www.andywardley.com/> - - - - -=head1 VERSION - -2.77, distributed as part of the -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -=head1 SEE ALSO - -L<Template|Template>, L<Template::Context|Template::Context>, L<Template::Manual::Filters|Template::Manual::Filters> - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Grammar.pm b/lib/Template/Grammar.pm deleted file mode 100644 index 8635426..0000000 --- a/lib/Template/Grammar.pm +++ /dev/null @@ -1,6179 +0,0 @@ -#============================================================= -*-Perl-*- -# -# Template::Grammar -# -# DESCRIPTION -# Grammar file for the Template Toolkit language containing token -# definitions and parser state/rules tables generated by Parse::Yapp. -# -# AUTHOR -# Andy Wardley <abw@wardley.org> -# -# COPYRIGHT -# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -#------------------------------------------------------------------------ -# -# NOTE: this module is constructed from the parser/Grammar.pm.skel -# file by running the parser/yc script. You only need to do this if -# you have modified the grammar in the parser/Parser.yp file and need -# to-recompile it. See the README in the 'parser' directory for more -# information (sub-directory of the Template distribution). -# -#------------------------------------------------------------------------ -# -# $Id: Grammar.pm,v 2.22 2004/01/13 16:19:10 abw Exp $ -# -#======================================================================== - -package Template::Grammar; - -require 5.004; - -use strict; -use vars qw( $VERSION ); - -$VERSION = sprintf("%d.%02d", q$Revision: 2.22 $ =~ /(\d+)\.(\d+)/); - -my (@RESERVED, %CMPOP, $LEXTABLE, $RULES, $STATES); -my ($factory, $rawstart); - - -#======================================================================== - -# Reserved words, comparison and binary operators -#======================================================================== - -@RESERVED = qw( - GET CALL SET DEFAULT INSERT INCLUDE PROCESS WRAPPER BLOCK END - USE PLUGIN FILTER MACRO PERL RAWPERL TO STEP AND OR NOT DIV MOD - IF UNLESS ELSE ELSIF FOR NEXT WHILE SWITCH CASE META IN - TRY THROW CATCH FINAL LAST RETURN STOP CLEAR VIEW DEBUG - ); - -# for historical reasons, != and == are converted to ne and eq to perform -# stringwise comparison (mainly because it doesn't generate "non-numerical -# comparison" warnings which != and == can) but the others (e.g. < > <= >=) -# are not converted to their stringwise equivalents. I added 'gt' et al, -# briefly for v2.04d and then took them out again in 2.04e. - -%CMPOP = qw( - != ne - == eq - < < - > > - >= >= - <= <= -); - - -#======================================================================== -# Lexer Token Table -#======================================================================== - -# lookup table used by lexer is initialised with special-cases -$LEXTABLE = { - 'FOREACH' => 'FOR', - 'BREAK' => 'LAST', - '&&' => 'AND', - '||' => 'OR', - '!' => 'NOT', - '|' => 'FILTER', - '.' => 'DOT', - '_' => 'CAT', - '..' => 'TO', -# ':' => 'MACRO', - '=' => 'ASSIGN', - '=>' => 'ASSIGN', -# '->' => 'ARROW', - ',' => 'COMMA', - '\\' => 'REF', - 'and' => 'AND', # explicitly specified so that qw( and or - 'or' => 'OR', # not ) can always be used in lower case, - 'not' => 'NOT', # regardless of ANYCASE flag - 'mod' => 'MOD', - 'div' => 'DIV', -}; - -# localise the temporary variables needed to complete lexer table -{ -# my @tokens = qw< ( ) [ ] { } ${ $ / ; : ? >; - my @tokens = qw< ( ) [ ] { } ${ $ + / ; : ? >; - my @cmpop = keys %CMPOP; -# my @binop = qw( + - * % ); # '/' above, in @tokens - my @binop = qw( - * % ); # '+' and '/' above, in @tokens - - # fill lexer table, slice by slice, with reserved words and operators - @$LEXTABLE{ @RESERVED, @cmpop, @binop, @tokens } - = ( @RESERVED, ('CMPOP') x @cmpop, ('BINOP') x @binop, @tokens ); -} - - -#======================================================================== -# CLASS METHODS -#======================================================================== - -sub new { - my $class = shift; - bless { - LEXTABLE => $LEXTABLE, - STATES => $STATES, - RULES => $RULES, - }, $class; -} - -# update method to set package-scoped $factory lexical -sub install_factory { - my ($self, $new_factory) = @_; - $factory = $new_factory; -} - - -#======================================================================== -# States -#======================================================================== - -$STATES = [ - {#State 0 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'template' => 52, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'switch' => 34, - 'try' => 35, - 'assign' => 19, - 'block' => 72, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 1 - ACTIONS => { - "\$" => 43, - 'LITERAL' => 75, - 'IDENT' => 2, - "\${" => 37 - }, - GOTOS => { - 'setlist' => 76, - 'item' => 39, - 'assign' => 19, - 'node' => 23, - 'ident' => 74 - } - }, - {#State 2 - DEFAULT => -130 - }, - {#State 3 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 79, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 4 - DEFAULT => -23 - }, - {#State 5 - ACTIONS => { - ";" => 80 - } - }, - {#State 6 - DEFAULT => -37 - }, - {#State 7 - DEFAULT => -14 - }, - {#State 8 - ACTIONS => { - "\"" => 89, - "\$" => 86, - 'LITERAL' => 88, - 'FILENAME' => 83, - 'IDENT' => 81, - 'NUMBER' => 84 - }, - GOTOS => { - 'filepart' => 87, - 'names' => 91, - 'nameargs' => 90, - 'filename' => 85, - 'name' => 82 - } - }, - {#State 9 - ACTIONS => { - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "]" => 94, - "\${" => 37 - }, - GOTOS => { - 'sterm' => 96, - 'item' => 39, - 'range' => 93, - 'node' => 23, - 'ident' => 77, - 'term' => 95, - 'list' => 92, - 'lterm' => 56 - } - }, - {#State 10 - ACTIONS => { - ";" => 97 - } - }, - {#State 11 - DEFAULT => -5 - }, - {#State 12 - ACTIONS => { - ";" => -20 - }, - DEFAULT => -27 - }, - {#State 13 - DEFAULT => -78, - GOTOS => { - '@5-1' => 98 - } - }, - {#State 14 - ACTIONS => { - 'IDENT' => 99 - }, - DEFAULT => -87, - GOTOS => { - 'blockargs' => 102, - 'metadata' => 101, - 'meta' => 100 - } - }, - {#State 15 - ACTIONS => { - 'IDENT' => 99 - }, - GOTOS => { - 'metadata' => 103, - 'meta' => 100 - } - }, - {#State 16 - ACTIONS => { - 'DOT' => 104, - 'ASSIGN' => 105 - }, - DEFAULT => -109 - }, - {#State 17 - ACTIONS => { - "\"" => 89, - "\$" => 86, - 'LITERAL' => 88, - 'FILENAME' => 83, - 'IDENT' => 81, - 'NUMBER' => 84 - }, - GOTOS => { - 'filepart' => 87, - 'names' => 91, - 'nameargs' => 106, - 'filename' => 85, - 'name' => 82 - } - }, - {#State 18 - ACTIONS => { - 'IDENT' => 107 - } - }, - {#State 19 - DEFAULT => -149 - }, - {#State 20 - DEFAULT => -12 - }, - {#State 21 - ACTIONS => { - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 108, - "\"" => 60, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'sterm' => 68, - 'item' => 39, - 'loopvar' => 110, - 'node' => 23, - 'ident' => 77, - 'term' => 109, - 'lterm' => 56 - } - }, - {#State 22 - DEFAULT => -40 - }, - {#State 23 - DEFAULT => -127 - }, - {#State 24 - DEFAULT => -6 - }, - {#State 25 - ACTIONS => { - "\"" => 117, - "\$" => 114, - 'LITERAL' => 116, - 'FILENAME' => 83, - 'IDENT' => 111, - 'NUMBER' => 84, - "\${" => 37 - }, - GOTOS => { - 'filepart' => 87, - 'names' => 91, - 'nameargs' => 118, - 'filename' => 85, - 'lvalue' => 112, - 'lnameargs' => 115, - 'item' => 113, - 'name' => 82 - } - }, - {#State 26 - DEFAULT => -113 - }, - {#State 27 - ACTIONS => { - "\$" => 43, - 'IDENT' => 2, - "\${" => 37 - }, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'ident' => 119 - } - }, - {#State 28 - ACTIONS => { - 'LITERAL' => 124, - 'FILENAME' => 83, - 'IDENT' => 120, - 'NUMBER' => 84 - }, - DEFAULT => -87, - GOTOS => { - 'blockargs' => 123, - 'filepart' => 87, - 'filename' => 122, - 'blockname' => 121, - 'metadata' => 101, - 'meta' => 100 - } - }, - {#State 29 - DEFAULT => -43 - }, - {#State 30 - ACTIONS => { - "\$" => 43, - 'LITERAL' => 129, - 'IDENT' => 2, - "\${" => 37 - }, - DEFAULT => -119, - GOTOS => { - 'params' => 128, - 'hash' => 125, - 'item' => 126, - 'param' => 127 - } - }, - {#State 31 - DEFAULT => -25 - }, - {#State 32 - ACTIONS => { - "\"" => 117, - "\$" => 114, - 'LITERAL' => 116, - 'FILENAME' => 83, - 'IDENT' => 111, - 'NUMBER' => 84, - "\${" => 37 - }, - GOTOS => { - 'filepart' => 87, - 'names' => 91, - 'nameargs' => 118, - 'filename' => 85, - 'lvalue' => 112, - 'lnameargs' => 130, - 'item' => 113, - 'name' => 82 - } - }, - {#State 33 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -2, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 131, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 34 - DEFAULT => -22 - }, - {#State 35 - DEFAULT => -24 - }, - {#State 36 - ACTIONS => { - "\"" => 89, - "\$" => 86, - 'LITERAL' => 88, - 'FILENAME' => 83, - 'IDENT' => 81, - 'NUMBER' => 84 - }, - GOTOS => { - 'filepart' => 87, - 'names' => 91, - 'nameargs' => 132, - 'filename' => 85, - 'name' => 82 - } - }, - {#State 37 - ACTIONS => { - "\"" => 60, - "\$" => 43, - 'LITERAL' => 78, - 'IDENT' => 2, - 'REF' => 27, - 'NUMBER' => 26, - "\${" => 37 - }, - GOTOS => { - 'sterm' => 133, - 'item' => 39, - 'node' => 23, - 'ident' => 77 - } - }, - {#State 38 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 134, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 39 - ACTIONS => { - "(" => 135 - }, - DEFAULT => -128 - }, - {#State 40 - ACTIONS => { - ";" => 136 - } - }, - {#State 41 - DEFAULT => -38 - }, - {#State 42 - DEFAULT => -11 - }, - {#State 43 - ACTIONS => { - 'IDENT' => 137 - } - }, - {#State 44 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 138, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 45 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 139, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 46 - DEFAULT => -42 - }, - {#State 47 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 140, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 48 - ACTIONS => { - 'IF' => 144, - 'FILTER' => 143, - 'FOR' => 142, - 'WHILE' => 146, - 'WRAPPER' => 145, - 'UNLESS' => 141 - } - }, - {#State 49 - DEFAULT => -39 - }, - {#State 50 - DEFAULT => -10 - }, - {#State 51 - ACTIONS => { - "\"" => 89, - "\$" => 86, - 'LITERAL' => 88, - 'FILENAME' => 83, - 'IDENT' => 81, - 'NUMBER' => 84 - }, - GOTOS => { - 'filepart' => 87, - 'names' => 91, - 'nameargs' => 147, - 'filename' => 85, - 'name' => 82 - } - }, - {#State 52 - ACTIONS => { - '' => 148 - } - }, - {#State 53 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 57, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 149, - 'term' => 58, - 'expr' => 151, - 'assign' => 150, - 'lterm' => 56 - } - }, - {#State 54 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 152, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 55 - ACTIONS => { - "\"" => 89, - "\$" => 86, - 'LITERAL' => 88, - 'FILENAME' => 83, - 'IDENT' => 81, - 'NUMBER' => 84 - }, - GOTOS => { - 'filepart' => 87, - 'names' => 91, - 'nameargs' => 153, - 'filename' => 85, - 'name' => 82 - } - }, - {#State 56 - DEFAULT => -103 - }, - {#State 57 - ACTIONS => { - 'ASSIGN' => 154 - }, - DEFAULT => -112 - }, - {#State 58 - DEFAULT => -146 - }, - {#State 59 - DEFAULT => -15 - }, - {#State 60 - DEFAULT => -176, - GOTOS => { - 'quoted' => 155 - } - }, - {#State 61 - ACTIONS => { - "\"" => 89, - "\$" => 86, - 'LITERAL' => 88, - 'FILENAME' => 83, - 'IDENT' => 81, - 'NUMBER' => 84 - }, - GOTOS => { - 'filepart' => 87, - 'names' => 91, - 'nameargs' => 156, - 'filename' => 85, - 'name' => 82 - } - }, - {#State 62 - ACTIONS => { - ";" => -16, - "+" => 157, - 'CAT' => 163, - 'CMPOP' => 164, - "?" => 158, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'AND' => 160, - 'BINOP' => 161, - 'OR' => 162 - }, - DEFAULT => -26 - }, - {#State 63 - DEFAULT => -13 - }, - {#State 64 - DEFAULT => -36 - }, - {#State 65 - ACTIONS => { - "\"" => 89, - "\$" => 86, - 'LITERAL' => 88, - 'FILENAME' => 83, - 'IDENT' => 81, - 'NUMBER' => 84 - }, - GOTOS => { - 'filepart' => 87, - 'names' => 91, - 'nameargs' => 167, - 'filename' => 85, - 'name' => 82 - } - }, - {#State 66 - DEFAULT => -9 - }, - {#State 67 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 168, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 68 - DEFAULT => -104 - }, - {#State 69 - ACTIONS => { - "\$" => 43, - 'LITERAL' => 75, - 'IDENT' => 2, - "\${" => 37 - }, - GOTOS => { - 'setlist' => 169, - 'item' => 39, - 'assign' => 19, - 'node' => 23, - 'ident' => 74 - } - }, - {#State 70 - ACTIONS => { - "\$" => 43, - 'COMMA' => 171, - 'LITERAL' => 75, - 'IDENT' => 2, - "\${" => 37 - }, - DEFAULT => -19, - GOTOS => { - 'item' => 39, - 'assign' => 170, - 'node' => 23, - 'ident' => 74 - } - }, - {#State 71 - DEFAULT => -8 - }, - {#State 72 - DEFAULT => -1 - }, - {#State 73 - DEFAULT => -21 - }, - {#State 74 - ACTIONS => { - 'ASSIGN' => 172, - 'DOT' => 104 - } - }, - {#State 75 - ACTIONS => { - 'ASSIGN' => 154 - } - }, - {#State 76 - ACTIONS => { - "\$" => 43, - 'COMMA' => 171, - 'LITERAL' => 75, - 'IDENT' => 2, - "\${" => 37 - }, - DEFAULT => -30, - GOTOS => { - 'item' => 39, - 'assign' => 170, - 'node' => 23, - 'ident' => 74 - } - }, - {#State 77 - ACTIONS => { - 'DOT' => 104 - }, - DEFAULT => -109 - }, - {#State 78 - DEFAULT => -112 - }, - {#State 79 - ACTIONS => { - 'CMPOP' => 164, - "?" => 158, - ";" => 173, - "+" => 157, - 'MOD' => 165, - 'DIV' => 159, - "/" => 166, - 'AND' => 160, - 'CAT' => 163, - 'BINOP' => 161, - 'OR' => 162 - } - }, - {#State 80 - DEFAULT => -7 - }, - {#State 81 - DEFAULT => -173 - }, - {#State 82 - DEFAULT => -166 - }, - {#State 83 - DEFAULT => -172 - }, - {#State 84 - DEFAULT => -174 - }, - {#State 85 - ACTIONS => { - 'DOT' => 174 - }, - DEFAULT => -168 - }, - {#State 86 - ACTIONS => { - "\$" => 43, - 'IDENT' => 2, - "\${" => 37 - }, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'ident' => 175 - } - }, - {#State 87 - DEFAULT => -171 - }, - {#State 88 - DEFAULT => -169 - }, - {#State 89 - DEFAULT => -176, - GOTOS => { - 'quoted' => 176 - } - }, - {#State 90 - DEFAULT => -35 - }, - {#State 91 - ACTIONS => { - "+" => 177, - "(" => 178 - }, - DEFAULT => -156, - GOTOS => { - 'args' => 179 - } - }, - {#State 92 - ACTIONS => { - "{" => 30, - 'COMMA' => 182, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "]" => 180, - "\${" => 37 - }, - GOTOS => { - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 181, - 'lterm' => 56 - } - }, - {#State 93 - ACTIONS => { - "]" => 183 - } - }, - {#State 94 - DEFAULT => -107 - }, - {#State 95 - DEFAULT => -116 - }, - {#State 96 - ACTIONS => { - 'TO' => 184 - }, - DEFAULT => -104 - }, - {#State 97 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 185, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 98 - ACTIONS => { - ";" => 186 - } - }, - {#State 99 - ACTIONS => { - 'ASSIGN' => 187 - } - }, - {#State 100 - DEFAULT => -99 - }, - {#State 101 - ACTIONS => { - 'COMMA' => 189, - 'IDENT' => 99 - }, - DEFAULT => -86, - GOTOS => { - 'meta' => 188 - } - }, - {#State 102 - ACTIONS => { - ";" => 190 - } - }, - {#State 103 - ACTIONS => { - 'COMMA' => 189, - 'IDENT' => 99 - }, - DEFAULT => -17, - GOTOS => { - 'meta' => 188 - } - }, - {#State 104 - ACTIONS => { - "\$" => 43, - 'IDENT' => 2, - 'NUMBER' => 192, - "\${" => 37 - }, - GOTOS => { - 'item' => 39, - 'node' => 191 - } - }, - {#State 105 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'WRAPPER' => 55, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - "\"" => 60, - 'PROCESS' => 61, - 'FILTER' => 25, - 'RETURN' => 64, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 193, - 'DEFAULT' => 69, - "{" => 30, - "\${" => 37 - }, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'term' => 58, - 'loop' => 4, - 'expr' => 195, - 'wrapper' => 46, - 'atomexpr' => 48, - 'atomdir' => 12, - 'mdir' => 194, - 'sterm' => 68, - 'filter' => 29, - 'ident' => 149, - 'perl' => 31, - 'setlist' => 70, - 'switch' => 34, - 'try' => 35, - 'assign' => 19, - 'directive' => 196, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 106 - DEFAULT => -33 - }, - {#State 107 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'INCLUDE' => 17, - "(" => 198, - 'SWITCH' => 54, - 'WRAPPER' => 55, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - "\"" => 60, - 'PROCESS' => 61, - 'FILTER' => 25, - 'RETURN' => 64, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 193, - 'DEFAULT' => 69, - "{" => 30, - "\${" => 37 - }, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'term' => 58, - 'loop' => 4, - 'expr' => 199, - 'wrapper' => 46, - 'atomexpr' => 48, - 'atomdir' => 12, - 'mdir' => 197, - 'sterm' => 68, - 'filter' => 29, - 'ident' => 149, - 'perl' => 31, - 'setlist' => 70, - 'switch' => 34, - 'try' => 35, - 'assign' => 19, - 'directive' => 196, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 108 - ACTIONS => { - 'IN' => 201, - 'ASSIGN' => 200 - }, - DEFAULT => -130 - }, - {#State 109 - DEFAULT => -156, - GOTOS => { - 'args' => 202 - } - }, - {#State 110 - ACTIONS => { - ";" => 203 - } - }, - {#State 111 - ACTIONS => { - 'ASSIGN' => -130 - }, - DEFAULT => -173 - }, - {#State 112 - ACTIONS => { - 'ASSIGN' => 204 - } - }, - {#State 113 - DEFAULT => -159 - }, - {#State 114 - ACTIONS => { - "\$" => 43, - 'IDENT' => 205, - "\${" => 37 - }, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'ident' => 175 - } - }, - {#State 115 - ACTIONS => { - ";" => 206 - } - }, - {#State 116 - ACTIONS => { - 'ASSIGN' => -161 - }, - DEFAULT => -169 - }, - {#State 117 - DEFAULT => -176, - GOTOS => { - 'quoted' => 207 - } - }, - {#State 118 - DEFAULT => -158 - }, - {#State 119 - ACTIONS => { - 'DOT' => 104 - }, - DEFAULT => -110 - }, - {#State 120 - ACTIONS => { - 'ASSIGN' => 187 - }, - DEFAULT => -173 - }, - {#State 121 - DEFAULT => -83 - }, - {#State 122 - ACTIONS => { - 'DOT' => 174 - }, - DEFAULT => -84 - }, - {#State 123 - ACTIONS => { - ";" => 208 - } - }, - {#State 124 - DEFAULT => -85 - }, - {#State 125 - ACTIONS => { - "}" => 209 - } - }, - {#State 126 - ACTIONS => { - 'ASSIGN' => 210 - } - }, - {#State 127 - DEFAULT => -122 - }, - {#State 128 - ACTIONS => { - "\$" => 43, - 'COMMA' => 212, - 'LITERAL' => 129, - 'IDENT' => 2, - "\${" => 37 - }, - DEFAULT => -118, - GOTOS => { - 'item' => 126, - 'param' => 211 - } - }, - {#State 129 - ACTIONS => { - 'ASSIGN' => 213 - } - }, - {#State 130 - DEFAULT => -73 - }, - {#State 131 - DEFAULT => -4 - }, - {#State 132 - ACTIONS => { - ";" => 214 - } - }, - {#State 133 - ACTIONS => { - "}" => 215 - } - }, - {#State 134 - ACTIONS => { - "+" => 157, - 'CAT' => 163, - 'CMPOP' => 164, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'BINOP' => 161 - }, - DEFAULT => -142 - }, - {#State 135 - DEFAULT => -156, - GOTOS => { - 'args' => 216 - } - }, - {#State 136 - DEFAULT => -76, - GOTOS => { - '@4-2' => 217 - } - }, - {#State 137 - DEFAULT => -132 - }, - {#State 138 - ACTIONS => { - 'CMPOP' => 164, - "?" => 158, - ";" => 218, - "+" => 157, - 'MOD' => 165, - 'DIV' => 159, - "/" => 166, - 'AND' => 160, - 'CAT' => 163, - 'BINOP' => 161, - 'OR' => 162 - } - }, - {#State 139 - ACTIONS => { - "+" => 157, - 'CAT' => 163, - 'CMPOP' => 164, - "?" => 158, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'AND' => 160, - 'BINOP' => 161, - 'OR' => 162 - }, - DEFAULT => -29 - }, - {#State 140 - ACTIONS => { - "+" => 157, - 'CAT' => 163, - 'CMPOP' => 164, - "?" => 158, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'AND' => 160, - 'BINOP' => 161, - 'OR' => 162 - }, - DEFAULT => -28 - }, - {#State 141 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 219, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 142 - ACTIONS => { - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 108, - "\"" => 60, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'sterm' => 68, - 'item' => 39, - 'loopvar' => 220, - 'node' => 23, - 'ident' => 77, - 'term' => 109, - 'lterm' => 56 - } - }, - {#State 143 - ACTIONS => { - "\"" => 117, - "\$" => 114, - 'LITERAL' => 116, - 'FILENAME' => 83, - 'IDENT' => 111, - 'NUMBER' => 84, - "\${" => 37 - }, - GOTOS => { - 'filepart' => 87, - 'names' => 91, - 'nameargs' => 118, - 'filename' => 85, - 'lvalue' => 112, - 'lnameargs' => 221, - 'item' => 113, - 'name' => 82 - } - }, - {#State 144 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 222, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 145 - ACTIONS => { - "\"" => 89, - "\$" => 86, - 'LITERAL' => 88, - 'FILENAME' => 83, - 'IDENT' => 81, - 'NUMBER' => 84 - }, - GOTOS => { - 'filepart' => 87, - 'names' => 91, - 'nameargs' => 223, - 'filename' => 85, - 'name' => 82 - } - }, - {#State 146 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 224, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 147 - DEFAULT => -41 - }, - {#State 148 - DEFAULT => 0 - }, - {#State 149 - ACTIONS => { - 'DOT' => 104, - 'ASSIGN' => 172 - }, - DEFAULT => -109 - }, - {#State 150 - ACTIONS => { - ")" => 225 - } - }, - {#State 151 - ACTIONS => { - 'CMPOP' => 164, - "?" => 158, - "+" => 157, - 'MOD' => 165, - 'DIV' => 159, - "/" => 166, - 'AND' => 160, - 'CAT' => 163, - 'BINOP' => 161, - ")" => 226, - 'OR' => 162 - } - }, - {#State 152 - ACTIONS => { - 'CMPOP' => 164, - "?" => 158, - ";" => 227, - "+" => 157, - 'MOD' => 165, - 'DIV' => 159, - "/" => 166, - 'AND' => 160, - 'CAT' => 163, - 'BINOP' => 161, - 'OR' => 162 - } - }, - {#State 153 - ACTIONS => { - ";" => 228 - } - }, - {#State 154 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 229, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 155 - ACTIONS => { - "\"" => 234, - 'TEXT' => 231, - ";" => 233, - "\$" => 43, - 'IDENT' => 2, - "\${" => 37 - }, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'ident' => 230, - 'quotable' => 232 - } - }, - {#State 156 - DEFAULT => -34 - }, - {#State 157 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 235, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 158 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 236, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 159 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 237, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 160 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 238, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 161 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 239, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 162 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 240, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 163 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 241, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 164 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 242, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 165 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 243, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 166 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 244, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 167 - DEFAULT => -32 - }, - {#State 168 - ACTIONS => { - 'CMPOP' => 164, - "?" => 158, - ";" => 245, - "+" => 157, - 'MOD' => 165, - 'DIV' => 159, - "/" => 166, - 'AND' => 160, - 'CAT' => 163, - 'BINOP' => 161, - 'OR' => 162 - } - }, - {#State 169 - ACTIONS => { - "\$" => 43, - 'COMMA' => 171, - 'LITERAL' => 75, - 'IDENT' => 2, - "\${" => 37 - }, - DEFAULT => -31, - GOTOS => { - 'item' => 39, - 'assign' => 170, - 'node' => 23, - 'ident' => 74 - } - }, - {#State 170 - DEFAULT => -147 - }, - {#State 171 - DEFAULT => -148 - }, - {#State 172 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 246, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 173 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 247, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 174 - ACTIONS => { - 'FILENAME' => 83, - 'IDENT' => 81, - 'NUMBER' => 84 - }, - GOTOS => { - 'filepart' => 248 - } - }, - {#State 175 - ACTIONS => { - 'DOT' => 104 - }, - DEFAULT => -156, - GOTOS => { - 'args' => 249 - } - }, - {#State 176 - ACTIONS => { - "\"" => 250, - 'TEXT' => 231, - ";" => 233, - "\$" => 43, - 'IDENT' => 2, - "\${" => 37 - }, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'ident' => 230, - 'quotable' => 232 - } - }, - {#State 177 - ACTIONS => { - "\"" => 89, - 'LITERAL' => 88, - 'FILENAME' => 83, - 'IDENT' => 81, - 'NUMBER' => 84 - }, - GOTOS => { - 'filepart' => 87, - 'filename' => 85, - 'name' => 251 - } - }, - {#State 178 - DEFAULT => -156, - GOTOS => { - 'args' => 252 - } - }, - {#State 179 - ACTIONS => { - "{" => 30, - 'COMMA' => 258, - 'LITERAL' => 256, - 'IDENT' => 2, - "\"" => 60, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - DEFAULT => -163, - GOTOS => { - 'sterm' => 68, - 'item' => 254, - 'param' => 255, - 'node' => 23, - 'ident' => 253, - 'term' => 257, - 'lterm' => 56 - } - }, - {#State 180 - DEFAULT => -105 - }, - {#State 181 - DEFAULT => -114 - }, - {#State 182 - DEFAULT => -115 - }, - {#State 183 - DEFAULT => -106 - }, - {#State 184 - ACTIONS => { - "\"" => 60, - "\$" => 43, - 'LITERAL' => 78, - 'IDENT' => 2, - 'REF' => 27, - 'NUMBER' => 26, - "\${" => 37 - }, - GOTOS => { - 'sterm' => 259, - 'item' => 39, - 'node' => 23, - 'ident' => 77 - } - }, - {#State 185 - ACTIONS => { - 'FINAL' => 260, - 'CATCH' => 262 - }, - DEFAULT => -72, - GOTOS => { - 'final' => 261 - } - }, - {#State 186 - ACTIONS => { - 'TEXT' => 263 - } - }, - {#State 187 - ACTIONS => { - "\"" => 266, - 'LITERAL' => 265, - 'NUMBER' => 264 - } - }, - {#State 188 - DEFAULT => -97 - }, - {#State 189 - DEFAULT => -98 - }, - {#State 190 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'template' => 267, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 72, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 191 - DEFAULT => -125 - }, - {#State 192 - DEFAULT => -126 - }, - {#State 193 - ACTIONS => { - ";" => 268 - } - }, - {#State 194 - DEFAULT => -89 - }, - {#State 195 - ACTIONS => { - ";" => -150, - "+" => 157, - 'LITERAL' => -150, - 'IDENT' => -150, - 'CAT' => 163, - "\$" => -150, - 'CMPOP' => 164, - "?" => 158, - 'DIV' => 159, - 'MOD' => 165, - 'COMMA' => -150, - "/" => 166, - 'AND' => 160, - 'BINOP' => 161, - 'OR' => 162, - "\${" => -150 - }, - DEFAULT => -26 - }, - {#State 196 - DEFAULT => -92 - }, - {#State 197 - DEFAULT => -91 - }, - {#State 198 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 57, - 'IDENT' => 269, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'sterm' => 68, - 'item' => 39, - 'margs' => 270, - 'node' => 23, - 'ident' => 149, - 'term' => 58, - 'expr' => 151, - 'assign' => 150, - 'lterm' => 56 - } - }, - {#State 199 - ACTIONS => { - "+" => 157, - 'CAT' => 163, - 'CMPOP' => 164, - "?" => 158, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'AND' => 160, - 'BINOP' => 161, - 'OR' => 162 - }, - DEFAULT => -26 - }, - {#State 200 - ACTIONS => { - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 271, - 'lterm' => 56 - } - }, - {#State 201 - ACTIONS => { - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 272, - 'lterm' => 56 - } - }, - {#State 202 - ACTIONS => { - "{" => 30, - 'COMMA' => 258, - 'LITERAL' => 256, - 'IDENT' => 2, - "\"" => 60, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - DEFAULT => -64, - GOTOS => { - 'sterm' => 68, - 'item' => 254, - 'param' => 255, - 'node' => 23, - 'ident' => 253, - 'term' => 257, - 'lterm' => 56 - } - }, - {#State 203 - DEFAULT => -56, - GOTOS => { - '@1-3' => 273 - } - }, - {#State 204 - ACTIONS => { - "\"" => 89, - "\$" => 86, - 'LITERAL' => 88, - 'FILENAME' => 83, - 'IDENT' => 81, - 'NUMBER' => 84 - }, - GOTOS => { - 'filepart' => 87, - 'names' => 91, - 'nameargs' => 274, - 'filename' => 85, - 'name' => 82 - } - }, - {#State 205 - ACTIONS => { - 'ASSIGN' => -132 - }, - DEFAULT => -130 - }, - {#State 206 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 275, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 207 - ACTIONS => { - "\"" => 276, - 'TEXT' => 231, - ";" => 233, - "\$" => 43, - 'IDENT' => 2, - "\${" => 37 - }, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'ident' => 230, - 'quotable' => 232 - } - }, - {#State 208 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 277, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 209 - DEFAULT => -108 - }, - {#State 210 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 278, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 211 - DEFAULT => -120 - }, - {#State 212 - DEFAULT => -121 - }, - {#State 213 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 279, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 214 - DEFAULT => -74, - GOTOS => { - '@3-3' => 280 - } - }, - {#State 215 - DEFAULT => -131 - }, - {#State 216 - ACTIONS => { - "{" => 30, - 'COMMA' => 258, - 'LITERAL' => 256, - 'IDENT' => 2, - "\"" => 60, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - ")" => 281, - "\${" => 37 - }, - GOTOS => { - 'sterm' => 68, - 'item' => 254, - 'param' => 255, - 'node' => 23, - 'ident' => 253, - 'term' => 257, - 'lterm' => 56 - } - }, - {#State 217 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 282, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 218 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 283, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 219 - ACTIONS => { - 'CMPOP' => 164, - "?" => 158, - "+" => 157, - 'MOD' => 165, - 'DIV' => 159, - "/" => 166, - 'AND' => 160, - 'CAT' => 163, - 'BINOP' => 161, - 'OR' => 162 - }, - DEFAULT => -47 - }, - {#State 220 - DEFAULT => -58 - }, - {#State 221 - DEFAULT => -81 - }, - {#State 222 - ACTIONS => { - 'CMPOP' => 164, - "?" => 158, - "+" => 157, - 'MOD' => 165, - 'DIV' => 159, - "/" => 166, - 'AND' => 160, - 'CAT' => 163, - 'BINOP' => 161, - 'OR' => 162 - }, - DEFAULT => -45 - }, - {#State 223 - DEFAULT => -66 - }, - {#State 224 - ACTIONS => { - 'CMPOP' => 164, - "?" => 158, - "+" => 157, - 'MOD' => 165, - 'DIV' => 159, - "/" => 166, - 'AND' => 160, - 'CAT' => 163, - 'BINOP' => 161, - 'OR' => 162 - }, - DEFAULT => -61 - }, - {#State 225 - DEFAULT => -144 - }, - {#State 226 - DEFAULT => -145 - }, - {#State 227 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 284, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 228 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 285, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 229 - ACTIONS => { - "+" => 157, - 'CAT' => 163, - 'CMPOP' => 164, - "?" => 158, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'AND' => 160, - 'BINOP' => 161, - 'OR' => 162 - }, - DEFAULT => -151 - }, - {#State 230 - ACTIONS => { - 'DOT' => 104 - }, - DEFAULT => -177 - }, - {#State 231 - DEFAULT => -178 - }, - {#State 232 - DEFAULT => -175 - }, - {#State 233 - DEFAULT => -179 - }, - {#State 234 - DEFAULT => -111 - }, - {#State 235 - ACTIONS => { - 'DIV' => 159, - 'MOD' => 165, - "/" => 166 - }, - DEFAULT => -135 - }, - {#State 236 - ACTIONS => { - ":" => 286, - 'CMPOP' => 164, - "?" => 158, - "+" => 157, - 'MOD' => 165, - 'DIV' => 159, - "/" => 166, - 'AND' => 160, - 'CAT' => 163, - 'BINOP' => 161, - 'OR' => 162 - } - }, - {#State 237 - ACTIONS => { - 'MOD' => 165 - }, - DEFAULT => -136 - }, - {#State 238 - ACTIONS => { - "+" => 157, - 'CAT' => 163, - 'CMPOP' => 164, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'BINOP' => 161 - }, - DEFAULT => -140 - }, - {#State 239 - ACTIONS => { - "+" => 157, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166 - }, - DEFAULT => -133 - }, - {#State 240 - ACTIONS => { - "+" => 157, - 'CAT' => 163, - 'CMPOP' => 164, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'BINOP' => 161 - }, - DEFAULT => -141 - }, - {#State 241 - ACTIONS => { - "+" => 157, - 'CMPOP' => 164, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'BINOP' => 161 - }, - DEFAULT => -139 - }, - {#State 242 - ACTIONS => { - "+" => 157, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'BINOP' => 161 - }, - DEFAULT => -138 - }, - {#State 243 - DEFAULT => -137 - }, - {#State 244 - ACTIONS => { - 'DIV' => 159, - 'MOD' => 165 - }, - DEFAULT => -134 - }, - {#State 245 - DEFAULT => -59, - GOTOS => { - '@2-3' => 287 - } - }, - {#State 246 - ACTIONS => { - "+" => 157, - 'CAT' => 163, - 'CMPOP' => 164, - "?" => 158, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'AND' => 160, - 'BINOP' => 161, - 'OR' => 162 - }, - DEFAULT => -150 - }, - {#State 247 - ACTIONS => { - 'ELSIF' => 290, - 'ELSE' => 288 - }, - DEFAULT => -50, - GOTOS => { - 'else' => 289 - } - }, - {#State 248 - DEFAULT => -170 - }, - {#State 249 - ACTIONS => { - "{" => 30, - 'COMMA' => 258, - 'LITERAL' => 256, - 'IDENT' => 2, - "\"" => 60, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - DEFAULT => -162, - GOTOS => { - 'sterm' => 68, - 'item' => 254, - 'param' => 255, - 'node' => 23, - 'ident' => 253, - 'term' => 257, - 'lterm' => 56 - } - }, - {#State 250 - DEFAULT => -167 - }, - {#State 251 - DEFAULT => -165 - }, - {#State 252 - ACTIONS => { - "{" => 30, - 'COMMA' => 258, - 'LITERAL' => 256, - 'IDENT' => 2, - "\"" => 60, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - ")" => 291, - "\${" => 37 - }, - GOTOS => { - 'sterm' => 68, - 'item' => 254, - 'param' => 255, - 'node' => 23, - 'ident' => 253, - 'term' => 257, - 'lterm' => 56 - } - }, - {#State 253 - ACTIONS => { - 'DOT' => 104, - 'ASSIGN' => 292 - }, - DEFAULT => -109 - }, - {#State 254 - ACTIONS => { - "(" => 135, - 'ASSIGN' => 210 - }, - DEFAULT => -128 - }, - {#State 255 - DEFAULT => -153 - }, - {#State 256 - ACTIONS => { - 'ASSIGN' => 213 - }, - DEFAULT => -112 - }, - {#State 257 - DEFAULT => -152 - }, - {#State 258 - DEFAULT => -155 - }, - {#State 259 - DEFAULT => -117 - }, - {#State 260 - ACTIONS => { - ";" => 293 - } - }, - {#State 261 - ACTIONS => { - 'END' => 294 - } - }, - {#State 262 - ACTIONS => { - ";" => 296, - 'DEFAULT' => 297, - 'FILENAME' => 83, - 'IDENT' => 81, - 'NUMBER' => 84 - }, - GOTOS => { - 'filepart' => 87, - 'filename' => 295 - } - }, - {#State 263 - ACTIONS => { - 'END' => 298 - } - }, - {#State 264 - DEFAULT => -102 - }, - {#State 265 - DEFAULT => -100 - }, - {#State 266 - ACTIONS => { - 'TEXT' => 299 - } - }, - {#State 267 - ACTIONS => { - 'END' => 300 - } - }, - {#State 268 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 301, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 269 - ACTIONS => { - 'COMMA' => -96, - 'IDENT' => -96, - ")" => -96 - }, - DEFAULT => -130 - }, - {#State 270 - ACTIONS => { - 'COMMA' => 304, - 'IDENT' => 302, - ")" => 303 - } - }, - {#State 271 - DEFAULT => -156, - GOTOS => { - 'args' => 305 - } - }, - {#State 272 - DEFAULT => -156, - GOTOS => { - 'args' => 306 - } - }, - {#State 273 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 307, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 274 - DEFAULT => -157 - }, - {#State 275 - ACTIONS => { - 'END' => 308 - } - }, - {#State 276 - ACTIONS => { - 'ASSIGN' => -160 - }, - DEFAULT => -167 - }, - {#State 277 - ACTIONS => { - 'END' => 309 - } - }, - {#State 278 - ACTIONS => { - "+" => 157, - 'CAT' => 163, - 'CMPOP' => 164, - "?" => 158, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'AND' => 160, - 'BINOP' => 161, - 'OR' => 162 - }, - DEFAULT => -124 - }, - {#State 279 - ACTIONS => { - "+" => 157, - 'CAT' => 163, - 'CMPOP' => 164, - "?" => 158, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'AND' => 160, - 'BINOP' => 161, - 'OR' => 162 - }, - DEFAULT => -123 - }, - {#State 280 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 310, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 281 - DEFAULT => -129 - }, - {#State 282 - ACTIONS => { - 'END' => 311 - } - }, - {#State 283 - ACTIONS => { - 'ELSIF' => 290, - 'ELSE' => 288 - }, - DEFAULT => -50, - GOTOS => { - 'else' => 312 - } - }, - {#State 284 - ACTIONS => { - 'CASE' => 313 - }, - DEFAULT => -55, - GOTOS => { - 'case' => 314 - } - }, - {#State 285 - ACTIONS => { - 'END' => 315 - } - }, - {#State 286 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 316, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 287 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 317, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 288 - ACTIONS => { - ";" => 318 - } - }, - {#State 289 - ACTIONS => { - 'END' => 319 - } - }, - {#State 290 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 320, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 291 - DEFAULT => -164 - }, - {#State 292 - ACTIONS => { - 'NOT' => 38, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "(" => 53, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'expr' => 321, - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 58, - 'lterm' => 56 - } - }, - {#State 293 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 322, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 294 - DEFAULT => -67 - }, - {#State 295 - ACTIONS => { - 'DOT' => 174, - ";" => 323 - } - }, - {#State 296 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 324, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 297 - ACTIONS => { - ";" => 325 - } - }, - {#State 298 - DEFAULT => -79 - }, - {#State 299 - ACTIONS => { - "\"" => 326 - } - }, - {#State 300 - DEFAULT => -82 - }, - {#State 301 - ACTIONS => { - 'END' => 327 - } - }, - {#State 302 - DEFAULT => -94 - }, - {#State 303 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'WRAPPER' => 55, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - "\"" => 60, - 'PROCESS' => 61, - 'FILTER' => 25, - 'RETURN' => 64, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 193, - 'DEFAULT' => 69, - "{" => 30, - "\${" => 37 - }, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'term' => 58, - 'loop' => 4, - 'expr' => 199, - 'wrapper' => 46, - 'atomexpr' => 48, - 'atomdir' => 12, - 'mdir' => 328, - 'sterm' => 68, - 'filter' => 29, - 'ident' => 149, - 'perl' => 31, - 'setlist' => 70, - 'switch' => 34, - 'try' => 35, - 'assign' => 19, - 'directive' => 196, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 304 - DEFAULT => -95 - }, - {#State 305 - ACTIONS => { - "{" => 30, - 'COMMA' => 258, - 'LITERAL' => 256, - 'IDENT' => 2, - "\"" => 60, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - DEFAULT => -62, - GOTOS => { - 'sterm' => 68, - 'item' => 254, - 'param' => 255, - 'node' => 23, - 'ident' => 253, - 'term' => 257, - 'lterm' => 56 - } - }, - {#State 306 - ACTIONS => { - "{" => 30, - 'COMMA' => 258, - 'LITERAL' => 256, - 'IDENT' => 2, - "\"" => 60, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - DEFAULT => -63, - GOTOS => { - 'sterm' => 68, - 'item' => 254, - 'param' => 255, - 'node' => 23, - 'ident' => 253, - 'term' => 257, - 'lterm' => 56 - } - }, - {#State 307 - ACTIONS => { - 'END' => 329 - } - }, - {#State 308 - DEFAULT => -80 - }, - {#State 309 - DEFAULT => -88 - }, - {#State 310 - ACTIONS => { - 'END' => 330 - } - }, - {#State 311 - DEFAULT => -77 - }, - {#State 312 - ACTIONS => { - 'END' => 331 - } - }, - {#State 313 - ACTIONS => { - ";" => 332, - 'DEFAULT' => 334, - "{" => 30, - 'LITERAL' => 78, - 'IDENT' => 2, - "\"" => 60, - "\$" => 43, - "[" => 9, - 'NUMBER' => 26, - 'REF' => 27, - "\${" => 37 - }, - GOTOS => { - 'sterm' => 68, - 'item' => 39, - 'node' => 23, - 'ident' => 77, - 'term' => 333, - 'lterm' => 56 - } - }, - {#State 314 - ACTIONS => { - 'END' => 335 - } - }, - {#State 315 - DEFAULT => -65 - }, - {#State 316 - ACTIONS => { - "+" => 157, - 'CAT' => 163, - 'CMPOP' => 164, - "?" => 158, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'AND' => 160, - 'BINOP' => 161, - 'OR' => 162 - }, - DEFAULT => -143 - }, - {#State 317 - ACTIONS => { - 'END' => 336 - } - }, - {#State 318 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 337, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 319 - DEFAULT => -46 - }, - {#State 320 - ACTIONS => { - 'CMPOP' => 164, - "?" => 158, - ";" => 338, - "+" => 157, - 'MOD' => 165, - 'DIV' => 159, - "/" => 166, - 'AND' => 160, - 'CAT' => 163, - 'BINOP' => 161, - 'OR' => 162 - } - }, - {#State 321 - ACTIONS => { - "+" => 157, - 'CAT' => 163, - 'CMPOP' => 164, - "?" => 158, - 'DIV' => 159, - 'MOD' => 165, - "/" => 166, - 'AND' => 160, - 'BINOP' => 161, - 'OR' => 162 - }, - DEFAULT => -154 - }, - {#State 322 - DEFAULT => -71 - }, - {#State 323 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 339, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 324 - ACTIONS => { - 'FINAL' => 260, - 'CATCH' => 262 - }, - DEFAULT => -72, - GOTOS => { - 'final' => 340 - } - }, - {#State 325 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 341, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 326 - DEFAULT => -101 - }, - {#State 327 - DEFAULT => -93 - }, - {#State 328 - DEFAULT => -90 - }, - {#State 329 - DEFAULT => -57 - }, - {#State 330 - DEFAULT => -75 - }, - {#State 331 - DEFAULT => -44 - }, - {#State 332 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 342, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 333 - ACTIONS => { - ";" => 343 - } - }, - {#State 334 - ACTIONS => { - ";" => 344 - } - }, - {#State 335 - DEFAULT => -51 - }, - {#State 336 - DEFAULT => -60 - }, - {#State 337 - DEFAULT => -49 - }, - {#State 338 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 345, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 339 - ACTIONS => { - 'FINAL' => 260, - 'CATCH' => 262 - }, - DEFAULT => -72, - GOTOS => { - 'final' => 346 - } - }, - {#State 340 - DEFAULT => -70 - }, - {#State 341 - ACTIONS => { - 'FINAL' => 260, - 'CATCH' => 262 - }, - DEFAULT => -72, - GOTOS => { - 'final' => 347 - } - }, - {#State 342 - DEFAULT => -54 - }, - {#State 343 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 348, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 344 - ACTIONS => { - 'SET' => 1, - 'PERL' => 40, - 'NOT' => 38, - 'IDENT' => 2, - 'CLEAR' => 41, - 'UNLESS' => 3, - 'IF' => 44, - "\$" => 43, - 'STOP' => 6, - 'CALL' => 45, - 'THROW' => 8, - 'GET' => 47, - "[" => 9, - 'TRY' => 10, - 'LAST' => 49, - 'DEBUG' => 51, - 'RAWPERL' => 13, - 'META' => 15, - 'INCLUDE' => 17, - "(" => 53, - 'SWITCH' => 54, - 'MACRO' => 18, - 'WRAPPER' => 55, - ";" => -18, - 'FOR' => 21, - 'NEXT' => 22, - 'LITERAL' => 57, - 'TEXT' => 24, - "\"" => 60, - 'PROCESS' => 61, - 'RETURN' => 64, - 'FILTER' => 25, - 'INSERT' => 65, - 'NUMBER' => 26, - 'REF' => 27, - 'WHILE' => 67, - 'BLOCK' => 28, - 'DEFAULT' => 69, - "{" => 30, - 'USE' => 32, - 'VIEW' => 36, - "\${" => 37 - }, - DEFAULT => -3, - GOTOS => { - 'item' => 39, - 'node' => 23, - 'rawperl' => 59, - 'term' => 58, - 'loop' => 4, - 'use' => 63, - 'expr' => 62, - 'capture' => 42, - 'statement' => 5, - 'view' => 7, - 'wrapper' => 46, - 'atomexpr' => 48, - 'chunk' => 11, - 'defblock' => 66, - 'atomdir' => 12, - 'anonblock' => 50, - 'sterm' => 68, - 'defblockname' => 14, - 'filter' => 29, - 'ident' => 16, - 'perl' => 31, - 'setlist' => 70, - 'chunks' => 33, - 'try' => 35, - 'switch' => 34, - 'assign' => 19, - 'block' => 349, - 'directive' => 71, - 'macro' => 20, - 'condition' => 73, - 'lterm' => 56 - } - }, - {#State 345 - ACTIONS => { - 'ELSIF' => 290, - 'ELSE' => 288 - }, - DEFAULT => -50, - GOTOS => { - 'else' => 350 - } - }, - {#State 346 - DEFAULT => -68 - }, - {#State 347 - DEFAULT => -69 - }, - {#State 348 - ACTIONS => { - 'CASE' => 313 - }, - DEFAULT => -55, - GOTOS => { - 'case' => 351 - } - }, - {#State 349 - DEFAULT => -53 - }, - {#State 350 - DEFAULT => -48 - }, - {#State 351 - DEFAULT => -52 - } -]; - - -#======================================================================== -# Rules -#======================================================================== - -$RULES = [ - [#Rule 0 - '$start', 2, undef - ], - [#Rule 1 - 'template', 1, -sub -#line 64 "Parser.yp" -{ $factory->template($_[1]) } - ], - [#Rule 2 - 'block', 1, -sub -#line 67 "Parser.yp" -{ $factory->block($_[1]) } - ], - [#Rule 3 - 'block', 0, -sub -#line 68 "Parser.yp" -{ $factory->block() } - ], - [#Rule 4 - 'chunks', 2, -sub -#line 71 "Parser.yp" -{ push(@{$_[1]}, $_[2]) - if defined $_[2]; $_[1] } - ], - [#Rule 5 - 'chunks', 1, -sub -#line 73 "Parser.yp" -{ defined $_[1] ? [ $_[1] ] : [ ] } - ], - [#Rule 6 - 'chunk', 1, -sub -#line 76 "Parser.yp" -{ $factory->textblock($_[1]) } - ], - [#Rule 7 - 'chunk', 2, -sub -#line 77 "Parser.yp" -{ return '' unless $_[1]; - $_[0]->location() . $_[1]; - } - ], - [#Rule 8 - 'statement', 1, undef - ], - [#Rule 9 - 'statement', 1, undef - ], - [#Rule 10 - 'statement', 1, undef - ], - [#Rule 11 - 'statement', 1, undef - ], - [#Rule 12 - 'statement', 1, undef - ], - [#Rule 13 - 'statement', 1, undef - ], - [#Rule 14 - 'statement', 1, undef - ], - [#Rule 15 - 'statement', 1, undef - ], - [#Rule 16 - 'statement', 1, -sub -#line 90 "Parser.yp" -{ $factory->get($_[1]) } - ], - [#Rule 17 - 'statement', 2, -sub -#line 91 "Parser.yp" -{ $_[0]->add_metadata($_[2]); } - ], - [#Rule 18 - 'statement', 0, undef - ], - [#Rule 19 - 'directive', 1, -sub -#line 95 "Parser.yp" -{ $factory->set($_[1]) } - ], - [#Rule 20 - 'directive', 1, undef - ], - [#Rule 21 - 'directive', 1, undef - ], - [#Rule 22 - 'directive', 1, undef - ], - [#Rule 23 - 'directive', 1, undef - ], - [#Rule 24 - 'directive', 1, undef - ], - [#Rule 25 - 'directive', 1, undef - ], - [#Rule 26 - 'atomexpr', 1, -sub -#line 109 "Parser.yp" -{ $factory->get($_[1]) } - ], - [#Rule 27 - 'atomexpr', 1, undef - ], - [#Rule 28 - 'atomdir', 2, -sub -#line 113 "Parser.yp" -{ $factory->get($_[2]) } - ], - [#Rule 29 - 'atomdir', 2, -sub -#line 114 "Parser.yp" -{ $factory->call($_[2]) } - ], - [#Rule 30 - 'atomdir', 2, -sub -#line 115 "Parser.yp" -{ $factory->set($_[2]) } - ], - [#Rule 31 - 'atomdir', 2, -sub -#line 116 "Parser.yp" -{ $factory->default($_[2]) } - ], - [#Rule 32 - 'atomdir', 2, -sub -#line 117 "Parser.yp" -{ $factory->insert($_[2]) } - ], - [#Rule 33 - 'atomdir', 2, -sub -#line 118 "Parser.yp" -{ $factory->include($_[2]) } - ], - [#Rule 34 - 'atomdir', 2, -sub -#line 119 "Parser.yp" -{ $factory->process($_[2]) } - ], - [#Rule 35 - 'atomdir', 2, -sub -#line 120 "Parser.yp" -{ $factory->throw($_[2]) } - ], - [#Rule 36 - 'atomdir', 1, -sub -#line 121 "Parser.yp" -{ $factory->return() } - ], - [#Rule 37 - 'atomdir', 1, -sub -#line 122 "Parser.yp" -{ $factory->stop() } - ], - [#Rule 38 - 'atomdir', 1, -sub -#line 123 "Parser.yp" -{ "\$output = '';"; } - ], - [#Rule 39 - 'atomdir', 1, -sub -#line 124 "Parser.yp" -{ $_[0]->{ INFOR } || $_[0]->{ INWHILE } - ? 'last LOOP;' - : 'last;' } - ], - [#Rule 40 - 'atomdir', 1, -sub -#line 127 "Parser.yp" -{ $_[0]->{ INFOR } - ? $factory->next() - : ($_[0]->{ INWHILE } - ? 'next LOOP;' - : 'next;') } - ], - [#Rule 41 - 'atomdir', 2, -sub -#line 132 "Parser.yp" -{ if ($_[2]->[0]->[0] =~ /^'(on|off)'$/) { - $_[0]->{ DEBUG_DIRS } = ($1 eq 'on'); - $factory->debug($_[2]); - } - else { - $_[0]->{ DEBUG_DIRS } ? $factory->debug($_[2]) : ''; - } - } - ], - [#Rule 42 - 'atomdir', 1, undef - ], - [#Rule 43 - 'atomdir', 1, undef - ], - [#Rule 44 - 'condition', 6, -sub -#line 145 "Parser.yp" -{ $factory->if(@_[2, 4, 5]) } - ], - [#Rule 45 - 'condition', 3, -sub -#line 146 "Parser.yp" -{ $factory->if(@_[3, 1]) } - ], - [#Rule 46 - 'condition', 6, -sub -#line 148 "Parser.yp" -{ $factory->if("!($_[2])", @_[4, 5]) } - ], - [#Rule 47 - 'condition', 3, -sub -#line 149 "Parser.yp" -{ $factory->if("!($_[3])", $_[1]) } - ], - [#Rule 48 - 'else', 5, -sub -#line 153 "Parser.yp" -{ unshift(@{$_[5]}, [ @_[2, 4] ]); - $_[5]; } - ], - [#Rule 49 - 'else', 3, -sub -#line 155 "Parser.yp" -{ [ $_[3] ] } - ], - [#Rule 50 - 'else', 0, -sub -#line 156 "Parser.yp" -{ [ undef ] } - ], - [#Rule 51 - 'switch', 6, -sub -#line 160 "Parser.yp" -{ $factory->switch(@_[2, 5]) } - ], - [#Rule 52 - 'case', 5, -sub -#line 164 "Parser.yp" -{ unshift(@{$_[5]}, [ @_[2, 4] ]); - $_[5]; } - ], - [#Rule 53 - 'case', 4, -sub -#line 166 "Parser.yp" -{ [ $_[4] ] } - ], - [#Rule 54 - 'case', 3, -sub -#line 167 "Parser.yp" -{ [ $_[3] ] } - ], - [#Rule 55 - 'case', 0, -sub -#line 168 "Parser.yp" -{ [ undef ] } - ], - [#Rule 56 - '@1-3', 0, -sub -#line 171 "Parser.yp" -{ $_[0]->{ INFOR }++ } - ], - [#Rule 57 - 'loop', 6, -sub -#line 172 "Parser.yp" -{ $_[0]->{ INFOR }--; - $factory->foreach(@{$_[2]}, $_[5]) } - ], - [#Rule 58 - 'loop', 3, -sub -#line 176 "Parser.yp" -{ $factory->foreach(@{$_[3]}, $_[1]) } - ], - [#Rule 59 - '@2-3', 0, -sub -#line 177 "Parser.yp" -{ $_[0]->{ INWHILE }++ } - ], - [#Rule 60 - 'loop', 6, -sub -#line 178 "Parser.yp" -{ $_[0]->{ INWHILE }--; - $factory->while(@_[2, 5]) } - ], - [#Rule 61 - 'loop', 3, -sub -#line 180 "Parser.yp" -{ $factory->while(@_[3, 1]) } - ], - [#Rule 62 - 'loopvar', 4, -sub -#line 183 "Parser.yp" -{ [ @_[1, 3, 4] ] } - ], - [#Rule 63 - 'loopvar', 4, -sub -#line 184 "Parser.yp" -{ [ @_[1, 3, 4] ] } - ], - [#Rule 64 - 'loopvar', 2, -sub -#line 185 "Parser.yp" -{ [ 0, @_[1, 2] ] } - ], - [#Rule 65 - 'wrapper', 5, -sub -#line 189 "Parser.yp" -{ $factory->wrapper(@_[2, 4]) } - ], - [#Rule 66 - 'wrapper', 3, -sub -#line 191 "Parser.yp" -{ $factory->wrapper(@_[3, 1]) } - ], - [#Rule 67 - 'try', 5, -sub -#line 195 "Parser.yp" -{ $factory->try(@_[3, 4]) } - ], - [#Rule 68 - 'final', 5, -sub -#line 199 "Parser.yp" -{ unshift(@{$_[5]}, [ @_[2,4] ]); - $_[5]; } - ], - [#Rule 69 - 'final', 5, -sub -#line 202 "Parser.yp" -{ unshift(@{$_[5]}, [ undef, $_[4] ]); - $_[5]; } - ], - [#Rule 70 - 'final', 4, -sub -#line 205 "Parser.yp" -{ unshift(@{$_[4]}, [ undef, $_[3] ]); - $_[4]; } - ], - [#Rule 71 - 'final', 3, -sub -#line 207 "Parser.yp" -{ [ $_[3] ] } - ], - [#Rule 72 - 'final', 0, -sub -#line 208 "Parser.yp" -{ [ 0 ] } - ], - [#Rule 73 - 'use', 2, -sub -#line 211 "Parser.yp" -{ $factory->use($_[2]) } - ], - [#Rule 74 - '@3-3', 0, -sub -#line 214 "Parser.yp" -{ $_[0]->push_defblock(); } - ], - [#Rule 75 - 'view', 6, -sub -#line 215 "Parser.yp" -{ $factory->view(@_[2,5], - $_[0]->pop_defblock) } - ], - [#Rule 76 - '@4-2', 0, -sub -#line 219 "Parser.yp" -{ ${$_[0]->{ INPERL }}++; } - ], - [#Rule 77 - 'perl', 5, -sub -#line 220 "Parser.yp" -{ ${$_[0]->{ INPERL }}--; - $_[0]->{ EVAL_PERL } - ? $factory->perl($_[4]) - : $factory->no_perl(); } - ], - [#Rule 78 - '@5-1', 0, -sub -#line 226 "Parser.yp" -{ ${$_[0]->{ INPERL }}++; - $rawstart = ${$_[0]->{'LINE'}}; } - ], - [#Rule 79 - 'rawperl', 5, -sub -#line 228 "Parser.yp" -{ ${$_[0]->{ INPERL }}--; - $_[0]->{ EVAL_PERL } - ? $factory->rawperl($_[4], $rawstart) - : $factory->no_perl(); } - ], - [#Rule 80 - 'filter', 5, -sub -#line 235 "Parser.yp" -{ $factory->filter(@_[2,4]) } - ], - [#Rule 81 - 'filter', 3, -sub -#line 237 "Parser.yp" -{ $factory->filter(@_[3,1]) } - ], - [#Rule 82 - 'defblock', 5, -sub -#line 242 "Parser.yp" -{ my $name = join('/', @{ $_[0]->{ DEFBLOCKS } }); - pop(@{ $_[0]->{ DEFBLOCKS } }); - $_[0]->define_block($name, $_[4]); - undef - } - ], - [#Rule 83 - 'defblockname', 2, -sub -#line 249 "Parser.yp" -{ push(@{ $_[0]->{ DEFBLOCKS } }, $_[2]); - $_[2]; - } - ], - [#Rule 84 - 'blockname', 1, undef - ], - [#Rule 85 - 'blockname', 1, -sub -#line 255 "Parser.yp" -{ $_[1] =~ s/^'(.*)'$/$1/; $_[1] } - ], - [#Rule 86 - 'blockargs', 1, undef - ], - [#Rule 87 - 'blockargs', 0, undef - ], - [#Rule 88 - 'anonblock', 5, -sub -#line 263 "Parser.yp" -{ local $" = ', '; - print STDERR "experimental block args: [@{ $_[2] }]\n" - if $_[2]; - $factory->anon_block($_[4]) } - ], - [#Rule 89 - 'capture', 3, -sub -#line 269 "Parser.yp" -{ $factory->capture(@_[1, 3]) } - ], - [#Rule 90 - 'macro', 6, -sub -#line 273 "Parser.yp" -{ $factory->macro(@_[2, 6, 4]) } - ], - [#Rule 91 - 'macro', 3, -sub -#line 274 "Parser.yp" -{ $factory->macro(@_[2, 3]) } - ], - [#Rule 92 - 'mdir', 1, undef - ], - [#Rule 93 - 'mdir', 4, -sub -#line 278 "Parser.yp" -{ $_[3] } - ], - [#Rule 94 - 'margs', 2, -sub -#line 281 "Parser.yp" -{ push(@{$_[1]}, $_[2]); $_[1] } - ], - [#Rule 95 - 'margs', 2, -sub -#line 282 "Parser.yp" -{ $_[1] } - ], - [#Rule 96 - 'margs', 1, -sub -#line 283 "Parser.yp" -{ [ $_[1] ] } - ], - [#Rule 97 - 'metadata', 2, -sub -#line 286 "Parser.yp" -{ push(@{$_[1]}, @{$_[2]}); $_[1] } - ], - [#Rule 98 - 'metadata', 2, undef - ], - [#Rule 99 - 'metadata', 1, undef - ], - [#Rule 100 - 'meta', 3, -sub -#line 291 "Parser.yp" -{ for ($_[3]) { s/^'//; s/'$//; - s/\\'/'/g }; - [ @_[1,3] ] } - ], - [#Rule 101 - 'meta', 5, -sub -#line 294 "Parser.yp" -{ [ @_[1,4] ] } - ], - [#Rule 102 - 'meta', 3, -sub -#line 295 "Parser.yp" -{ [ @_[1,3] ] } - ], - [#Rule 103 - 'term', 1, undef - ], - [#Rule 104 - 'term', 1, undef - ], - [#Rule 105 - 'lterm', 3, -sub -#line 307 "Parser.yp" -{ "[ $_[2] ]" } - ], - [#Rule 106 - 'lterm', 3, -sub -#line 308 "Parser.yp" -{ "[ $_[2] ]" } - ], - [#Rule 107 - 'lterm', 2, -sub -#line 309 "Parser.yp" -{ "[ ]" } - ], - [#Rule 108 - 'lterm', 3, -sub -#line 310 "Parser.yp" -{ "{ $_[2] }" } - ], - [#Rule 109 - 'sterm', 1, -sub -#line 313 "Parser.yp" -{ $factory->ident($_[1]) } - ], - [#Rule 110 - 'sterm', 2, -sub -#line 314 "Parser.yp" -{ $factory->identref($_[2]) } - ], - [#Rule 111 - 'sterm', 3, -sub -#line 315 "Parser.yp" -{ $factory->quoted($_[2]) } - ], - [#Rule 112 - 'sterm', 1, undef - ], - [#Rule 113 - 'sterm', 1, undef - ], - [#Rule 114 - 'list', 2, -sub -#line 320 "Parser.yp" -{ "$_[1], $_[2]" } - ], - [#Rule 115 - 'list', 2, undef - ], - [#Rule 116 - 'list', 1, undef - ], - [#Rule 117 - 'range', 3, -sub -#line 325 "Parser.yp" -{ $_[1] . '..' . $_[3] } - ], - [#Rule 118 - 'hash', 1, undef - ], - [#Rule 119 - 'hash', 0, -sub -#line 330 "Parser.yp" -{ "" } - ], - [#Rule 120 - 'params', 2, -sub -#line 333 "Parser.yp" -{ "$_[1], $_[2]" } - ], - [#Rule 121 - 'params', 2, undef - ], - [#Rule 122 - 'params', 1, undef - ], - [#Rule 123 - 'param', 3, -sub -#line 338 "Parser.yp" -{ "$_[1] => $_[3]" } - ], - [#Rule 124 - 'param', 3, -sub -#line 339 "Parser.yp" -{ "$_[1] => $_[3]" } - ], - [#Rule 125 - 'ident', 3, -sub -#line 342 "Parser.yp" -{ push(@{$_[1]}, @{$_[3]}); $_[1] } - ], - [#Rule 126 - 'ident', 3, -sub -#line 343 "Parser.yp" -{ push(@{$_[1]}, - map {($_, 0)} split(/\./, $_[3])); - $_[1]; } - ], - [#Rule 127 - 'ident', 1, undef - ], - [#Rule 128 - 'node', 1, -sub -#line 349 "Parser.yp" -{ [ $_[1], 0 ] } - ], - [#Rule 129 - 'node', 4, -sub -#line 350 "Parser.yp" -{ [ $_[1], $factory->args($_[3]) ] } - ], - [#Rule 130 - 'item', 1, -sub -#line 353 "Parser.yp" -{ "'$_[1]'" } - ], - [#Rule 131 - 'item', 3, -sub -#line 354 "Parser.yp" -{ $_[2] } - ], - [#Rule 132 - 'item', 2, -sub -#line 355 "Parser.yp" -{ $_[0]->{ V1DOLLAR } - ? "'$_[2]'" - : $factory->ident(["'$_[2]'", 0]) } - ], - [#Rule 133 - 'expr', 3, -sub -#line 360 "Parser.yp" -{ "$_[1] $_[2] $_[3]" } - ], - [#Rule 134 - 'expr', 3, -sub -#line 361 "Parser.yp" -{ "$_[1] $_[2] $_[3]" } - ], - [#Rule 135 - 'expr', 3, -sub -#line 362 "Parser.yp" -{ "$_[1] $_[2] $_[3]" } - ], - [#Rule 136 - 'expr', 3, -sub -#line 363 "Parser.yp" -{ "int($_[1] / $_[3])" } - ], - [#Rule 137 - 'expr', 3, -sub -#line 364 "Parser.yp" -{ "$_[1] % $_[3]" } - ], - [#Rule 138 - 'expr', 3, -sub -#line 365 "Parser.yp" -{ "$_[1] $CMPOP{ $_[2] } $_[3]" } - ], - [#Rule 139 - 'expr', 3, -sub -#line 366 "Parser.yp" -{ "$_[1] . $_[3]" } - ], - [#Rule 140 - 'expr', 3, -sub -#line 367 "Parser.yp" -{ "$_[1] && $_[3]" } - ], - [#Rule 141 - 'expr', 3, -sub -#line 368 "Parser.yp" -{ "$_[1] || $_[3]" } - ], - [#Rule 142 - 'expr', 2, -sub -#line 369 "Parser.yp" -{ "! $_[2]" } - ], - [#Rule 143 - 'expr', 5, -sub -#line 370 "Parser.yp" -{ "$_[1] ? $_[3] : $_[5]" } - ], - [#Rule 144 - 'expr', 3, -sub -#line 371 "Parser.yp" -{ $factory->assign(@{$_[2]}) } - ], - [#Rule 145 - 'expr', 3, -sub -#line 372 "Parser.yp" -{ "($_[2])" } - ], - [#Rule 146 - 'expr', 1, undef - ], - [#Rule 147 - 'setlist', 2, -sub -#line 376 "Parser.yp" -{ push(@{$_[1]}, @{$_[2]}); $_[1] } - ], - [#Rule 148 - 'setlist', 2, undef - ], - [#Rule 149 - 'setlist', 1, undef - ], - [#Rule 150 - 'assign', 3, -sub -#line 382 "Parser.yp" -{ [ $_[1], $_[3] ] } - ], - [#Rule 151 - 'assign', 3, -sub -#line 383 "Parser.yp" -{ [ @_[1,3] ] } - ], - [#Rule 152 - 'args', 2, -sub -#line 390 "Parser.yp" -{ push(@{$_[1]}, $_[2]); $_[1] } - ], - [#Rule 153 - 'args', 2, -sub -#line 391 "Parser.yp" -{ push(@{$_[1]->[0]}, $_[2]); $_[1] } - ], - [#Rule 154 - 'args', 4, -sub -#line 392 "Parser.yp" -{ push(@{$_[1]->[0]}, "'', " . - $factory->assign(@_[2,4])); $_[1] } - ], - [#Rule 155 - 'args', 2, -sub -#line 394 "Parser.yp" -{ $_[1] } - ], - [#Rule 156 - 'args', 0, -sub -#line 395 "Parser.yp" -{ [ [ ] ] } - ], - [#Rule 157 - 'lnameargs', 3, -sub -#line 405 "Parser.yp" -{ push(@{$_[3]}, $_[1]); $_[3] } - ], - [#Rule 158 - 'lnameargs', 1, undef - ], - [#Rule 159 - 'lvalue', 1, undef - ], - [#Rule 160 - 'lvalue', 3, -sub -#line 410 "Parser.yp" -{ $factory->quoted($_[2]) } - ], - [#Rule 161 - 'lvalue', 1, undef - ], - [#Rule 162 - 'nameargs', 3, -sub -#line 414 "Parser.yp" -{ [ [$factory->ident($_[2])], $_[3] ] } - ], - [#Rule 163 - 'nameargs', 2, -sub -#line 415 "Parser.yp" -{ [ @_[1,2] ] } - ], - [#Rule 164 - 'nameargs', 4, -sub -#line 416 "Parser.yp" -{ [ @_[1,3] ] } - ], - [#Rule 165 - 'names', 3, -sub -#line 419 "Parser.yp" -{ push(@{$_[1]}, $_[3]); $_[1] } - ], - [#Rule 166 - 'names', 1, -sub -#line 420 "Parser.yp" -{ [ $_[1] ] } - ], - [#Rule 167 - 'name', 3, -sub -#line 423 "Parser.yp" -{ $factory->quoted($_[2]) } - ], - [#Rule 168 - 'name', 1, -sub -#line 424 "Parser.yp" -{ "'$_[1]'" } - ], - [#Rule 169 - 'name', 1, undef - ], - [#Rule 170 - 'filename', 3, -sub -#line 436 "Parser.yp" -{ "$_[1].$_[3]" } - ], - [#Rule 171 - 'filename', 1, undef - ], - [#Rule 172 - 'filepart', 1, undef - ], - [#Rule 173 - 'filepart', 1, undef - ], - [#Rule 174 - 'filepart', 1, undef - ], - [#Rule 175 - 'quoted', 2, -sub -#line 450 "Parser.yp" -{ push(@{$_[1]}, $_[2]) - if defined $_[2]; $_[1] } - ], - [#Rule 176 - 'quoted', 0, -sub -#line 452 "Parser.yp" -{ [ ] } - ], - [#Rule 177 - 'quotable', 1, -sub -#line 455 "Parser.yp" -{ $factory->ident($_[1]) } - ], - [#Rule 178 - 'quotable', 1, -sub -#line 456 "Parser.yp" -{ $factory->text($_[1]) } - ], - [#Rule 179 - 'quotable', 1, -sub -#line 457 "Parser.yp" -{ undef } - ] -]; - - - -1; - - - - - - - - - - - - diff --git a/lib/Template/Iterator.pm b/lib/Template/Iterator.pm deleted file mode 100644 index 710ecdc..0000000 --- a/lib/Template/Iterator.pm +++ /dev/null @@ -1,456 +0,0 @@ -#============================================================= -*-Perl-*- -# -# Template::Iterator -# -# DESCRIPTION -# -# Module defining an iterator class which is used by the FOREACH -# directive for iterating through data sets. This may be -# sub-classed to define more specific iterator types. -# -# An iterator is an object which provides a consistent way to -# navigate through data which may have a complex underlying form. -# This implementation uses the get_first() and get_next() methods to -# iterate through a dataset. The get_first() method is called once -# to perform any data initialisation and return the first value, -# then get_next() is called repeatedly to return successive values. -# Both these methods return a pair of values which are the data item -# itself and a status code. The default implementation handles -# iteration through an array (list) of elements which is passed by -# reference to the constructor. An empty list is used if none is -# passed. The module may be sub-classed to provide custom -# implementations which iterate through any kind of data in any -# manner as long as it can conforms to the get_first()/get_next() -# interface. The object also implements the get_all() method for -# returning all remaining elements as a list reference. -# -# For further information on iterators see "Design Patterns", by the -# "Gang of Four" (Erich Gamma, Richard Helm, Ralph Johnson, John -# Vlissides), Addision-Wesley, ISBN 0-201-63361-2. -# -# AUTHOR -# Andy Wardley <abw@kfs.org> -# -# COPYRIGHT -# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -#---------------------------------------------------------------------------- -# -# $Id: Iterator.pm,v 2.64 2004/01/13 16:19:15 abw Exp $ -# -#============================================================================ - -package Template::Iterator; - -require 5.004; - -use strict; -use vars qw( $VERSION $DEBUG $AUTOLOAD ); # AUTO? -use base qw( Template::Base ); -use Template::Constants; -use Template::Exception; - -$VERSION = sprintf("%d.%02d", q$Revision: 2.64 $ =~ /(\d+)\.(\d+)/); -$DEBUG = 0 unless defined $DEBUG; - - -#======================================================================== -# ----- CLASS METHODS ----- -#======================================================================== - -#------------------------------------------------------------------------ -# new(\@target, \%options) -# -# Constructor method which creates and returns a reference to a new -# Template::Iterator object. A reference to the target data (array -# or hash) may be passed for the object to iterate through. -#------------------------------------------------------------------------ - -sub new { - my $class = shift; - my $data = shift || [ ]; - my $params = shift || { }; - - if (ref $data eq 'HASH') { - # map a hash into a list of { key => ???, value => ??? } hashes, - # one for each key, sorted by keys - $data = [ map { { key => $_, value => $data->{ $_ } } } - sort keys %$data ]; - } - elsif (UNIVERSAL::can($data, 'as_list')) { - $data = $data->as_list(); - } - elsif (ref $data ne 'ARRAY') { - # coerce any non-list data into an array reference - $data = [ $data ] ; - } - - bless { - _DATA => $data, - _ERROR => '', - }, $class; -} - - -#======================================================================== -# ----- PUBLIC OBJECT METHODS ----- -#======================================================================== - -#------------------------------------------------------------------------ -# get_first() -# -# Initialises the object for iterating through the target data set. The -# first record is returned, if defined, along with the STATUS_OK value. -# If there is no target data, or the data is an empty set, then undef -# is returned with the STATUS_DONE value. -#------------------------------------------------------------------------ - -sub get_first { - my $self = shift; - my $data = $self->{ _DATA }; - - $self->{ _DATASET } = $self->{ _DATA }; - my $size = scalar @$data; - my $index = 0; - - return (undef, Template::Constants::STATUS_DONE) unless $size; - - # initialise various counters, flags, etc. - @$self{ qw( SIZE MAX INDEX COUNT FIRST LAST ) } - = ( $size, $size - 1, $index, 1, 1, $size > 1 ? 0 : 1, undef ); - @$self{ qw( PREV NEXT ) } = ( undef, $self->{ _DATASET }->[ $index + 1 ]); - - return $self->{ _DATASET }->[ $index ]; -} - - - -#------------------------------------------------------------------------ -# get_next() -# -# Called repeatedly to access successive elements in the data set. -# Should only be called after calling get_first() or a warning will -# be raised and (undef, STATUS_DONE) returned. -#------------------------------------------------------------------------ - -sub get_next { - my $self = shift; - my ($max, $index) = @$self{ qw( MAX INDEX ) }; - my $data = $self->{ _DATASET }; - - # warn about incorrect usage - unless (defined $index) { - my ($pack, $file, $line) = caller(); - warn("iterator get_next() called before get_first() at $file line $line\n"); - return (undef, Template::Constants::STATUS_DONE); ## RETURN ## - } - - # if there's still some data to go... - if ($index < $max) { - # update counters and flags - $index++; - @$self{ qw( INDEX COUNT FIRST LAST ) } - = ( $index, $index + 1, 0, $index == $max ? 1 : 0 ); - @$self{ qw( PREV NEXT ) } = @$data[ $index - 1, $index + 1 ]; - return $data->[ $index ]; ## RETURN ## - } - else { - return (undef, Template::Constants::STATUS_DONE); ## RETURN ## - } -} - - -#------------------------------------------------------------------------ -# get_all() -# -# Method which returns all remaining items in the iterator as a Perl list -# reference. May be called at any time in the life-cycle of the iterator. -# The get_first() method will be called automatically if necessary, and -# then subsequent get_next() calls are made, storing each returned -# result until the list is exhausted. -#------------------------------------------------------------------------ - -sub get_all { - my $self = shift; - my ($max, $index) = @$self{ qw( MAX INDEX ) }; - my @data; - - # if there's still some data to go... - if ($index < $max) { - $index++; - @data = @{ $self->{ _DATASET } } [ $index..$max ]; - - # update counters and flags - @$self{ qw( INDEX COUNT FIRST LAST ) } - = ( $max, $max + 1, 0, 1 ); - - return \@data; ## RETURN ## - } - else { - return (undef, Template::Constants::STATUS_DONE); ## RETURN ## - } -} - - -#------------------------------------------------------------------------ -# AUTOLOAD -# -# Provides access to internal fields (e.g. size, first, last, max, etc) -#------------------------------------------------------------------------ - -sub AUTOLOAD { - my $self = shift; - my $item = $AUTOLOAD; - $item =~ s/.*:://; - return if $item eq 'DESTROY'; - - # alias NUMBER to COUNT for backwards compatability - $item = 'COUNT' if $item =~ /NUMBER/i; - - return $self->{ uc $item }; -} - - -#======================================================================== -# ----- PRIVATE DEBUG METHODS ----- -#======================================================================== - -#------------------------------------------------------------------------ -# _dump() -# -# Debug method which returns a string detailing the internal state of -# the iterator object. -#------------------------------------------------------------------------ - -sub _dump { - my $self = shift; - join('', - " Data: ", $self->{ _DATA }, "\n", - " Index: ", $self->{ INDEX }, "\n", - "Number: ", $self->{ NUMBER }, "\n", - " Max: ", $self->{ MAX }, "\n", - " Size: ", $self->{ SIZE }, "\n", - " First: ", $self->{ FIRST }, "\n", - " Last: ", $self->{ LAST }, "\n", - "\n" - ); -} - - -1; - -__END__ - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Iterator - Data iterator used by the FOREACH directive - -=head1 SYNOPSIS - - my $iter = Template::Iterator->new(\@data, \%options); - -=head1 DESCRIPTION - -The Template::Iterator module defines a generic data iterator for use -by the FOREACH directive. - -It may be used as the base class for custom iterators. - -=head1 PUBLIC METHODS - -=head2 new($data) - -Constructor method. A reference to a list of values is passed as the -first parameter. Subsequent calls to get_first() and get_next() calls -will return each element from the list. - - my $iter = Template::Iterator->new([ 'foo', 'bar', 'baz' ]); - -The constructor will also accept a reference to a hash array and will -expand it into a list in which each entry is a hash array containing -a 'key' and 'value' item, sorted according to the hash keys. - - my $iter = Template::Iterator->new({ - foo => 'Foo Item', - bar => 'Bar Item', - }); - -This is equivalent to: - - my $iter = Template::Iterator->new([ - { key => 'bar', value => 'Bar Item' }, - { key => 'foo', value => 'Foo Item' }, - ]); - -When passed a single item which is not an array reference, the constructor -will automatically create a list containing that single item. - - my $iter = Template::Iterator->new('foo'); - -This is equivalent to: - - my $iter = Template::Iterator->new([ 'foo' ]); - -Note that a single item which is an object based on a blessed ARRAY -references will NOT be treated as an array and will be folded into -a list containing that one object reference. - - my $list = bless [ 'foo', 'bar' ], 'MyListClass'; - my $iter = Template::Iterator->new($list); - -equivalent to: - - my $iter = Template::Iterator->new([ $list ]); - -If the object provides an as_list() method then the Template::Iterator -constructor will call that method to return the list of data. For example: - - package MyListObject; - - sub new { - my $class = shift; - bless [ @_ ], $class; - } - - package main; - - my $list = MyListObject->new('foo', 'bar'); - my $iter = Template::Iterator->new($list); - -This is then functionally equivalent to: - - my $iter = Template::Iterator->new([ $list ]); - -The iterator will return only one item, a reference to the MyListObject -object, $list. - -By adding an as_list() method to the MyListObject class, we can force -the Template::Iterator constructor to treat the object as a list and -use the data contained within. - - package MyListObject; - - ... - - sub as_list { - my $self = shift; - return $self; - } - - package main; - - my $list = MyListObject->new('foo', 'bar'); - my $iter = Template::Iterator->new($list); - -The iterator will now return the two item, 'foo' and 'bar', which the -MyObjectList encapsulates. - -=head2 get_first() - -Returns a ($value, $error) pair for the first item in the iterator set. -The $error returned may be zero or undefined to indicate a valid datum -was successfully returned. Returns an error of STATUS_DONE if the list -is empty. - -=head2 get_next() - -Returns a ($value, $error) pair for the next item in the iterator set. -Returns an error of STATUS_DONE if all items in the list have been -visited. - -=head2 get_all() - -Returns a (\@values, $error) pair for all remaining items in the iterator -set. Returns an error of STATUS_DONE if all items in the list have been -visited. - -=head2 size() - -Returns the size of the data set or undef if unknown. - -=head2 max() - -Returns the maximum index number (i.e. the index of the last element) -which is equivalent to size() - 1. - -=head2 index() - -Returns the current index number which is in the range 0 to max(). - -=head2 count() - -Returns the current iteration count in the range 1 to size(). This is -equivalent to index() + 1. Note that number() is supported as an alias -for count() for backwards compatability. - -=head2 first() - -Returns a boolean value to indicate if the iterator is currently on -the first iteration of the set. - -=head2 last() - -Returns a boolean value to indicate if the iterator is currently on -the last iteration of the set. - -=head2 prev() - -Returns the previous item in the data set, or undef if the iterator is -on the first item. - -=head2 next() - -Returns the next item in the data set or undef if the iterator is on the -last item. - -=head1 AUTHOR - -Andy Wardley E<lt>abw@andywardley.comE<gt> - -L<http://www.andywardley.com/|http://www.andywardley.com/> - - - - -=head1 VERSION - -2.64, distributed as part of the -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -=head1 SEE ALSO - -L<Template|Template> - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Library/HTML.pod b/lib/Template/Library/HTML.pod deleted file mode 100644 index e39c120..0000000 --- a/lib/Template/Library/HTML.pod +++ /dev/null @@ -1,316 +0,0 @@ -#============================================================= -*-perl-*- -# -# Template::Library::HTML -# -# DESCRIPTION -# The HTML library provides a number of basic templates for use in -# building HTML pages. -# -# AUTHOR -# Andy Wardley <abw@andywardley.com> -# -# COPYRIGHT -# Copyright (C) 1996-2001 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2001 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -# REVISION -# 2.69 -# -#======================================================================== - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Library::HTML - Template library for building basic HTML pages - -=head1 DESCRIPTION - -B<NOTE:> This documentation is incomplete and may be incorrect -in places. - -The 'html' template library is distributed as part of the Template -Toolkit. It can be found in the 'templates' sub-directory of the -installation directory. - - use Template; - - my $tt2 = Template->new({ - INCLUDE_PATH => '/usr/local/tt2/templates', - }); - -For a portable way to determine the installation 'templates' directory, -you can use the C<Template::Config-E<gt>instdir()> class method. - - use Template; - - my $tt2 = Template->new({ - INCLUDE_PATH => Template::Config->instdir('templates'), - }); - -You should now be able to access the html library as, for example: - - [% INCLUDE html/header %] - -Note that some of the more basic elements don't give you much more -than the raw HTML tags. In many cases you might be well advised to -stick to regular HTML rather than complicating matters by the use -of template elements. - -e.g. - - <table> - . . . - </table> - -vs - - [% WRAPPER html/table %] - . . . - [% END %] - -However, the use of template elements to generate the underlying HTML -does have some important benefits, particularly as the constructs start -to get more complicated and more magical. - -See the example in the 'examples' sub-directory of the distribution -directory for further examples and enlightenment on using this library. - -=head2 Headers, Footers and Pages - -=over 4 - -=item header - -The 'header' element generates the regular header required as the -pre-amble for an HTML document. That is, everything from the initial -E<lt>htmlE<gt> to the opening E<lt>bodyE<gt>. - - [% INCLUDE html/header - title = 'This is a Test' - bgcol = '#ffffff' - %] - -Additional header items can be provided by explicitly setting the 'headers' -variable, e.g. - - [% headers = BLOCK %] - <META name="description" content="Template Toolkit"> - <META name="REVISIT-AFTER" content="14 days"> - <META name="keywords" content="Templates, Web, ...etc..."> - [% END %] - - [% INCLUDE html/header - title = 'This is a Test' - bgcol = '#ffffff' - %] - -=item footer - -The 'footer' element generates the terminating E<lt>/bodyE<gt> and -E<lt>/htmlE<gt> element to balance the header. - - [% PROCESS html/header %] - - ...page content here... - - [% PROCESS html/footer %] - -=item page - -The 'page' element combines the 'html/header' and 'html/footer' elements. - - [% WRAPPER html/page %] - - ...page content here... - - [% END %] - -Page content should be defined in the 'content' variable (e.g. via WRAPPER). -Additional HTML headers should be defined in the 'headers' variable. - - [% WRAPPER html/page - headers = '<META name="keywords" content="foo, bar, ...">' - %] - - ...page content here... - - [% END %] - -=back - -=head2 Tables, Bars and Boxes - -=over 4 - -=item table - -A basic element for creating HTML tables. - - [% WRAPPER html/table pad=10 space=4 col='#404040' %] - <tr> - <td>Hello</td> <td>World</td> - </tr> - [% END %] - -The following variables may be defined: - -=over 4 - -=item border - -Set the border width (default: 0) - -=item col - -Set the background colour (default: none). - -=item width - -Set a fixed table width. - -=item pad - -Set the cellpadding. - -=item space - -Set the cellspacing. - -=item content - -Content for the box. Supplied automatically if used via WRAPPER. - -=back - -=item row - -A basic element for creating HTML table rows. - - [% WRAPPER html/table %] - [% WRAPPER html/row %] - <td>Hello</td> <td>World</td> - [% END %] - [% END %] - -The following variables may be defined: - -=over 4 - -=item col - -Set the background colour (default: none). - -=item valign - -Set the vertical alignment. - -=item rowspan - -Specify the number of rows to span. - -=item content - -Content for the box. Supplied automatically if used via WRAPPER. - -=back - -=item cell - -A basic element for creating HTML table cells. - - [% WRAPPER html/table %] - [% WRAPPER html/row %] - [% INCLUDE html/cell - FOREACH content = ['Hello', 'World'] %] - [% END %] - [% END %] - -The following variables may be defined: - -=over 4 - -=item col - -Set the background colour (default: none). - -=item align - -Set the horizontal alignment. - -=item colspan - -Specify the number of columns to span. - -=item content - -Content for the cell. Supplied automatically if used via WRAPPER. - -=back - -=item bar - -The bar element is a wrapping of html/table + html/row. - - [% WRAPPER html/bar %] - <td>Foo</td> <td>Bar</td> - [% END %] - -=item box - -The box element is a wrapping of html/table + html/row + html/cell - - [% WRAPPER html/box %] - Hello World! - [% END %] - -=back - -=head1 AUTHOR - -Andy Wardley E<lt>abw@andywardley.comE<gt> - -L<http://www.andywardley.com/|http://www.andywardley.com/> - - - - -=head1 VERSION - -2.69, distributed as part of the -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -=head1 SEE ALSO - -L<Template::Library::Splash|Template::Library::Splash> - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Library/PostScript.pod b/lib/Template/Library/PostScript.pod deleted file mode 100644 index c30246c..0000000 --- a/lib/Template/Library/PostScript.pod +++ /dev/null @@ -1,78 +0,0 @@ -#============================================================= -*-perl-*- -# -# Template::Library::PostScript -# -# DESCRIPTION -# This library contains a number of useful templates for generating -# PostScript pages. -# -# AUTHOR -# Andy Wardley <abw@andywardley.com> -# -# COPYRIGHT -# Copyright (C) 1996-2001 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2001 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -# REVISION -# 2.69 -# -#======================================================================== - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Library::PostScript - Template library for generating PostScript - -=head1 DESCRIPTION - -The PostScript library contains a number of templates for generating -PostScript pages. It's very new, very incomplete, very ad-hoc and -isn't yet documented. - -=head1 AUTHOR - -Andy Wardley E<lt>abw@andywardley.comE<gt> - -L<http://www.andywardley.com/|http://www.andywardley.com/> - - - - -=head1 VERSION - -2.69, distributed as part of the -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - - - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Library/Splash.pod b/lib/Template/Library/Splash.pod deleted file mode 100644 index e8c4f8b..0000000 --- a/lib/Template/Library/Splash.pod +++ /dev/null @@ -1,1030 +0,0 @@ -#============================================================= -*-perl-*- -# -# Template::Library::Splash -# -# DESCRIPTION -# The Splash! library is built on top of the HTML library and -# implements a set of widgets for easy construction of stylish HTML -# pages -# -# AUTHOR -# Andy Wardley <abw@andywardley.com> -# -# COPYRIGHT -# Copyright (C) 1996-2001 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2001 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -# REVISION -# 2.69 -# -#======================================================================== - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Library::Splash - Template library for building stylish HTML user interfaces - -=head1 DESCRIPTION - -B<NOTE:> This documentation is incomplete, incorrect and outdated. -The Splash! library is still evolving and subject to change. See -the examples for a much more recent and accurate demonstration of -use. - -=head2 Introduction - -The 'Splash' template library is distributed as part of the Template -Toolkit. It can be found in the 'templates' sub-directory of the -installation directory. - - /your/tt2/installation - | - +-- docs - | ... - | - +-- images - | ... - | - +-- examples - | ... - | - +-- templates - | - +-- html - | ... - +-- pod - | ... - +-- splash <<<< YOU ARE HERE - ... - - -To use the Splash library, you first need to tell the Template Toolkit -where to find the template files. - - use Template; - - my $tt2 = Template->new({ - INCLUDE_PATH => '/usr/local/tt2/templates', - }); - -For a portable way to determine the installation 'templates' directory, -you can use the C<Template::Config-E<gt>instdir()> class method. - - use Template; - - my $tt2 = Template->new({ - INCLUDE_PATH => Template::Config->instdir('templates'), - }); - -Note that you should set the INCLUDE_PATH to the 'templates' directory -as shown here and don't be tempted to set the INCLUDE_PATH to -'templates/splash'. Many of the Splash! components use elements in -the 'html' directory and contain directives of the form: - - [% INCLUDE html/something %]. - -=head2 Configuration - -The 'splash/config' template defines a 'splash' hash array which -contains numerous configuration items for the Splash library. You -must PROCESS this template to ensure that the hash definition is -imported into your calling template. An INCLUDE is not sufficient as -it localises variables and prevents the 'splash' hash array from -existing outside the splash/config template. - - [% PROCESS splash/config %] - -Alternately, you can define the splash/config template as a PRE_PROCESS -item when you create the Template processor. - - use Template; - - my $tt2 = Template->new({ - INCLUDE_PATH => Template::Config->instdir('templates'), - PRE_PROCESS => 'splash/config', - }); - -You can modify the default configuration by creating your own -PRE_PROCESS config file which loads the 'splash/config' and then -tweaks the settings to your own preferences. - - my $tt2 = Template->new({ - INCLUDE_PATH => [ '/home/abw/tt2/templates', - Template::Config->instdir('templates') ], - PRE_PROCESS => 'config' - }); - -/home/abw/tt2/templates/config: - - [% # load the 'splash' configuration - PROCESS splash/config; - - # tweak values to personal preferences - splash.images = '/~abw/tt2/images/splash' - splash.select.col = 'leaf' - splash.unselect.col = 'bud' - %] - -The splash/config file includes some instructional comments on -things you might like to tweak. - -=head2 Colours - -The Splash! library uses the colours defined in the html/rgb template. -The 'rgb' hash defined therein is imported as the 'splash.rgb' hash. - - [% INCLUDE splash/box col='grey75' %] - -See the examples for further enlightenment on using colour. - -=head2 Style - -There are two very primitive "styles" implemented called "select" and -"unselect". These are used to indicate which item on a menu is -selected, for example. Each style defines characteristics like -background colour, font face, size and colour, text alignment, and so -on. - -The styles are implemented as hashes within the 'splash' hash. Many -of the components respond to a 'style' variable being set and you can -pass a direct reference to splash.select or splash.unselect (or your -own styles). e.g. - - [% INCLUDE splash/button - content = "Unselected" - style = splash.unselect - %] - [% INCLUDE splash/button - content ="Selected" - style = splash.select - %] - -Alternately, you can use the 'select' variable to indicate either -of the inbuilt styles: splash.select or splash.unselect. - - [% INCLUDE splash/button - content = "Unselected" - select = 0 - %] - [% INCLUDE splash/button - content = "Selected" - select = 1 - %] - -=head1 COMPONENT TEMPLATES - -This section describes some of the component templates in the Splash! -library. This documentation is incomplete and may also be inaccurate -in places. The examples in the 'examples' directory are likely to be -a much better reference. - - -=head2 splash/text - -Simple template to format text according to a selected/unselected style, -adding links, etc. - - [% INCLUDE splash/text - content = 'Template Toolkit' - link = 'http://www.template-toolkit.org' - select = 0 - bold = 1 - %] - - -Configuration items: - -=over 4 - - -=item content - -Text content. - - -=item link - -URL which can be defined to make the text a link. - - -=item style - -Reference to a style hash. - - -=item select - -Flag to default the style to splash.select (select == true value) or -splash.unselect (select == false value). - - -=back - -The following items default to the relevant style values: - -=over 4 - - -=item col (style.col.text) - - -=item font (style.font.face) - - -=item bold (style.font.bold) - - -=item size (style.font.size) - - -=back - - - -=head2 splash/table - -A thin wrapper around html/table, allowing a colour to be specified -by name. - - [% WRAPPER splash/table - col = 'aqua' - pad = 4 - width = '100%' - %] - <tr> - <td>Foo</td> - <td>Bar</td> - </tr> - [% END %] - - -Configuration items: - -=over 4 - - -=item content - -Table content. - - -=item col - -Background colour. - - -=item border - -Border width (default: 0) - - -=item width - -Width in absolute pixels (e.g. '100') or as a percentage (e.g. '50%'). - -=item pad - -Cell padding. - - -=item space - -Cell padding. - - -=back - - - -=head2 splash/row - -Creates a row for an HTML table. - - [% WRAPPER splash/table %] - - [% WRAPPER splash/row col='marine' %] - <td>Foo</td><td>Bar</td> - [% END %] - - [% WRAPPER splash/row col='aqua' %] - <td>Foo</td><td>Bar</td> - [% END %] - - [% END %] - - -Configuration items: - -=over 4 - - -=item content - -Row content. - - -=item col - -Background colour. - - -=item valign - -Vertical alignment - - -=item rowspan - -Number of rows to span. - - -=back - - - -=head2 splash/cell - -Creates a cell for an HTML table. - - [% WRAPPER splash/table + splash/row + splash/cell col='grey75' %] - Hello World - [% END %] - - -Configuration items: - -=over 4 - - -=item content - -Cell content. - - -=item col - -Background colour. - - -=item align - -Horizontal alignment - - -=item colspan - -Number of columns to span. - - -=back - - - -=head2 splash/box - -A box created from a union of splash/table, splash/row and splash/cell. -The following is equivalent to the previous example. - - [% WRAPPER splash/box col='grey75' %] - Hello World - [% END %] - -Configuration items are as per the individual templates. - - -=head2 splash/button - -Creates a small button with rounded corners. - - [% INCLUDE splash/button - content = 'Template Toolkit' - select = 1 - width = '50%' - %] - - -Configuration items: - -=over 4 - - -=item content - -Button content. - - -=item style - -Reference to a style hash. - - -=item select - -Flag to default the style to splash.select (select == true value) or -splash.unselect (select == false value). - - -=item width - -Width in absolute pixels (e.g. '100') or as a percentage (e.g. '50%'). - -=back - -The following items default to the relevant style values: - -=over 4 - - -=item col (style.col.text) - - -=item textcol (style.col.text) - - -=item font (style.font.face) - - -=item size (style.font.size) - - -=item bold (style.font.bold) - - -=item width (style.button.width) - - -=item align (style.button.align) - - -=back - - - -=head2 splash/bar - -Creates a bar with rounded corners at either the top or bottom, and -square corners on the other. Default has rounded at the top, set -'invert' to select bottom. - - [% INCLUDE splash/bar - content = 'Hello World', - select = 1 - %] - - -Configuration items: - -=over 4 - - -=item content - -Bar content. - - -=item style - -Reference to a style hash. - - -=item select - -Flag to default the style to splash.select (select == true value) or -splash.unselect (select == false value). - - -=item width - -Width in absolute pixels (e.g. '100') or as a percentage (e.g. '50%'). - -=item invert - -Flag to invert bar to hang down instead of sitting -upright. - - -=back - -The following items default to the relevant style values: - -=over 4 - - -=item col (style.col.text) - - -=item textcol (style.col.text) - - -=item font (style.font.face) - - -=item size (style.font.size) - - -=item bold (style.font.bold) - - -=item width (style.button.width) - - -=item align (style.button.align) - - -=back - - -=head2 splash/hair - -Generates a frame enclosing the content within crosshair corners. - - [% INCLUDE splash/hair - content = 'Template Toolkit' - %] - - -Configuration items: - -=over 4 - - -=item content - -Hair content. - - -=item style - -Reference to a style hash. - - -=back - -The following items default to the relevant style values: - -=over 4 - - -=item col (style.col.text) - - -=item bgcol (style.col.back) - - -=item align (style.button.align) - - -=back - - -=head2 splash/menu - -Creates a menu as a series of splash/button elements. - - [% buttons = [ - { text => 'One', link => 'one.html' } - { text => 'Two', link => 'two.html' } - ] - %] - - [% INCLUDE splash/menu - select = 2 # Two - %] - - -Configuration items: - -=over 4 - - -=item buttons - -A reference to a list of hash arrays containing 'text' and 'link' items. - - -=item select (n or 0) - -Indicates which button should be selected. First item is 1. 0 indicates -no button selected. - - -=item width - -Width in absolute pixels (e.g. '100') or as a percentage (e.g. '50%'). - -=item align - -Horizontal alignment - - -=back - - - -=head2 splash/menubar - -As above, but incorporated into a wider bar. - - [% WRAPPER splash/menubar %] - Section Title - [% END %] - - -Configuration items: - -=over 4 - - -=item buttons - -A reference to a list of hash arrays containing 'text' and 'link' items. - - -=item select (n or 0) - -Indicates which button should be selected. First item is 1. 0 indicates -no button selected. - - -=item width - -Width in absolute pixels (e.g. '100') or as a percentage (e.g. '50%'). - -=item align - -Horizontal alignment - - -=back - - - -=head2 splash/panel - -A table with a coloured edge. - - [% WRAPPER splash/panel edge='black' fill='grey75' border=2 %] - <tr> - <td>Hello World</td> - </tr> - [% END %] - - -Configuration items: - -=over 4 - - -=item content - -Panel content. - - -=item style - -Reference to a style hash. - - -=item select - -Flag to default the style to splash.select (select == true value) or -splash.unselect (select == false value). - - -=item width - -Width in absolute pixels (e.g. '100') or as a percentage (e.g. '50%'). - -=item align - -Horizontal alignment - - -=item border - -Border width (default: 0) - - -=back - -The following items default to the relevant style values: - -=over 4 - - -=item edge (style.col.edge) - - -=item fill (style.col.fill) - - -=item pad (style.pad) - - -=back - - - -=head2 splash/pane - -A union of splash/row + splash/cell. - - [% WRAPPER splash/panel select=1 %] - [% WRAPPER splash/pane col='grey75' %] - Hello World - [% END %] - - [% WRAPPER splash/pane col='grey50' %] - Hello Again - [% END %] - [% END %] - - -=head2 splash/tab - -A simple button looking like a page tab. - - [% INCLUDE splash/tab - content = 'Option 1' - col = 'aqua' - %] - - -Configuration items: - -=over 4 - - -=item content - -Tab content. - - -=item style - -Reference to a style hash. - - -=item select - -Flag to default the style to splash.select (select == true value) or -splash.unselect (select == false value). - - -=item width - -Width in absolute pixels (e.g. '100') or as a percentage (e.g. '50%'). - -=item align - -Horizontal alignment - - -=back - -The following items default to the relevant style values: - -=over 4 - - -=item col (style.col.text) - - -=item textcol (style.col.text) - - -=item font (style.font.face) - - -=item size (style.font.size) - - -=item bold (style.font.bold) - - -=item tabalign (style.tab.align) - - -=back - - - -=head2 splash/tabset - -A set of splash/tab components, similar to a menu. - - -Configuration items: - -=over 4 - - -=item tabs - -List of hash references containing text/link entries, as per -menu buttons. - - -=item select - -Flag to default the style to splash.select (select == true value) or -splash.unselect (select == false value). - - -=item invert - -Flag to invert tab to hang down instead of sitting -upright. - - -=back - - - -=head2 splash/tabbox - -Add a splash/tab to the top of a splash/box. - - -Configuration items: - -=over 4 - - -=item title - - title. - - -=item content - - content. - - -=item width - -Width in absolute pixels (e.g. '100') or as a percentage (e.g. '50%'). - -=item tabwidth - -Width of tabs. - - -=item select - -Flag to default the style to splash.select (select == true value) or -splash.unselect (select == false value). - - -=item border - -Border width (default: 0) - - -=back - -The following items default to the relevant style values: - -=over 4 - - -=item col (style.col.text) - - -=item fill (style.col.fill) - - -=item tabalign (style.tab.align) - - -=item tablocate (style.tab.locate) - - -=back - - - -=head2 splash/tabsbox - -Add a splash/tabset to the top of a splash/box. - - -Configuration items: - -=over 4 - - -=item tabs - -List of hash references containing text/link entries, as per -menu buttons. - - -=item select - -Flag to default the style to splash.select (select == true value) or -splash.unselect (select == false value). - - -=item content - - content. - - -=item width - -Width in absolute pixels (e.g. '100') or as a percentage (e.g. '50%'). - -=item border - -Border width (default: 0) - - -=item invert - -Flag to invert to hang down instead of sitting -upright. - - -=back - -The following items default to the relevant style values: - -=over 4 - - -=item col (style.col.text) - - -=item fill (style.col.fill) - - -=item tabalign (style.tab.align) - - -=item tablocate (style.tab.locate) - - -=back - - -=head2 splash/tabspanel - -As per splash/tabsbox, but attached to a splash/panel instead of a -splash/box. - - -=head1 EXAMPLES - -See the examples in the 'examples' sub-directory of the installation -for comprehensive examples showing use of the Splash! library. - -=head1 AUTHOR - -Andy Wardley E<lt>abw@andywardley.comE<gt> - -L<http://www.andywardley.com/|http://www.andywardley.com/> - - - - -=head1 VERSION - -2.69, distributed as part of the -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -=head1 SEE ALSO - -L<Template::Library::HTML|Template::Library::HTML> - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Manual.pod b/lib/Template/Manual.pod deleted file mode 100644 index 8775a5b..0000000 --- a/lib/Template/Manual.pod +++ /dev/null @@ -1,180 +0,0 @@ -#============================================================= -*-perl-*- -# -# Template::Manual -# -# DESCRIPTION -# This is the comprehensive user guide and reference manual for the -# Template Toolkit. -# -# AUTHOR -# Andy Wardley <abw@andywardley.com> -# -# COPYRIGHT -# Copyright (C) 1996-2001 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2001 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -# REVISION -# -# -#======================================================================== - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Manual - User guide and reference manual for the Template Toolkit - -=head1 DESCRIPTION - -This is the comprehensive user guide and reference manual for the -Template Toolkit. - -=over 4 - -=item L<Template::Manual::Intro|Template::Manual::Intro> - -Introduction to the Template Toolkit - -This section provides a general introduction to the Template Toolkit, -giving a quick overview of features, examples of template directives -and use of the Template.pm module. It also described the basic concept -underlying the toolkit: the separation of presentation elements from -application logic and data. - -=item L<Template::Manual::Syntax|Template::Manual::Syntax> - -Directive syntax, structure and semantics - -This section describes the syntax, structure and semantics of the -Template Toolkit directives and general presentation language. - -=item L<Template::Manual::Directives|Template::Manual::Directives> - -Template directives - -This section provides a reference of all Template Toolkit directives, -complete with examples of use. - -=item L<Template::Manual::Variables|Template::Manual::Variables> - -Template variables and code bindings - -This section describes the different ways in which Perl data can be -bound to template variables and accessed via Template Toolkit -directives. - -=item L<Template::Manual::VMethods|Template::Manual::VMethods> - -Virtual Methods - -The Template Toolkit provides virtual methods for manipulating variable -values. Most of them are analogous to regular Perl functions of the -same names. This section describes the different virtual methods that -can be applied to scalar, list and hash values. - -=item L<Template::Manual::Config|Template::Manual::Config> - -Configuration options - -This section contains details of all the configuration options that can -be used to customise the behaviour and extend the features of the -Template Toolkit. - -=item L<Template::Manual::Filters|Template::Manual::Filters> - -Standard filters - -This section lists all the standard filters distributed with the -Template Toolkit for post-processing output. - -=item L<Template::Manual::Plugins|Template::Manual::Plugins> - -Standard plugins - -This section lists the standard plugins which can be used to extend the -runtime functionality of the Template Toolkit. The plugins are -distributed with the Template Toolkit but may required additional -modules from CPAN. - -=item L<Template::Manual::Internals|Template::Manual::Internals> - -Template Toolkit internals - -This document provides an overview of the internal architecture of the -Template Toolkit. It is a work in progress and is far from complete, -currently providing little more than an overview of how the major -components fit together. Nevertheless, it's a good starting point for -anyone wishing to delve into the source code to find out how it all -works. - -=item L<Template::Manual::Views|Template::Manual::Views> - -Template Toolkit views (experimental) - -This section describes dynamic views: a powerful but experimental new -feature in version 2.01 of the Template Toolkit. - -=item L<Template::Manual::Refs|Template::Manual::Refs> - -Related modules, projects and other resources - -This section provides references to external modules, projects and -other resources related to the Template Toolkit. - -=item L<Template::Manual::Credits|Template::Manual::Credits> - -Author and contributor credits - -This section provides a brief history of the Template Toolkit and -details the primary author and numerous other people who have -contributed to it. - - - -=back - -=head1 AUTHOR - -Andy Wardley E<lt>abw@andywardley.comE<gt> - -L<http://www.andywardley.com/|http://www.andywardley.com/> - - - - -=head1 VERSION - -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - - - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Manual/Config.pod b/lib/Template/Manual/Config.pod deleted file mode 100644 index 5020556..0000000 --- a/lib/Template/Manual/Config.pod +++ /dev/null @@ -1,2122 +0,0 @@ -#============================================================= -*-perl-*- -# -# Template::Manual::Config -# -# DESCRIPTION -# This section contains details of all the configuration options that -# can be used to customise the behaviour and extend the features of -# the Template Toolkit. -# -# AUTHOR -# Andy Wardley <abw@andywardley.com> -# -# COPYRIGHT -# Copyright (C) 1996-2001 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2001 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -# REVISION -# -# -#======================================================================== - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Manual::Config - Configuration options - -=head1 DESCRIPTION - -This section contains details of all the configuration options that can -be used to customise the behaviour and extend the features of the -Template Toolkit. - -=head2 Template Style and Parsing Options - -=over 4 - - - -=item START_TAG, END_TAG - -The START_TAG and END_TAG options are used to specify character -sequences or regular expressions that mark the start and end of a -template directive. The default values for START_TAG and END_TAG are -'[%' and '%]' respectively, giving us the familiar directive style: - - [% example %] - -Any Perl regex characters can be used and therefore should be escaped -(or use the Perl C<quotemeta> function) if they are intended to -represent literal characters. - - my $template = Template->new({ - START_TAG => quotemeta('<+'), - END_TAG => quotemeta('+>'), - }); - -example: - - <+ INCLUDE foobar +> - -The TAGS directive can also be used to set the START_TAG and END_TAG values -on a per-template file basis. - - [% TAGS <+ +> %] - - - - - - -=item TAG_STYLE - -The TAG_STYLE option can be used to set both START_TAG and END_TAG -according to pre-defined tag styles. - - my $template = Template->new({ - TAG_STYLE => 'star', - }); - -Available styles are: - - template [% ... %] (default) - template1 [% ... %] or %% ... %% (TT version 1) - metatext %% ... %% (Text::MetaText) - star [* ... *] (TT alternate) - php <? ... ?> (PHP) - asp <% ... %> (ASP) - mason <% ... > (HTML::Mason) - html <!-- ... --> (HTML comments) - -Any values specified for START_TAG and/or END_TAG will over-ride -those defined by a TAG_STYLE. - -The TAGS directive may also be used to set a TAG_STYLE - - [% TAGS html %] - <!-- INCLUDE header --> - - - - - - -=item PRE_CHOMP, POST_CHOMP - -Anything outside a directive tag is considered plain text and is -generally passed through unaltered (but see the INTERPOLATE option). -This includes all whitespace and newlines characters surrounding -directive tags. Directives that don't generate any output will leave -gaps in the output document. - -Example: - - Foo - [% a = 10 %] - Bar - -Output: - - Foo - - Bar - -The PRE_CHOMP and POST_CHOMP options can help to clean up some of this -extraneous whitespace. Both are disabled by default. - - my $template = Template->new({ - PRE_CHOMP => 1, - POST_CHOMP => 1, - }); - -With PRE_CHOMP set to 1, the newline and whitespace preceding a directive -at the start of a line will be deleted. This has the effect of -concatenating a line that starts with a directive onto the end of the -previous line. - - Foo <----------. - | - ,---(PRE_CHOMP)----' - | - `-- [% a = 10 %] --. - | - ,---(POST_CHOMP)---' - | - `-> Bar - -With POST_CHOMP set to 1, any whitespace after a directive up to and -including the newline will be deleted. This has the effect of joining -a line that ends with a directive onto the start of the next line. - -If PRE_CHOMP or POST_CHOMP is set to 2, then instead of removing all -the whitespace, the whitespace will be collapsed to a single space. -This is useful for HTML, where (usually) a contiguous block of -whitespace is rendered the same as a single space. - -You may use the CHOMP_NONE, CHOMP_ALL, and CHOMP_COLLAPSE constants -from the Template::Constants module to deactivate chomping, remove -all whitespace, or collapse whitespace to a single space. - -PRE_CHOMP and POST_CHOMP can be activated for individual directives by -placing a '-' immediately at the start and/or end of the directive. - - [% FOREACH user = userlist %] - [%- user -%] - [% END %] - -The '-' characters activate both PRE_CHOMP and POST_CHOMP for the one -directive '[%- name -%]'. Thus, the template will be processed as if -written: - - [% FOREACH user = userlist %][% user %][% END %] - -Note that this is the same as if PRE_CHOMP and POST_CHOMP were set -to CHOMP_ALL; the only way to get the CHOMP_COLLAPSE behavior is -to set PRE_CHOMP or POST_CHOMP accordingly. If PRE_CHOMP or POST_CHOMP -is already set to CHOMP_COLLAPSE, using '-' will give you CHOMP_COLLAPSE -behavior, not CHOMP_ALL behavior. - -Similarly, '+' characters can be used to disable PRE_CHOMP or -POST_CHOMP (i.e. leave the whitespace/newline intact) options on a -per-directive basis. - - [% FOREACH user = userlist %] - User: [% user +%] - [% END %] - -With POST_CHOMP enabled, the above example would be parsed as if written: - - [% FOREACH user = userlist %]User: [% user %] - [% END %] - - - - - -=item TRIM - -The TRIM option can be set to have any leading and trailing whitespace -automatically removed from the output of all template files and BLOCKs. - -By example, the following BLOCK definition - - [% BLOCK foo %] - Line 1 of foo - [% END %] - -will be processed is as "\nLine 1 of foo\n". When INCLUDEd, the surrounding -newlines will also be introduced. - - before - [% INCLUDE foo %] - after - -output: - before - - Line 1 of foo - - after - -With the TRIM option set to any true value, the leading and trailing -newlines (which count as whitespace) will be removed from the output -of the BLOCK. - - before - Line 1 of foo - after - -The TRIM option is disabled (0) by default. - - - - - -=item INTERPOLATE - -The INTERPOLATE flag, when set to any true value will cause variable -references in plain text (i.e. not surrounded by START_TAG and END_TAG) -to be recognised and interpolated accordingly. - - my $template = Template->new({ - INTERPOLATE => 1, - }); - -Variables should be prefixed by a '$' to identify them. Curly braces -can be used in the familiar Perl/shell style to explicitly scope the -variable name where required. - - # INTERPOLATE => 0 - <a href="http://[% server %]/[% help %]"> - <img src="[% images %]/help.gif"></a> - [% myorg.name %] - - # INTERPOLATE => 1 - <a href="http://$server/$help"> - <img src="$images/help.gif"></a> - $myorg.name - - # explicit scoping with { } - <img src="$images/${icon.next}.gif"> - -Note that a limitation in Perl's regex engine restricts the maximum length -of an interpolated template to around 32 kilobytes or possibly less. Files -that exceed this limit in size will typically cause Perl to dump core with -a segmentation fault. If you routinely process templates of this size -then you should disable INTERPOLATE or split the templates in several -smaller files or blocks which can then be joined backed together via -PROCESS or INCLUDE. - - - - - - - -=item ANYCASE - -By default, directive keywords should be expressed in UPPER CASE. The -ANYCASE option can be set to allow directive keywords to be specified -in any case. - - # ANYCASE => 0 (default) - [% INCLUDE foobar %] # OK - [% include foobar %] # ERROR - [% include = 10 %] # OK, 'include' is a variable - - # ANYCASE => 1 - [% INCLUDE foobar %] # OK - [% include foobar %] # OK - [% include = 10 %] # ERROR, 'include' is reserved word - -One side-effect of enabling ANYCASE is that you cannot use a variable -of the same name as a reserved word, regardless of case. The reserved -words are currently: - - GET CALL SET DEFAULT INSERT INCLUDE PROCESS WRAPPER - IF UNLESS ELSE ELSIF FOR FOREACH WHILE SWITCH CASE - USE PLUGIN FILTER MACRO PERL RAWPERL BLOCK META - TRY THROW CATCH FINAL NEXT LAST BREAK RETURN STOP - CLEAR TO STEP AND OR NOT MOD DIV END - - -The only lower case reserved words that cannot be used for variables, -regardless of the ANYCASE option, are the operators: - - and or not mod div - - - - - - -=back - -=head2 Template Files and Blocks - -=over 4 - - - -=item INCLUDE_PATH - -The INCLUDE_PATH is used to specify one or more directories in which -template files are located. When a template is requested that isn't -defined locally as a BLOCK, each of the INCLUDE_PATH directories is -searched in turn to locate the template file. Multiple directories -can be specified as a reference to a list or as a single string where -each directory is delimited by ':'. - - my $template = Template->new({ - INCLUDE_PATH => '/usr/local/templates', - }); - - my $template = Template->new({ - INCLUDE_PATH => '/usr/local/templates:/tmp/my/templates', - }); - - my $template = Template->new({ - INCLUDE_PATH => [ '/usr/local/templates', - '/tmp/my/templates' ], - }); - -On Win32 systems, a little extra magic is invoked, ignoring delimiters -that have ':' followed by a '/' or '\'. This avoids confusion when using -directory names like 'C:\Blah Blah'. - -When specified as a list, the INCLUDE_PATH path can contain elements -which dynamically generate a list of INCLUDE_PATH directories. These -generator elements can be specified as a reference to a subroutine or -an object which implements a paths() method. - - my $template = Template->new({ - INCLUDE_PATH => [ '/usr/local/templates', - \&incpath_generator, - My::IncPath::Generator->new( ... ) ], - }); - -Each time a template is requested and the INCLUDE_PATH examined, the -subroutine or object method will be called. A reference to a list of -directories should be returned. Generator subroutines should report -errors using die(). Generator objects should return undef and make an -error available via its error() method. - -For example: - - sub incpath_generator { - - # ...some code... - - if ($all_is_well) { - return \@list_of_directories; - } - else { - die "cannot generate INCLUDE_PATH...\n"; - } - } - -or: - - package My::IncPath::Generator; - - # Template::Base (or Class::Base) provides error() method - use Template::Base; - use base qw( Template::Base ); - - sub paths { - my $self = shift; - - # ...some code... - - if ($all_is_well) { - return \@list_of_directories; - } - else { - return $self->error("cannot generate INCLUDE_PATH...\n"); - } - } - - 1; - - - - - -=item DELIMITER - -Used to provide an alternative delimiter character sequence for -separating paths specified in the INCLUDE_PATH. The default -value for DELIMITER is ':'. - - # tolerate Silly Billy's file system conventions - my $template = Template->new({ - DELIMITER => '; ', - INCLUDE_PATH => 'C:/HERE/NOW; D:/THERE/THEN', - }); - - # better solution: install Linux! :-) - -On Win32 systems, the default delimiter is a little more intelligent, -splitting paths only on ':' characters that aren't followed by a '/'. -This means that the following should work as planned, splitting the -INCLUDE_PATH into 2 separate directories, C:/foo and C:/bar. - - # on Win32 only - my $template = Template->new({ - INCLUDE_PATH => 'C:/Foo:C:/Bar' - }); - -However, if you're using Win32 then it's recommended that you -explicitly set the DELIMITER character to something else (e.g. ';') -rather than rely on this subtle magic. - - - - -=item ABSOLUTE - -The ABSOLUTE flag is used to indicate if templates specified with -absolute filenames (e.g. '/foo/bar') should be processed. It is -disabled by default and any attempt to load a template by such a -name will cause a 'file' exception to be raised. - - my $template = Template->new({ - ABSOLUTE => 1, - }); - - # this is why it's disabled by default - [% INSERT /etc/passwd %] - -On Win32 systems, the regular expression for matching absolute -pathnames is tweaked slightly to also detect filenames that start -with a driver letter and colon, such as: - - C:/Foo/Bar - - - - - - -=item RELATIVE - -The RELATIVE flag is used to indicate if templates specified with -filenames relative to the current directory (e.g. './foo/bar' or -'../../some/where/else') should be loaded. It is also disabled by -default, and will raise a 'file' error if such template names are -encountered. - - my $template = Template->new({ - RELATIVE => 1, - }); - - [% INCLUDE ../logs/error.log %] - - - - - -=item DEFAULT - -The DEFAULT option can be used to specify a default template which should -be used whenever a specified template can't be found in the INCLUDE_PATH. - - my $template = Template->new({ - DEFAULT => 'notfound.html', - }); - -If a non-existant template is requested through the Template process() -method, or by an INCLUDE, PROCESS or WRAPPER directive, then the -DEFAULT template will instead be processed, if defined. Note that the -DEFAULT template is not used when templates are specified with -absolute or relative filenames, or as a reference to a input file -handle or text string. - - - - - -=item BLOCKS - -The BLOCKS option can be used to pre-define a default set of template -blocks. These should be specified as a reference to a hash array -mapping template names to template text, subroutines or Template::Document -objects. - - my $template = Template->new({ - BLOCKS => { - header => 'The Header. [% title %]', - footer => sub { return $some_output_text }, - another => Template::Document->new({ ... }), - }, - }); - - - - -=item AUTO_RESET - -The AUTO_RESET option is set by default and causes the local BLOCKS -cache for the Template::Context object to be reset on each call to the -Template process() method. This ensures that any BLOCKs defined -within a template will only persist until that template is finished -processing. This prevents BLOCKs defined in one processing request -from interfering with other independent requests subsequently -processed by the same context object. - -The BLOCKS item may be used to specify a default set of block definitions -for the Template::Context object. Subsequent BLOCK definitions in templates -will over-ride these but they will be reinstated on each reset if AUTO_RESET -is enabled (default), or if the Template::Context reset() method is called. - - - - - - - - - -=item RECURSION - -The template processor will raise a file exception if it detects -direct or indirect recursion into a template. Setting this option to -any true value will allow templates to include each other recursively. - - - -=back - -=head2 Template Variables - -=over 4 - -=item VARIABLES, PRE_DEFINE - -The VARIABLES option (or PRE_DEFINE - they're equivalent) can be used -to specify a hash array of template variables that should be used to -pre-initialise the stash when it is created. These items are ignored -if the STASH item is defined. - - my $template = Template->new({ - VARIABLES => { - title => 'A Demo Page', - author => 'Joe Random Hacker', - version => 3.14, - }, - }; - -or - - my $template = Template->new({ - PRE_DEFINE => { - title => 'A Demo Page', - author => 'Joe Random Hacker', - version => 3.14, - }, - }; - - - - -=item CONSTANTS - -The CONSTANTS option can be used to specify a hash array of template -variables that are compile-time constants. These variables are -resolved once when the template is compiled, and thus don't require -further resolution at runtime. This results in significantly faster -processing of the compiled templates and can be used for variables that -don't change from one request to the next. - - my $template = Template->new({ - CONSTANTS => { - title => 'A Demo Page', - author => 'Joe Random Hacker', - version => 3.14, - }, - }; - -=item CONSTANT_NAMESPACE - -Constant variables are accessed via the 'constants' namespace by -default. - - [% constants.title %] - -The CONSTANTS_NAMESPACE option can be set to specify an alternate -namespace. - - my $template = Template->new({ - CONSTANTS => { - title => 'A Demo Page', - # ...etc... - }, - CONSTANTS_NAMESPACE => 'const', - }; - -In this case the constants would then be accessed as: - - [% const.title %] - -=item NAMESPACE - -The constant folding mechanism described above is an example of a -namespace handler. Namespace handlers can be defined to provide -alternate parsing mechanisms for variables in different namespaces. - -Under the hood, the Template module converts a constructor configuration -such as: - - my $template = Template->new({ - CONSTANTS => { - title => 'A Demo Page', - # ...etc... - }, - CONSTANTS_NAMESPACE => 'const', - }; - -into one like: - - my $template = Template->new({ - NAMESPACE => { - const => Template:::Namespace::Constants->new({ - title => 'A Demo Page', - # ...etc... - }), - }, - }; - -You can use this mechanism to define multiple constant namespaces, or -to install custom handlers of your own. - - my $template = Template->new({ - NAMESPACE => { - site => Template:::Namespace::Constants->new({ - title => "Wardley's Widgets", - version => 2.718, - }), - author => Template:::Namespace::Constants->new({ - name => 'Andy Wardley', - email => 'abw@andywardley.com', - }), - voodoo => My::Namespace::Handler->new( ... ), - }, - }; - -Now you have 2 constant namespaces, for example: - - [% site.title %] - [% author.name %] - -as well as your own custom namespace handler installed for the 'voodoo' -namespace. - - [% voodoo.magic %] - -See L<Template::Namespace::Constants|Template::Namespace::Constants> -for an example of what a namespace handler looks like on the inside. - - - - - -=back - -=head2 Template Processing Options - - -The following options are used to specify any additional templates -that should be processed before, after, around or instead of the -template passed as the first argument to the Template process() -method. These options can be perform various useful tasks such as -adding standard headers or footers to all pages, wrapping page output -in other templates, pre-defining variables or performing -initialisation or cleanup tasks, automatically generating page summary -information, navigation elements, and so on. - -The task of processing the template is delegated internally to the -Template::Service module which, unsurprisingly, also has a process() -method. Any templates defined by the PRE_PROCESS option are processed -first and any output generated is added to the output buffer. Then -the main template is processed, or if one or more PROCESS templates -are defined then they are instead processed in turn. In this case, -one of the PROCESS templates is responsible for processing the main -template, by a directive such as: - - [% PROCESS $template %] - -The output of processing the main template or the PROCESS template(s) -is then wrapped in any WRAPPER templates, if defined. WRAPPER -templates don't need to worry about explicitly processing the template -because it will have been done for them already. Instead WRAPPER -templates access the content they are wrapping via the 'content' -variable. - - wrapper before - [% content %] - wrapper after - -This output generated from processing the main template, and/or any -PROCESS or WRAPPER templates is added to the output buffer. Finally, -any POST_PROCESS templates are processed and their output is also -added to the output buffer which is then returned. - -If the main template throws an exception during processing then any -relevant template(s) defined via the ERROR option will be processed -instead. If defined and successfully processed, the output from the -error template will be added to the output buffer in place of the -template that generated the error and processing will continue, -applying any WRAPPER and POST_PROCESS templates. If no relevant ERROR -option is defined, or if the error occurs in one of the PRE_PROCESS, -WRAPPER or POST_PROCESS templates, then the process will terminate -immediately and the error will be returned. - - - -=over 4 - - - -=item PRE_PROCESS, POST_PROCESS - -These values may be set to contain the name(s) of template files -(relative to INCLUDE_PATH) which should be processed immediately -before and/or after each template. These do not get added to -templates processed into a document via directives such as INCLUDE, -PROCESS, WRAPPER etc. - - my $template = Template->new({ - PRE_PROCESS => 'header', - POST_PROCESS => 'footer', - }; - -Multiple templates may be specified as a reference to a list. Each is -processed in the order defined. - - my $template = Template->new({ - PRE_PROCESS => [ 'config', 'header' ], - POST_PROCESS => 'footer', - }; - -Alternately, multiple template may be specified as a single string, -delimited by ':'. This delimiter string can be changed via the -DELIMITER option. - - my $template = Template->new({ - PRE_PROCESS => 'config:header', - POST_PROCESS => 'footer', - }; - -The PRE_PROCESS and POST_PROCESS templates are evaluated in the same -variable context as the main document and may define or update -variables for subsequent use. - -config: - - [% # set some site-wide variables - bgcolor = '#ffffff' - version = 2.718 - %] - -header: - - [% DEFAULT title = 'My Funky Web Site' %] - <html> - <head> - <title>[% title %] - - - -footer: - -
- Version [% version %] - - - -The Template::Document object representing the main template being processed -is available within PRE_PROCESS and POST_PROCESS templates as the 'template' -variable. Metadata items defined via the META directive may be accessed -accordingly. - - $template->process('mydoc.html', $vars); - -mydoc.html: - - [% META title = 'My Document Title' %] - blah blah blah - ... - -header: - - - - [% template.title %] - - - - - - - - - - - - - - - -=item PROCESS - -The PROCESS option may be set to contain the name(s) of template files -(relative to INCLUDE_PATH) which should be processed instead of the -main template passed to the Template process() method. This can -be used to apply consistent wrappers around all templates, similar to -the use of PRE_PROCESS and POST_PROCESS templates. - - my $template = Template->new({ - PROCESS => 'content', - }; - - # processes 'content' instead of 'foo.html' - $template->process('foo.html'); - -A reference to the original template is available in the 'template' -variable. Metadata items can be inspected and the template can be -processed by specifying it as a variable reference (i.e. prefixed by -'$') to an INCLUDE, PROCESS or WRAPPER directive. - -content: - - - - [% template.title %] - - - - [% PROCESS $template %] -
- © Copyright [% template.copyright %] - - - -foo.html: - - [% META - title = 'The Foo Page' - author = 'Fred Foo' - copyright = '2000 Fred Foo' - %] -

[% template.title %]

- Welcome to the Foo Page, blah blah blah - -output: - - - - The Foo Page - - - -

The Foo Page

- Welcome to the Foo Page, blah blah blah -
- © Copyright 2000 Fred Foo - - - - - - - - - -=item WRAPPER - -The WRAPPER option can be used to specify one or more templates which -should be used to wrap around the output of the main page template. -The main template is processed first (or any PROCESS template(s)) and -the output generated is then passed as the 'content' variable to the -WRAPPER template(s) as they are processed. - - my $template = Template->new({ - WRAPPER => 'wrapper', - }; - - # process 'foo' then wrap in 'wrapper' - $template->process('foo', { message => 'Hello World!' }); - -wrapper: - - - [% content %] - - -foo: - - This is the foo file! - Message: [% message %] - -The output generated from this example is: - - - This is the foo file! - Message: Hello World! - - -You can specify more than one WRAPPER template by setting the value to -be a reference to a list of templates. The WRAPPER templates will be -processed in reverse order with the output of each being passed to the -next (or previous, depending on how you look at it) as the 'content' -variable. It sounds complicated, but the end result is that it just -"Does The Right Thing" to make wrapper templates nest in the order you -specify. - - my $template = Template->new({ - WRAPPER => [ 'outer', 'inner' ], - }; - - # process 'foo' then wrap in 'inner', then in 'outer' - $template->process('foo', { message => 'Hello World!' }); - -outer: - - - [% content %] - - -inner: - - - [% content %] - - -The output generated is then: - - - - This is the foo file! - Message: Hello World! - - - -One side-effect of the "inside-out" processing of the WRAPPER -configuration item (and also the WRAPPER directive) is that any -variables set in the template being wrapped will be visible to the -template doing the wrapping, but not the other way around. - -You can use this to good effect in allowing page templates to set -pre-defined values which are then used in the wrapper templates. For -example, our main page template 'foo' might look like this: - -foo: - - [% page = { - title = 'Foo Page' - subtitle = 'Everything There is to Know About Foo' - author = 'Frank Oliver Octagon' - } - %] - -

- Welcome to the page that tells you everything about foo - blah blah blah... -

- -The 'foo' template is processed before the wrapper template meaning -that the 'page' data structure will be defined for use in the wrapper -template. - -wrapper: - - - - [% page.title %] - - -

[% page.title %]

-

[% page.subtitle %]

-

by [% page.author %]

- - [% content %] - - - -It achieves the same effect as defining META items which are then -accessed via the 'template' variable (which you are still free to -use within WRAPPER templates), but gives you more flexibility in -the type and complexity of data that you can define. - - - - - -=item ERROR - -The ERROR (or ERRORS if you prefer) configuration item can be used to -name a single template or specify a hash array mapping exception types -to templates which should be used for error handling. If an uncaught -exception is raised from within a template then the appropriate error -template will instead be processed. - -If specified as a single value then that template will be processed -for all uncaught exceptions. - - my $template = Template->new({ - ERROR => 'error.html' - }); - -If the ERROR item is a hash reference the keys are assumed to be -exception types and the relevant template for a given exception will -be selected. A 'default' template may be provided for the general -case. Note that 'ERROR' can be pluralised to 'ERRORS' if you find -it more appropriate in this case. - - my $template = Template->new({ - ERRORS => { - user => 'user/index.html', - dbi => 'error/database', - default => 'error/default', - }, - }); - -In this example, any 'user' exceptions thrown will cause the -'user/index.html' template to be processed, 'dbi' errors are handled -by 'error/database' and all others by the 'error/default' template. -Any PRE_PROCESS and/or POST_PROCESS templates will also be applied -to these error templates. - -Note that exception types are hierarchical and a 'foo' handler will -catch all 'foo.*' errors (e.g. foo.bar, foo.bar.baz) if a more -specific handler isn't defined. Be sure to quote any exception types -that contain periods to prevent Perl concatenating them into a single -string (i.e. C is parsed as 'user'.'passwd'). - - my $template = Template->new({ - ERROR => { - 'user.login' => 'user/login.html', - 'user.passwd' => 'user/badpasswd.html', - 'user' => 'user/index.html', - 'default' => 'error/default', - }, - }); - -In this example, any template processed by the $template object, or -other templates or code called from within, can raise a 'user.login' -exception and have the service redirect to the 'user/login.html' -template. Similarly, a 'user.passwd' exception has a specific -handling template, 'user/badpasswd.html', while all other 'user' or -'user.*' exceptions cause a redirection to the 'user/index.html' page. -All other exception types are handled by 'error/default'. - - -Exceptions can be raised in a template using the THROW directive, - - [% THROW user.login 'no user id: please login' %] - -or by calling the throw() method on the current Template::Context object, - - $context->throw('user.passwd', 'Incorrect Password'); - $context->throw('Incorrect Password'); # type 'undef' - -or from Perl code by calling die() with a Template::Exception object, - - die (Template::Exception->new('user.denied', 'Invalid User ID')); - -or by simply calling die() with an error string. This is -automagically caught and converted to an exception of 'undef' -type which can then be handled in the usual way. - - die "I'm sorry Dave, I can't do that"; - - - - - - -=back - -=head2 Template Runtime Options - -=over 4 - - - - -=item EVAL_PERL - -This flag is used to indicate if PERL and/or RAWPERL blocks should be -evaluated. By default, it is disabled and any PERL or RAWPERL blocks -encountered will raise exceptions of type 'perl' with the message -'EVAL_PERL not set'. Note however that any RAWPERL blocks should -always contain valid Perl code, regardless of the EVAL_PERL flag. The -parser will fail to compile templates that contain invalid Perl code -in RAWPERL blocks and will throw a 'file' exception. - -When using compiled templates (see -L and -L), -the EVAL_PERL has an affect when the template is compiled, and again -when the templates is subsequently processed, possibly in a different -context to the one that compiled it. - -If the EVAL_PERL is set when a template is compiled, then all PERL and -RAWPERL blocks will be included in the compiled template. If the -EVAL_PERL option isn't set, then Perl code will be generated which -B throws a 'perl' exception with the message 'EVAL_PERL not -set' B the compiled template code is run. - -Thus, you must have EVAL_PERL set if you want your compiled templates -to include PERL and RAWPERL blocks. - -At some point in the future, using a different invocation of the -Template Toolkit, you may come to process such a pre-compiled -template. Assuming the EVAL_PERL option was set at the time the -template was compiled, then the output of any RAWPERL blocks will be -included in the compiled template and will get executed when the -template is processed. This will happen regardless of the runtime -EVAL_PERL status. - -Regular PERL blocks are a little more cautious, however. If the -EVAL_PERL flag isn't set for the I context, that is, the -one which is trying to process it, then it will throw the familiar 'perl' -exception with the message, 'EVAL_PERL not set'. - -Thus you can compile templates to include PERL blocks, but optionally -disable them when you process them later. Note however that it is -possible for a PERL block to contain a Perl "BEGIN { # some code }" -block which will always get run regardless of the runtime EVAL_PERL -status. Thus, if you set EVAL_PERL when compiling templates, it is -assumed that you trust the templates to Do The Right Thing. Otherwise -you must accept the fact that there's no bulletproof way to prevent -any included code from trampling around in the living room of the -runtime environment, making a real nuisance of itself if it really -wants to. If you don't like the idea of such uninvited guests causing -a bother, then you can accept the default and keep EVAL_PERL disabled. - - - - - - - -=item OUTPUT - -Default output location or handler. This may be specified as one of: -a file name (relative to OUTPUT_PATH, if defined, or the current -working directory if not specified absolutely); a file handle -(e.g. GLOB or IO::Handle) opened for writing; a reference to a text -string to which the output is appended (the string isn't cleared); a -reference to a subroutine which is called, passing the output text as -an argument; as a reference to an array, onto which the content will be -push()ed; or as a reference to any object that supports the print() -method. This latter option includes the Apache::Request object which -is passed as the argument to Apache/mod_perl handlers. - -example 1 (file name): - - my $template = Template->new({ - OUTPUT => "/tmp/foo", - }); - -example 2 (text string): - - my $output = ''; - - my $template = Template->new({ - OUTPUT => \$output, - }); - -example 3 (file handle): - - open (TOUT, "> $file") || die "$file: $!\n"; - - my $template = Template->new({ - OUTPUT => \*TOUT, - }); - -example 4 (subroutine): - - sub output { my $out = shift; print "OUTPUT: $out" } - - my $template = Template->new({ - OUTPUT => \&output, - }); - -example 5 (array reference): - - my $template = Template->new({ - OUTPUT => \@output, - }) - -example 6 (Apache/mod_perl handler): - - sub handler { - my $r = shift; - - my $t = Template->new({ - OUTPUT => $r, - }); - ... - } - -The default OUTPUT location be overridden by passing a third parameter -to the Template process() method. This can be specified as any of the -above argument types. - - $t->process($file, $vars, "/tmp/foo"); - $t->process($file, $vars, "bar"); - $t->process($file, $vars, \*MYGLOB); - $t->process($file, $vars, \@output); - $t->process($file, $vars, $r); # Apache::Request - ... - - - - - - - - -=item OUTPUT_PATH - -The OUTPUT_PATH allows a directory to be specified into which output -files should be written. An output file can be specified by the -OUTPUT option, or passed by name as the third parameter to the -Template process() method. - - my $template = Template->new({ - INCLUDE_PATH => "/tmp/src", - OUTPUT_PATH => "/tmp/dest", - }); - - my $vars = { - ... - }; - - foreach my $file ('foo.html', 'bar.html') { - $template->process($file, $vars, $file) - || die $template->error(); - } - -This example will read the input files '/tmp/src/foo.html' and -'/tmp/src/bar.html' and write the processed output to '/tmp/dest/foo.html' -and '/tmp/dest/bar.html', respectively. - - - - - - - - -=item DEBUG - -The DEBUG option can be used to enable debugging within the various -different modules that comprise the Template Toolkit. The -L module defines a set of -DEBUG_XXXX constants which can be combined using the logical OR -operator, '|'. - - use Template::Constants qw( :debug ); - - my $template = Template->new({ - DEBUG => DEBUG_PARSER | DEBUG_PROVIDER, - }); - -For convenience, you can also provide a string containing a list -of lower case debug options, separated by any non-word characters. - - my $template = Template->new({ - DEBUG => 'parser, provider', - }); - -The following DEBUG_XXXX flags can be used: - -=over 4 - -=item DEBUG_SERVICE - -Enables general debugging messages for the -L module. - -=item DEBUG_CONTEXT - -Enables general debugging messages for the -L module. - -=item DEBUG_PROVIDER - -Enables general debugging messages for the -L module. - -=item DEBUG_PLUGINS - -Enables general debugging messages for the -L module. - -=item DEBUG_FILTERS - -Enables general debugging messages for the -L module. - -=item DEBUG_PARSER - -This flag causes the L to generate -debugging messages that show the Perl code generated by parsing and -compiling each template. - -=item DEBUG_UNDEF - -This option causes the Template Toolkit to throw an 'undef' error -whenever it encounters an undefined variable value. - -=item DEBUG_DIRS - -This option causes the Template Toolkit to generate comments -indicating the source file, line and original text of each directive -in the template. These comments are embedded in the template output -using the format defined in the DEBUG_FORMAT configuration item, or a -simple default format if unspecified. - -For example, the following template fragment: - - - Hello World - -would generate this output: - - ## input text line 1 : ## - Hello - ## input text line 2 : World ## - World - -=item DEBUG_ALL - -Enables all debugging messages. - -=item DEBUG_CALLER - -This option causes all debug messages that aren't newline terminated -to have the file name and line number of the caller appended to them. - - -=back - -=item DEBUG_FORMAT - -The DEBUG_FORMAT option can be used to specify a format string for the -debugging messages generated via the DEBUG_DIRS option described -above. Any occurances of C<$file>, C<$line> or C<$text> will be -replaced with the current file name, line or directive text, -respectively. Notice how the format is single quoted to prevent Perl -from interpolating those tokens as variables. - - my $template = Template->new({ - DEBUG => 'dirs', - DEBUG_FORMAT => '', - }); - -The following template fragment: - - [% foo = 'World' %] - Hello [% foo %] - -would then generate this output: - - - Hello World - -The DEBUG directive can also be used to set a debug format within -a template. - - [% DEBUG format '' %] - - -=back - -=head2 Caching and Compiling Options - -=over 4 - - - -=item CACHE_SIZE - -The Template::Provider module caches compiled templates to avoid the need -to re-parse template files or blocks each time they are used. The CACHE_SIZE -option is used to limit the number of compiled templates that the module -should cache. - -By default, the CACHE_SIZE is undefined and all compiled templates are -cached. When set to any positive value, the cache will be limited to -storing no more than that number of compiled templates. When a new -template is loaded and compiled and the cache is full (i.e. the number -of entries == CACHE_SIZE), the least recently used compiled template -is discarded to make room for the new one. - -The CACHE_SIZE can be set to 0 to disable caching altogether. - - my $template = Template->new({ - CACHE_SIZE => 64, # only cache 64 compiled templates - }); - - my $template = Template->new({ - CACHE_SIZE => 0, # don't cache any compiled templates - }); - - - - - - -=item COMPILE_EXT - -From version 2 onwards, the Template Toolkit has the ability to -compile templates to Perl code and save them to disk for subsequent -use (i.e. cache persistence). The COMPILE_EXT option may be -provided to specify a filename extension for compiled template files. -It is undefined by default and no attempt will be made to read or write -any compiled template files. - - my $template = Template->new({ - COMPILE_EXT => '.ttc', - }); - -If COMPILE_EXT is defined (and COMPILE_DIR isn't, see below) then compiled -template files with the COMPILE_EXT extension will be written to the same -directory from which the source template files were loaded. - -Compiling and subsequent reuse of templates happens automatically -whenever the COMPILE_EXT or COMPILE_DIR options are set. The Template -Toolkit will automatically reload and reuse compiled files when it -finds them on disk. If the corresponding source file has been modified -since the compiled version as written, then it will load and re-compile -the source and write a new compiled version to disk. - -This form of cache persistence offers significant benefits in terms of -time and resources required to reload templates. Compiled templates can -be reloaded by a simple call to Perl's require(), leaving Perl to handle -all the parsing and compilation. This is a Good Thing. - -=item COMPILE_DIR - -The COMPILE_DIR option is used to specify an alternate directory root -under which compiled template files should be saved. - - my $template = Template->new({ - COMPILE_DIR => '/tmp/ttc', - }); - -The COMPILE_EXT option may also be specified to have a consistent file -extension added to these files. - - my $template1 = Template->new({ - COMPILE_DIR => '/tmp/ttc', - COMPILE_EXT => '.ttc1', - }); - - my $template2 = Template->new({ - COMPILE_DIR => '/tmp/ttc', - COMPILE_EXT => '.ttc2', - }); - - -When COMPILE_EXT is undefined, the compiled template files have the -same name as the original template files, but reside in a different -directory tree. - -Each directory in the INCLUDE_PATH is replicated in full beneath the -COMPILE_DIR directory. This example: - - my $template = Template->new({ - COMPILE_DIR => '/tmp/ttc', - INCLUDE_PATH => '/home/abw/templates:/usr/share/templates', - }); - -would create the following directory structure: - - /tmp/ttc/home/abw/templates/ - /tmp/ttc/usr/share/templates/ - -Files loaded from different INCLUDE_PATH directories will have their -compiled forms save in the relevant COMPILE_DIR directory. - -On Win32 platforms a filename may by prefixed by a drive letter and -colon. e.g. - - C:/My Templates/header - -The colon will be silently stripped from the filename when it is added -to the COMPILE_DIR value(s) to prevent illegal filename being generated. -Any colon in COMPILE_DIR elements will be left intact. For example: - - # Win32 only - my $template = Template->new({ - DELIMITER => ';', - COMPILE_DIR => 'C:/TT2/Cache', - INCLUDE_PATH => 'C:/TT2/Templates;D:/My Templates', - }); - -This would create the following cache directories: - - C:/TT2/Cache/C/TT2/Templates - C:/TT2/Cache/D/My Templates - - -=back - -=head2 Plugins and Filters - -=over 4 - - - -=item PLUGINS - -The PLUGINS options can be used to provide a reference to a hash array -that maps plugin names to Perl module names. A number of standard -plugins are defined (e.g. 'table', 'cgi', 'dbi', etc.) which map to -their corresponding Template::Plugin::* counterparts. These can be -redefined by values in the PLUGINS hash. - - my $template = Template->new({ - PLUGINS => { - cgi => 'MyOrg::Template::Plugin::CGI', - foo => 'MyOrg::Template::Plugin::Foo', - bar => 'MyOrg::Template::Plugin::Bar', - }, - }); - -The USE directive is used to create plugin objects and does so by -calling the plugin() method on the current Template::Context object. -If the plugin name is defined in the PLUGINS hash then the -corresponding Perl module is loaded via require(). The context then -calls the load() class method which should return the class name -(default and general case) or a prototype object against which the -new() method can be called to instantiate individual plugin objects. - -If the plugin name is not defined in the PLUGINS hash then the PLUGIN_BASE -and/or LOAD_PERL options come into effect. - - - - - -=item PLUGIN_BASE - -If a plugin is not defined in the PLUGINS hash then the PLUGIN_BASE is used -to attempt to construct a correct Perl module name which can be successfully -loaded. - -The PLUGIN_BASE can be specified as a single value or as a reference -to an array of multiple values. The default PLUGIN_BASE value, -'Template::Plugin', is always added the the end of the PLUGIN_BASE -list (a single value is first converted to a list). Each value should -contain a Perl package name to which the requested plugin name is -appended. - -example 1: - - my $template = Template->new({ - PLUGIN_BASE => 'MyOrg::Template::Plugin', - }); - - [% USE Foo %] # => MyOrg::Template::Plugin::Foo - or Template::Plugin::Foo - -example 2: - - my $template = Template->new({ - PLUGIN_BASE => [ 'MyOrg::Template::Plugin', - 'YourOrg::Template::Plugin' ], - }); - - [% USE Foo %] # => MyOrg::Template::Plugin::Foo - or YourOrg::Template::Plugin::Foo - or Template::Plugin::Foo - - - - - - -=item LOAD_PERL - -If a plugin cannot be loaded using the PLUGINS or PLUGIN_BASE -approaches then the provider can make a final attempt to load the -module without prepending any prefix to the module path. This allows -regular Perl modules (i.e. those that don't reside in the -Template::Plugin or some other such namespace) to be loaded and used -as plugins. - -By default, the LOAD_PERL option is set to 0 and no attempt will be made -to load any Perl modules that aren't named explicitly in the PLUGINS -hash or reside in a package as named by one of the PLUGIN_BASE -components. - -Plugins loaded using the PLUGINS or PLUGIN_BASE receive a reference to -the current context object as the first argument to the new() -constructor. Modules loaded using LOAD_PERL are assumed to not -conform to the plugin interface. They must provide a new() class -method for instantiating objects but it will not receive a reference -to the context as the first argument. Plugin modules should provide a -load() class method (or inherit the default one from the -Template::Plugin base class) which is called the first time the plugin -is loaded. Regular Perl modules need not. In all other respects, -regular Perl objects and Template Toolkit plugins are identical. - -If a particular Perl module does not conform to the common, but not -unilateral, new() constructor convention then a simple plugin wrapper -can be written to interface to it. - - - - -=item FILTERS - -The FILTERS option can be used to specify custom filters which can -then be used with the FILTER directive like any other. These are -added to the standard filters which are available by default. Filters -specified via this option will mask any standard filters of the same -name. - -The FILTERS option should be specified as a reference to a hash array -in which each key represents the name of a filter. The corresponding -value should contain a reference to an array containing a subroutine -reference and a flag which indicates if the filter is static (0) or -dynamic (1). A filter may also be specified as a solitary subroutine -reference and is assumed to be static. - - $template = Template->new({ - FILTERS => { - 'sfilt1' => \&static_filter, # static - 'sfilt2' => [ \&static_filter, 0 ], # same as above - 'dfilt1' => [ \&dyanamic_filter_factory, 1 ], - }, - }); - -Additional filters can be specified at any time by calling the -define_filter() method on the current Template::Context object. -The method accepts a filter name, a reference to a filter -subroutine and an optional flag to indicate if the filter is -dynamic. - - my $context = $template->context(); - $context->define_filter('new_html', \&new_html); - $context->define_filter('new_repeat', \&new_repeat, 1); - -Static filters are those where a single subroutine reference is used -for all invocations of a particular filter. Filters that don't accept -any configuration parameters (e.g. 'html') can be implemented -statically. The subroutine reference is simply returned when that -particular filter is requested. The subroutine is called to filter -the output of a template block which is passed as the only argument. -The subroutine should return the modified text. - - sub static_filter { - my $text = shift; - # do something to modify $text... - return $text; - } - -The following template fragment: - - [% FILTER sfilt1 %] - Blah blah blah. - [% END %] - -is approximately equivalent to: - - &static_filter("\nBlah blah blah.\n"); - -Filters that can accept parameters (e.g. 'truncate') should be -implemented dynamically. In this case, the subroutine is taken to be -a filter 'factory' that is called to create a unique filter subroutine -each time one is requested. A reference to the current -Template::Context object is passed as the first parameter, followed by -any additional parameters specified. The subroutine should return -another subroutine reference (usually a closure) which implements the -filter. - - sub dynamic_filter_factory { - my ($context, @args) = @_; - - return sub { - my $text = shift; - # do something to modify $text... - return $text; - } - } - -The following template fragment: - - [% FILTER dfilt1(123, 456) %] - Blah blah blah - [% END %] - -is approximately equivalent to: - - my $filter = &dynamic_filter_factory($context, 123, 456); - &$filter("\nBlah blah blah.\n"); - -See the FILTER directive for further examples. - - -=back - -=head2 Compatibility, Customisation and Extension - -=over 4 - - - -=item V1DOLLAR - -In version 1 of the Template Toolkit, an optional leading '$' could be placed -on any template variable and would be silently ignored. - - # VERSION 1 - [% $foo %] === [% foo %] - [% $hash.$key %] === [% hash.key %] - -To interpolate a variable value the '${' ... '}' construct was used. -Typically, one would do this to index into a hash array when the key -value was stored in a variable. - -example: - - my $vars = { - users => { - aba => { name => 'Alan Aardvark', ... }, - abw => { name => 'Andy Wardley', ... }, - ... - }, - uid => 'aba', - ... - }; - - $template->process('user/home.html', $vars) - || die $template->error(), "\n"; - -'user/home.html': - - [% user = users.${uid} %] # users.aba - Name: [% user.name %] # Alan Aardvark - -This was inconsistent with double quoted strings and also the -INTERPOLATE mode, where a leading '$' in text was enough to indicate a -variable for interpolation, and the additional curly braces were used -to delimit variable names where necessary. Note that this use is -consistent with UNIX and Perl conventions, among others. - - # double quoted string interpolation - [% name = "$title ${user.name}" %] - - # INTERPOLATE = 1 - - - -For version 2, these inconsistencies have been removed and the syntax -clarified. A leading '$' on a variable is now used exclusively to -indicate that the variable name should be interpolated -(e.g. subsituted for its value) before being used. The earlier example -from version 1: - - # VERSION 1 - [% user = users.${uid} %] - Name: [% user.name %] - -can now be simplified in version 2 as: - - # VERSION 2 - [% user = users.$uid %] - Name: [% user.name %] - -The leading dollar is no longer ignored and has the same effect of -interpolation as '${' ... '}' in version 1. The curly braces may -still be used to explicitly scope the interpolated variable name -where necessary. - -e.g. - - [% user = users.${me.id} %] - Name: [% user.name %] - -The rule applies for all variables, both within directives and in -plain text if processed with the INTERPOLATE option. This means that -you should no longer (if you ever did) add a leading '$' to a variable -inside a directive, unless you explicitly want it to be interpolated. - -One obvious side-effect is that any version 1 templates with variables -using a leading '$' will no longer be processed as expected. Given -the following variable definitions, - - [% foo = 'bar' - bar = 'baz' - %] - -version 1 would interpret the following as: - - # VERSION 1 - [% $foo %] => [% GET foo %] => bar - -whereas version 2 interprets it as: - - # VERSION 2 - [% $foo %] => [% GET $foo %] => [% GET bar %] => baz - -In version 1, the '$' is ignored and the value for the variable 'foo' is -retrieved and printed. In version 2, the variable '$foo' is first interpolated -to give the variable name 'bar' whose value is then retrieved and printed. - -The use of the optional '$' has never been strongly recommended, but -to assist in backwards compatibility with any version 1 templates that -may rely on this "feature", the V1DOLLAR option can be set to 1 -(default: 0) to revert the behaviour and have leading '$' characters -ignored. - - my $template = Template->new({ - V1DOLLAR => 1, - }); - - - - -=item LOAD_TEMPLATES - -The LOAD_TEMPLATE option can be used to provide a reference to a list -of Template::Provider objects or sub-classes thereof which will take -responsibility for loading and compiling templates. - - my $template = Template->new({ - LOAD_TEMPLATES => [ - MyOrg::Template::Provider->new({ ... }), - Template::Provider->new({ ... }), - ], - }); - -When a PROCESS, INCLUDE or WRAPPER directive is encountered, the named -template may refer to a locally defined BLOCK or a file relative to -the INCLUDE_PATH (or an absolute or relative path if the appropriate -ABSOLUTE or RELATIVE options are set). If a BLOCK definition can't be -found (see the Template::Context template() method for a discussion of -BLOCK locality) then each of the LOAD_TEMPLATES provider objects is -queried in turn via the fetch() method to see if it can supply the -required template. Each provider can return a compiled template, an -error, or decline to service the request in which case the -responsibility is passed to the next provider. If none of the -providers can service the request then a 'not found' error is -returned. The same basic provider mechanism is also used for the -INSERT directive but it bypasses any BLOCK definitions and doesn't -attempt is to parse or process the contents of the template file. - -This is an implementation of the 'Chain of Responsibility' -design pattern as described in -"Design Patterns", Erich Gamma, Richard Helm, Ralph Johnson, John -Vlissides), Addision-Wesley, ISBN 0-201-63361-2, page 223 -. - -If LOAD_TEMPLATES is undefined, a single default provider will be -instantiated using the current configuration parameters. For example, -the Template::Provider INCLUDE_PATH option can be specified in the Template configuration and will be correctly passed to the provider's -constructor method. - - my $template = Template->new({ - INCLUDE_PATH => '/here:/there', - }); - - - - - -=item LOAD_PLUGINS - -The LOAD_PLUGINS options can be used to specify a list of provider -objects (i.e. they implement the fetch() method) which are responsible -for loading and instantiating template plugin objects. The -Template::Content plugin() method queries each provider in turn in a -"Chain of Responsibility" as per the template() and filter() methods. - - my $template = Template->new({ - LOAD_PLUGINS => [ - MyOrg::Template::Plugins->new({ ... }), - Template::Plugins->new({ ... }), - ], - }); - -By default, a single Template::Plugins object is created using the -current configuration hash. Configuration items destined for the -Template::Plugins constructor may be added to the Template -constructor. - - my $template = Template->new({ - PLUGIN_BASE => 'MyOrg::Template::Plugins', - LOAD_PERL => 1, - }); - - - - - -=item LOAD_FILTERS - -The LOAD_FILTERS option can be used to specify a list of provider -objects (i.e. they implement the fetch() method) which are responsible -for returning and/or creating filter subroutines. The -Template::Context filter() method queries each provider in turn in a -"Chain of Responsibility" as per the template() and plugin() methods. - - my $template = Template->new({ - LOAD_FILTERS => [ - MyTemplate::Filters->new(), - Template::Filters->new(), - ], - }); - -By default, a single Template::Filters object is created for the -LOAD_FILTERS list. - - - - - -=item TOLERANT - -The TOLERANT flag is used by the various Template Toolkit provider -modules (Template::Provider, Template::Plugins, Template::Filters) to -control their behaviour when errors are encountered. By default, any -errors are reported as such, with the request for the particular -resource (template, plugin, filter) being denied and an exception -raised. When the TOLERANT flag is set to any true values, errors will -be silently ignored and the provider will instead return -STATUS_DECLINED. This allows a subsequent provider to take -responsibility for providing the resource, rather than failing the -request outright. If all providers decline to service the request, -either through tolerated failure or a genuine disinclination to -comply, then a 'EresourceE not found' exception is raised. - - - - - - -=item SERVICE - -A reference to a Template::Service object, or sub-class thereof, to which -the Template module should delegate. If unspecified, a Template::Service -object is automatically created using the current configuration hash. - - my $template = Template->new({ - SERVICE => MyOrg::Template::Service->new({ ... }), - }); - - - - - -=item CONTEXT - -A reference to a Template::Context object which is used to define a -specific environment in which template are processed. A Template::Context -object is passed as the only parameter to the Perl subroutines that -represent "compiled" template documents. Template subroutines make -callbacks into the context object to access Template Toolkit functionality, -for example, to to INCLUDE or PROCESS another template (include() and -process() methods, respectively), to USE a plugin (plugin()) or -instantiate a filter (filter()) or to access the stash (stash()) which -manages variable definitions via the get() and set() methods. - - my $template = Template->new({ - CONTEXT => MyOrg::Template::Context->new({ ... }), - }); - - - -=item STASH - -A reference to a Template::Stash object or sub-class which will take -responsibility for managing template variables. - - my $stash = MyOrg::Template::Stash->new({ ... }); - my $template = Template->new({ - STASH => $stash, - }); - -If unspecified, a default stash object is created using the VARIABLES -configuration item to initialise the stash variables. These may also -be specified as the PRE_DEFINE option for backwards compatibility with -version 1. - - my $template = Template->new({ - VARIABLES => { - id => 'abw', - name => 'Andy Wardley', - }, - }; - - - - - -=item PARSER - -The Template::Parser module implements a parser object for compiling -templates into Perl code which can then be executed. A default object -of this class is created automatically and then used by the -Template::Provider whenever a template is loaded and requires -compilation. The PARSER option can be used to provide a reference to -an alternate parser object. - - my $template = Template->new({ - PARSER => MyOrg::Template::Parser->new({ ... }), - }); - - - - - -=item GRAMMAR - -The GRAMMAR configuration item can be used to specify an alternate -grammar for the parser. This allows a modified or entirely new -template language to be constructed and used by the Template Toolkit. - -Source templates are compiled to Perl code by the Template::Parser -using the Template::Grammar (by default) to define the language -structure and semantics. Compiled templates are thus inherently -"compatible" with each other and there is nothing to prevent any -number of different template languages being compiled and used within -the same Template Toolkit processing environment (other than the usual -time and memory constraints). - -The Template::Grammar file is constructed from a YACC like grammar -(using Parse::YAPP) and a skeleton module template. These files are -provided, along with a small script to rebuild the grammar, in the -'parser' sub-directory of the distribution. You don't have to know or -worry about these unless you want to hack on the template language or -define your own variant. There is a README file in the same directory -which provides some small guidance but it is assumed that you know -what you're doing if you venture herein. If you grok LALR parsers, -then you should find it comfortably familiar. - -By default, an instance of the default Template::Grammar will be -created and used automatically if a GRAMMAR item isn't specified. - - use MyOrg::Template::Grammar; - - my $template = Template->new({ - GRAMMAR = MyOrg::Template::Grammar->new(); - }); - - - -=back - -=head1 AUTHOR - -Andy Wardley Eabw@andywardley.comE - -L - - - - -=head1 VERSION - -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - - - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Manual/Credits.pod b/lib/Template/Manual/Credits.pod deleted file mode 100644 index 64999ac..0000000 --- a/lib/Template/Manual/Credits.pod +++ /dev/null @@ -1,188 +0,0 @@ -#============================================================= -*-perl-*- -# -# Template::Manual::Credits -# -# DESCRIPTION -# This section provides a brief history of the Template Toolkit and -# details the primary author and numerous other people who have -# contributed to it. -# -# AUTHOR -# Andy Wardley -# -# COPYRIGHT -# Copyright (C) 1996-2001 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2001 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -# REVISION -# -# -#======================================================================== - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Manual::Credits - Author and contributor credits - -=head1 DESCRIPTION - -This section provides a brief history of the Template Toolkit and -details the primary author and numerous other people who have -contributed to it. - -=head1 HISTORY - -The Template Toolkit began its life as the Text::MetaText module, -originally released to CPAN around 1996. This itself was the public -manifestation of an earlier template processing system I developed -while working at Peritas (now Knowledge Pool - - http://www.knowledgepool.com/) - -Text::MetaText was the prototype - the one we always planned to throw -away. It did the job well, showing us what worked and what didn't, what -was good and what was bad, and gave us some ideas about what could be -done better, given the chance to start again from scratch. - -Some time late in 1998 I threw away the prototype and started work on -the Template Toolkit. By then I was working at Canon Research Centre -Europe Ltd. (http://www.cre.canon.co.uk), involved in a general -research programme related to web publishing and dynamic content -generation. The first alpha release was in June 1999, followed by -numerous more alpha and beta releases culminating in 1.00 being -released on 2nd December 1999. - -A month or so later, work had begun on version 2.00. The plan was to -get the template language relatively stable in version 1.00 and not -worry too much about performance or other internal matters. Then, -version 2.00 would follow to improve performance, clean up the -architecture and fix anything that, with the benefit of hindsight, we -thought could be improved. As it happens, me starting work on version -2.00 coincided with Doug Steinwand sending me his parser variant which -compiled templates to Perl code, giving a major performance boost. -As well as the speedups, there are a whole host of significant new -features in version 2.00, and a greatly improved internal architecture. -Apart from a few minor "fixups" the template directives and language -have remained the same as in version 1.00 - -Version 2.00 was available in beta release form in July 2000, just -in time for the 4th Perl Conference where version 1.00 was awarded -"Best New Perl Module". After another extended beta release period, -version 2.00 was released on 1st December 2000. - - - - -=head1 CONTRIBUTORS - -Many people have contributed ideas, inspiration, fixes and features to -the Template Toolkit. Their efforts continue to be very much appreciated. -Please let me know if you think anyone is missing from this list. - - Chuck Adams - Stephen Adkins - Ivan Adzhubey - Mark Anderson - Bradley Baetz - Thierry-Michel Barral - Craig Barratt - Stas Bekman - Tony Bowden - Neil Bowers - Leon Brocard - Lyle Brooks - Dave Cash - Piers Cawley - Darren Chamberlain - Eric Cholet - Dave Cross - Chris Dean - Francois Desarmenien - Horst Dumcke - Mark Fowler - Michael Fowler - Axel Gerstmair - Dylan William Hardison - Perrin Harkins - Bryce Harrington - Dave Hodgkinson - Harald Joerg - Colin Johnson - Vivek Khera - Rafael Kitover - Ivan Kurmanov - Hans von Lengerke - Jonas Liljegren - Simon Luff - Paul Makepeace - Gervase Markham - Simon Matthews - Robert McArthur - Craig McLane - Leslie Michael Orchard - Eugene Miretskiy - Tatsuhiko Miyagawa - Keith G. Murphy - Chris Nandor - Briac Pilpré - Martin Portman - Slaven Rezic - Christian Schaffner - Randal L. Schwartz - Paul Sharpe - Ville Skyttä - Doug Steinwand - Michael Stevens - Drew Taylor - Swen Thuemmler - Richard Tietjen - Stathy G. Touloumis - Jim Vaughan - Simon Wilcox - Chris Winters - -=head1 AUTHOR - -Andy Wardley Eabw@andywardley.comE - -L - - - - -=head1 VERSION - -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - - - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Manual/Directives.pod b/lib/Template/Manual/Directives.pod deleted file mode 100644 index 3b8af3e..0000000 --- a/lib/Template/Manual/Directives.pod +++ /dev/null @@ -1,2179 +0,0 @@ -#============================================================= -*-perl-*- -# -# Template::Manual::Directives -# -# DESCRIPTION -# This section provides a reference of all Template Toolkit -# directives, complete with examples of use. -# -# AUTHOR -# Andy Wardley -# -# COPYRIGHT -# Copyright (C) 1996-2001 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2001 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -# REVISION -# -# -#======================================================================== - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Manual::Directives - Template directives - -=head1 DESCRIPTION - -This section provides a reference of all Template Toolkit directives, -complete with examples of use. - -=head2 Accessing and Updating Template Variables - -=over 4 - - -=item GET - -The GET directive retrieves and outputs the value of the named variable. - - [% GET foo %] - -The GET keyword is optional. A variable can be specified in a directive -tag by itself. - - [% foo %] - -The variable can have an unlimited number of elements, each separated -by a dot '.'. Each element can have arguments specified within -parentheses. - - [% foo %] - [% bar.baz %] - [% biz.baz(10) %] - ...etc... - -See L for a full discussion on template -variables. - -You can also specify expressions using the logical (and, or, not, ?:) and -mathematic operators (+ - * / % mod div). - - [% template.title or default.title %] - - [% score * 100 %] - - [% order.nitems ? checkout(order.total) : 'no items' %] - -The 'div' operator returns the integer result of division. Both '%' and -'mod' return the modulus (i.e. remainder) of division. 'mod' is provided -as an alias for '%' for backwards compatibility with version 1. - - [% 15 / 6 %] # 2.5 - [% 15 div 6 %] # 2 - [% 15 mod 6 %] # 3 - - - -=item CALL - -The CALL directive is similar to GET in evaluating the variable named, -but doesn't print the result returned. This can be useful when a -variable is bound to a sub-routine or object method which you want to -call but aren't interested in the value returned. - - [% CALL dbi.disconnect %] - - [% CALL inc_page_counter(page_count) %] - - - - -=item SET - -The SET directive allows you to assign new values to existing variables -or create new temporary variables. - - [% SET title = 'Hello World' %] - -The SET keyword is also optional. - - [% title = 'Hello World' %] - -Variables may be assigned the values of other variables, unquoted -numbers (digits), literal text ('single quotes') or quoted text -("double quotes"). In the latter case, any variable references within -the text will be interpolated when the string is evaluated. Variables -should be prefixed by '$', using curly braces to explicitly scope -the variable name where necessary. - - [% foo = 'Foo' %] # literal value 'Foo' - [% bar = foo %] # value of variable 'foo' - [% cost = '$100' %] # literal value '$100' - [% item = "$bar: ${cost}.00" %] # value "Foo: $100.00" - -Multiple variables may be assigned in the same directive and are -evaluated in the order specified. Thus, the above could have been -written: - - [% foo = 'Foo' - bar = foo - cost = '$100' - item = "$bar: ${cost}.00" - %] - -Simple expressions can also be used, as per GET. - - [% ten = 10 - twenty = 20 - thirty = twenty + ten - forty = 2 * twenty - fifty = 100 div 2 - six = twenty mod 7 - %] - -You can concatenate strings together using the ' _ ' operator. In Perl 5, -the '.' is used for string concatenation, but in Perl 6, as in the Template -Toolkit, the '.' will be used as the method calling operator and ' _ ' will -be used for string concatenation. Note that the operator must be -specified with surrounding whitespace which, as Larry says, is construed as -a feature: - - [% copyright = '(C) Copyright' _ year _ ' ' _ author %] - -You can, of course, achieve a similar effect with double quoted string -interpolation. - - [% copyright = "(C) Copyright $year $author" %] - - - - - -=item DEFAULT - -The DEFAULT directive is similar to SET but only updates variables -that are currently undefined or have no "true" value (in the Perl -sense). - - [% DEFAULT - name = 'John Doe' - id = 'jdoe' - %] - -This can be particularly useful in common template components to -ensure that some sensible default are provided for otherwise -undefined variables. - - [% DEFAULT - title = 'Hello World' - bgcol = '#ffffff' - %] - - - [% title %] - - - - - -=back - -=head2 Processing Other Template Files and Blocks - -=over 4 - - -=item INSERT - -The INSERT directive is used to insert the contents of an external file -at the current position. - - [% INSERT myfile %] - -No attempt to parse or process the file is made. The contents, -possibly including any embedded template directives, are inserted -intact. - -The filename specified should be relative to one of the INCLUDE_PATH -directories. Absolute (i.e. starting with C) and relative -(i.e. starting with C<.>) filenames may be used if the ABSOLUTE and -RELATIVE options are set, respectively. Both these options are -disabled by default. - - my $template = Template->new({ - INCLUDE_PATH => '/here:/there', - }); - - $template->process('myfile'); - -'myfile': - - [% INSERT foo %] # looks for /here/foo then /there/foo - [% INSERT /etc/passwd %] # file error: ABSOLUTE not set - [% INSERT ../secret %] # file error: RELATIVE not set - -For convenience, the filename does not need to be quoted as long as it -contains only alphanumeric characters, underscores, dots or forward -slashes. Names containing any other characters should be quoted. - - [% INSERT misc/legalese.txt %] - [% INSERT 'dos98/Program Files/stupid' %] - -To evaluate a variable to specify a filename, you should explicitly -prefix it with a '$' or use double-quoted string interpolation. - - [% language = 'en' - legalese = 'misc/legalese.txt' - %] - - [% INSERT $legalese %] # 'misc/legalese.txt' - [% INSERT "$language/$legalese" %] # 'en/misc/legalese.txt' - -Multiple files can be specified using '+' as a delimiter. All files -should be unquoted names or quoted strings. Any variables should be -interpolated into double-quoted strings. - - [% INSERT legalese.txt + warning.txt %] - [% INSERT "$legalese" + warning.txt %] # requires quoting - - - - - - - - - - - - - - - - - -=item INCLUDE - -The INCLUDE directive is used to process and include the output of -another template file or block. - - [% INCLUDE header %] - -If a BLOCK of the specified name is defined in the same file, or in a file -from which the current template has been called (i.e. a parent template) -then it will be used in preference to any file of the same name. - - [% INCLUDE table %] # uses BLOCK defined below - - [% BLOCK table %] - - ... -
- [% END %] - -If a BLOCK definition is not currently visible then the template name -should be a file relative to one of the INCLUDE_PATH directories, or -an absolute or relative file name if the ABSOLUTE/RELATIVE options are -appropriately enabled. The INCLUDE directive automatically quotes the -filename specified, as per INSERT described above. When a variable -contains the name of the template for the INCLUDE directive, it should -be explicitly prefixed by '$' or double-quoted - - [% myheader = 'my/misc/header' %] - [% INCLUDE myheader %] # 'myheader' - [% INCLUDE $myheader %] # 'my/misc/header' - [% INCLUDE "$myheader" %] # 'my/misc/header' - -Any template directives embedded within the file will be processed -accordingly. All variables currently defined will be visible and -accessible from within the included template. - - [% title = 'Hello World' %] - [% INCLUDE header %] - - ... - -'header': - - - [% title %] - -output: - - - Hello World - - ... - -Local variable definitions may be specified after the template name, -temporarily masking any existing variables. Insignificant whitespace -is ignored within directives so you can add variable definitions on the -same line, the next line or split across several line with comments -interspersed, if you prefer. - - [% INCLUDE table %] - - [% INCLUDE table title="Active Projects" %] - - [% INCLUDE table - title = "Active Projects" - bgcolor = "#80ff00" # chartreuse - border = 2 - %] - -The INCLUDE directive localises (i.e. copies) all variables before -processing the template. Any changes made within the included -template will not affect variables in the including template. - - [% foo = 10 %] - - foo is originally [% foo %] - [% INCLUDE bar %] - foo is still [% foo %] - - [% BLOCK bar %] - foo was [% foo %] - [% foo = 20 %] - foo is now [% foo %] - [% END %] - -output: - foo is originally 10 - foo was 10 - foo is now 20 - foo is still 10 - -Technical Note: the localisation of the stash (that is, the process by -which variables are copied before an INCLUDE to prevent being -overwritten) is only skin deep. The top-level variable namespace -(hash) is copied, but no attempt is made to perform a deep-copy of -other structures (hashes, arrays, objects, etc.) Therefore, a 'foo' -variable referencing a hash will be copied to create a new 'foo' -variable but which points to the same hash array. Thus, if you update -compound variables (e.g. foo.bar) then you will change the original -copy, regardless of any stash localisation. If you're not worried -about preserving variable values, or you trust the templates you're -including then you might prefer to use the PROCESS directive which is -faster by virtue of not performing any localisation. - -From version 2.04 onwards, you can specify dotted variables as "local" -variables to an INCLUDE directive. However, be aware that because of -the localisation issues explained above (if you skipped the previous -Technical Note above then you might want to go back and read it or -skip this section too), the variables might not actualy be "local". -If the first element of the variable name already references a hash -array then the variable update will affect the original variable. - - [% foo = { - bar = 'Baz' - } - %] - - [% INCLUDE somefile foo.bar='Boz' %] - - [% foo.bar %] # Boz - -This behaviour can be a little unpredictable (and may well be improved -upon in a future version). If you know what you're doing with it and -you're sure that the variables in question are defined (nor not) as you -expect them to be, then you can rely on this feature to implement some -powerful "global" data sharing techniques. Otherwise, you might prefer -to steer well clear and always pass simple (undotted) variables as -parameters to INCLUDE and other similar directives. - -If you want to process several templates in one go then you can -specify each of their names (quoted or unquoted names only, no unquoted -'$variables') joined together by '+'. The INCLUDE directive -will then process them in order. - - [% INCLUDE html/header + "site/$header" + site/menu - title = "My Groovy Web Site" - %] - -The variable stash is localised once and then the templates specified -are processed in order, all within that same variable context. This -makes it slightly faster than specifying several separate INCLUDE -directives (because you only clone the variable stash once instead of -n times), but not quite as "safe" because any variable changes in the -first file will be visible in the second, third and so on. This -might be what you want, of course, but then again, it might not. - - - -=item PROCESS - -The PROCESS directive is similar to INCLUDE but does not perform any -localisation of variables before processing the template. Any changes -made to variables within the included template will be visible in the -including template. - - [% foo = 10 %] - - foo is [% foo %] - [% PROCESS bar %] - foo is [% foo %] - - [% BLOCK bar %] - [% foo = 20 %] - changed foo to [% foo %] - [% END %] - -output: - - foo is 10 - changed foo to 20 - foo is 20 - -Parameters may be specified in the PROCESS directive, but these too will -become visible changes to current variable values. - - [% foo = 10 %] - foo is [% foo %] - [% PROCESS bar - foo = 20 - %] - foo is [% foo %] - - [% BLOCK bar %] - this is bar, foo is [% foo %] - [% END %] - -output: - - foo is 10 - this is bar, foo is 20 - foo is 20 - -The PROCESS directive is slightly faster than INCLUDE because it -avoids the need to localise (i.e. copy) the variable stash before -processing the template. As with INSERT and INCLUDE, the first -parameter does not need to be quoted as long as it contains only -alphanumeric characters, underscores, periods or forward slashes. -A '$' prefix can be used to explicitly indicate a variable which -should be interpolated to provide the template name: - - [% myheader = 'my/misc/header' %] - [% PROCESS myheader %] # 'myheader' - [% PROCESS $myheader %] # 'my/misc/header' - -As with INCLUDE, multiple templates can be specified, delimited by -'+', and are processed in order. - - [% PROCESS html/header + my/header %] - - - - - -=item WRAPPER - -It's not unusual to find yourself adding common headers and footers to -pages or sub-sections within a page. Something like this: - - [% INCLUDE section/header - title = 'Quantum Mechanics' - %] - Quantum mechanics is a very interesting subject wish - should prove easy for the layman to fully comprehend. - [% INCLUDE section/footer %] - - [% INCLUDE section/header - title = 'Desktop Nuclear Fusion for under $50' - %] - This describes a simple device which generates significant - sustainable electrical power from common tap water by process - of nuclear fusion. - [% INCLUDE section/footer %] - -The individual template components being included might look like these: - -section/header: - -

-

[% title %]

- -section/footer: - -

- -The WRAPPER directive provides a way of simplifying this a little. It -encloses a block up to a matching END directive, which is first -processed to generate some output. This is then passed to the named -template file or BLOCK as the 'content' variable. - - [% WRAPPER section - title = 'Quantum Mechanics' - %] - Quantum mechanics is a very interesting subject wish - should prove easy for the layman to fully comprehend. - [% END %] - - [% WRAPPER section - title = 'Desktop Nuclear Fusion for under $50' - %] - This describes a simple device which generates significant - sustainable electrical power from common tap water by process - of nuclear fusion. - [% END %] - -The single 'section' template can then be defined as: - -

-

[% title %]

- [% content %] -

- -Like other block directives, it can be used in side-effect notation: - - [% INSERT legalese.txt WRAPPER big_bold_table %] - -It's also possible to specify multiple templates to a WRAPPER directive. -The specification order indicates outermost to innermost wrapper templates. -For example, given the following template block definitions: - - [% BLOCK bold %][% content %][% END %] - [% BLOCK italic %][% content %][% END %] - -the directive - - [% WRAPPER bold+italic %]Hello World[% END %] - -would generate the following output: - - Hello World - - - - - - - - - - - - - - - - - - -=item BLOCK - -The BLOCK ... END construct can be used to define template component -blocks which can be processed with the INCLUDE, PROCESS and WRAPPER -directives. - - [% BLOCK tabrow %] - [% name %][% email %] - [% END %] - - - [% PROCESS tabrow name='Fred' email='fred@nowhere.com' %] - [% PROCESS tabrow name='Alan' email='alan@nowhere.com' %] -
- -A BLOCK definition can be used before it is defined, as long as the -definition resides in the same file. The block definition itself does -not generate any output. - - [% PROCESS tmpblk %] - - [% BLOCK tmpblk %] This is OK [% END %] - -You can use an anonymous BLOCK to capture the output of a template -fragment. - - [% julius = BLOCK %] - And Caesar's spirit, ranging for revenge, - With Ate by his side come hot from hell, - Shall in these confines with a monarch's voice - Cry 'Havoc', and let slip the dogs of war; - That this foul deed shall smell above the earth - With carrion men, groaning for burial. - [% END %] - -Like a named block, it can contain any other template directives which -are processed when the block is defined. The output generated by the -block is then assigned to the variable 'julius'. - -Anonymous BLOCKs can also be used to define block macros. The -enclosing block is processed each time the macro is called. - - [% MACRO locate BLOCK %] - The [% animal %] sat on the [% place %]. - [% END %] - - [% locate(animal='cat', place='mat') %] # The cat sat on the mat - [% locate(animal='dog', place='log') %] # The dog sat on the log - - - -=back - -=head2 Conditional Processing - -=over 4 - - -=item IF / UNLESS / ELSIF / ELSE - -The IF and UNLESS directives can be used to process or ignore a -block based on some run-time condition. - - [% IF frames %] - [% INCLUDE frameset %] - [% END %] - - [% UNLESS text_mode %] - [% INCLUDE biglogo %] - [% END %] - -Multiple conditions may be joined with ELSIF and/or ELSE blocks. - - [% IF age < 10 %] - Hello [% name %], does your mother know you're - using her AOL account? - [% ELSIF age < 18 %] - Sorry, you're not old enough to enter - (and too dumb to lie about your age) - [% ELSE %] - Welcome [% name %]. - [% END %] - -The following conditional and boolean operators may be used: - - == != < <= > >= && || ! and or not - -Note that C, C and C are also provided as aliases for -C<&&>, C<||> and C, respectively. - -Conditions may be arbitrarily complex and are evaluated with the same -precedence as in Perl. Parenthesis may be used to explicitly -determine evaluation order. - - # ridiculously contrived complex example - [% IF (name == 'admin' || uid <= 0) && mode == 'debug' %] - I'm confused. - [% ELSIF more > less %] - That's more or less correct. - [% END %] - - - - - - -=item SWITCH / CASE - -The SWITCH / CASE construct can be used to perform a multi-way -conditional test. The SWITCH directive expects an expression which is -first evaluated and then compared against each CASE statement in turn. -Each CASE directive should contain a single value or a list of values -which should match. CASE may also be left blank or written as [% CASE -DEFAULT %] to specify a default match. Only one CASE matches, there -is no drop-through between CASE statements. - - [% SWITCH myvar %] - [% CASE value1 %] - ... - [% CASE [ value2 value3 ] %] # multiple values - ... - [% CASE myhash.keys %] # ditto - ... - [% CASE %] # default - ... - [% END %] - - - - -=back - -=head2 Loop Processing - -=over 4 - - -=item FOREACH - -The FOREACH directive will iterate through the items in a list, processing -the enclosed block for each one. - - my $vars = { - foo => 'Foo', - items => [ 'one', 'two', 'three' ], - }; - -template: - - Things: - [% FOREACH thing = [ foo 'Bar' "$foo Baz" ] %] - * [% thing %] - [% END %] - - Items: - [% FOREACH i = items %] - * [% i %] - [% END %] - - Stuff: - [% stuff = [ foo "$foo Bar" ] %] - [% FOREACH s = stuff %] - * [% s %] - [% END %] - -output: - - Things: - * Foo - * Bar - * Foo Baz - - Items: - * one - * two - * three - - Stuff: - * Foo - * Foo Bar - -You can use also use 'IN' instead of '=' if you prefer. - - [% FOREACH crook IN government %] - -When the FOREACH directive is used without specifying a target variable, -any iterated values which are hash references will be automatically -imported. - - [% userlist = [ - { id => 'tom', name => 'Thomas' }, - { id => 'dick', name => 'Richard' }, - { id => 'larry', name => 'Lawrence' }, - ] - %] - - [% FOREACH user IN userlist %] - [% user.id %] [% user.name %] - [% END %] - -short form: - - [% FOREACH userlist %] - [% id %] [% name %] - [% END %] - -Note that this particular usage creates a localised variable context -to prevent the imported hash keys from overwriting any existing -variables. The imported definitions and any other variables defined -in such a FOREACH loop will be lost at the end of the loop, when the -previous context and variable values are restored. - -However, under normal operation, the loop variable remains in scope -after the FOREACH loop has ended (caveat: overwriting any variable -previously in scope). This is useful as the loop variable is secretly -an iterator object (see below) and can be used to analyse the last -entry processed by the loop. - -The FOREACH directive can also be used to iterate through the entries -in a hash array. Each entry in the hash is returned in sorted order -(based on the key) as a hash array containing 'key' and 'value' items. - - [% users = { - tom => 'Thomas', - dick => 'Richard', - larry => 'Lawrence', - } - %] - - [% FOREACH u IN users %] - * [% u.key %] : [% u.value %] - [% END %] - -Output: - - * dick : Richard - * larry : Lawrence - * tom : Thomas - -The NEXT directive starts the next iteration in the FOREACH loop. - - [% FOREACH user IN userlist %] - [% NEXT IF user.isguest %] - Name: [% user.name %] Email: [% user.email %] - [% END %] - -The LAST directive can be used to prematurely exit the loop. BREAK is -also provided as an alias for LAST. - - [% FOREACH match IN results.nsort('score').reverse %] - [% LAST IF match.score < 50 %] - [% match.score %] : [% match.url %] - [% END %] - -The FOREACH directive is implemented using the Template::Iterator -module. A reference to the iterator object for a FOREACH directive is -implicitly available in the 'loop' variable. The following methods -can be called on the 'loop' iterator. - - size() number of elements in the list - max() index number of last element (size - 1) - index() index of current iteration from 0 to max() - count() iteration counter from 1 to size() (i.e. index() + 1) - first() true if the current iteration is the first - last() true if the current iteration is the last - prev() return the previous item in the list - next() return the next item in the list - -See L for further details. - -Example: - - [% FOREACH item IN [ 'foo', 'bar', 'baz' ] -%] - [%- "
    \n" IF loop.first %] -
  • [% loop.count %]/[% loop.size %]: [% item %] - [%- "
\n" IF loop.last %] - [% END %] - -Output: - -
    -
  • 1/3: foo -
  • 2/3: bar -
  • 3/3: baz -
- -Note that the number() method is supported as an alias for count() for -backwards compatibility but may be deprecated in some future version. - -Nested loops will work as expected, with the 'loop' variable correctly -referencing the innermost loop and being restored to any previous -value (i.e. an outer loop) at the end of the loop. - - [% FOREACH group IN grouplist; - # loop => group iterator - "Groups:\n" IF loop.first; - - FOREACH user IN group.userlist; - # loop => user iterator - "$loop.count: $user.name\n"; - END; - - # loop => group iterator - "End of Groups\n" IF loop.last; - END - %] - -The 'iterator' plugin can also be used to explicitly create an -iterator object. This can be useful within nested loops where you -need to keep a reference to the outer iterator within the inner loop. -The iterator plugin effectively allows you to create an iterator by a -name other than 'loop'. See Template::Plugin::Iterator for further -details. - - [% USE giter = iterator(grouplist) %] - - [% FOREACH group IN giter %] - [% FOREACH user IN group.userlist %] - user #[% loop.count %] in - group [% giter.count %] is - named [% user.name %] - [% END %] - [% END %] - - - - -=item WHILE - -The WHILE directive can be used to repeatedly process a template block -while a conditional expression evaluates true. The expression may -be arbitrarily complex as per IF / UNLESS. - - [% WHILE total < 100 %] - ... - [% total = calculate_new_total %] - [% END %] - -An assignment can be enclosed in parenthesis to evaluate the assigned -value. - - [% WHILE (user = get_next_user_record) %] - [% user.name %] - [% END %] - -The NEXT directive can be used to start the next iteration of a -WHILE loop and BREAK can be used to exit the loop, both as per FOREACH. - -The Template Toolkit uses a failsafe counter to prevent runaway WHILE -loops which would otherwise never terminate. If the loop exceeds 1000 -iterations then an 'undef' exception will be thrown, reporting the -error: - - WHILE loop terminated (> 1000 iterations) - -The $Template::Directive::WHILE_MAX variable controls this behaviour -and can be set to a higher value if necessary. - - -=back - -=head2 Filters, Plugins, Macros and Perl - -=over 4 - - -=item FILTER - -The FILTER directive can be used to post-process the output of a -block. A number of standard filters are provided with the Template -Toolkit. The 'html' filter, for example, escapes the 'E', 'E' -and '&' characters to prevent them from being interpreted as HTML tags -or entity reference markers. - - [% FILTER html %] - HTML text may have < and > characters embedded - which you want converted to the correct HTML entities. - [% END %] - -output: - - HTML text may have < and > characters embedded - which you want converted to the correct HTML entities. - -The FILTER directive can also follow various other non-block directives. -For example: - - [% INCLUDE mytext FILTER html %] - -The '|' character can also be used as an alias for 'FILTER'. - - [% INCLUDE mytext | html %] - -Multiple filters can be chained together and will be called in sequence. - - [% INCLUDE mytext FILTER html FILTER html_para %] - -or - - [% INCLUDE mytext | html | html_para %] - -Filters come in two flavours, known as 'static' or 'dynamic'. A -static filter is a simple subroutine which accepts a text string as -the only argument and returns the modified text. The 'html' filter is -an example of a static filter, implemented as: - - sub html_filter { - my $text = shift; - for ($text) { - s/&/&/g; - s//>/g; - } - return $text; - } - -Dynamic filters can accept arguments which are specified when the filter -is called from a template. The 'repeat' filter is such an example, -accepting a numerical argument which specifies the number of times -that the input text should be repeated. - - [% FILTER repeat(3) %]blah [% END %] - -output: - - blah blah blah - -These are implemented as filter 'factories'. The factory subroutine -is passed a reference to the current Template::Context object along -with any additional arguments specified. It should then return a -subroutine reference (e.g. a closure) which implements the filter. -The 'repeat' filter factory is implemented like this: - - sub repeat_filter_factory { - my ($context, $iter) = @_; - $iter = 1 unless defined $iter; - - return sub { - my $text = shift; - $text = '' unless defined $text; - return join('\n', $text) x $iter; - } - } - -The FILTERS option, described in L, allows -custom filters to be defined when a Template object is instantiated. -The Template::Context define_filter() method allows further filters -to be defined at any time. - -When using a filter, it is possible to assign an alias to it for -further use. This is most useful for dynamic filters that you want -to re-use with the same configuration. - - [% FILTER echo = repeat(2) %] - Is there anybody out there? - [% END %] - - [% FILTER echo %] - Mother, should I build a wall? - [% END %] - -Output: - - Is there anybody out there? - Is there anybody out there? - - Mother, should I build a wall? - Mother, should I build a wall? - -The FILTER directive automatically quotes the name of the filter. As -with INCLUDE et al, you can use a variable to provide the name of the -filter, prefixed by '$'. - - [% myfilter = 'html' %] - [% FILTER $myfilter %] # same as [% FILTER html %] - ... - [% END %] - -A template variable can also be used to define a static filter -subroutine. However, the Template Toolkit will automatically call any -subroutine bound to a variable and use the value returned. Thus, the -above example could be implemented as: - - my $vars = { - myfilter => sub { return 'html' }, - }; - -template: - - [% FILTER $myfilter %] # same as [% FILTER html %] - ... - [% END %] - -To define a template variable that evaluates to a subroutine reference -that can be used by the FILTER directive, you should create a -subroutine that, when called automatically by the Template Toolkit, -returns another subroutine reference which can then be used to perform -the filter operation. Note that only static filters can be -implemented in this way. - - my $vars = { - myfilter => sub { \&my_filter_sub }, - }; - - sub my_filter_sub { - my $text = shift; - # do something - return $text; - } - -template: - - [% FILTER $myfilter %] - ... - [% END %] - -Alternately, you can bless a subroutine reference into a class (any -class will do) to fool the Template Toolkit into thinking it's an -object rather than a subroutine. This will then bypass the automatic -"call-a-subroutine-to-return-a-value" magic. - - my $vars = { - myfilter => bless(\&my_filter_sub, 'anything_you_like'), - }; - -template: - - [% FILTER $myfilter %] - ... - [% END %] - -Filters bound to template variables remain local to the variable -context in which they are defined. That is, if you define a filter in -a PERL block within a template that is loaded via INCLUDE, then the -filter definition will only exist until the end of that template when -the stash is delocalised, restoring the previous variable state. If -you want to define a filter which persists for the lifetime of the -processor, or define additional dynamic filter factories, then you can -call the define_filter() method on the current Template::Context -object. - -See L for a complete list of available filters, -their descriptions and examples of use. - - - - - - -=item USE - -The USE directive can be used to load and initialise "plugin" -extension modules. - - [% USE myplugin %] - -A plugin is a regular Perl module that conforms to a particular -object-oriented interface, allowing it to be loaded into and used -automatically by the Template Toolkit. For details of this interface -and information on writing plugins, consult L. - -The plugin name is case-sensitive and will be appended to the -PLUGIN_BASE value (default: 'Template::Plugin') to construct a full -module name. Any periods, '.', in the name will be converted to '::'. - - [% USE MyPlugin %] # => Template::Plugin::MyPlugin - [% USE Foo.Bar %] # => Template::Plugin::Foo::Bar - -Various standard plugins are included with the Template Toolkit (see -below and L). These can be specified in lower -case and are mapped to the appropriate name. - - [% USE cgi %] # => Template::Plugin::CGI - [% USE table %] # => Template::Plugin::Table - -Any additional parameters supplied in parenthesis after the plugin -name will be also be passed to the new() constructor. A reference to -the current Template::Context object is always passed as the first -parameter. - - [% USE MyPlugin('foo', 123) %] - -equivalent to: - - Template::Plugin::MyPlugin->new($context, 'foo', 123); - -Named parameters may also be specified. These are collated into a -hash which is passed by reference as the last parameter to the -constructor, as per the general code calling interface. - - [% USE url('/cgi-bin/foo', mode='submit', debug=1) %] - -equivalent to: - - Template::Plugin::URL->new($context, '/cgi-bin/foo' - { mode => 'submit', debug => 1 }); - -The plugin may represent any data type; a simple variable, hash, list or -code reference, but in the general case it will be an object reference. -Methods can be called on the object (or the relevant members of the -specific data type) in the usual way: - - [% USE table(mydata, rows=3) %] - - [% FOREACH row = table.rows %] - - [% FOREACH item = row %] - [% item %] - [% END %] - - [% END %] - -An alternative name may be provided for the plugin by which it can be -referenced: - - [% USE scores = table(myscores, cols=5) %] - - [% FOREACH row = scores.rows %] - ... - [% END %] - -You can use this approach to create multiple plugin objects with -different configurations. This example shows how the 'format' plugin -is used to create sub-routines bound to variables for formatting text -as per printf(). - - [% USE bold = format('%s') %] - [% USE ital = format('%s') %] - - [% bold('This is bold') %] - [% ital('This is italic') %] - -Output: - - This is bold - This is italic - -This next example shows how the URL plugin can be used to build -dynamic URLs from a base part and optional query parameters. - - [% USE mycgi = URL('/cgi-bin/foo.pl', debug=1) %] - ... - ... - ... - -The CGI plugin is an example of one which delegates to another Perl -module. In this this case, it is to Lincoln Stein's CGI.pm module. -All of the methods provided by CGI.pm are available via the plugin. - - [% USE CGI %] - - [% CGI.start_form %] - - [% CGI.checkbox_group(name => 'colours', - values => [ 'red' 'green' 'blue' ]) - %] - - [% CGI.popup_menu(name => 'items', - values => [ 'foo' 'bar' 'baz' ]) - %] - - [% CGI.end_form %] - -Simon Matthews has written the DBI plugin which provides an interface -to Tim Bunce's DBI module (available from CPAN). Here's a short -example: - - [% USE DBI('DBI:mSQL:mydbname') %] - - [% FOREACH user = DBI.query('SELECT * FROM users') %] - [% user.id %] [% user.name %] [% user.etc.etc %] - [% END %] - -See L for more information on the plugins -distributed with the toolkit or available from CPAN. - -The LOAD_PERL option (disabled by default) provides a further way by -which external Perl modules may be loaded. If a regular Perl module -(i.e. not a Template::Plugin::* or other module relative to some -PLUGIN_BASE) supports an object-oriented interface and a new() -constructor then it can be loaded and instantiated automatically. The -following trivial example shows how the IO::File module might be used. - - [% USE file = IO.File('/tmp/mydata') %] - - [% WHILE (line = file.getline) %] - - [% END %] - - - - - - -=item MACRO - -The MACRO directive allows you to define a directive or directive block -which is then evaluated each time the macro is called. - - [% MACRO header INCLUDE header %] - -Calling the macro as: - - [% header %] - -is then equivalent to: - - [% INCLUDE header %] - -Macros can be passed named parameters when called. These values remain -local to the macro. - - [% header(title='Hello World') %] - -equivalent to: - - [% INCLUDE header title='Hello World' %] - -A MACRO definition may include parameter names. Values passed to the -macros are then mapped to these local variables. Other named parameters -may follow these. - - [% MACRO header(title) INCLUDE header %] - - [% header('Hello World') %] - [% header('Hello World', bgcol='#123456') %] - -equivalent to: - - [% INCLUDE header title='Hello World' %] - [% INCLUDE header title='Hello World' bgcol='#123456' %] - -Here's another example, defining a macro for display numbers -in comma-delimited groups of 3, using the chunk and join virtual -method. - - [% MACRO number(n) GET n.chunk(-3).join(',') %] - - [% number(1234567) %] # 1,234,567 - -A MACRO may precede any directive and must conform to the structure -of the directive. - - [% MACRO header IF frames %] - [% INCLUDE frames/header %] - [% ELSE %] - [% INCLUDE header %] - [% END %] - - [% header %] - -A MACRO may also be defined as an anonymous BLOCK. The block will be -evaluated each time the macro is called. - - [% MACRO header BLOCK %] - ...content... - [% END %] - - [% header %] - -If you've got the EVAL_PERL option set, then you can even define a -MACRO as a PERL block (see below): - - [% MACRO triple(n) PERL %] - my $n = $stash->get('n'); - print $n * 3; - [% END -%] - - - - - - - -=item PERL - -(for the advanced reader) - -The PERL directive is used to mark the start of a block which contains -Perl code for evaluation. The EVAL_PERL option must be enabled for Perl -code to be evaluated or a 'perl' exception will be thrown with the -message 'EVAL_PERL not set'. - -Perl code is evaluated in the Template::Perl package. The $context -package variable contains a reference to the current Template::Context -object. This can be used to access the functionality of the Template -Toolkit to process other templates, load plugins, filters, etc. -See L for further details. - - [% PERL %] - print $context->include('myfile'); - [% END %] - -The $stash variable contains a reference to the top-level stash object -which manages template variables. Through this, variable values can -be retrieved and updated. See L for further details. - - [% PERL %] - $stash->set(foo => 'bar'); - print "foo value: ", $stash->get('foo'); - [% END %] - -Output - foo value: bar - -Output is generated from the PERL block by calling print(). Note that -the Template::Perl::PERLOUT handle is selected (tied to an output -buffer) instead of STDOUT. - - [% PERL %] - print "foo\n"; # OK - print PERLOUT "bar\n"; # OK, same as above - print Template::Perl::PERLOUT "baz\n"; # OK, same as above - print STDOUT "qux\n"; # WRONG! - [% END %] - -The PERL block may contain other template directives. These are -processed before the Perl code is evaluated. - - [% name = 'Fred Smith' %] - - [% PERL %] - print "[% name %]\n"; - [% END %] - -Thus, the Perl code in the above example is evaluated as: - - print "Fred Smith\n"; - -Exceptions may be thrown from within PERL blocks via die() and will be -correctly caught by enclosing TRY blocks. - - [% TRY %] - [% PERL %] - die "nothing to live for\n"; - [% END %] - [% CATCH %] - error: [% error.info %] - [% END %] - -output: - error: nothing to live for - - - - -=item RAWPERL - -(for the very advanced reader) - -The Template Toolkit parser reads a source template and generates the -text of a Perl subroutine as output. It then uses eval() to evaluate -it into a subroutine reference. This subroutine is then called to -process the template, passing a reference to the current -Template::Context object through which the functionality of the -Template Toolkit can be accessed. The subroutine reference can be -cached, allowing the template to be processed repeatedly without -requiring any further parsing. - -For example, a template such as: - - [% PROCESS header %] - The [% animal %] sat on the [% location %] - [% PROCESS footer %] - -is converted into the following Perl subroutine definition: - - sub { - my $context = shift; - my $stash = $context->stash; - my $output = ''; - my $error; - - eval { BLOCK: { - $output .= $context->process('header'); - $output .= "The "; - $output .= $stash->get('animal'); - $output .= " sat on the "; - $output .= $stash->get('location'); - $output .= $context->process('footer'); - $output .= "\n"; - } }; - if ($@) { - $error = $context->catch($@, \$output); - die $error unless $error->type eq 'return'; - } - - return $output; - } - -To examine the Perl code generated, such as in the above example, set -the $Template::Parser::DEBUG package variable to any true value. You -can also set the $Template::Directive::PRETTY variable true to have -the code formatted in a readable manner for human consumption. The -source code for each generated template subroutine will be printed to -STDERR on compilation (i.e. the first time a template is used). - - $Template::Parser::DEBUG = 1; - $Template::Directive::PRETTY = 1; - - ... - - $template->process($file, $vars) - || die $template->error(), "\n"; - -The PERL ... END construct allows Perl code to be embedded into a -template (when the EVAL_PERL option is set), but it is evaluated at -"runtime" using eval() each time the template subroutine is called. -This is inherently flexible, but not as efficient as it could be, -especially in a persistent server environment where a template may be -processed many times. - -The RAWPERL directive allows you to write Perl code that is integrated -directly into the generated Perl subroutine text. It is evaluated -once at compile time and is stored in cached form as part of the -compiled template subroutine. This makes RAWPERL blocks more -efficient than PERL blocks. - -The downside is that you must code much closer to the metal. Within -PERL blocks, you can call print() to generate some output. RAWPERL -blocks don't afford such luxury. The code is inserted directly into -the generated subroutine text and should conform to the convention of -appending to the '$output' variable. - - [% PROCESS header %] - - [% RAWPERL %] - $output .= "Some output\n"; - ... - $output .= "Some more output\n"; - [% END %] - -The critical section of the generated subroutine for this example would -then look something like: - - ... - eval { BLOCK: { - $output .= $context->process('header'); - $output .= "\n"; - $output .= "Some output\n"; - ... - $output .= "Some more output\n"; - $output .= "\n"; - } }; - ... - -As with PERL blocks, the $context and $stash references are pre-defined -and available for use within RAWPERL code. - - -=back - -=head2 Exception Handling and Flow Control - -=over 4 - - -=item TRY / THROW / CATCH / FINAL - -(more advanced material) - -The Template Toolkit supports fully functional, nested exception -handling. The TRY directive introduces an exception handling scope -which continues until the matching END directive. Any errors that -occur within that block will be caught and can be handled by one -of the CATCH blocks defined. - - [% TRY %] - ...blah...blah... - [% CALL somecode %] - ...etc... - [% INCLUDE someblock %] - ...and so on... - [% CATCH %] - An error occurred! - [% END %] - -Errors are raised as exceptions (objects of the Template::Exception -class) and contain two fields, 'type' and 'info'. The exception -'type' can be any string containing letters, numbers, '_' or '.', and -is used to indicate the kind of error that occurred. The 'info' field -contains an error message indicating what actually went wrong. Within -a catch block, the exception object is aliased to the 'error' variable. -You can access the 'type' and 'info' fields directly. - - [% mydsn = 'dbi:MySQL:foobar' %] - ... - - [% TRY %] - [% USE DBI(mydsn) %] - [% CATCH %] - ERROR! Type: [% error.type %] - Info: [% error.info %] - [% END %] - -output (assuming a non-existant database called 'foobar'): - - ERROR! Type: DBI - Info: Unknown database "foobar" - -The 'error' variable can also be specified by itself and will return a -string of the form "$type error - $info". - - ... - [% CATCH %] - ERROR: [% error %] - [% END %] - -output: - - ERROR: DBI error - Unknown database "foobar" - -Each CATCH block may be specified with a particular exception type -denoting the kind of error that it should catch. Multiple CATCH -blocks can be provided to handle different types of exception that may -be thrown in the TRY block. A CATCH block specified without any type, -as in the previous example, is a default handler which will catch any -otherwise uncaught exceptions. This can also be specified as -[% CATCH DEFAULT %]. - - [% TRY %] - [% INCLUDE myfile %] - [% USE DBI(mydsn) %] - [% CALL somecode %] - ... - [% CATCH file %] - File Error! [% error.info %] - [% CATCH DBI %] - [% INCLUDE database/error.html %] - [% CATCH %] - [% error %] - [% END %] - -Remember that you can specify multiple directives within a single tag, -each delimited by ';'. Thus, you might prefer to write your simple -CATCH blocks more succinctly as: - - [% TRY %] - ... - [% CATCH file; "File Error! $error.info" %] - [% CATCH DBI; INCLUDE database/error.html %] - [% CATCH; error %] - [% END %] - -or even: - - [% TRY %] - ... - [% CATCH file ; - "File Error! $error.info" ; - CATCH DBI ; - INCLUDE database/error.html ; - CATCH ; - error ; - END - %] - -The DBI plugin throws exceptions of the 'DBI' type (in case that -wasn't already obvious). The other specific exception caught here is -of the 'file' type. - -A 'file' error is automatically thrown by the Template Toolkit when it -can't find a file, or fails to load, parse or process a file that has -been requested by an INCLUDE, PROCESS, INSERT or WRAPPER directive. -If 'myfile' can't be found in the example above, the [% INCLUDE myfile -%] directive will raise a 'file' exception which is then caught by the -[% CATCH file %] block, generating the output: - - File Error! myfile: not found - -Note that the DEFAULT option (disabled by default) allows you to -specify a default file to be used any time a template file can't be -found. This will prevent file exceptions from ever being raised when -a non-existant file is requested (unless, of course, the DEFAULT file -doesn't exist). Errors encountered once the file has been found -(i.e. read error, parse error) will be raised as file exceptions as per -usual. - -Uncaught exceptions (i.e. the TRY block doesn't have a type specific -or default CATCH handler) may be caught by enclosing TRY blocks which -can be nested indefinitely across multiple templates. If the error -isn't caught at any level then processing will stop and the Template -process() method will return a false value to the caller. The -relevant Template::Exception object can be retrieved by calling the -error() method. - - [% TRY %] - ... - [% TRY %] - [% INCLUDE $user.header %] - [% CATCH file %] - [% INCLUDE header %] - [% END %] - ... - [% CATCH DBI %] - [% INCLUDE database/error.html %] - [% END %] - -In this example, the inner TRY block is used to ensure that the first -INCLUDE directive works as expected. We're using a variable to -provide the name of the template we want to include, user.header, and -it's possible this contains the name of a non-existant template, or -perhaps one containing invalid template directives. If the INCLUDE fails - with a 'file' error then we CATCH it in the inner block and INCLUDE -the default 'header' file instead. Any DBI errors that occur within -the scope of the outer TRY block will be caught in the relevant CATCH -block, causing the 'database/error.html' template to be processed. -Note that included templates inherit all currently defined template -variable so these error files can quite happily access the 'error' -variable to retrieve information about the currently caught exception. -e.g. - -'database/error.html': - -

Database Error

- A database error has occurred: [% error.info %] - -You can also specify a FINAL block. This is always processed -regardless of the outcome of the TRY and/or CATCH block. If an -exception is uncaught then the FINAL block is processed before jumping -to the enclosing block or returning to the caller. - - [% TRY %] - ... - [% CATCH this %] - ... - [% CATCH that %] - ... - [% FINAL %] - All done! - [% END %] - -The output from the TRY block is left intact up to the point where an -exception occurs. For example, this template: - - [% TRY %] - This gets printed - [% THROW food 'carrots' %] - This doesn't - [% CATCH food %] - culinary delights: [% error.info %] - [% END %] - -generates the following output: - - This gets printed - culinary delights: carrots - -The CLEAR directive can be used in a CATCH or FINAL block to clear -any output created in the TRY block. - - [% TRY %] - This gets printed - [% THROW food 'carrots' %] - This doesn't - [% CATCH food %] - [% CLEAR %] - culinary delights: [% error.info %] - [% END %] - -output: - - culinary delights: carrots - -Exception types are hierarchical, with each level being separated by -the familiar dot operator. A 'DBI.connect' exception is a more -specific kind of 'DBI' error. Similarly, a 'myown.error.barf' is a -more specific kind of 'myown.error' type which itself is also a -'myown' error. A CATCH handler that specifies a general exception -type (such as 'DBI' or 'myown.error') will also catch more specific -types that have the same prefix as long as a more specific handler -isn't defined. Note that the order in which CATCH handlers are -defined is irrelevant; a more specific handler will always catch an -exception in preference to a more generic or default one. - - [% TRY %] - ... - [% CATCH DBI ; - INCLUDE database/error.html ; - CATCH DBI.connect ; - INCLUDE database/connect.html ; - CATCH ; - INCLUDE error.html ; - END - %] - -In this example, a 'DBI.connect' error has it's own handler, a more -general 'DBI' block is used for all other DBI or DBI.* errors and a -default handler catches everything else. - -Exceptions can be raised in a template using the THROW directive. The -first parameter is the exception type which doesn't need to be quoted -(but can be, it's the same as INCLUDE) followed by the relevant error -message which can be any regular value such as a quoted string, -variable, etc. - - [% THROW food "Missing ingredients: $recipe.error" %] - - [% THROW user.login 'no user id: please login' %] - - [% THROW $myerror.type "My Error: $myerror.info" %] - -It's also possible to specify additional positional or named -parameters to the THROW directive if you want to pass more than -just a simple message back as the error info field. - - [% THROW food 'eggs' 'flour' msg='Missing Ingredients' %] - -In this case, the error 'info' field will be a hash array containing -the named arguments, in this case 'msg' =E 'Missing Ingredients', -and an 'args' item which contains a list of the positional arguments, -in this case 'eggs' and 'flour'. The error 'type' field remains -unchanged, here set to 'food'. - - [% CATCH food %] - [% error.info.msg %] - [% FOREACH item = error.info.args %] - * [% item %] - [% END %] - [% END %] - -This produces the output: - - Missing Ingredients - * eggs - * flour - -In addition to specifying individual positional arguments as -[% error.info.args.n %], the 'info' hash contains keys directly -pointing to the positional arguments, as a convenient shortcut. - - [% error.info.0 %] # same as [% error.info.args.0 %] - -Exceptions can also be thrown from Perl code which you've bound to -template variables, or defined as a plugin or other extension. To -raise an exception, call die() passing a reference to a -Template::Exception object as the argument. This will then be caught -by any enclosing TRY blocks from where the code was called. - - use Template::Exception; - ... - - my $vars = { - foo => sub { - # ... do something ... - die Template::Exception->new('myerr.naughty', - 'Bad, bad error'); - }, - }; - -template: - - [% TRY %] - ... - [% foo %] - ... - [% CATCH myerr ; - "Error: $error" ; - END - %] - -output: - - Error: myerr.naughty error - Bad, bad error - -The 'info' field can also be a reference to another object or data -structure, if required. - - die Template::Exception->new('myerror', { - module => 'foo.pl', - errors => [ 'bad permissions', 'naughty boy' ], - }); - -Later, in a template: - - [% TRY %] - ... - [% CATCH myerror %] - [% error.info.errors.size or 'no'; - error.info.errors.size == 1 ? ' error' : ' errors' %] - in [% error.info.module %]: - [% error.info.errors.join(', ') %]. - [% END %] - -Generating the output: - - 2 errors in foo.pl: - bad permissions, naughty boy. - -You can also call die() with a single string, as is common in much -existing Perl code. This will automatically be converted to an -exception of the 'undef' type (that's the literal string 'undef', -not the undefined value). If the string isn't terminated with a -newline then Perl will append the familiar " at $file line $line" -message. - - sub foo { - # ... do something ... - die "I'm sorry, Dave, I can't do that\n"; - } - -If you're writing a plugin, or some extension code that has the -current Template::Context in scope (you can safely skip this section -if this means nothing to you) then you can also raise an exception by -calling the context throw() method. You can pass it an -Template::Exception object reference, a pair of ($type, $info) parameters -or just an $info string to create an exception of 'undef' type. - - $context->throw($e); # exception object - $context->throw('Denied'); # 'undef' type - $context->throw('user.passwd', 'Bad Password'); - - - - - - - -=item NEXT - -The NEXT directive can be used to start the next iteration of a FOREACH -or WHILE loop. - - [% FOREACH user = userlist %] - [% NEXT IF user.isguest %] - Name: [% user.name %] Email: [% user.email %] - [% END %] - - - - - -=item LAST - -The LAST directive can be used to prematurely exit a FOREACH or WHILE -loop. - - [% FOREACH user = userlist %] - Name: [% user.name %] Email: [% user.email %] - [% LAST IF some.condition %] - [% END %] - -BREAK can also be used as an alias for LAST. - - - - -=item RETURN - -The RETURN directive can be used to stop processing the current -template and return to the template from which it was called, resuming -processing at the point immediately after the INCLUDE, PROCESS or -WRAPPER directive. If there is no enclosing template then the -Template process() method will return to the calling code with a -true value. - - Before - [% INCLUDE half_wit %] - After - - [% BLOCK half_wit %] - This is just half... - [% RETURN %] - ...a complete block - [% END %] - -output: - - Before - This is just half... - After - - - - -=item STOP - -The STOP directive can be used to indicate that the processor should -stop gracefully without processing any more of the template document. -This is a planned stop and the Template process() method will return a -B value to the caller. This indicates that the template was -processed successfully according to the directives within it. - - [% IF something.terrible.happened %] - [% INCLUDE fatal/error.html %] - [% STOP %] - [% END %] - - [% TRY %] - [% USE DBI(mydsn) %] - ... - [% CATCH DBI.connect %] -

Cannot connect to the database: [% error.info %]

-
- We apologise for the inconvenience. The cleaning lady - has removed the server power to plug in her vacuum cleaner. - Please try again later. -

- [% INCLUDE footer %] - [% STOP %] - [% END %] - - - - -=item CLEAR - -The CLEAR directive can be used to clear the output buffer for the current -enclosing block. It is most commonly used to clear the output generated -from a TRY block up to the point where the error occurred. - - [% TRY %] - blah blah blah # this is normally left intact - [% THROW some 'error' %] # up to the point of error - ... - [% CATCH %] - [% CLEAR %] # clear the TRY output - [% error %] # print error string - [% END %] - - - - -=back - -=head2 Miscellaneous - -=over 4 - - -=item META - -The META directive allows simple metadata items to be defined within a -template. These are evaluated when the template is parsed and as such -may only contain simple values (e.g. it's not possible to interpolate -other variables values into META variables). - - [% META - title = 'The Cat in the Hat' - author = 'Dr. Seuss' - version = 1.23 - %] - -The 'template' variable contains a reference to the main template -being processed. These metadata items may be retrieved as attributes -of the template. - -

[% template.title %]

-

[% template.author %]

- -The 'name' and 'modtime' metadata items are automatically defined for -each template to contain its name and modification time in seconds -since the epoch. - - [% USE date %] # use Date plugin to format time - ... - [% template.name %] last modified - at [% date.format(template.modtime) %] - -The PRE_PROCESS and POST_PROCESS options allow common headers and -footers to be added to all templates. The 'template' reference is -correctly defined when these templates are processed, allowing headers -and footers to reference metadata items from the main template. - - $template = Template->new({ - PRE_PROCESS => 'header', - POST_PROCESS => 'footer', - }); - - $template->process('cat_in_hat'); - -header: - - - - [% template.title %] - - - -cat_in_hat: - - [% META - title = 'The Cat in the Hat' - author = 'Dr. Seuss' - version = 1.23 - year = 2000 - %] - - The cat in the hat sat on the mat. - -footer: - -
- © [% template.year %] [% template.author %] - - - -The output generated from the above example is: - - - - The Cat in the Hat - - - - The cat in the hat sat on the mat. - -
- © 2000 Dr. Seuss - - - - - -=item TAGS - -The TAGS directive can be used to set the START_TAG and END_TAG values -on a per-template file basis. - - [% TAGS <+ +> %] - - <+ INCLUDE header +> - -The TAGS directive may also be used to set a named TAG_STYLE - - [% TAGS html %] - - -See the TAGS and TAG_STYLE configuration options for further details. - - - - - - - - -=item DEBUG - -The DEBUG directive can be used to enable or disable directive debug -messages within a template. The DEBUG configuration option must be -set to include DEBUG_DIRS for the DEBUG directives to have any effect. -If DEBUG_DIRS is not set then the parser will automatically ignore and -remove any DEBUG directives. - -The DEBUG directive can be used with an 'on' or 'off' parameter to -enable or disable directive debugging messages from that point -forward. When enabled, the output of each directive in the generated -output will be prefixed by a comment indicate the file, line and -original directive text. - - [% DEBUG on %] - directive debugging is on (assuming DEBUG option is set true) - [% DEBUG off %] - directive debugging is off - -The 'format' parameter can be used to change the format of the debugging -message. - - [% DEBUG format '' %] - - - - - -=back - -=head1 AUTHOR - -Andy Wardley Eabw@andywardley.comE - -L - - - - -=head1 VERSION - -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - - - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Manual/Filters.pod b/lib/Template/Manual/Filters.pod deleted file mode 100644 index c42f2ef..0000000 --- a/lib/Template/Manual/Filters.pod +++ /dev/null @@ -1,529 +0,0 @@ -#============================================================= -*-perl-*- -# -# Template::Manual::Filters -# -# DESCRIPTION -# This section lists all the standard filters distributed with the -# Template Toolkit for post-processing output. -# -# AUTHOR -# Andy Wardley -# -# COPYRIGHT -# Copyright (C) 1996-2001 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2001 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -# REVISION -# -# -#======================================================================== - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Manual::Filters - Standard filters - -=head1 DESCRIPTION - -This section lists all the standard filters distributed with the -Template Toolkit for post-processing output. - -=head1 STANDARD FILTERS - - - -=head2 format(format) - -The 'format' filter takes a format string as a parameter (as per -printf()) and formats each line of text accordingly. - - [% FILTER format('') %] - This is a block of text filtered - through the above format. - [% END %] - -output: - - - - -=head2 upper - -Folds the input to UPPER CASE. - - [% "hello world" FILTER upper %] - -output: - - HELLO WORLD - -=head2 lower - -Folds the input to lower case. - - [% "Hello World" FILTER lower %] - -output: - - hello world - -=head2 ucfirst - -Folds the first character of the input to UPPER CASE. - - [% "hello" FILTER ucfirst %] - -output: - - Hello - -=head2 lcfirst - -Folds the first character of the input to lower case. - - [% "HELLO" FILTER lcfirst %] - -output: - - hELLO - -=head2 trim - -Trims any leading or trailing whitespace from the input text. Particularly -useful in conjunction with INCLUDE, PROCESS, etc., having the same effect -as the TRIM configuration option. - - [% INCLUDE myfile | trim %] - -=head2 collapse - -Collapse any whitespace sequences in the input text into a single space. -Leading and trailing whitespace (which would be reduced to a single space) -is removed, as per trim. - - [% FILTER collapse %] - - The cat - - sat on - - the mat - - [% END %] - -output: - - The cat sat on the mat - -=head2 html - -Converts the characters 'E', 'E' and '&' to '<', '>' and -'&', respectively, protecting them from being interpreted as -representing HTML tags or entities. - - [% FILTER html %] - Binary "<=>" returns -1, 0, or 1 depending on... - [% END %] - -output: - - Binary "<=>" returns -1, 0, or 1 depending on... - -=head2 html_entity - -The html filter is fast and simple but it doesn't encode the full -range of HTML entities that your text may contain. The html_entity -filter uses either the Apache::Util module (which is written in C and -is therefore faster) or the HTML::Entities module (written in Perl but -equally as comprehensive) to perform the encoding. If one or other of -these modules are installed on your system then the text will be -encoded (via the escape_html() or encode_entities() subroutines -respectively) to convert all extended characters into their -appropriate HTML entities (e.g. converting 'é' to 'é'). If -neither module is available on your system then an 'html_entity' exception -will be thrown reporting an appropriate message. - -For further information on HTML entity encoding, see -http://www.w3.org/TR/REC-html40/sgml/entities.html. - -=head2 html_para - -This filter formats a block of text into HTML paragraphs. A sequence of -two or more newlines is used as the delimiter for paragraphs which are -then wrapped in HTML EpE...E/pE tags. - - [% FILTER html_para %] - The cat sat on the mat. - - Mary had a little lamb. - [% END %] - -output: - -

- The cat sat on the mat. -

- -

- Mary had a little lamb. -

- -=head2 html_break / html_para_break - -Similar to the html_para filter described above, but uses the HTML tag -sequence EbrEEbrE to join paragraphs. - - [% FILTER html_break %] - The cat sat on the mat. - - Mary had a little lamb. - [% END %] - -output: - - The cat sat on the mat. -
-
- Mary had a little lamb. - -=head2 html_line_break - -This filter replaces any newlines with EbrE HTML tags, -thus preserving the line breaks of the original text in the -HTML output. - - [% FILTER html_line_break %] - The cat sat on the mat. - Mary had a little lamb. - [% END %] - -output: - - The cat sat on the mat.
- Mary had a little lamb.
- -=head2 uri - -This filter URI escapes the input text, converting any characters -outside of the permitted URI character set (as defined by RFC 2396) -into a C<%nn> hex escape. - - [% 'my file.html' | uri %] - -output: - - my%20file.html - -Note that URI escaping isn't always enough when generating hyperlinks in -an HTML document. The C<&> character, for example, is valid in a URI and -will not be escaped by the URI filter. In this case you should also filter -the text through the 'html' filter. - -
click here - -=head2 indent(pad) - -Indents the text block by a fixed pad string or width. The 'pad' argument -can be specified as a string, or as a numerical value to indicate a pad -width (spaces). Defaults to 4 spaces if unspecified. - - [% FILTER indent('ME> ') %] - blah blah blah - cabbages, rhubard, onions - [% END %] - -output: - - ME> blah blah blah - ME> cabbages, rhubard, onions - -=head2 truncate(length) - -Truncates the text block to the length specified, or a default length of -32. Truncated text will be terminated with '...' (i.e. the '...' falls -inside the required length, rather than appending to it). - - [% FILTER truncate(21) %] - I have much to say on this matter that has previously - been said on more than one occasion. - [% END %] - -output: - - I have much to say... - -=head2 repeat(iterations) - -Repeats the text block for as many iterations as are specified (default: 1). - - [% FILTER repeat(3) %] - We want more beer and we want more beer, - [% END %] - We are the more beer wanters! - -output: - - We want more beer and we want more beer, - We want more beer and we want more beer, - We want more beer and we want more beer, - We are the more beer wanters! - -=head2 remove(string) - -Searches the input text for any occurrences of the specified string and -removes them. A Perl regular expression may be specified as the search -string. - - [% "The cat sat on the mat" FILTER remove('\s+') %] - -output: - - Thecatsatonthemat - -=head2 replace(search, replace) - -Similar to the remove filter described above, but taking a second parameter -which is used as a replacement string for instances of the search string. - - [% "The cat sat on the mat" | replace('\s+', '_') %] - -output: - - The_cat_sat_on_the_mat - -=head2 redirect(file, options) - -The 'redirect' filter redirects the output of the block into a separate -file, specified relative to the OUTPUT_PATH configuration item. - - [% FOREACH user = myorg.userlist %] - [% FILTER redirect("users/${user.id}.html") %] - [% INCLUDE userinfo %] - [% END %] - [% END %] - -or more succinctly, using side-effect notation: - - [% INCLUDE userinfo - FILTER redirect("users/${user.id}.html") - FOREACH user = myorg.userlist - %] - -A 'file' exception will be thrown if the OUTPUT_PATH option is undefined. - -An optional 'binmode' argument can follow the filename to explicitly set -the output file to binary mode. - - [% PROCESS my/png/generator - FILTER redirect("images/logo.png", binmode=1) %] - -For backwards compatibility with earlier versions, a single true/false -value can be used to set binary mode. - - [% PROCESS my/png/generator - FILTER redirect("images/logo.png", 1) %] - -For the sake of future compatibility and clarity, if nothing else, we -would strongly recommend you explicitly use the named 'binmode' option -as shown in the first example. - -=head2 eval / evaltt - -The 'eval' filter evaluates the block as template text, processing -any directives embedded within it. This allows template variables to -contain template fragments, or for some method to be provided for -returning template fragments from an external source such as a -database, which can then be processed in the template as required. - - my $vars = { - fragment => "The cat sat on the [% place %]", - }; - $template->process($file, $vars); - -The following example: - - [% fragment | eval %] - -is therefore equivalent to - - The cat sat on the [% place %] - -The 'evaltt' filter is provided as an alias for 'eval'. - -=head2 perl / evalperl - -The 'perl' filter evaluates the block as Perl code. The EVAL_PERL -option must be set to a true value or a 'perl' exception will be -thrown. - - [% my_perl_code | perl %] - -In most cases, the [% PERL %] ... [% END %] block should suffice for -evaluating Perl code, given that template directives are processed -before being evaluate as Perl. Thus, the previous example could have -been written in the more verbose form: - - [% PERL %] - [% my_perl_code %] - [% END %] - -as well as - - [% FILTER perl %] - [% my_perl_code %] - [% END %] - -The 'evalperl' filter is provided as an alias for 'perl' for backwards -compatibility. - -=head2 stdout(options) - -The stdout filter prints the output generated by the enclosing block to -STDOUT. The 'binmode' option can be passed as either a named parameter -or a single argument to set STDOUT to binary mode (see the -binmode perl function). - - [% PROCESS something/cool - FILTER stdout(binmode=1) # recommended %] - - [% PROCESS something/cool - FILTER stdout(1) # alternate %] - -The stdout filter can be used to force binmode on STDOUT, or also inside -redirect, null or stderr blocks to make sure that particular output goes -to stdout. See the null filter below for an example. - -=head2 stderr - -The stderr filter prints the output generated by the enclosing block to -STDERR. - -=head2 null - -The null filter prints nothing. This is useful for plugins whose -methods return values that you don't want to appear in the output. -Rather than assigning every plugin method call to a dummy variable -to silence it, you can wrap the block in a null filter: - - [% FILTER null; - USE im = GD.Image(100,100); - black = im.colorAllocate(0, 0, 0); - red = im.colorAllocate(255,0, 0); - blue = im.colorAllocate(0, 0, 255); - im.arc(50,50,95,75,0,360,blue); - im.fill(50,50,red); - im.png | stdout(1); - END; - -%] - -Notice the use of the stdout filter to ensure that a particular expression -generates output to stdout (in this case in binary mode). - -=head2 latex(outputType) - -Passes the text block to LaTeX and produces either PDF, DVI or -PostScript output. The 'outputType' argument determines the output -format and it should be set to one of the strings: "pdf" (default), -"dvi", or "ps". - -The text block should be a complete LaTeX source file. - - [% FILTER latex("pdf") -%] - \documentclass{article} - - \begin{document} - - \title{A Sample TT2 \LaTeX\ Source File} - \author{Craig Barratt} - \maketitle - - \section{Introduction} - This is some text. - - \end{document} - [% END -%] - -The output will be a PDF file. You should be careful not to prepend or -append any extraneous characters or text outside the FILTER block, -since this text will wrap the (binary) output of the latex filter. -Notice the END directive uses '-%]' for the END_TAG to remove the -trailing new line. - -One example where you might prepend text is in a CGI script where -you might include the Content-Type before the latex output, eg: - - Content-Type: application/pdf - - [% FILTER latex("pdf") -%] - \documentclass{article} - \begin{document} - ... - \end{document} - [% END -%] - -In other cases you might use the redirect filter to put the output -into a file, rather than delivering it to stdout. This might be -suitable for batch scripts: - - [% output = FILTER latex("pdf") -%] - \documentclass{article} - \begin{document} - ... - \end{document} - [% END; output | redirect("document.pdf", 1) -%] - -(Notice the second argument to redirect to force binary mode.) - -Note that the latex filter runs one or two external programs, so it -isn't very fast. But for modest documents the performance is adequate, -even for interactive applications. - -A error of type 'latex' will be thrown if there is an error reported -by latex, pdflatex or dvips. - -=head1 AUTHOR - -Andy Wardley Eabw@andywardley.comE - -L - - - - -=head1 VERSION - -Template Toolkit version 2.13, released on 30 January 2004. - -=head1 COPYRIGHT - - Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. - Copyright (C) 1998-2002 Canon Research Centre Europe Ltd. - -This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - - - -=cut - -# Local Variables: -# mode: perl -# perl-indent-level: 4 -# indent-tabs-mode: nil -# End: -# -# vim: expandtab shiftwidth=4: diff --git a/lib/Template/Manual/Internals.pod b/lib/Template/Manual/Internals.pod deleted file mode 100644 index b8cf80b..0000000 --- a/lib/Template/Manual/Internals.pod +++ /dev/null @@ -1,556 +0,0 @@ -#============================================================= -*-perl-*- -# -# Template::Manual::Internals -# -# DESCRIPTION -# This document provides an overview of the internal architecture of -# the Template Toolkit. It is a work in progress and is far from -# complete, currently providing little more than an overview of how -# the major components fit together. Nevertheless, it's a good -# starting point for anyone wishing to delve into the source code to -# find out how it all works. -# -# AUTHOR -# Andy Wardley -# -# COPYRIGHT -# Copyright (C) 1996-2001 Andy Wardley. All Rights Reserved. -# Copyright (C) 1998-2001 Canon Research Centre Europe Ltd. -# -# This module is free software; you can redistribute it and/or -# modify it under the same terms as Perl itself. -# -# REVISION -# -# -#======================================================================== - - -#------------------------------------------------------------------------ -# IMPORTANT NOTE -# This documentation is generated automatically from source -# templates. Any changes you make here may be lost. -# -# The 'docsrc' documentation source bundle is available for download -# from http://www.template-toolkit.org/docs.html and contains all -# the source templates, XML files, scripts, etc., from which the -# documentation for the Template Toolkit is built. -#------------------------------------------------------------------------ - -=head1 NAME - -Template::Manual::Internals - Template Toolkit internals - -=head1 DESCRIPTION - -This document provides an overview of the internal architecture of the -Template Toolkit. It is a work in progress and is far from complete, -currently providing little more than an overview of how the major -components fit together. Nevertheless, it's a good starting point for -anyone wishing to delve into the source code to find out how it all -works. - -=head2 Outside Looking In - -The B