Permalink
Browse files

*** empty log message ***

git-svn-id: svn://svn.tt2.org/tt/Template2/trunk@25 d5a88997-0a34-4036-9ed2-92fb5d660d91
  • Loading branch information...
abw committed Jul 25, 2000
1 parent 3ee03fd commit 5068caf4a88045539464a720c7c1774bf71dc567
View
49 Changes
@@ -12,6 +12,55 @@
# $Id$
#========================================================================
+* Reorganised the Template::Filters modules and changed the calling
+ convention for requesting filters via the fetch() method. This now
+ expects a reference to the calling Template::Context object as the
+ third parameter (after filter name and reference to a list of arguments).
+ Static filter sub-routines are returned as before and the context has
+ no effect. Dynamic filter factories (denoted by a $is_dynamic flag
+ in the FILTER_FACTORY table) are called to create a filter sub-routine
+ (closure) for each request. The context is now passed as the first
+ parameters, followed by the expansion of any arguments. Filter
+ factories should return a sub-routine or (undef, $error) on error.
+
+* Added several new filters:
+ - 'stderr' prints the output to STDERR (i.e. for generating output
+ in the Apache logfile, for example). e.g. [% message | stderr %]
+
+ - 'file' is the equivalent of the version 1 redirect() filter which
+ writes the output to a new file, relative to OUTPUT_PATH. Throws
+ a 'file' exception if OUTPUT_PATH is not set. There should perhaps
+ be some other way to disable this without relying on OUTPUT_PATH.
+
+ - 'eval' evaluates the input as a template and processes it. Proposed
+ by Simon Matthews for times when you might be returning templates
+ fragments from a database, for example. e.g. [% dirtext | eval %]
+
+ - 'evalperl' evaluate the input as Perl code, as suggested by Jonas
+ Liligren. Requires the EVAL_PERL option to be set and will throw a
+ 'perl' error if not (see next item). e.g. [% perlcode | evalperl %]
+
+* Changed PERL blocks to throw a 'perl' error if EVAL_PERL is not set.
+ Any other errors thrown in a Perl blocks are left intact. Previously,
+ these were converted to 'perl' exceptions which prevented exceptions
+ of other kinds being throw from within Perl code.
+
+* Changed Template::Base::error() to accept a reference (e.g. exception)
+ as the first parameter. In this case, no attempt is made to
+ concatenate (and thereby stringify) the arguments.
+
+* Added a direct stash() accessor method to Template::Context rather
+ than relying on the slower AUTOLOAD method.
+
+* Fixed a bug with persistant templates not loading Template::Iterator.
+ Thanks to Doug Steinwand who identified the problem. Also uncovered
+ and fixed a problem with persistant templates not being reloaded due
+ to the %INC hash. This caused 1 to be returned from require()
+ instead of the compiled template.
+
+* Applied documentation and test patches from Leon Brocard.
+
+
#========================================================================
# Changes from version 2.00-beta1 to 2.00-beta2
#========================================================================
View
30 TODO
@@ -2,6 +2,12 @@
# TO-DO
#------------------------------------------------------------------------
+* Exception names. Also, we cannot catch 'perl'.
+
+* Document FILTER_FACTORY
+
+* load Template::Iterator for persistant templates...
+
* move v1 Template::* to Template::v1::*. Add 'version1' load flag
as an EXPORT_FAIL to Tempate.pm to load v1.
@@ -27,7 +33,7 @@
[% something->first %] => $stash->{'something'}->{'first'}
[% something.first %] => $stash->get('something', 0, 'first', 0)
- The second example is as per the current V2 bet and allows
+ The second example is as per the current V2 beta and allows
'something' to be either a hash with a 'first' member (which may be
a sub-routine which is then run), or an object with a 'first'
method, or a list from which the first item is returned. All magic
@@ -48,12 +54,6 @@
the 'loop' reference to test 'first', 'last', etc., against, but it would
be faster for those cases when you didn't need that.
-* Change filter factory interface to accept $context as first parameter.
- Dynamic dynamic filters can't grab context reference and some of them
- need it.
-
-* Add 'perl' filter, but can't do that until I fix the above.
-
* Filters and plugins cache may bloat. Perhaps reset() should accept
flags to clear BLOCKS, PLUGINS, FILTERS, etc.
@@ -65,10 +65,6 @@
be, but I think that some of the problems for which refs were conceived
are still valid.
-* Do something (i.e. mail Lincoln) about the CGI special case in
- Template::Stash to work around the problem of CGI objects disclaiming
- membership of the UNIVERSAL class after the first method call.
-
* Note that no recursion checking is performed for BLOCKs, only
Template::Document instances. Should be documented.
@@ -170,3 +166,15 @@
* check [% INCLUDE $template %] works where $template is a
Template::Document
+-- v2.00 beta 3 --
+
+* Change filter factory interface to accept $context as first parameter.
+ Dynamic dynamic filters can't grab context reference and some of them
+ need it.
+
+* Did something (i.e. spoke to Lincoln at TPC4) about the CGI special
+ case in Template::Stash to work around the problem of CGI objects
+ disclaiming membership of the UNIVERSAL class after the first method
+ call. Current solution is to test UNIVERSAL::can($obj, 'can').
+
+* Added eval, evalperl, file and stderr filters.
View
@@ -72,7 +72,7 @@ sub error {
$errvar = ref $self ? \$self->{ _ERROR } : \${"$self\::ERROR"};
}
if (@_) {
- $$errvar = join('', @_);
+ $$errvar = ref($_[0]) ? shift : join('', @_);
return undef;
}
else {
View
@@ -105,7 +105,6 @@ sub template {
foreach my $provider (@{ $self->{ LOAD_TEMPLATES } }) {
($template, $error) = $provider->fetch($name);
return $template unless $error;
-# print STDERR "template() error: $error\ntemplate: $template";
return $self->error($template)
if $error == &Template::Constants::STATUS_ERROR;
}
@@ -165,7 +164,7 @@ sub filter {
# print STDERR "Asking filter provider $provider for $name...\n"
# if $DEBUG;
- ($filter, $error) = $provider->fetch($name, $args);
+ ($filter, $error) = $provider->fetch($name, $args, $self);
last unless $error;
return $self->error($filter)
if $error == &Template::Constants::STATUS_ERROR;
@@ -225,9 +224,12 @@ sub process {
if (ref $template eq 'CODE') {
$output = &$template($self);
}
- else {
+ elsif (ref $template) {
$output = $template->process($self);
}
+ else {
+ die "invalid template reference: $template\n";
+ }
if ($self->{ TRIM }) {
for ($output) {
@@ -272,9 +274,12 @@ sub include {
if (ref $template eq 'CODE') {
$output = &$template($self);
}
- else {
+ elsif (ref $template) {
$output = $template->process($self);
}
+ else {
+ die "invalid template reference: $template\n";
+ }
};
$error = $@;
@@ -447,12 +452,26 @@ sub reset {
}
+#------------------------------------------------------------------------
+# 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 };
+}
+
+
#------------------------------------------------------------------------
# AUTOLOAD
#
# Provides pseudo-methods for read-only access to various internal
-# members. For example, stash(), templates(), plugins(), filters(),
-# eval_perl(), load_perl(), etc.
+# 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 {
@@ -540,10 +559,12 @@ sub _init {
# EVAL_PERL - flag indicating if PERL blocks should be processed
# EVAL_PERL - flag to remove leading and trailing whitespace from output
# BLKSTACK - list of hashes of BLOCKs defined in current template(s)
+ # CONFIG - original configuration hash
$self->{ EVAL_PERL } = $config->{ EVAL_PERL } || 0;
$self->{ TRIM } = $config->{ TRIM } || 0;
$self->{ BLKSTACK } = [ ];
+ $self->{ CONFIG } = $config;
return $self;
}
View
@@ -599,22 +599,27 @@ sub use {
sub perl {
my ($class, $block) = @_;
- $block = pad($block, 1) if $PRETTY;
+ $block = pad($block, 2) if $PRETTY;
return <<EOF;
# PERL
-$OUTPUT do {
- my \$output = "package Template::Perl;\\n";
+if (\$context->eval_perl()) {
+ $OUTPUT do {
+ my \$output = "package Template::Perl;\\n";
$block
- \$Template::Perl::context = \$context;
- \$Template::Perl::stash = \$stash;
- \$output = eval \$output;
- \$context->throw('perl', \$@) if \$@;
- \$output;
-} if \$context->eval_perl();
+ \$Template::Perl::context = \$context;
+ \$Template::Perl::stash = \$stash;
+ \$output = eval \$output;
+ \$context->throw(\$@) if \$@;
+ \$output;
+ };
+}
+else {
+ \$context->throw('perl', 'EVAL_PERL not set');
+}
EOF
}
View
@@ -32,6 +32,7 @@ use strict;
use vars qw( $VERSION $ERROR $COMPERR $DEBUG $AUTOLOAD );
use base qw( Template::Base );
use Template::Constants;
+use Template::Iterator;
$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
Oops, something went wrong.

0 comments on commit 5068caf

Please sign in to comment.