]> Dogcows Code - chaz/p5-CGI-Ex/blobdiff - lib/CGI/Ex/Template.pod
CGI::Ex 2.08
[chaz/p5-CGI-Ex] / lib / CGI / Ex / Template.pod
index e0ea84279a47c1ebea6a2222d7291a873fd16927..fe89aa9bc9fc45c67ca9d0dee6b91b39b2ea3579 100644 (file)
@@ -70,7 +70,7 @@ In general the following statements are true:
     If you use Template::Stash::XS with a cached in memory template,
     then CET is about as fast.
 
-    Using TT with a compiled-in-memory template is only 33
+    Using TT with a compiled-in-memory template is only 33%
     faster than CET with a new object compiling each time.
 
 It is pretty hard to beat the speed of XS stash with compiled in
@@ -102,8 +102,8 @@ commonly used public methods are listed later in this document.
 
 =item C<process>
 
-This is the main method call for staring processing.  Any errors that results in the
-template being stopped processing will be stored and available via the ->error method.
+This is the main method call for starting processing.  Any errors that result in the
+template processing being stopped will be stored and available via the ->error method.
 
 Process takes three arguments.
 
@@ -175,128 +175,248 @@ to Template::Stash::define_vmethod.
 
 =head1 TODO
 
-    Add WRAPPER config item
+    Add WRAPPER configuration item (the WRAPPER directive is supported).
 
     Add ERROR config item
 
 =head1 HOW IS CGI::Ex::Template DIFFERENT
 
-CET uses the same template syntax and configuration items
-as TT2, but the internals of CET were written from scratch.  In
-addition to this, the following is a list of some of the ways that
-configuration and syntax of CET different from that of TT.
+CET uses the same base template syntax and configuration items as TT2,
+but the internals of CET were written from scratch.  Additionally much
+of the planned TT3 syntax is supported.  The following is a list of
+some of the ways that the configuration and syntax of CET are
+different from that of TT2.  Note: items that are planned to work in
+TT3 are marked with (TT3).
 
 =over 4
 
-Numerical hash keys work [% a = {1 => 2} %]
+=item Numerical hash keys work
 
-Quoted hash key interpolation is fine [% a = {"$foo" => 1} %]
+    [% a = {1 => 2} %]
 
-Multiple ranges in same constructor [% a = [1..10, 21..30] %]
+=item Quoted hash key interpolation is fine
 
-Constructor types can call virtual methods
+    [% a = {"$foo" => 1} %]
 
-   [% a = [1..10].reverse %]
+=item Multiple ranges in same constructor
 
-   [% "$foo".length %]
+    [% a = [1..10, 21..30] %]
 
-   [% 123.length %]   # = 3
+=item Constructor types can call virtual methods. (TT3)
 
-   [% 123.4.length %]  # = 5
+    [% a = [1..10].reverse %]
 
-   [% -123.4.length %] # = -5 ("." binds more tightly than "-")
+    [% "$foo".length %]
 
-   [% (a ~ b).length %]
+    [% 123.length %]   # = 3
 
-   [% "hi".repeat(3) %]
+    [% 123.4.length %]  # = 5
 
-   [% {a => b}.size %]
+    [% -123.4.length %] # = -5 ("." binds more tightly than "-")
 
-Reserved names are less reserved
+    [% (a ~ b).length %]
 
-   [% GET GET %] # gets the variable named "GET"
+    [% "hi".repeat(3) %]
 
-   [% GET $GET %] # gets the variable who's name is stored in "GET"
+    [% {a => b}.size %]
 
-Filters and SCALAR_OPS are interchangeable.
+=item The "${" and "}" variable interpolators can contain expressions,
+not just variables.
 
-   [% a | length %]
+    [% [0..10].${ 1 + 2 } %] # = 4
 
-   [% b . lower %]
+    [% {ab => 'AB'}.${ 'a' ~ 'b' } %] # = AB
 
-Pipe "|" can be used anywhere dot "." can be and means to call
-the virtual method.
+    [% color = qw/Red Blue/; FOR [1..4] ; color.${ loop.index % color.size } ; END %]
+      # = RedBlueRedBlue
 
-   [% a = {size => "foo"} %][% a.size %] # = foo
+=item Arrays can be accessed with non-integer numbers.
 
-   [% a = {size => "foo"} %][% a|size %] # = 1 (size of hash)
+    [% [0..10].${ 2.3 } %] # = 3
 
-Pipe "|" and "." can be mixed.
+=item Reserved names are less reserved. (TT3)
 
-   [% "aa" | repeat(2) . length %] # = 4
+    [% GET GET %] # gets the variable named "GET"
 
-Whitespace is less meaningful.
+    [% GET $GET %] # gets the variable who's name is stored in "GET"
 
-   [% 2-1 %] # = 1 (fails in TT)
+=item Filters and SCALAR_OPS are interchangeable. (TT3)
 
-Added pow operator.
+    [% a | length %]
 
-   [% 2 ** 3 %] [% 2 pow 3 %] # = 8 8
+    [% b . lower %]
 
-FOREACH variables can be nested
+=item Pipe "|" can be used anywhere dot "." can be and means to call
+the virtual method. (TT3)
 
-   [% FOREACH f.b = [1..10] ; f.b ; END %]
+    [% a = {size => "foo"} %][% a.size %] # = foo
 
-   Note that nested variables are subject to scoping issues.
-   f.b will not be reset to its value before the FOREACH.
+    [% a = {size => "foo"} %][% a|size %] # = 1 (size of hash)
 
-Post operative directives can be nested.
+=item Pipe "|" and "." can be mixed. (TT3)
 
-   [% one IF two IF three %]
+    [% "aa" | repeat(2) . length %] # = 4
 
-   same as
+=item Added Virtual Object Namespaces. (TT3)
 
-   [% IF three %][% IF two %][% one %][% END %][% END %]
+The Text, List, and Hash types give direct access
+to virtual methods.
 
+    [% a = "foobar" %][% Text.length(a) %] # = 6
 
