[Templates-cvs] cvs commit: TT3/lib/Template/TT3 Tag.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
Mon, 15 Dec 2003 15:32:43 +0000
cvs 03/12/15 15:32:42
Modified: lib/Template/TT3 Tag.pm
Log:
* moved scanning for end tag and line counting out of tag into scanner
scan() method
Revision Changes Path
1.3 +7 -72 TT3/lib/Template/TT3/Tag.pm
Index: Tag.pm
===================================================================
RCS file: /template-toolkit/TT3/lib/Template/TT3/Tag.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Tag.pm 2003/12/11 15:11:01 1.2
+++ Tag.pm 2003/12/15 15:32:42 1.3
@@ -17,7 +17,7 @@
# modify it under the same terms as Perl itself.
#
# REVISION
-# $Id: Tag.pm,v 1.2 2003/12/11 15:11:01 abw Exp $
+# $Id: Tag.pm,v 1.3 2003/12/15 15:32:42 abw Exp $
#
#========================================================================
@@ -29,7 +29,7 @@
use vars qw( $VERSION $DEBUG $ERROR $WARNING $TAG );
use base qw( Template::TT3::Base );
-$VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
+$VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
$DEBUG = 0 unless defined $DEBUG;
$ERROR = '';
$TAG = {
@@ -70,78 +70,13 @@
#------------------------------------------------------------------------
-# scan($start_tag, $textref, $document)
-#
-# Called when a start tag is matched, this method scans up to any defined
-# end tag and then calls the parse() method to handle the content.
+# scan($textref, $document, $start, $end)
#------------------------------------------------------------------------
sub scan {
- my ($self, $start, $textref, $document) = @_;
- my ($end, $regex, $content, $size, $result);
- $self->{ start_match } = $start;
-
- $self->debug("Tag<$self->{ name }> scan()\n") if $DEBUG;
-
- if (defined ($end = $self->{ end }) && length($end)) {
- # this is a closed tag that has pre-defined start and end tokens.
- # we scan up to the end tag, figure out how many lines the directive
- # covers and then call the parse() method to parse the contents
-
- # generate regex to match end tag
- $regex = $self->{ end_regex } ||= do {
- $end = ref $end eq 'Regexp' ? $end : quotemeta($end);
- qr/ \G (.*?) ($end) /sx;
- };
-
- $self->debug("scanning for end with $end\n") if $DEBUG;
-
- # scan for closing tag and report error if not found
- return $self->error("no closing tag to match $start")
- unless $$textref =~ /$regex/gc;
- $content = $1;
- $end = $self->{ end_match } = $2;
-
- # count lines in start tag, content and end tag
- $size = ($start =~ tr/\n//) + ($content =~ tr/\n//) + ($end =~ tr/\n//);
- $document->size($size) if $size;
-
- # call parse method to parse tag content
- $result = $self->parse(\$content, $document);
-
- # TODO: check for trailing cruft in content?
-
- # update document position if required
- $document->move() if $size;
- }
- else {
- # an open tag that has a start but no pre-defined end token.
- # we save the current regex position, call the parse method to
- # gobble up as much of the text as it likes, and then examine
- # the regex position again, and count the newlines in the
- # intervening text to update the document line position
-
- # save starting regex position
- my $start_pos = pos($$textref) || 0;
-
- # no end match
- $end = $self->{ end_match } = undef;
-
- $self->debug("parsing open tag\n") if $DEBUG;
-
- # parse item
- $result = $self->parse($textref, $document);
-
- # count any newlines consumed by parser between start and end positions
- my $end_pos = pos $$textref || 0;
- my $substr = substr($$textref, $start_pos, $end_pos - $start_pos);
- $size = ($substr =~ tr/\n//);
-
- # update document position if required
- $document->move($size) if $size;
- }
-
- return $result;
+ my ($self, $textref, $document, $start, $end) = @_;
+ @$self{ qw( start_match end_match ) } = ($start, $end);
+ $self->parse($textref, $document);
}
@@ -297,7 +232,7 @@
=head1 VERSION
-$Revision: 1.2 $
+$Revision: 1.3 $
=head1 COPYRIGHT