This module defines a number of constants used by other modules in the Template Toolkit. It is a subclass of Badger::Constants and inherits all of the default constants defined therein.
Constants can be used by specifying the Template::TT3::Constants package explicitly as part of the name:
use Template::TT3::Constants; print Template::TT3::Constants::CHOMP_ALL; # 2
Constants may be imported into the caller's namespace by naming them as
options to the use Template::TT3::Constants
statement:
use Template::TT3::Constants 'CHOMP_ALL'; print CHOMP_ALL; # 2
Alternatively, one of the tagset identifiers may be specified to import different sets of constants.
use Template::TT3::Constants ':chomp'; print CHOMP_ALL; # 2
The following tag sets and associated constants are defined:
Constants used as whitespace chomping options.
CHOMP_NONE # do not remove whitespace CHOMP_ONE # remove one line of whitespace CHOMP_ALL # remove all whitespace including newlines CHOMP_SPACE # collapse whitespace to single space CHOMP_TAG # remove the tag (e.g. [%# comment %]) PRE_CHOMP_FLAGS # array ref of pre-chomp flags, e.g. '+', '-', '~', etc. POST_CHOMP_FLAGS # ditto for post-chomp flags
Constants used to control caching.
CACHE_ALL # cache everything CACHE_NONE # cache nothing
Constants that define the default names for templates read from text strings and file handles, or constructed as wrappers around existing subroutines.
FROM_TEXT # template text FROM_CODE # template code FROM_HANDLE # template read from file handle
Constants used as the scheme:
prefix when constructing URIs for templates
TEXT_SCHEME # text FILE_SCHEME # file CODE_SCHEME # code NAME_SCHEME # name COLON # :
Constants defining the names of the core services that Template::TT3::Engine::TT3 fetches from Template::TT3::Services to construct a template service pipeline.
INPUT_SERVICE # input OUTPUT_SERVICE # output
Constants used by various Template::TT3::Element module to denote pre-define operator precedence levels
ARG_PRECEDENCE # 200 CMD_PRECEDENCE # 100
These constants define semantic aliases for the array offsets used by
Template::TT3::Templates
in its internal path lookup cache.
ID # 0 EXPIRES # 1
Constants that represent the offsets of particular slots within array based objects. In this case they are the slots used by data types.
TODO: They need a good cleanup and the name should possible be changed to something more suitable.
# variable data slots META # 0 CONTEXT # 1 NAME # 2 VALUE # 3 PARENT # 4 # variable metadata slots CONFIG # 0 VARS # 1 METHODS # 2
Constants that represent the offsets of particular slots within Template::TT3::Element objects. The first 4 slots are common to all element types.
META # 0 NEXT # 1 TOKEN # 2 POS # 3
The remaining slots have different meanings depending on the element type.
Unary expressions (including those with blocks) refer to the next 2 slots
as EXPR
and BLOCK
EXPR # 4 BLOCK # 5
Binary expressions use LHS
and RHS
instead.
LHS # 4 RHS # 5
Expressions that have additional arguments put them in the next slot.
ARGS # 6
Those that have an additional branch (e.g. the else
hanging off an if
block) store it in the BRANCH
slot.
BRANCH # 7
Any that have a fragment (e.g. end#for
) store it in FRAGMENT
.
FRAGMENT # 8
The first slot in an element (META
) contains a reference to a metadata
structure which is also an array reference (an entry in the grammar symbol
table - see the source code for
Template::TT3::Grammar::TT3
for an example.
The following constants define aliases for the slots in the metadata list.
CONFIG # configuration parameters ELEMS # reference to elements factory LPREC # leftward precedence RPREC # rightward precedence
The final two constants are used by element evaluation methods.
SELF # 0 CONTEXT # 1
The element classes have many small methods that do very little. We try to avoid shifting items off the stack wherever possible (for the sake of speed) and instead reference arguments directly on the stack.
So instead of something like this:
sub some_method { my ($self, $context) = @_; $self->something_trivial($context); }
You'll instead see:
sub some_method { $_[SELF]->something_trivial($_[CONTEXT]); }
Which is slightly more meaningful than:
sub some_method { $_[0]->something_trivial($_[1]); }
Andy Wardley http://wardley.org/
Copyright (C) 1996-2009 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
This module is a subclass of Badger::Constants .
See Badger::Exporter for more information on exporting variables.