-   [% a = [[1..3], [5..7]] %][% i FOREACH i = j FOREACH j = a %] # = 123567
+    [% a = [1 .. 10] %][% List.size(a) %] # = 10
 
-CATCH blocks can be empty.
+    [% a = {a=>"A", b=>"B"} ; Hash.size(a) %] = 2
 
-CET does not generate Perl code.  It generates an "opcode" tree.
+    [% foo = {a => 1, b => 2}
+       | Hash.keys
+       | List.join(", ") %] # = a, b
 
-CET uses storable for its compiled templates.  If EVAL_PERL is off,
-CET will not eval_string on ANY piece of information.
+=item Added "fmt" scalar, list, and hash virtual methods.
 
-There is no context.  CET provides a context object that mimics the
-Template::Context interface for use by some TT filters, eval perl
-blocks, and plugins.
+    [% list.fmt("%s", ", ") %]
 
-There is no stash.  CET only supports the variables passed in
-VARIABLES, PRE_DEFINE, and those passed to the process method.  CET
-provides a stash object that mimics the Template::Stash interface for
-use by some TT filters, eval perl blocks, and plugins.
+    [% hash.fmt("%s => %s", "\n") %]
 
-There is no provider.  CET uses the load_parsed_tree method to get and
-cache templates.
+=item Whitespace is less meaningful. (TT3)
 
-There is no grammar.  CET has its own built in grammar system.
+    [% 2-1 %] # = 1 (fails in TT2)
 
-There is no VIEW directive.
+=item Added pow operator.
 
-There are no references.  (There was in initial beta tests, but it was decided
-to remove the little used feature).
+    [% 2 ** 3 %] [% 2 pow 3 %] # = 8 8
 
-The DEBUG directive only understands DEBUG_DIRS (8) and DEBUG_UNDEF (2).
+=item Added self modifiers (+=, -=, *=, /=, %=, **=, ~=). (TT3)
 
-When debug dirs is on, directives on different lines separated by colons show the line they
+    [% a = 2;  a *= 3  ; a %] # = 6
+    [% a = 2; (a *= 3) ; a %] # = 66
+
+=item Added pre and post increment and decrement (++ --). (TT3)
+
+    [% ++a ; ++a %] # = 12
+    [% a-- ; a-- %] # = 0-1
+
+=item Added qw// contructor. (TT3)
+
+    [% a = qw(a b c); a.1 %] # = b
+
+    [% qw/a b c/.2 %] # = c
+
+=item Allow for scientific notation. (TT3)
+
+    [% a = 1.2e-20 %]
+
+    [% 123.fmt('%.3e') %] # = 1.230e+02
+
+=item Allow for hexidecimal input. (TT3)
+
+    [% a = 0xff0000 %][% a %] # = 16711680
+
+    [% a = 0xff2 / 0xd; a.fmt('%x') %] # = 13a
+
+=item FOREACH variables can be nested.
+
+    [% FOREACH f.b = [1..10] ; f.b ; END %]
+
+Note that nested variables are subject to scoping issues.
+f.b will not be reset to its value before the FOREACH.
+
+=item Post operative directives can be nested. (TT3)
+
+Andy Wardley calls this side-by-side effect notation.
+
+    [% one IF two IF three %]
+
+    same as
+
+    [% IF three %][% IF two %][% one %][% END %][% END %]
+
+
+    [% a = [[1..3], [5..7]] %][% i FOREACH i = j FOREACH j = a %] # = 123567
+
+=item Semi-colons on directives in the same tag are optional. (TT3)
+
+    [% SET a = 1
+       GET a
+     %]
+
+    [% FOREACH i = [1 .. 10]
+         i
+       END %]
+
+Note: a semi-colon is still required in front of any block directive
+that can be used as a post-operative directive.
+
+    [% 1 IF 0
+       2 %]   # prints 2
+
+    [% 1; IF 0
+       2
+       END %] # prints 1
+
+=item CATCH blocks can be empty.
+
+TT2 requires them to contain something.
+
+=item Added a DUMP directive.
+
+Used for Data::Dumpering the passed variable or expression.
+
+   [% DUMP a.a %]
+
+=item CET does not generate Perl code.
+
+It generates an "opcode" tree.
+
+=item CET uses storable for its compiled templates.
+
+If EVAL_PERL is off, CET will not eval_string on ANY piece of information.
+
+=item There is no context.
+
+CET provides a context object that mimics the Template::Context
+interface for use by some TT filters, eval perl blocks, and plugins.
+
+=item There is no stash.
+
+Well there is but it isn't an object.
+
+CET only supports the variables passed in VARIABLES, PRE_DEFINE, and
+those passed to the process method.  CET provides a stash object that
+mimics the Template::Stash interface for use by some TT filters, eval
+perl blocks, and plugins.
+
+=item There is no provider.
+
+CET uses the load_parsed_tree method to get and cache templates.
+
+=item There is no grammar.
+
+CET has its own built in recursive grammar system.
+
+=item There is no VIEW directive.
+
+
+=item There are no references.
+
+There were in initial beta tests, but it was decided to remove the little used feature which
+took a length of code to implement.
+
+=item The DEBUG directive is more limited.
+
+It only understands DEBUG_DIRS (8) and DEBUG_UNDEF (2).
+
+=item When debug dirs is on, directives on different lines separated by colons show the line they
 are on rather than a general line range.
 
-There is no ANYCASE configuration item.  There was in initial beta tests, but it
-was dropped in favor of consistent parsing syntax.
+=item There is no ANYCASE configuration item.
+
+There was in initial beta tests, but it was dropped in favor of consistent parsing syntax (and
+a minimal amount of speedup).
 
-There is no V1DOLLAR configuration item.  This is a TT version 1 compatibility item and
-is not available in CET.
+=item There is no V1DOLLAR configuration item.
+
+This is a TT version 1 compatibility item and is not available in CET.
 
 =back
 
