| Hash.keys
| List.join(", ") %] # = a, b
-=item Added "as" scalar, list, and hash virtual methods.
+=item Added "fmt" scalar, list, and hash virtual methods.
- [% list.as("%s", ", ") %]
+ [% list.fmt("%s", ", ") %]
- [% hash.as("%s => %s", "\n") %]
+ [% hash.fmt("%s => %s", "\n") %]
=item Whitespace is less meaningful. (TT3)
[% a = 1.2e-20 %]
- [% 123.as('%.3e') %] # = 1.230e+02
+ [% 123.fmt('%.3e') %] # = 1.230e+02
=item Allow for hexidecimal input. (TT3)
[% a = 0xff0000 %][% a %] # = 16711680
- [% a = 0xff2 / 0xd; a.as('%x') %] # = 13a
+ [% a = 0xff2 / 0xd; a.fmt('%x') %] # = 13a
=item FOREACH variables can be nested.
=item There are no references.
-There was in initial beta tests, but it was decided to remove the little used feature.
-
-It makes it the same as
-
- [% obj.method("foo") %]
-
-This is removed in CET.
+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.
=item There is no ANYCASE configuration item.
-There was in initial beta tests, but it was dropped in favor of consistent parsing syntax.
+There was in initial beta tests, but it was dropped in favor of consistent parsing syntax (and
+a minimal amount of speedup).
=item There is no V1DOLLAR configuration item.
[% cet %]
- [% cet.dump_parse('1 + 2').replace('\s+', ' ') %]
+ [% cet.dump_parse_expr('1 + 2').replace('\s+', ' ') %]
Would print something like:
[% 314159e-5 + 0 %] Prints 3.14159.
- [% .0000001.as('%.1e') %] Prints 1.0e-07
+ [% .0000001.fmt('%.1e') %] Prints 1.0e-07
Hexidecimal input is also supported.
[% 0xff + 0 %] Prints 255
- [% 48875.as('%x') %] Prints beeb
+ [% 48875.fmt('%x') %] Prints beeb
=item Single quoted strings.
=item '0'
- [% item = 'foo' %][% item.0 %] Returns self. Allows for scalars to mask as arrays.
-
-=item as
-
- [% item.as('%d') %]
-
-Similar to format. Returns a string formatted with the passed pattern. Default pattern is %s.
+ [% 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
Same as the redirect filter.
+=item fmt
+
+ [% item.fmt('%d') %]
+
+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
+ [% item.format('%d') %] 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
=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.replace("\s+", " ") %] Globally replace all space with
- [% item.replace("foo", "bar", 0) Replace only 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
=over 4
-=item as
+=item fmt
- [% mylist.as('%s', ', ') %]
+ [% mylist.fmt('%s', ', ') %]
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.
=over 4
-=item as
+=item fmt
- [% myhash.as('%s => %s', "\n") %]
+ [% myhash.fmt('%s => %s', "\n") %]
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.
# 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:
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 was handled by SET
+ [% a = 2 %][% a += 3 %] --- [% a %] => --- 5 # is handled by SET
[% a = 2 %][% (a += 3) %] --- [% a %] => 5 --- 5
=item C<=>
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 # is was handled by SET
+ [% a = 1 %] --- [% a %] => --- 1 # is handled by SET
[% (a = 1) %] --- [% a %] => 1 --- 1
=item C<not NOT>
Hello.
- [%- "Hi." -%]
+ [%= "Hi." =%]
Howdy.
Hello.
- [%- "Hi." -%]
+ [%~ "Hi." ~%]
Howdy.
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);
Would print:
- (11111)
- (22222)
- (33333)
+ 1 (11111)
+ 2 (22222)
+ 3 (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
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
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
=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>
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