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

cvs@template-toolkit.org cvs@template-toolkit.org
Fri, 19 Dec 2003 12:08:05 +0000


cvs         03/12/19 12:08:04

  Added:       benchmark/lib/Document List.pm
  Log:
  added benchmark files
  
  Revision  Changes    Path
  1.1                  TT3/benchmark/lib/Document/List.pm
  
  Index: List.pm
  ===================================================================
  package Document::List;
  use Template::TT3::Document;
  use base qw( Template::TT3::Document );
  use strict;
  use warnings;
  
  our $DEBUG = 0 unless defined $DEBUG;
  
  sub text {
      my ($self, $text, $line, $size) = @_;
      my $locn = $size ? $line . '-' . ($line + $size) : $line;
      push(@{ $self->{ body } }, [ text => $text, $locn ]);
      print STDERR " - text at line $locn : ", $self->short_text($$text), "\n"
          if $DEBUG;
      return $self;
  }
  
  sub tag {
      my ($self, $type, $tag, $line, $size) = @_;
      my $locn = $size ? $line . '-' . ($line + $size) : $line;
      push(@{ $self->{ body } }, [ $type => $tag, $locn ]);
      print STDERR " - $type at line $locn : ", $self->short_text($$tag), "\n"
          if $DEBUG;
      return $self;
  }
  
  sub short_text {
      my ($self, $text) = @_;
      my $newtext = $text;
      $newtext =~ s/\n/\\n/g;
      $newtext = substr($newtext, 0, 32);
      $newtext .= '...' if length($text) > length($newtext);
      return $newtext;
  }
  
  
  1;