@@ -333,7 +453,7 @@ a hashref as the second argument to the process method, or by setting the "VARIA
     ### pass the variables during object creation (will be available to every process call)
     my $cet = CGI::Ex::Template->new(VARIABLES => \%vars);
 
-=head1 GETTING VARIABLES
+=head2 GETTING VARIABLES
 
 Once you have variables defined, they can be used directly in the template by using their name
 in the stash.  Or by using the GET directive.
@@ -351,13 +471,13 @@ Would print when processed:
 To access members of a hashref or an arrayref, you can chain together the names using a ".".
 
     [% some_data.a %]
-    [% my_list.0] [% my_list.1 %]
+    [% my_list.0] [% my_list.1 %] [% my_list.-1 %]
     [% some_data.c.2 %]
 
 Would print:
 
     A
-    20 21
+    20 21 50
     4
 
 If the value of a variable is a code reference, it will be called.  You can add a set of parenthesis
@@ -373,13 +493,13 @@ Would print:
     You passed me ().
     You passed me ().
     You passed me (bar).
-    You passed me (1, 2, 3).
+    You passed me (1.0, 2, 3).
 
 If the value of a variable is an object, methods can be called using the "." operator.
 
     [% cet %]
 
-    [% cet.dump_parse('1 + 2').replace('\s+', ' ') %]
+    [% cet.dump_parse_expr('1 + 2').replace('\s+', ' ') %]
 
 Would print something like:
 
@@ -387,9 +507,11 @@ Would print something like:
 
     $VAR1 = [ \[ '+', '1', '2' ], 0 ];
 
-Each type of data has virtual methods associated with them.  Virtual methods
-allow for access to common functions.  For the full list of built in virtual
-methods, please see the section titled VIRTUAL METHODS
+Each type of data (string, array and hash) have virtual methods
+associated with them.  Virtual methods allow for access to functions
+that are commonly used on those types of data.  For the full list of
+built in virtual methods, please see the section titled VIRTUAL
+METHODS
 
     [% foo.length %]
     [% my_list.size %]
@@ -403,7 +525,7 @@ Would print:
 
 It is also possible to "interpolate" variable names using a "$".  This allows for storing
 the name of a variable inside another variable.  If a variable name is a little
-more complex, it can be embedded inside of "${" and "}".
+more complex it can be embedded inside of "${" and "}".
 
     [% $vname %]
     [% ${vname} %]
@@ -419,6 +541,19 @@ Would print:
     3234
     3234
 
+In CET it is also possible to embed any expression (non-directive) in "${" and "}"
+and it is possible to use non-integers for array access.  (This is not available in TT2)
+
+    [% ['a'..'z'].${ 2.3 } %]
+    [% {ab => 'AB'}.${ 'a' ~ 'b' } %]
+    [% color = qw/Red Blue/; FOR [1..4] ; color.${ loop.index % color.size } ; END %]
+
+Would print:
+
+    c
+    AB
+    RedBlueRedBlue
+
 =head2 SETTING VARIABLES.
 
 To define variables during processing, you can use the = operator.  In most cases
@@ -445,7 +580,7 @@ Would print:
     2
     val1 val2
 
