[Templates-cvs] cvs commit: TT3/lib/Template Handler.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
Wed, 17 Nov 2004 14:52:56 +0000
cvs 04/11/17 14:52:56
Modified: lib/Template Handler.pm
Log:
* added start_expr() and end_expr() for handling block directives
Revision Changes Path
1.3 +43 -3 TT3/lib/Template/Handler.pm
Index: Handler.pm
===================================================================
RCS file: /template-toolkit/TT3/lib/Template/Handler.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Handler.pm 2004/11/12 18:33:29 1.2
+++ Handler.pm 2004/11/17 14:52:56 1.3
@@ -17,7 +17,7 @@
# modify it under the same terms as Perl itself.
#
# REVISION
-# $Id: Handler.pm,v 1.2 2004/11/12 18:33:29 abw Exp $
+# $Id: Handler.pm,v 1.3 2004/11/17 14:52:56 abw Exp $
#
#========================================================================
@@ -29,7 +29,7 @@
use Template::Base;
use base qw( Template::Base );
-our $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
+our $VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
our $DEBUG = 0 unless defined $DEBUG;
our $ERROR = '';
our $THROW = 'handler';
@@ -65,6 +65,37 @@
}
+sub start_expr {
+ my $self = shift;
+ my $expr = @_ && UNIVERSAL::isa($_[0], 'ARRAY') ? shift : [ splice(@_) ];
+ my $opts = @_ && UNIVERSAL::isa($_[0], 'HASH') ? shift : { @_ };
+
+ $self->debug("starting expression [@$expr]\n") if $DEBUG;
+
+ $opts->{ expr } = $expr;
+ $opts->{ content } = [ $opts->{ type } || 'block' ];
+ $opts->{ parent } = $self;
+ $self->new($opts);
+}
+
+
+sub end_expr {
+ my $self = shift;
+ my $expr = $self->{ expr };
+ push(@$expr, $self->{ content });
+
+ # look for a parent to report to, otherwise return expression
+ my $parent = delete $self->{ parent }
+ || return $expr;
+
+ $self->debug("ended expression [@$expr]\n") if $DEBUG;
+
+ # TODO: force commit => 1 ?
+ return $parent->expr($expr, @_)
+ || $self->error($parent->error());
+}
+
+
sub element {
my $self = shift;
@@ -358,6 +389,15 @@
+# TODO: this may break pending/rollback, etc. - be very careful
+
+sub line {
+ my $self = shift;
+ $self->expr([ line => @_ ], commit => 1);
+}
+
+
+
@@ -398,7 +438,7 @@
=head1 VERSION
-$Revision: 1.2 $
+$Revision: 1.3 $
=head1 COPYRIGHT