[Templates-cvs] cvs commit: TT3/lib/Template/Directive Wrapper.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
Wed, 17 Nov 2004 14:51:23 +0000
cvs 04/11/17 14:51:23
Modified: lib/Template/Directive Wrapper.pm
Log:
* fixed up to work with new parser and handler
Revision Changes Path
1.2 +24 -50 TT3/lib/Template/Directive/Wrapper.pm
Index: Wrapper.pm
===================================================================
RCS file: /template-toolkit/TT3/lib/Template/Directive/Wrapper.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Wrapper.pm 2004/11/10 18:26:30 1.1
+++ Wrapper.pm 2004/11/17 14:51:23 1.2
@@ -1,6 +1,6 @@
#========================================================================
#
-# Template::Directive::WRAPPER
+# Template::Directive::Wrapper
#
# DESCRIPTION
# The WRAPPER directive.
@@ -10,14 +10,12 @@
#
# COPYRIGHT
# Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved.
-# Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
-# Copyright (C) 2003-2004 Fotango Ltd.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
-# $Id: Wrapper.pm,v 1.1 2004/11/10 18:26:30 abw Exp $
+# $Id: Wrapper.pm,v 1.2 2004/11/17 14:51:23 abw Exp $
#
#========================================================================
@@ -25,59 +23,37 @@
use strict;
use warnings;
-use Template::Directive::Block;
-use base qw( Template::Directive::Block );
+use Template::Directive;
+use base qw( Template::Directive );
-our $VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);
+our $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
our $ERROR = '';
our $KEYWORD = 'WRAPPER';
sub parse {
- my ($self, $textref, $handler, $keyword) = @_;
- $keyword ||= $self->keyword();
+ my ($self, $textref, $handler, $match) = @_;
- # filename is mandatory
- my $filename = $handler->parse_filename($textref)
- || return $self->decline("$keyword expects a template name");
-
- # params are optional
- my $params = $handler->parse_params($textref);
-
- # TODO: this should be extend() (or something similar) - see
- # Template::Directive
-
- return $self->new({
- parent => $handler,
- keyword => $keyword,
- filename => $filename,
- params => $params,
- directives => {
- # TODO: must also import parent's directives???
- END => 'TODO::My::End::Keyword',
- %{ $handler->{ directives } },
- },
- });
+ my $parser = $match->{ parser }
+ || return $self->error('no parser defined');
-# return $handler->accept($self->element($filename, $params));
+ my $template = $parser->parse_template_name($textref)
+ || return $self->error('missing template name after ',
+ $self->keyword($match));
+
+ my $args = $parser->parse_params($textref)
+ || return $self->error('missing arguments in ',
+ $self->keyword($match), ' directive');
+
+ if (my $body = $handler->rollback()) {
+ return $handler->expr([ wrapper => $template, $args, $body ]);
+ }
+ else {
+ return $handler->start_expr([ wrapper => $template, $args ]);
+ }
}
-sub end {
- my $self = shift;
- my $parent = delete $self->{ parent };
- return $parent->accept(
- $self->element(@$self{ qw( filename params content ) })
- );
-}
-
-sub element {
- my ($self, $filename, $params, $content) = @_;
- return [ wrapper => $filename, $params, $content ];
-}
-
-
-
1;
__END__
@@ -106,13 +82,11 @@
=head1 VERSION
-$Revision: 1.1 $
+$Revision: 1.2 $
=head1 COPYRIGHT
- Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved.
- Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
- Copyright (C) 2003-2004 Fotango Ltd.
+Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.