-It is possible to set multiple values at the same time.
+It is possible to set multiple values in the same SET directive.
 
     [% SET a = 'A'
            b = 'B'
@@ -474,10 +609,11 @@ Would print
 
 =head1 LITERALS AND CONSTRUCTORS
 
-The following are the types of literals allowed in CET.  They can be used as arguments
-to functions, in place of variables in directives, and in place of variables in expressions.
-
-In CET it is also possible to call virtual methods on literal values.
+The following are the types of literals (numbers and strings) and
+constructors (hash and array constructs) allowed in CET.  They can be
+used as arguments to functions, in place of variables in directives,
+and in place of variables in expressions.  In CET it is also possible
+to call virtual methods on literal values.
 
 =over 4
 
@@ -488,57 +624,80 @@ In CET it is also possible to call virtual methods on literal values.
     [% pi = 3.14159 %]   Sets the value of the variable.
     [% 3.13159.length %] Prints 7 (the string length of the number)
 
+Scientific notation is supported.
+
+    [% 314159e-5 + 0 %]      Prints 3.14159.
 
-=item Single quoted string.
+    [% .0000001.fmt('%.1e') %]  Prints 1.0e-07
+
+Hexidecimal input is also supported.
+
+    [% 0xff + 0 %]    Prints 255
+
+    [% 48875.fmt('%x') %]  Prints beeb
+
+=item Single quoted strings.
 
 Returns the string.  No variable interpolation happens.
 
     [% 'foobar' %]          Prints "foobar".
-    [% '$foo\n' %]          Prints "$foo\\n".  # the \\n is a literal "\" and a "\n"
+    [% '$foo\n' %]          Prints "$foo\\n".  # the \\n is a literal "\" and an "n"
     [% 'That\'s nice' %]    Prints "That's nice".
     [% str = 'A string' %]  Sets the value of str.
     [% 'A string'.split %]  Splits the string on ' ' and returns the list.
 
 Note: virtual methods can only be used on literal strings in CET, not in TT.
 
-=item Double quoted string.
+=item Double quoted strings.
 
 Returns the string.  Variable interpolation happens.
 
     [% "foobar" %]                   Prints "foobar".
     [% "$foo"   %]                   Prints "bar" (assuming the value of foo is bar).
-    [% "${foo}  %]                   Prints "bar" (assuming the value of foo is bar).
+    [% "${foo}" %]                   Prints "bar" (assuming the value of foo is bar).
     [% "foobar\n" %]                 Prints "foobar\n".  # the \n is a newline.
     [% str = "Hello" %]              Sets the value of str.
     [% "foo".replace('foo','bar') %] Prints "bar".
 
 Note: virtual methods can only be used on literal strings in CET, not in TT.
 
-=item Array Constructor.
+=item Array Constructs.
 
     [% [1, 2, 3] %]               Prints something like ARRAY(0x8309e90).
-    [% [4, 5, 6].size %]          Prints 3.
-    [% [7, 8, 9].reverse.0 %]     Prints 9.
     [% array1 = [1 .. 3] %]       Sets the value of array1.
     [% array2 = [foo, 'a', []] %] Sets the value of array2.
+    [% [4, 5, 6].size %]          Prints 3.
+    [% [7, 8, 9].reverse.0 %]     Prints 9.
+
+Note: virtual methods can only be used on array contructs in CET, not in TT.
+
+=item Quoted Array Constructs.
+
+    [% qw/1 2 3/ %]                Prints something like ARRAY(0x8309e90).
+    [% array1 = qw{Foo Bar Baz} %] Sets the value of array1.
+    [% qw[4 5 6].size %]           Prints 3.
+    [% qw(Red Blue).reverse.0 %]   Prints Blue.
 
-Note: virtual methods can only be used on array contructors in CET, not in TT.
+Note: this works in CET and is planned for TT3.
 
-=item Hash Constructor.
+=item Hash Constructs.
 
     [% {foo => 'bar'} %]                 Prints something like HASH(0x8305880)
+    [% hash = {foo => 'bar', c => {}} %] Sets the value of hash.
     [% {a => 'A', b => 'B'}.size %]      Prints 2.
     [% {'a' => 'A', 'b' => 'B'}.size %]  Prints 2.
-    [% hash = {foo => 'bar', c => {}} %] Sets the value of hash.
+    [% name = "Tom" %]
+    [% {Tom => 'You are Tom',
+        Kay => 'You are Kay'}.$name %]   Prints You are Tom
 
-Note: virtual methods can only be used on hash contructors in CET, not in TT.
+Note: virtual methods can only be used on hash contructs in CET, not in TT.
 
 =head1 EXPRESSIONS
 
-Expressions are one or more variables or literals joined together
+Expressions are one or more variables or literals joined together with
 operators.  An expression can be used anywhere a variable can be used
-with the exception of the variable name of SET, and the filename of
-PROCESS, INCLUDE, WRAPPER, and INSERT.
+with the exception of the variable name in the SET directive, and the
+filename of PROCESS, INCLUDE, WRAPPER, and INSERT.
 
 The following section shows some samples of expressions.  For a full list
 of available operators, please see the section titled OPERATORS.
@@ -563,13 +722,16 @@ the "|" means to always call the virtual method or filter rather than
 looking in the hashref for a key by that name, or trying to call that
 method on the object.  This is similar to how TT3 will function.
 
+Virtual methods are also made available via Virtual Objects which
+are discussed in a later section.
+
 =head2 SCALAR VIRTUAL METHODS AND FILTERS
 
 The following is the list of builtin virtual methods and filters
 that can be called on scalar data types.  In CET and TT3, filters and
-virtual methods are more closely related.  In general anywhere a
-virtual method can be used a filter can be used also - and vice versa
-- all scalar virtual methods can be used as filters.
+virtual methods are more closely related than in TT2.  In general anywhere a
+virtual method can be used a filter can be used also - and likewise all scalar
+virtual methods can be used as filters.
 
 In addition to the filters listed below, CET will automatically load
 Template::Filters and use them if Template::Toolkit is installed.
@@ -578,8 +740,16 @@ In addition to the scalar virtual methods, any scalar will be
 automatically converted to a single item list if a list virtual method
 is called on it.
 
+Scalar virtual methods are also available through the "Text" virtual
+object (except for true filters such as eval and redirect).
+
 =over 4
 
+=item '0'
+
+    [% item = 'foo' %][% item.0 %] Returns self.  Allows for scalars to mask as arrays (scalars
+                                   already will, but this allows for more direct access).
+
 =item chunk
 
     [% item.chunk(60).join("\n") %] Split string up into a list of chunks of text 60 chars wide.
@@ -600,9 +770,13 @@ is called on it.
 
 =item eval
 
-    [% item.eval %] Process the string as though it was a template.  This will start the parsing
-    engine and will use the same configuration as the current process.  CET is several times
-    faster at doing this than TT is and is considered acceptable.
+    [% item.eval %]
+
+Process the string as though it was a template.  This will start the parsing
+engine and will use the same configuration as the current process.  CET is several times
+faster at doing this than TT is and is considered acceptable.
+
+This is a filter and is not available via the Text virtual object.
 
 =item evaltt
 
@@ -612,10 +786,23 @@ is called on it.
 
     Same as the redirect filter.
 
+=item fmt
+
+    [% item.fmt('%d') %]
+    [% item.fmt('%6s') %]
+    [% item.fmt('%*s', 6) %]
+
+Similar to format.  Returns a string formatted with the passed pattern.  Default pattern is %s.
+
 =item format
 
-    [% item.format('%d') %] Print the string out in the specified format.  Each line is
-    processed separately.
+    [% item.format('%d') %]
+    [% item.format('%6s') %]
+    [% item.format('%*s', 6) %]
+
+Print the string out in the specified format.  It is similar to
+the "fmt" virtual method, except that the item is split on newline and each line is
+processed separately.
 
 =item hash
 
@@ -625,6 +812,10 @@ is called on it.
 
     [% item.html %] Performs a very basic html encoding (swaps out &, <, > and " for the html entities)
 
+=item int
+
+    [% item.int %] Return the integer portion of the value (0 if none).
+
 =item lcfirst
 
     [% item.lcfirst %] Capitalize the leading letter.
@@ -633,6 +824,10 @@ is called on it.
 
     [% item.length %] Return the length of the string.
 
+=item list
+
+    [% item.list %] Returns a list with a single value of the item.
+
 =item lower
 
     [% item.lower %] Return a lower-casified string.
@@ -647,14 +842,25 @@ is called on it.
 
     [% item.null %] Do nothing.
 
+=item rand
+
+    [% item = 10; item.rand %] Returns a number greater or equal to 0 but less than 10.
+    [% 1.rand %]
+
+Note: This filter is not available as of TT2.15.
+
 =item remove
 
-    [% item.remove("\s+") %] Same as remove - but is global and replaces with nothing.
+    [% item.remove("\s+") %] Same as replace - but is global and replaces with nothing.
 
 =item redirect
 
-    [% item.redirect("output_file.html") %] - Writes the contents out to the specified file.  The filename
-    must be relative to the OUTPUT_PATH configuration variable and the OUTPUT_PATH variable must be set.
+    [% item.redirect("output_file.html") %]
+
+Writes the contents out to the specified file.  The filename
+must be relative to the OUTPUT_PATH configuration variable and the OUTPUT_PATH variable must be set.
+
+This is a filter and is not available via the Text virtual object.
 
 =item repeat
 
@@ -666,19 +872,19 @@ is called on it.
 
     [% item.replace("\s+", "&nbsp;") %] Globally replace all space with &nbsp;
 
-    [% item.replace("foo", "bar", 0) Replace the first instance of foo with bar.
+    [% item.replace("foo", "bar", 0) %] Replace only the first instance of foo with bar.
 
     [% item.replace("(\w+)", "($1)") %] Surround all words with parenthesis.
 
 =item search
 
-    [% item.search("(\w+)" %] Tests if the given pattern is in the string.
+    [% item.search("(\w+)") %] Tests if the given pattern is in the string.
 
 =item size
 
     [% item.size %] Always returns 1.
 
-=item split    => \&vmethod_split,
+=item split
 
     [% item.split %] Returns an arrayref from the item split on " "
 
@@ -716,12 +922,25 @@ is called on it.
 
 =head2 LIST VIRTUAL METHODS
 
-=over 4
-
 The following methods can be called on an arrayref type data structures (scalar
 types will automatically promote to a single element list and call these methods
 if needed):
 
+Additionally, list virtual methods can be accessed via the List
+Virtual Object.
+
+=over 4
+
+=item fmt
+
+    [% mylist.fmt('%s', ', ') %]
+    [% mylist.fmt('%6s', ', ') %]
+    [% mylist.fmt('%*s', ', ', 6) %]
+
+Passed a pattern and an string to join on.  Returns a string of the values of the list
+formatted with the passed pattern and joined with the passed string.
+Default pattern is %s and the default join string is a space.
+
 =item first
 
     [% mylist.first(3) %]  Returns a list of the first 3 items in the list.
@@ -768,6 +987,13 @@ if needed):
 
     [% mylist.push(23) %] Adds an element to the end of the arrayref (the stash is modified).
 
+=item random
+
+    [% mylist.random %] Returns a random item from the list.
+    [% ['a' .. 'z'].random %]
+
+Note: This filter is not available as of TT2.15.
+
 =item reverse
 
     [% mylist.reverse %] Returns the list in reverse order.
@@ -810,8 +1036,21 @@ if needed):
 
 The following methods can be called on hash type data structures:
 
+Additionally, list virtual methods can be accessed via the Hash
+Virtual Object.
+
 =over 4
 
+=item fmt
+
+    [% myhash.fmt('%s => %s', "\n") %]
+    [% myhash.fmt('%4s => %5s', "\n") %]
+    [% myhash.fmt('%*s => %*s', "\n", 4, 5) %]
+
+Passed a pattern and an string to join on.  Returns a string of the key/value pairs
+of the hash formatted with the passed pattern and joined with the passed string.
+Default pattern is "%s\t%s" and the default join string is a newline.
+
 =item defined
 
     [% myhash.defined('a') %]  Checks if a is defined in the hash.
@@ -837,6 +1076,14 @@ The following methods can be called on hash type data structures:
 
     [% myhash.import(hash2) %]  Overlays the keys of hash2 over the keys of myhash.
 
+=item item
+
+    [% myhash.item(key) %] Returns the hashes value for that key.
+
+=item items
+
+    [% myhash.items %] Returns a list of the key and values (flattened hash)
+
 =item keys
 
     [% myhash.keys.join(', ') %] Returns an arrayref of the keys of the hash.
@@ -868,14 +1115,100 @@ The following methods can be called on hash type data structures:
 
 =back
 
+=head1 VIRTUAL OBJECTS
+
+TT3 has a concept of Text, List, and Hash virtual objects which provide
+direct access to the scalar, list, and hash virtual methods.  In the TT3
+engine this will allow for more concise generated code.  Because CET does
+not generated perl code to be executed later, CET provides for these virtual
+objects but does so as more of a namespace (using the methods does not
+provide a speed optimization in your template - just may help clarify things).
+
+    [% a = "foo"; a.length %] => 3
+
+    [% a = "foo"; Text.length(a) %] => 3
+
+    [% a = Text.new("foo"); a.length %] => 3
+
+
+    [% a = [1 .. 30]; a.size %] => 30
+
+    [% a = [1 .. 30]; List.size(a) %] => 30
+
+    [% a = List.new(1 .. 30); a.size %] => 30
+
+
+    [% a = {a => 1, b => 2}; a.size %] => 2
+
+    [% a = {a => 1, b => 2}; Hash.size(a) %] => 2
+
+    [% a = Hash.new({a => 1, b => 2}); a.size %] => 2
+
+    [% a = Hash.new(a => 1, b => 2); a.size %] => 2
+
+    [% a = Hash.new(a = 1, b = 2); a.size %] => 2
+
+    [% a = Hash.new('a', 1, 'b', 2); a.size %] => 2
+
+One limitation is that if you pass a key named "Text",
+"List", or "Hash" in your variable stash - the corresponding
+virtual object will be hidden.
+
+Additionally, you can use all of the Virtual object methods with
+the pipe operator.
+
+    [% {a => 1, b => 2}
+       | Hash.keys
+       | List.join(", ") %] => a, b
+
+Again, there aren't any speed optimizations to using the virtual
+objects in CET, but it can help clarify the intent in some cases.
+
+Note: these aren't really objects.  All of the "virtual objects" are
+references to the $SCALAR_OPS, $LIST_OPS, and $HASH_OPS hashes
+found in the $VOBJS hash of CGI::Ex::Template.
+
 =head1 DIRECTIVES
 
-This section contains the alphabetical list of DIRECTIVES available
-in the TT language.  DIRECTIVES are the "functions" and control
-structures that implement the Template Toolkit mini-language.  For
-further discussion and examples, please refer to the TT directives
-documentation.
+This section contains the alphabetical list of DIRECTIVES available in
+the TT language.  DIRECTIVES are the "functions" and control
+structures of the Template Toolkit mini-language.  For further
+discussion and examples beyond what is listed below, please refer to
+the TT directives documentation.
+
+    [% IF 1 %]One[% END %]
+    [% FOREACH a = [1 .. 3] %]
+        a = [% a %]
+    [% END %]
+
+    [% SET a = 1 %][% SET a = 2 %][% GET a %]
+
+Multiple directives can be inside the same set of '[%' and '%]' tags
+as long as they are separated by space or semi-colons (;).  Any block
+directive that can also be used as a post-operative directive (such as
+IF, WHILE, FOREACH, UNLESS, FILTER, and WRAPPER) must be separated
+from preceding directives with a semi-colon if it is being used as a
+block directive.  It is more safe to always use a semi-colon.  Note:
+separating by space is only available in CET but is a planned TT3
+feature.
+
+    [% SET a = 1 ; SET a = 2 ; GET a %]
+    [% SET a = 1
+       SET a = 2
+       GET a
+     %]
+
+    [% GET 1
+         IF 0   # is a post-operative
+       GET 2 %] # prints 2
+
+    [% GET 1;
+       IF 0     # it is block based
+         GET 2
+       END
+     %]         # prints 1
 
+The following is the list of directives.
 
 =over 4
 
@@ -1493,7 +1826,7 @@ file).
 
     # The LOAD_PERL directive should be set to 1
     [% USE cet = CGI::Ex::Template %]
-    [%~ cet.dump_parse('2 * 3').replace('\s+', ' ') %]
+    [%~ cet.dump_parse_expr('2 * 3').replace('\s+', ' ') %]
 
 Would print:
 
@@ -1587,7 +1920,7 @@ tighter it binds).
 
 =item C<.>
 
-Binary.  The dot operator.  Allows for accessing sub-members, methods, or
+The dot operator.  Allows for accessing sub-members, methods, or
 virtual methods of nested data structures.
 
     my $obj->process(\$content, {a => {b => [0, {c => [34, 57]}]}}, \$output);
@@ -1605,7 +1938,7 @@ call the vmethod - use "|".
 
 =item C<|>
 
-Binary.  The pipe operator.  Similar to the dot operator.  Allows for
+The pipe operator.  Similar to the dot operator.  Allows for
 explicit calling of virtual methods and filters (filters are "merged"
 with virtual methods in CGI::Ex::Template and TT3) when accessing
 hashrefs and objects.  See the note for the "." operator.
@@ -1648,31 +1981,42 @@ A simple fix is to do any of the following:
 This shouldn't be too much hardship and offers the great return of disambiguating
 virtual method access.
 
+=item C<++ -->
+
+Pre and post increment and decrement.  My be used as either a prefix
+or postfix operator.
+
+    [% ++a %][% ++a %] => 12
+
+    [% a++ %][% a++ %] => 01
+
+    [% --a %][% --a %] => -1-2
+
+    [% a-- %][% a-- %] => 0-1
+
 =item C<**  ^  pow>
 
-Binary.  X raised to the Y power.  This isn't available in TT 2.15.
+Right associative binary.  X raised to the Y power.  This isn't available in TT 2.15.
 
     [% 2 ** 3 %] => 8
 
 =item C<!>
 
-Unary not.  Negation of the value.
+Prefix not.  Negation of the value.
 
-=item C<-  unary_minus>
+=item C<->
 
-Unary minus.  Returns the value multiplied by -1.  The operator
-"unary_minus" is used internally by CGI::Ex::Template to provide for -
-to be listed in the precedence table twice.
+Prefix minus.  Returns the value multiplied by -1.
 
     [% a = 1 ; b = -a ; b %] => -1
 
 =item C<*>
 
-Binary. Multiplication.
+Left associative binary. Multiplication.
 
 =item C</  div  DIV>
 
-Binary. Division.  Note that / is floating point division, but div and
+Left associative binary. Division.  Note that / is floating point division, but div and
 DIV are integer division.
 
    [% 10  /  4 %] => 2.5
@@ -1680,58 +2024,63 @@ DIV are integer division.
 
 =item C<%  mod  MOD>
 
-Binary. Modulus.
+Left associative binary. Modulus.
 
    [% 15 % 8 %] => 7
 
 =item C<+>
 
-Binary.  Addition.
+Left associative binary.  Addition.
 
 =item C<->
 
-Binary.  Minus.
+Left associative binary.  Minus.
 
 =item C<_  ~>
 
-Binary.  String concatenation.
+Left associative binary.  String concatenation.
 
     [% "a" ~ "b" %] => ab
 
 =item C<< <  >  <=  >= >>
 
-Binary.  Numerical comparators.
+Non associative binary.  Numerical comparators.
 
 =item C<lt  gt  le  ge>
 
-Binary.  String comparators.
+Non associative binary.  String comparators.
 
 =item C<==  eq>
 
-Binary.  Equality test.  TT chose to use Perl's eq for both operators.
+Non associative binary.  Equality test.  TT chose to use Perl's eq for both operators.
 There is no test for numeric equality.
 
 =item C<!= ne>
 
-Binary.  Non-equality test.  TT chose to use Perl's ne for both
+Non associative binary.  Non-equality test.  TT chose to use Perl's ne for both
 operators.  There is no test for numeric non-equality.
 
 =item C<&&>
 
-Multiple arity.  And.  All values must be true.  If all values are true, the last
+Left associative binary.  And.  All values must be true.  If all values are true, the last
 value is returned as the truth value.
 
     [% 2 && 3 && 4 %] => 4
 
 =item C<||>
 
-Multiple arity.  Or.  The first true value is returned.
+Right associative binary.  Or.  The first true value is returned.
 
     [% 0 || '' || 7 %] => 7
 
+Note: perl is left associative on this operator - but it doesn't matter because
+|| has its own precedence level.  Setting it to right allows for CET to short
+circuit earlier in the expression optree (left is (((1,2), 3), 4) while right
+is (1, (2, (3, 4))).
+
 =item C<..>
 
-Binary.  Range creator.  Returns an arrayref containing the values
+Non associative binary.  Range creator.  Returns an arrayref containing the values
 between and including the first and last arguments.
 
     [% t = [1 .. 5] %] => variable t contains an array with 1,2,3,4, and 5
@@ -1744,40 +2093,51 @@ The .. operator is the only operator that returns a list of items.
 
 =item C<? :>
 
-Trinary.  Can be nested with other ?: pairs.
+Ternary - right associative.  Can be nested with other ?: pairs.
 
     [% 1 ? 2 : 3 %] => 2
     [% 0 ? 2 : 3 %] => 3
 
+=item C<*= += -= /= **= %= ~=>
+
+Self-modifying assignment - right associative.  Sets the left hand side
+to the operation of the left hand side and right (clear as mud).
+In order to not conflict with SET, FOREACH and other operations, this
+operator is only available in parenthesis.
+
+   [% a = 2 %][%  a += 3  %] --- [% a %]    => --- 5   # is handled by SET
+   [% a = 2 %][% (a += 3) %] --- [% a %]    => 5 --- 5
+
 =item C<=>
 
-Assignment.  Sets the left-hand side to the value of the righthand side.  In order
+Assignment - right associative.  Sets the left-hand side to the value of the righthand side.  In order
 to not conflict with SET, FOREACH and other operations, this operator is only
 available in parenthesis.  Returns the value of the righthand side.
 
-   [% (a = 1) %] --- [% a %] => 1 --- 1
+   [%  a = 1  %] --- [% a %]    => --- 1   # is handled by SET
+   [% (a = 1) %] --- [% a %]    => 1 --- 1
 
 =item C<not  NOT>
 
-Lower precedence version of the '!' operator.
+Prefix. Lower precedence version of the '!' operator.
 
 =item C<and  AND>
 
-Lower precedence version of the '&&' operator.
+Left associative. Lower precedence version of the '&&' operator.
 
 =item C<or OR>
 
-Lower precedence version of the '||' operator.
+Right associative. Lower precedence version of the '||' operator.
 
 =item C<hash>
 
-Multiple arity.  This operator is not used in TT.  It is used internally
+This operator is not used in TT.  It is used internally
 by CGI::Ex::Template to delay the creation of a hash until the
 execution of the compiled template.
 
 =item C<array>
 
-Multiple arity.  This operator is not used in TT.  It is used internally
+This operator is not used in TT.  It is used internally
 by CGI::Ex::Template to delay the creation of an array until the
 execution of the compiled template.
 
@@ -1843,7 +2203,7 @@ Collapse adjacent whitespace to a single space.  The "=" is used to indicate CHO
 
     Hello.
 
-    [%- "Hi." -%]
+    [%= "Hi." =%]
 
     Howdy.
 
@@ -1857,7 +2217,7 @@ Remove all adjacent whitespace.  The "~" is used to indicate CHOMP_GREEDY.
 
     Hello.
 
-    [%- "Hi." -%]
+    [%~ "Hi." ~%]
 
     Howdy.
 
@@ -1936,49 +2296,7 @@ compiled template.  Variables defined here cannot be overridden.
     Will have the value 42 compiled in.
 
 Constants defined in this way can be chained as in [%
-constant.foo.bar.baz %] but may only interpolate values that are set
-before the compile process begins.  This goes one step beyond TT in
-that any variable set in VARIABLES, or PRE_DEFINE, or passed to the
-process method are allowed - they are not in TT.  Variables defined in
-the template are not available during the compile process.
-
-    GOOD:
-
-    CONSTANTS => {
-        foo  => {
-            bar => {baz => 42},
-            bim => 57,
-        },
-        bing => 'baz',
-        bang => 'bim',
-    },
-    VARIABLES => {
-        bam  => 'bar',
-    },
-
-    In the template
-
-    [% constants.foo.${constants.bang} %]
-
-    Will correctly print 57.
-
-    GOOD (non-tt behavior)
-
-    [% constants.foo.$bam.${constants.bing} %]
-
-    CGI::Ex::Template will print 42 because the value of bam is
-    known at compile time.  TT would print '' because the value of $bam
-    is not yet defined in the TT engine.
-
-    BAD:
-
-    In the template:
-
-    [% bam = 'somethingelse' %]
-    [% constants.foo.$bam.${constants.bing} %]
-
-    Will still print 42 because the value of bam used comes from
-    variables defined before the template was compiled.  TT will still print ''.
+constant.foo.bar.baz %].
 
 =item CONSTANT_NAMESPACE
 
@@ -1987,9 +2305,9 @@ value is 'constants'.
 
 =item DEBUG
 
-    Takes a list of constants |'ed together which enables different
-    debugging modes.  Alternately the lowercase names may be used (multiple
-    values joined by a ",".
+Takes a list of constants |'ed together which enables different
+debugging modes.  Alternately the lowercase names may be used
+(multiple values joined by a ",").
 
     The only supported TT values are:
     DEBUG_UNDEF (2)    - debug when an undefined value is used.
@@ -2010,7 +2328,7 @@ directive.
 
 =item DEFAULT
 
-The name of a default template file to use if the passed on is not found.
+The name of a default template file to use if the passed one is not found.
 
 =item DELIMITER
 
@@ -2040,9 +2358,9 @@ Allow for passing in TT style filters.
 
     my $str = q{
         [% a = "Hello" %]
-        1([% a | filter1 %])
-        2([% a | filter2 %])
-        3([% a | filter3 %])
+        1 ([% a | filter1 %])
+        2 ([% a | filter2 %])
+        3 ([% a | filter3 %])
     };
 
     my $obj = CGI::Ex::Template->new(FILTERS => $filters);
@@ -2050,9 +2368,9 @@ Allow for passing in TT style filters.
 
 Would print:
 
-        (11111)
-        (22222)
-        (33333)
+        (11111)
+        (22222)
+        (33333)
 
 Filters passed in as an arrayref should contain a coderef and a value
 indicating if they are dynamic or static (true meaning dynamic).  The
@@ -2132,7 +2450,8 @@ See the USE directive for more information.
 
 Default value is Template::Plugin.  The base module namespace
 that template plugins will be looked for.  See the USE directive
-for more information.
+for more information.  May be either a single namespace, or an arrayref
+of namespaces.
 
 =item POST_CHOMP
 
@@ -2197,7 +2516,7 @@ been executed.
 =item UNDEFINED_ANY
 
 This is not a TT configuration option.  This option expects to be a code
-ref that will be called if a variable is undefined during a call to get_variable.
+ref that will be called if a variable is undefined during a call to play_expr.
 It is passed the variable identity array as a single argument.  This
 is most similar to the "undefined" method of Template::Stash.  It allows
 for the "auto-defining" of a variable for use in the template.  It is
@@ -2274,7 +2593,7 @@ Template::Toolkit or the appropriate plugin module.
 CGI::Ex::Template uses its own mechanism for loading filters.  TT
 would use the Template::Filters object to load filters requested via the
 FILTER directive.  The functionality for doing this in CGI::Ex::Template
-is contained in the list_filters method and the get_variable method.
+is contained in the list_filters method and the play_expr method.
 
 Full support is offered for the FILTERS configuration item.
 
@@ -2325,7 +2644,7 @@ name level.  Operators are parsed and stored as part of the variable (it
 may be more appropriate to say we are parsing a term or an expression).
 
 The following table shows a variable or expression and the corresponding parsed tree
-(this is what the parse_variable method would return).
+(this is what the parse_expr method would return).
 
     one                [ 'one',  0 ]
     one()              [ 'one',  [] ]
@@ -2368,12 +2687,12 @@ Some notes on the parsing.
 
 The following perl can be typed at the command line to view the parsed variable tree:
 
-    perl -e 'use CGI::Ex::Template; print CGI::Ex::Template::dump_parse("foo.bar + 2")."\n"'
+    perl -e 'use CGI::Ex::Template; print CGI::Ex::Template::dump_parse_expr("foo.bar + 2")."\n"'
 
 Also the following can be included in a template to view the output in a template:
 
     [% USE cet = CGI::Ex::Template %]
-    [%~ cet.dump_parse('foo.bar + 2').replace('\s+', ' ') %]
+    [%~ cet.dump_parse_expr('foo.bar + 2').replace('\s+', ' ') %]
 
 
 =head1 SEMI PUBLIC METHODS
@@ -2385,6 +2704,10 @@ may be re-implemented by subclasses of CET.
 
 =item C<dump_parse>
 
+This method allows for returning a Data::Dumper dump of a parsed template.  It is mainly used for testing.
+
+=item C<dump_parse_expr>
+
 This method allows for returning a Data::Dumper dump of a parsed variable.  It is mainly used for testing.
 
 =item C<exception>
@@ -2396,7 +2719,7 @@ $CGI::Ex::Template::PACKAGE_EXCEPTION.
 
 Executes a parsed tree (returned from parse_tree)
 
-=item C<get_variable>
+=item C<play_expr>
 
 Turns a variable identity array into the parsed variable.  This
 method is also responsible for playing operators and running virtual methods
@@ -2434,14 +2757,14 @@ hash that contains the parsed tree.
 Allow for the multitudinous ways that TT parses arguments.  This allows
 for positional as well as named arguments.  Named arguments can be separated with a "=" or "=>",
 and positional arguments should be separated by " " or ",".  This only returns an array
-of parsed variables.  Use vivify_args to translate to the actual values.
+of parsed variables.   To get the actual values, you must call play_expr on each value.
 
 =item C<parse_tree>
 
 Used by load_parsed_tree.  This is the main grammar engine of the program.  It
 uses method in the $DIRECTIVES hashref to parse different DIRECTIVE TYPES.
 
-=item C<parse_variable>
+=item C<parse_expr>
 
 Used to parse a variable, an expression, a literal string, or a number.  It
 returns a parsed variable tree.  Samples of parsed variables can be found in the VARIABLE PARSE TREE
@@ -2458,7 +2781,7 @@ Creates an exception object from the arguments and dies.
 
 =item C<undefined_any>
 
-Called during get_variable if a value is returned that is undefined.  This could
+Called during play_expr if a value is returned that is undefined.  This could
 be used to magically create variables on the fly.  This is similar to Template::Stash::undefined.
 It is suggested that undefined_get be used instead.  Default behavior returns undef.  You
 may also pass a coderef via the UNDEFINED_ANY configuration variable.  Also, you can try using
@@ -2470,11 +2793,6 @@ Called when a variable is undefined during a GET directive.  This is useful to
 see if a value that is about to get inserted into the text is undefined.  undefined_any is a little
 too general for most cases.  Also, you may pass a coderef via the UNDEFINED_GET configuration variable.
 
-=item C<vivify_args>
-
-Turns an arrayref of arg identities parsed by parse_args and turns
-them into the actual values.
-
 =back
 
 
@@ -2495,7 +2813,7 @@ upon operator precedence.
 Used to create a "pseudo" context object that allows for portability
 of TT plugins, filters, and perl blocks that need a context object.
 
-=ITEM C<DEBUG>
+=item C<DEBUG>
 
 TT2 Holdover that is used once for binmode setting during a TT2 test.
 
@@ -2548,11 +2866,6 @@ by the pseudo context object and may disappear at some point.
 
 Methods by these names implement virtual methods that are more than one line.
 
-=item C<weak_copy>
-
-Used to create a weak reference to self to avoid circular references. (this
-is needed by macros)
-
 =back
 
 
This page took 0.059246 seconds and 4 git commands to generate.