Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

*** empty log message ***

git-svn-id: svn://svn.tt2.org/tt/Template2/trunk@43 d5a88997-0a34-4036-9ed2-92fb5d660d91
  • Loading branch information...
commit d52480d182cf4a9f50d5eaef1a8ace2c37b91886 1 parent 0b63aae
@abw authored
View
50 Changes
@@ -17,25 +17,16 @@
#========================================================================
#------------------------------------------------------------------------
-# Version 2.00 beta 4
+# Version 2.00 beta 4 12th September 2000
#------------------------------------------------------------------------
-* Added the PROCESS option which allows a template or templates to be
- specified which is/are processed instead of the template passed as
- an argument to the Template process() method. The original template
- is available as the 'template' variable and can be processed by
- calling INCLUDE or PROCESS as [% INCLUDE $template %].
+* Added the PROCESS config option which allows a template or templates
+ to be specified which is/are processed instead of the template
+ passed as an argument to the Template process() method. The
+ original template is available as the 'template' variable and can be
+ processed by calling INCLUDE or PROCESS as [% INCLUDE $template %].
-* Added the reference operator, '\' which allows a "reference" to
- another variable to be taken. The implementation creates a closure
- around the referenced variable which, when called, will return the
- actual variable value. It is really a form of lazy evaluation, rather
- than genuine reference taking, but it looks and smells almost the same.
- Primarily, it is useful for allowing sub-routine references to be
- passed to another sub-routine. See t/refs.t for examples until
- documentation arrives.
-
-* Changed what was the CASE option to now be enabled by default and
+* Changed what was the CASE option to now be enabled by default, and
then changed the name of the option to ANYCASE to make it more
obvious as to what it did. You must now specify directive keywords
(INCLUDE, FOREACH, IF, etc) in UPPER CASE only, or enable the
@@ -60,8 +51,8 @@
[% END %] $output;
[% END %]
-* The IMPORT directive and magical IMPORT variable have been removed
- and replaced with a general purpose virtual hash method, import().
+* The IMPORT directive and magical IMPORT variable have been replaced
+ with a general purpose virtual hash method, import().
[% hash1.import(hash2) %] # was "hash1.IMPORT = hash2"
[% import(hash1) %] # was "IMPORT hash1" or "IMPORT = hash1"
@@ -79,6 +70,12 @@
[% data.sort.join(', ') %] # 1, 10, 11, 5
[% data.nsort.join(', ') %] # 1, 5, 10, 11
+* Added 'div' operator to provider integer division (e.g. 'a div b' =>
+ 'int(a / b)' and 'mod' which is identical to '%' but added for backwards
+ compatibility with V1.
+
+* Changed the (undocumented) FORNEXT directive to NEXT and documented it.
+
* Fixed a bug in the persistant caching mechanism in Template::Provider
which was failing to write compiled template files for source templates
specifed in the form [% INCLUDE foo/bar %]. Intermediate directories
@@ -92,12 +89,29 @@
exceptions to be raised. Thanks to Jonas Liljegren for reporting the
problems.
+* Added the reference operator, '\' which allows a "reference" to
+ another variable to be taken. The implementation creates a closure
+ around the referenced variable which, when called, will return the
+ actual variable value. It is really a form of lazy evaluation, rather
+ than genuine reference taking, but it looks and smells almost the same.
+ Primarily, it is useful for allowing sub-routine references to be
+ passed to another sub-routine. This is currently undocumented
+ because I'm not sure about the validity of adding it, but See t/refs.t
+ for examples for now.
+
* Changed parser to automatically unescape any escaped characters in
double quoted strings except for \n and \$. This permits strings to
be constructed that include tag characters. e.g.
[% directive = "[\% INSERT thing %\]" %]
+* Fixed a bug in the use of the 'component' variable when the current
+ component is a sub-routine rather than a Template::Document.
+
+* Added the '--define var=val' option to tpage to allow template
+ variables to be defined from the command line. Added support to
+ ttree for various new Template configuration options.
+
* Added $Template::Test::PRESERVE package variable which can be set to
prevent newlines in test output from being automatically mangled to
literal '\n'.
View
1  MANIFEST
@@ -43,7 +43,6 @@ lib/Template/Plugins.pm
lib/Template/Plugins.pod
lib/Template/Provider.pm
lib/Template/Provider.pod
-lib/Template/README
lib/Template/Service.pm
lib/Template/Service.pod
lib/Template/Stash.pm
View
28 Makefile.PL
@@ -5,10 +5,13 @@ $| = 1;
select STDOUT;
warn(<<EOF);
- Template Toolkit Version 2.00 beta 3
+
+ Template Toolkit Version 2.00 beta 4
------------------------------------
- This is stable beta code. Please read the README and Changes files.
+ This is stable beta code and a release candidate for Version 2.00
+ proper. Please read the README file and consult the Changes and
+ TODO files for further information.
EOF
@@ -24,24 +27,19 @@ unless ($@) {
If you install these modules you will totally screw up your
Version $Template::VERSION installation. If you're ready to take
the plunge and aren't relying too heavily on any of the "features"
- that have changed from version 1.xx to 2.xx (see Changes file),
- then go ahead. Be bold. See the Changes file for a summary of
- all the great new things for you to play with, and the issues that
- you might need to attend to.
+ that have changed from version 1.xx to 2.xx then go ahead, be
+ bold. The Changes file contains details of visible changes from
+ versions 1.xx and 2.xx beta releases and highlights some issues
+ that you you might need to attend to. The TODO file contains
+ details of the (very few) known bugs, problems, limitations, etc.
- You might then decide to re-install Version $Template::VERSION to a different
- location in case you ever need it, e.g.
+ If you want to install the Template Toolkit to an alternate
+ directory when you can do it like this:
perl Makefile.PL PREFIX=/some/where/else
Remember to add "use lib '/some/where/else'" to your Perl scripts
- that want to use Version 1.07, and also to the V1 'tpage' and
- 'ttree' scripts (in /some/where/else/bin) so that they continue to
- use the right versions of the modules.
-
- Alternatively, you can install this Version 2.00 beta to a
- different location and follow the strategy outlined above, or not
- "make install" it at all.
+ so that they can find and load the relevant modules.
EOF
}
View
82 README
@@ -1,66 +1,44 @@
- Template Toolkit Version 2.00 Beta Release 3
+ Template Toolkit Version 2.00 Beta Release 4
- 10-August-2000
+ 12th September 2000
- ** IMPORTANT WARNING FOR VERSION 1.xx USERS **
+This is the fourth (and almost certainly, final) beta release of
+Version 2.00 of the Perl Template Toolkit. It is fully-featured,
+reliable and all known bugs have been fixed (but see the TODO list for
+a few outstanding issues and minor "features"). The Changes file
+details changes from the last beta release, and versions before that.
+It also includes the major changes from Version 1.xx to 2.00.
- If you install these modules you will totally screw up your
- existing version 1.* installation (if you have one, that is). If
- you're ready to take the plunge and aren't relying too heavily on
- any of the "features" that have changed from version 1.xx to 2.xx
- (see Changes file), then go ahead. Be bold. See the Changes file
- for a summary of all the great new things for you to play with,
- and the issues that you might need to attend to.
+Installation is as you might expect:
- You might then decide to re-install Version 1.07 to a different
- location in case you ever need it, e.g.
+ perl Makefile.PL
+ make
+ make test
+ make install
- perl Makefile.PL PREFIX=/some/where/else
+If you have version 1.xx installed then be warned that version 2.00
+will render it totally useless. This probably isn't an issue unless
+you're relying heavily on any of the more obscure "features" that have
+changed from version 1.xx to 2.00 (see Changes file).
- Remember to add "use lib '/some/where/else'" to your Perl scripts
- that want to use Version 1.07, and also to the V1 'tpage' and
- 'ttree' scripts (in /some/where/else/bin) so that they continue to
- use the right versions of the modules.
+You can specify the PREFIX option to install the Template Toolkit to a
+different location if you want to preserve an existing installation
+(see ExtUtils::MakeMaker). Or preferably, install version 2.00 as per
+usual and then go back and install version 1.07 to an alternate
+location, thus ensuring that version 2.00 is the default.
- Alternatively, you can install this Version 2.00 beta to a
- different location and follow the strategy outlined above, or not
- "make install" it at all.
+ perl Makefile.PL PREFIX=/some/where/else
+ make, etc.
- ** END OF IMPORTANT WARNING **
+The documentation is now complete in all its 100+ page glory.
-Hello World
------------
+ perldoc Template
-This is the third (and possibly final) beta release of Version 2.00 of
-the Perl Template Toolkit. It is fully-featured, reliable and all
-known bugs have been fixed (but see the TODO list for a few
-outstanding issues and minor "features"). The Changes file details
-changes from the last beta release, and versions before that. It also
-includes the major changes from Version 1.xx to 2.00.
+Any errors, inaccuracies or omissions are bugs and should be reported
+to the overworked and underpaid author who really needs to take a
+vacation. 8-)
-The API is now frozen for Version 2.00. The final remaining effort
-was to improve the filters interface and this is now up to scratch with
-the rest of the toolkit and suitable for release.
-
-Most, if not all of the individual modules are fully documented and
-reasonably accurate and complete. I need to do one final sweep to
-tidy up some loose ends, but on the whole they're pretty much there.
-
-The main Template.pod document is complete or very nearly complete in
-all the important areas. Configuration options are fully documented
-and all but a few of the directives are documented, although with a
-handful of TODO's littered around marking sections that are incomplete
-or in need of work. We're still missing a general overview and possibly
-a few other meta-sections. The documentation should probably be broken
-up into smaller sections and converted to HTML for those that want it
-that way. That may happen before, or possibly after the release of
-Version 2.00
-
-Enjoy!
+Enjoy
A
-
-
-
-
View
79 TODO
@@ -1,35 +1,53 @@
#------------------------------------------------------------------------
-# KNOWN BUGS AND/OR LIMITATIONS
+# PENDING TODO ITEMS
#------------------------------------------------------------------------
-* Template::Hacking / Template::Internals, etc.
+* URL plugin may be incorrect in not escaping certain characters such as
+ '&'.
-* TPC4 paper
+* XML::Simple plugin (I wrote this once already but my laptop died and
+ took it with it). An XML::XPath plugin would also be nice. Both are
+ trivial, although XML::Simple should use a singleton parser object,
+ instantiated via load() which can then cache parsed documents if
+ required. new() would then be used to parse a file/text and return
+ the data tree. There may be cleanup issues. Haven't looked at writing
+ an XML::XPath plugin yet, but it should be reasonably similar.
-* NEXT
+* XML::DOM plugin may leak memory due to it not properly cleaning up
+ the data model which has massively circular references. Simon
+ Matthews <sam@knowledgepool.com> has fixed this problem and also
+ added a wonderfully powerful to_template() method. Will integrate
+ his changes before V2 proper.
-* XML::Simple plugin
+* DBI plugin, also by Simon Matthews, will be distributed with V2.
+ Makefile.PL will need some hacking to incorporate DBI testing options.
-* test IMPORT and import options
+* Document the TT internals and describe how, where and why to hack on
+ them.
-* fix div (integer division) and mod
+* The documentation should be broken up into smaller chunks (or
+ published as a book!). An HTML/XML version will also be forthcoming.
+
+#------------------------------------------------------------------------
+# KNOWN BUGS AND/OR LIMITATIONS
+#------------------------------------------------------------------------
* empty hashes can cause a harmless, but possibly annoying parser error.
* Template process($file) method returns a string if the named
template ($file) can't be found, rather than an exception. This
- should be changed so that an exception is returned whatever?
-
-* It's currently not possible to catch a 'perl' exception because 'PERL'
- is a reserved word. You need to enable the CASE option to be able to
- make a distinction between them. THROW and CATCH should accept quoted
- exception names to prevent these kind of issues.
+ should be changed so that an exception is returned whatever. The
+ fix is fairly simple, but requires a careful examination of the code
+ as there may be many places in which this happens.
* Filters and plugins cache may bloat. Perhaps reset() should accept
- flags to clear BLOCKS, PLUGINS, FILTERS, etc. I need to check this.
+ flags to clear BLOCKS, PLUGINS, FILTERS, etc? I need to check this.
-* The 'ttree' script doesn't yet have knowledge of all the new
- configuration items.
+* If you use 'ttree' with a COMPILE_EXT or COMPILE_DIR option then
+ templates in the 'lib' directories will be compiled, but those in
+ the src directories will not. This is because ttree does a chdir()
+ to the src directory and processes files as './myfile'. TT doesn't
+ compile RELATIVE files by default.
* There's no easy way to run version 1 and version 2 on the same
machine. If you're happy to junk version 1 then no problem, go
@@ -43,15 +61,18 @@
use lib qw( /home/abw/tt1 );
- I've been playing around with moving version 1 modules into
- Template::v1::* to allow them to co-exist. I think this is nearly
- ready to roll out, but it still needs some polish and it's lowish
- priority at the moment.
+ I was planning on moving version 1 modules into Template::v1::* to
+ allow them to co-exist but I think this will prove to be more trouble
+ than it's worth.
* Note that no recursion checking is performed for BLOCKs, only
Template::Document instances. This is probably the way it will stay
(unless anyone shouts loudly enough) but it should be documented
- anyway.
+ anyway. STOP PRESS: I had an idea that bare BLOCK subs should
+ be blessed into Template::Document class to allow $template->process()
+ to be called regardless. Template::Document methods would need to
+ test $self for CODE/HASH and Do The Right Thing. This would then
+ allow recursion testing for BLOCKs as well as Template::Document objects.
* I've had a few reports of tests failing (provider.t test 37 and several
in args.t) but haven't been able to reproduce them. If you do get
@@ -60,27 +81,13 @@
send me the output, along with any other relevant information. If you're
able to track down the problem then so much the better. The test suite
is well organised and fairly pleasant to work with these days so please
- don't be afraid to go digging for answers.
+ don't be afraid to go digging for answers (this means you, Perrin :-)
* The XML::RSS plugin test may generate warnings (but passes all tests)
under Perl 5.6
#------------------------------------------------------------------------
-# PENDING ITEMS ON THE 'TO-DO' LIST
-#------------------------------------------------------------------------
-
-* document DEBUG option (or think of a better name)
-
-* test and document 'component' variable
-
-* fix _private and .private tests in t/object.t
-
-* 'tpage' could do with a '--define var=value' variable and possibly
- others.
-
-
-#------------------------------------------------------------------------
# POSSIBLE FUTURE ENHANCEMENTS
#------------------------------------------------------------------------
View
22 bin/tpage
@@ -31,6 +31,16 @@ if (grep /^--?h(elp)?/, @ARGV) {
print "usage: tpage file [ file [...] ]\n";
exit 0;
}
+my $vars = { };
+my ($var, $val);
+
+while ($ARGV[0] && $ARGV[0] =~ /--?d(efine)?/) {
+ shift(@ARGV);
+ die "--define expect a 'variable=value' argument\n"
+ unless defined ($var = shift(@ARGV));
+ ($var, $val) = split(/\s*=\s*/, $var, 2);
+ $vars->{ $var } = $val;
+}
# read from STDIN if no files specified
push(@ARGV, '-') unless @ARGV;
@@ -44,7 +54,7 @@ my $template = Template->new({
# process each input file
foreach my $file (@ARGV) {
$file = \*STDIN if $file eq '-';
- $template->process($file)
+ $template->process($file, $vars)
|| die $template->error();
}
@@ -58,22 +68,26 @@ tpage - processes template documents using the Perl Template Toolkit.
=head1 USAGE
- tpage file [ file [...] ]
+ tpage [ --define var=value ] file(s)
=head1 DESCRIPTION
The B<tpage> script is a simple wrapper around the Template Toolkit processor.
Files specified by name on the command line are processed in turn by the
template processor and the resulting output is sent to STDOUT and can be
-redirected accordingly.
+redirected accordingly. e.g.
-e.g.
tpage myfile > myfile.out
tpage header myfile footer > myfile.html
If no file names are specified on the command line then B<tpage> will read
STDIN for input.
+The --define option can be used to set the values of template variables.
+e.g.
+
+ tpage --define author="Andy Wardley" skeleton.pm > MyModule.pm
+
See L<Template> for general information about the Perl Template
Toolkit and the template language and features.
View
39 bin/ttree
@@ -27,7 +27,6 @@
#
#========================================================================
-use lib qw( /home/abw/templates/src/Template2/lib );
use strict;
use Template;
use AppConfig qw( :expand );
@@ -83,8 +82,12 @@ my %ttopts = $config->varlist('^template_', 1);
my %ucttopts;
@ucttopts{ map { uc } keys %ttopts } = values %ttopts;
+#print "TT config: ", join(', ', map { "$_ => $ucttopts{ $_ }"}
+# keys %ucttopts), "\n";
+
# get all template variable definitions
my $replace = $config->get('define');
+
#print "replace hash: ", join(', ', map { "$_ => $replace->{ $_ }"}
# keys %$replace), "\n";
@@ -94,18 +97,8 @@ my $ttopts = {
RELATIVE => 1,
INCLUDE_PATH => [ @$libdir, '.' ],
OUTPUT_PATH => $destdir,
-# ERROR => \&error,
};
-
-sub error {
- my $error = join('', @_);
- chomp $error;
- print STDERR " ! $error\n";
-}
-$SIG{__WARN__} = \&error;
-
-
#------------------------------------------------------------------------
# pre-amble
#------------------------------------------------------------------------
@@ -324,7 +317,7 @@ sub read_config {
'ignore=s@',
'copy=s@',
'accept=s@',
- 'template_case|case',
+ 'template_anycase|anycase',
'template_eval_perl|eval_perl',
'template_load_perl|load_perl',
'template_interpolate|interpolate',
@@ -333,9 +326,14 @@ sub read_config {
'template_trim|trim',
'template_pre_process|pre_process|preprocess=s',
'template_post_process|post_process|postprocess=s',
+ 'template_process|process=s',
+ 'template_default|default=s',
+ 'template_error|error=s',
'template_start_tag|start_tag|starttag=s',
'template_end_tag|end_tag|endtag=s',
'template_tag_style|tag_style|tagstyle=s',
+ 'template_compile_ext|compile_ext=s',
+ 'template_compile_dir|compile_dir=s',
'template_plugin_base|plugin_base|pluginbase=s@',
'perl5lib|perllib=s@'
);
@@ -488,18 +486,23 @@ File search specifications (all may appear multiple times):
Additional options to set Template Toolkit configuration items:
--define var=value Define template variable
--interpolate Interpolate '\$var' references in text
- --case Case sensitivity of reserved words
- --eval_perl Evaluate [% PERL %] ... [% END %] code blocks
- --load_perl Load regular Perl modules via USE directive
+ --anycase Accept directive keywords in any case.
--pre_chomp Chomp leading whitespace
--post_chomp Chomp trailing whitespace
--trim Trim blank lines around template blocks
- --pre_process=TEMPLATE Use TEMPLATE as header
- --post_process=TEMPLATE Use TEMPLATE as footer
+ --eval_perl Evaluate [% PERL %] ... [% END %] code blocks
+ --load_perl Load regular Perl modules via USE directive
+ --pre_process=TEMPLATE Add TEMPLATE as header for each file
+ --post_process=TEMPLATE Add TEMPLATE as footer for each file
+ --process=TEMPLATE Use TEMPLATE as wrapper around each file
+ --default=TEMPLATE Use TEMPLATE as default
+ --error=TEMPLATE Use TEMPLATE to handle errors
--start_tag=STRING STRING defines start of directive tag
--end_tag=STRING STRING defined end of directive tag
--tag_style=STYLE Use pre-defined tag STYLE
--plugin_base=PACKAGE Base PACKAGE for plugins
+ --compile_ext=STRING File extension for compiled template files
+ --compile_dir=DIR Directory for compiled template files
--perl5lib=DIR Specify additional Perl library directories
See 'perldoc ttree' for further information. Note that earlier versions
@@ -511,6 +514,8 @@ END_OF_HELP
exit(0);
}
+
+
__END__
#------------------------------------------------------------------------
View
2  lib/Template.pm
@@ -39,7 +39,7 @@ use File::Path;
## This is the main version number for the Template Toolkit.
## It is extracted by ExtUtils::MakeMaker and inserted in various places.
-$VERSION = '2.00-beta3';
+$VERSION = '2.00-beta4';
$ERROR = '';
$DEBUG = 0;
View
10 lib/Template/Context.pm
@@ -205,6 +205,7 @@ sub filter {
sub process {
my ($self, $template, $params) = @_;
my ($blocks, $output);
+ my $name = $template;
# request compiled template from cache
$template = $self->template($template)
@@ -219,7 +220,9 @@ sub process {
# update stash with any new parameters passed
$params ||= { };
- $params->{ component } = $template;
+ $params->{ component } = ref $template eq 'CODE'
+ ? { ref $name ? () : (name => $name, modtime => time()) }
+ : $template;
$self->{ STASH }->update($params);
# if $params;
@@ -262,6 +265,7 @@ sub include {
my ($self, $template, $params) = @_;
my ($error, $blocks);
my $output = '';
+ my $name = $template;
# request compiled template from cache
$template = $self->template($template)
@@ -270,7 +274,9 @@ sub include {
# localise the variable stash with any parameters passed
$params ||= { };
- $params->{ component } = $template;
+ $params->{ component } = ref $template eq 'CODE'
+ ? { ref $name ? () : (name => $name, modtime => time()) }
+ : $template;
$self->{ STASH } = $self->{ STASH }->clone($params);
eval {
View
4 lib/Template/Directive.pm
@@ -370,7 +370,9 @@ sub foreach {
}
else {
$loop_save = '$stash = $context->localise()';
- $loop_set = "\$stash->set('IMPORT', \$value) "
+# $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()';
}
View
4 lib/Template/Document.pm
@@ -238,6 +238,10 @@ sub write_perl_file {
};
print CFH <<EOF;
+#------------------------------------------------------------------------
+# Compiled template generated by the Template Toolkit version $Template::VERSION
+#------------------------------------------------------------------------
+
bless {
$metadata
_HOT => 0,
View
3,421 lib/Template/Grammar.pm
1,771 additions, 1,650 deletions not shown
View
4 lib/Template/Service.pm
@@ -56,6 +56,7 @@ sub process {
my ($self, $template, $params) = @_;
my $context = $self->{ CONTEXT };
my ($name, $output, $procout, $error);
+ $output = '';
$context->reset()
if $self->{ AUTO_RESET };
@@ -91,7 +92,7 @@ sub process {
last SERVICE
unless defined ($procout = $self->_recover(\$error));
}
- $output .= $procout;
+ $output .= $procout if defined $procout;
# POST_PROCESS
eval {
@@ -136,6 +137,7 @@ sub _init {
# by splitting on non-word characters
foreach $item (qw( PRE_PROCESS PROCESS POST_PROCESS )) {
$data = $config->{ $item };
+ next unless defined $data;
$data = [ split(/\W+/, $data || '') ]
unless ref $data eq 'ARRAY';
$self->{ $item } = $data;
View
2  lib/Template/Stash.pm
@@ -486,7 +486,7 @@ sub _assign {
unless $root and defined $item and $item !~ /^[\._]/;
if ($rootref eq 'HASH' || $rootref eq __PACKAGE__) {
-# if ($item eq 'import' && UNIVERSAL::isa($value, 'HASH')) {
+# if ($item eq 'IMPORT' && UNIVERSAL::isa($value, 'HASH')) {
# # import hash entries into root hash
# @$root{ keys %$value } = values %$value;
# return ''; ## RETURN
View
10 parser/Grammar.pm.skel
@@ -49,8 +49,8 @@ my ($factory, $rawstart);
@RESERVED = qw(
GET CALL SET DEFAULT INSERT INCLUDE PROCESS WRAPPER BLOCK END
- USE PLUGIN FILTER MACRO PERL RAWPERL TO STEP AND OR NOT
- IF UNLESS ELSE ELSIF FOR FORNEXT WHILE SWITCH CASE META
+ USE PLUGIN FILTER MACRO PERL RAWPERL TO STEP AND OR NOT DIV MOD
+ IF UNLESS ELSE ELSIF FOR NEXT WHILE SWITCH CASE META
TRY THROW CATCH FINAL BREAK RETURN STOP CLEAR
);
@@ -78,14 +78,16 @@ $LEXTABLE = {
'\\' => 'REF',
'and' => 'AND', # explicitly specified so that qw( and or
'or' => 'OR', # not ) can always be used in lower case,
- 'not' => 'NOT' # regardless of CASE sensitivity flag
+ 'not' => 'NOT', # regardless of ANYCASE flag
+ 'mod' => 'MOD',
+ 'div' => 'DIV',
};
# localise the temporary variables needed to complete lexer table
{
my @tokens = qw< ( ) [ ] { } ${ $ / ; : ? >;
my @cmpop = keys %CMPOP;
- my @binop = qw( + - * % ); # '/' above, in @tokens
+ my @binop = qw( + - * % ); # '/' above, in @tokens
# fill lexer table, slice by slice, with reserved words and operators
@$LEXTABLE{ @RESERVED, @cmpop, @binop, @tokens }
View
7 parser/Parser.yp
@@ -46,6 +46,8 @@
%left CMPOP
%left BINOP
%left '/'
+%left DIV
+%left MOD
%left TO
%%
@@ -107,13 +109,12 @@ atomdir: GET expr { $factory->get($_[2]) }
| INSERT nameargs { $factory->insert($_[2]) }
| INCLUDE nameargs { $factory->include($_[2]) }
| PROCESS nameargs { $factory->process($_[2]) }
-# | PLUGIN nameargs { $factory->plugin($_[2]) }
| THROW nameargs { $factory->throw($_[2]) }
| RETURN { $factory->return() }
| STOP { $factory->stop() }
| CLEAR { "\$output = '';"; }
| BREAK { 'last;' }
- | FORNEXT { $_[0]->{ INFOR }
+ | NEXT { $_[0]->{ INFOR }
? $factory->next()
: 'next;' }
| wrapper
@@ -306,6 +307,8 @@ item: IDENT { "'$_[1]'" }
expr: expr BINOP expr { "$_[1] $_[2] $_[3]" }
| expr '/' expr { "$_[1] $_[2] $_[3]" }
+ | expr DIV expr { "int($_[1] / $_[3])" }
+ | expr MOD expr { "$_[1] % $_[3]" }
| expr CMPOP expr { "$_[1] $CMPOP{ $_[2] } $_[3]" }
| expr AND expr { "($_[1]) && ($_[3])" }
| expr OR expr { "($_[1]) || ($_[3])" }
View
6 t/binop.t
@@ -319,5 +319,9 @@ maxi: 54
mega: 106
-- test --
-fail
+[% 10 mod 4 +%] [% 10 MOD 4 +%]
+[% 10 div 3 %] [% 10 DIV 3 %]
-- expect --
+2 2
+3 3
+
View
28 t/case.t
@@ -29,17 +29,12 @@ my $ttdef = Template->new({
POST_CHOMP => 1,
});
-my $ttcaseon = Template->new({
- CASE => 1,
+my $ttanycase = Template->new({
+ ANYCASE => 1,
POST_CHOMP => 1,
});
-my $ttcaseoff = Template->new({
- CASE => 0,
- POST_CHOMP => 1,
-});
-
-my $tts = [ default => $ttdef, caseon => $ttcaseon, caseoff => $ttcaseoff ];
+my $tts = [ default => $ttdef, anycase => $ttanycase ];
test_expect(\*DATA, $tts, callsign());
@@ -80,18 +75,15 @@ good
alpha
-- test --
--- use caseon --
-[% include = 10 %]
-include: [% include %]
--- expect --
-include: 10
-
--- test --
--- use caseoff --
+-- use anycase --
[% include foo bar='baz' %]
[% BLOCK foo %]this is foo, bar = [% bar %][% END %]
-- expect --
this is foo, bar = baz
-
-
+-- test --
+[% 10 div 3 %] [% 10 DIV 3 +%]
+[% 10 mod 3 %] [% 10 MOD 3 %]
+-- expect --
+3 3
+1 1
View
4 t/config.t
@@ -66,7 +66,7 @@ ok( $provider->{ PARSER }->{ POST_CHOMP } == 1);
$provider = $factory->provider({
INCLUDE_PATH => 'cat:mat',
- CASE => 1,
+ ANYCASE => 1,
INTERPOLATE => 1
}) || print STDERR $factory->error(), "\n";
@@ -77,7 +77,7 @@ ok( join('...', @{ $provider->{ INCLUDE_PATH } }) eq 'cat...mat' );
# parameters.
my $text = 'The cat sat on the mat';
ok( $provider->fetch(\$text) );
-ok( $provider->{ PARSER }->{ CASE } == 1);
+ok( $provider->{ PARSER }->{ ANYCASE } == 1);
ok( $provider->{ PARSER }->{ INTERPOLATE } == 1);
View
6 t/date.t
@@ -187,4 +187,8 @@ Bad date: bad time/date string: expects 'h:m:s d:m:y' got: 'some stupid date'
-- test --
[% USE date %]
-[% template.name %] [% date.format(template.modtime) %]
+[% template.name %] [% date.format(template.modtime, format='%Y') %]
+-- expect --
+-- process --
+input text [% now('%Y') %]
+
View
18 t/document.t
@@ -25,6 +25,8 @@ use Template::Document;
$^W = 1;
$Template::Test::DEBUG = 0;
$Template::Document::DEBUG = 0;
+#$Template::Parser::DEBUG = 1;
+#$Template::Directive::PRETTY = 1;
my $DEBUG = 0;
@@ -106,6 +108,22 @@ title: [% template.title or title %]
title: My Template Title
-- test --
+[% BLOCK header -%]
+HEADER
+component title: [% component.name %]
+ template title: [% template.name %]
+[% END -%]
+component title: [% component.name %]
+ template title: [% template.name %]
+[% PROCESS header %]
+-- expect --
+component title: input text
+ template title: input text
+HEADER
+component title: header
+ template title: input text
+
+-- test --
[% META title = 'My Template Title' -%]
[% BLOCK header -%]
title: [% title or template.title %]
View
47 t/foreach.t
@@ -80,7 +80,7 @@ sub format {
}
}
-my $template = Template->new({ INTERPOLATE => 1, POST_CHOMP => 1 });
+my $template = Template->new({ INTERPOLATE => 1, POST_CHOMP => 1, ANYCASE => 1 });
test_expect(\*DATA, $template, $params);
@@ -119,26 +119,6 @@ Fire!
1..2..3..
-- test --
-[% for count = [ 1 2 3 ] %]${count}..[% END %]
--- expect --
-1..2..3..
-
--- test --
-[% foreach count = [ 1 2 3 ] %]${count}..[% END %]
--- expect --
-1..2..3..
-
--- test --
-[% for [ 1 2 3 ] %]<blip>..[% END %]
--- expect --
-<blip>..<blip>..<blip>..
-
--- test --
-[% foreach [ 1 2 3 ] %]<blip>..[% END %]
--- expect --
-<blip>..<blip>..<blip>..
-
--- test --
people:
[% bloke = r %]
[% people = [ c, bloke, o, 'frank' ] %]
@@ -449,7 +429,7 @@ Section List:
-- test --
[% FOREACH a = [ 2..6 ] %]
before [% a %]
-[% FORNEXT IF a == 5 +%]
+[% NEXT IF a == 5 +%]
after [% a +%]
[% END %]
-- expect --
@@ -465,7 +445,7 @@ after 6
-- test --
[% count = 1; WHILE (count < 10) %]
[% count = count + 1 %]
-[% FORNEXT if count < 5 %]
+[% NEXT if count < 5 %]
count: [% count +%]
[% END %]
-- expect --
@@ -475,3 +455,24 @@ count: 7
count: 8
count: 9
count: 10
+
+-- test --
+[% for count = [ 1 2 3 ] %]${count}..[% END %]
+-- expect --
+1..2..3..
+
+-- test --
+[% foreach count = [ 1 2 3 ] %]${count}..[% END %]
+-- expect --
+1..2..3..
+
+-- test --
+[% for [ 1 2 3 ] %]<blip>..[% END %]
+-- expect --
+<blip>..<blip>..<blip>..
+
+-- test --
+[% foreach [ 1 2 3 ] %]<blip>..[% END %]
+-- expect --
+<blip>..<blip>..<blip>..
+
View
56 t/object.t
@@ -41,6 +41,9 @@ sub new {
DAYS => [ qw( Monday Tuesday Wednesday Thursday
Friday Saturday Sunday ) ],
DAY => 0,
+ 'public' => 314,
+ '.private' => 425,
+ '_hidden' => 537,
}, $class;
}
@@ -199,62 +202,25 @@ Tuesday
Wednesday Thursday Friday Saturday Sunday .
--- stop --
-#========================================================================
-# TODO: test _private and .private members
-#========================================================================
-
#------------------------------------------------------------------------
# test private methods do not get exposed
#------------------------------------------------------------------------
-- test --
-[% TRY %]
-before[% thing._private %]after
-[% CATCH %]
-ERROR: [% error.info %]
-[% END %]
+before[% thing._private %] mid [% thing._hidden %]after
-- expect --
+before mid after
-- test --
-[% TRY %]
-[% thing._private = 10 %]
-[% CATCH %]
-ERROR: [% error.info %]
-[% END %]
--- expect --
-ERROR: invalid member name '_private'
-
-
--- test --
-[% TRY %]
[% key = '_private' -%]
-[% thing.${key} %]
-[% CATCH %]
-ERROR: [% error.info %]
-[% END %]
+[[% thing.$key %]]
-- expect --
-ERROR: invalid member name '_private'
+[]
-- test --
-[% TRY %]
[% key = '.private' -%]
-[% thing.${key} = 'foo' %]
-[% CATCH %]
-ERROR: [% error.info %]
-[% END %]
--- expect --
-ERROR: invalid member name '.private'
-
--- test --
-[% other.foo %]
-[% other.Help %]
--- expect --
-bar
-Help Yourself
-
--- test --
-[% localise = 10 -%]
-[% localise %]
+[[% thing.$key = 'foo' %]]
+[[% thing.$key %]]
-- expect --
-10
+[]
+[]
View
6 t/parser.t
@@ -32,6 +32,7 @@ $^W = 1;
my $p2 = Template::Parser->new({
START_TAG => '\[\*',
END_TAG => '\*\]',
+ ANYCASE => 1,
PRE_CHOMP => 1,
V1DOLLAR => 1,
});
@@ -39,15 +40,16 @@ my $p2 = Template::Parser->new({
my $p3 = Template::Config->parser({
TAG_STYLE => 'html',
POST_CHOMP => 1,
+ ANYCASE => 1,
INTERPOLATE => 1,
});
my $p4 = Template::Config->parser({
- CASE => 1,
+ ANYCASE => 0,
});
my $tt = [
- tt1 => Template->new(),
+ tt1 => Template->new(ANYCASE => 1),
tt2 => Template->new(PARSER => $p2),
tt3 => Template->new(PARSER => $p3),
tt4 => Template->new(PARSER => $p4),
View
4 t/provider.t
@@ -20,7 +20,7 @@ use strict;
use lib qw( ./lib ../lib );
use Template::Test;
use Template::Config;
- use Template::Provider;
+use Template::Provider;
use Cwd 'abs_path';
$^W = 1;
@@ -59,7 +59,7 @@ sub update_file {
local *FP;
sleep(2); # ensure file time stamps are different
open(FP, ">$newfile") || die "$newfile: $!\n";
- print FP @_;
+ print(FP @_) || die "failed to write $newfile: $!\n";
close(FP);
}
View
4 t/skel.t
@@ -22,8 +22,8 @@ use Template::Test;
$^W = 1;
$Template::Test::DEBUG = 0;
-$Template::Parser::DEBUG = 1;
-$Template::Directive::PRETTY = 1;
+#$Template::Parser::DEBUG = 1;
+#$Template::Directive::PRETTY = 1;
ok(1);
View
7 t/vars.t
@@ -85,7 +85,10 @@ my $params = {
# don't define a 'z' - DEFAULT test relies on its non-existance
};
-test_expect(\*DATA, { INTERPOLATE => 1, ANYCASE => 1 }, $params);
+my $tt = [ default => Template->new({ INTERPOLATE => 1, ANYCASE => 1 }),
+ notcase => Template->new({ INTERPOLATE => 1, ANYCASE => 0 }) ];
+
+test_expect(\*DATA, $tt, $params);
#------------------------------------------------------------------------
@@ -252,6 +255,7 @@ Now it looks as though they're here to stay.
Oh I believe in yesterday.
-- test --
+-- use notcase --
[% day.next %]
$day.next
-- expect --
@@ -264,6 +268,7 @@ Tuesday
Wednesday Thursday Friday Saturday Sunday
-- test --
+-- use default --
before
[% halt %]
after
View
14 t/varsv1.t
@@ -81,7 +81,17 @@ my $params = {
# don't define a 'z' - DEFAULT test relies on its non-existance
};
-test_expect(\*DATA, { INTERPOLATE => 1, V1DOLLAR => 1 }, $params);
+my $tt = [ default => Template->new({
+ INTERPOLATE => 1,
+ ANYCASE => 1,
+ V1DOLLAR => 1,
+ }),
+ notcase => Template->new({
+ INTERPOLATE => 1,
+ V1DOLLAR => 0,
+ }) ];
+
+test_expect(\*DATA, $tt, $params);
#------------------------------------------------------------------------
# subs
@@ -256,6 +266,7 @@ Now it looks as though they're here to stay.
Oh I believe in yesterday.
-- test --
+-- use notcase --
[% day.next %]
$day.next
-- expect --
@@ -268,6 +279,7 @@ Tuesday
Wednesday Thursday Friday Saturday Sunday
-- test --
+-- use default --
before
[% halt %]
after
View
15 t/while.t
@@ -25,6 +25,7 @@ $^W = 1;
$Template::Test::DEBUG = 0;
#$Template::Parser::DEBUG = 1;
+#$Template::Directive::PRETTY = 1;
# set low limit on WHILE's maximum iteration count
$Template::Directive::WHILE_MAX = 100;
@@ -116,7 +117,13 @@ error: [% error.info %]
error: WHILE loop terminated (> 100 iterations)
-
-
-
-
+-- test --
+[% reset %]
+[% WHILE (item = next) %]
+[% NEXT IF item == 'yankee' -%]
+* [% item +%]
+[% END %]
+-- expect --
+Reset list
+* x-ray
+* zulu
Please sign in to comment.
Something went wrong with that request. Please try again.