[Templates-cvs] cvs commit: TT3/lib/Template/TT3 Document.pm

cvs@template-toolkit.org cvs@template-toolkit.org
Mon, 15 Dec 2003 15:35:11 +0000


cvs         03/12/15 15:35:11

  Modified:    lib/Template/TT3 Document.pm
  Log:
  * changed line handling to delegate to scanner - note that this
    breaks some tests in t/document.t
  
  Revision  Changes    Path
  1.4       +18 -42    TT3/lib/Template/TT3/Document.pm
  
  Index: Document.pm
  ===================================================================
  RCS file: /template-toolkit/TT3/lib/Template/TT3/Document.pm,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Document.pm	2003/12/11 17:29:44	1.3
  +++ Document.pm	2003/12/15 15:35:11	1.4
  @@ -18,7 +18,7 @@
   #   modify it under the same terms as Perl itself.
   #
   # REVISION
  -#   $Id: Document.pm,v 1.3 2003/12/11 17:29:44 abw Exp $
  +#   $Id: Document.pm,v 1.4 2003/12/15 15:35:11 abw Exp $
   #
   #========================================================================
   
  @@ -31,7 +31,7 @@
   use vars qw( $VERSION $DEBUG $ERROR $WARNING $TAGS );
   use base qw( Template::TT3::Base );
   
  -$VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
  +$VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
   $DEBUG   = 0 unless defined $DEBUG;
   $ERROR   = '';
   
  @@ -56,8 +56,6 @@
   
       $self->{ name } = $name;
       $self->{ text } = ref $text ? $text : \$text;
  -    $self->{ line } = 1;
  -    $self->{ size } = 0;
       $self->{ body } = [ ];
   
       return $self;
  @@ -73,10 +71,9 @@
   
   sub scan {
       my ($self, $scanner) = @_;
  -
  -    $scanner->scan($self->{ text }, $self)
  -        || return $self->error($scanner->error());
  -
  +    $self->{ scanner } = $scanner;
  +    return $scanner->scan($self->{ text }, $self)
  +        || $self->error($scanner->error());
   }
   
   
  @@ -97,25 +94,21 @@
       return $tagdir;
   }
   
  +
   #------------------------------------------------------------------------
   # text($text)
   #
  -# Add a chunk of text to the current block on the stack.  Newlines are
  -# counted in the text and the internal 'line' and 'position' members
  -# updated accordingly.
  +# Add a chunk of text to the current block on the stack.
   #------------------------------------------------------------------------
   
   sub text {
       my ($self, $text) = @_;
       my $textref = ref $text ? $text : \$text;
  -    $self->debug("text at line $self->{ line } [$$textref]\n") if $DEBUG;
  +#    $self->debug("text at line $self->{ line } [$$textref]\n") if $DEBUG;
   
       # for debugging
       my $posn = $self->position();
   
  -    $self->{ line } += ($$textref =~ tr/\n//);
  -    $self->{ size }  = 0;
  -
       # can't have a pending side-effect directive run across text
       delete $self->{ pending };
   
  @@ -229,40 +222,23 @@
   
   sub line {
       my $self = shift;
  -    return @_ ? ($self->{ line } = shift) : $self->{ line };
  +    my $scanner = $self->{ scanner }
  +        || return $self->error("line unknown");    # TEMP HACK
  +    return $scanner->line();
   }
   
   sub size {
  -    my $self = shift;
  -    return @_ ? ($self->{ size } = shift) : $self->{ size };
  -}
  -
  -sub move {
       my $self = shift;
  -
  -    if (@_) {
  -        $self->{ line } += shift;
  -    }
  -    elsif ($self->{ size }) {
  -        $self->{ line } += $self->{ size };
  -    }
  -    $self->{ size } = 0;
  -    return $self->{ line };
  +    my $scanner = $self->{ scanner }
  +        || return $self->error("line unknown");    # TEMP HACK
  +    return $scanner->size();
   }
   
   sub position {
       my $self = shift;
  -    if (@_) {
  -        $self->{ line } += shift;
  -        $self->{ size }  = @_ ? shift : 0;
  -    }
  -    if ($self->{ size }) {
  -        my $end = $self->{ line } + $self->{ size };
  -        return "$self->{ line }-$end";
  -    }
  -    else {
  -        return $self->{ line };
  -    }
  +    my $scanner = $self->{ scanner }
  +        || return $self->error("line unknown");    # TEMP HACK
  +    return $scanner->position();
   }
   
   sub location {
  @@ -403,7 +379,7 @@
   
   =head1 VERSION
   
  -$Revision: 1.3 $
  +$Revision: 1.4 $
   
   =head1 COPYRIGHT