[Templates-cvs] cvs commit: TT3/benchmark/lib/Tag Dir.pm Var.pm

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


cvs         03/12/19 12:08:31

  Added:       benchmark/lib/Tag Dir.pm Var.pm
  Log:
  added benchmark files
  
  Revision  Changes    Path
  1.1                  TT3/benchmark/lib/Tag/Dir.pm
  
  Index: Dir.pm
  ===================================================================
  package Tag::Dir;
  use Template::TT3::Tag;
  use Template::TT3::Constants qw( :chomp );
  use base qw( Template::TT3::Tag );
  use vars qw( $TAG );
  use strict;
  use vars;
  
  $TAG = {
      start => '[%',
      end   => '%]',
      name  => 'dir',
      pre_chomp => 0,
      post_chomp => 0,
  };
  
  sub scan {
      my ($self, $text, $handler, $line, $size, $start, $end) = @_;
  
  #    print STDERR "dir scan(text, handler, line:$line, size:$size, start:$start, end:$end\n" if $DEBUG;
  
      # check for opening comment/chomp flag and remove leading whitespace
      $$text =~ s/ ^ ([-=+\#])? \s* //sx;
      my $flag  = $1 || '';
      my $comment;
      my $result = $handler;
  
      # examine opening flag and pre_chomp options
      if ($flag eq '#') {
          # it's a comment
          $comment = 1;
      }
      elsif ($flag eq '+') {
          # do nothing - leave whitespace alone
      }
      elsif ($flag eq '=' || $self->{ pre_chomp } == CHOMP_COLLAPSE) {
          # collapse preceding whitespace into a single space
          $handler->pre_chomp(CHOMP_COLLAPSE);
      }
      elsif ($flag eq '-' || $self->{ pre_chomp }) {
          # remove all preceding whitespace
          $handler->pre_chomp(CHOMP_ALL);
      }
  
      # check for closing chomp flag and remove trailing whitespace 
      $$text =~ s/ \s* ([-=+])? $ //sx;
      $flag = $1 || '';
  
      # parse ye olde content
      unless ($comment) {
          $result = $handler->tag( directive => $text, $line, $size );
      }
  
      # examine closing flag and post_chomp options
      if ($flag eq '+') {
          # do nothing - leave whitespace alone
      }
      elsif ($flag eq '=' || $self->{ post_chomp } == CHOMP_COLLAPSE) {
          # collapse followint whitespace into a single space
          $handler->post_chomp(CHOMP_COLLAPSE);
      }
      elsif ($flag eq '-' || $self->{ post_chomp }) {
          # remove all following whitespace
          $handler->post_chomp(CHOMP_ALL);
      }
  
      return $result;
  }
  
  
  1;
  
  
  
  
  1.1                  TT3/benchmark/lib/Tag/Var.pm
  
  Index: Var.pm
  ===================================================================
  package Tag::Var;
  use Template::TT3::Tag;
  use base qw( Template::TT3::Tag );
  use vars qw( $TAG );
  
  $TAG = {
      start => '$',
      name  => 'var',
  };
  
  sub scan {
      my ($self, $text, $handler, $line, $size, $start, $end) = @_;
  #    print STDERR "var scan(text, handler, line:$line, size:$size, start:$start\n";
      $$text =~ / \G (\w+) /gcx
          || return $self->error("missing variable after $start at $line");
      my $var = $1;
      return $handler->tag( variable => \$var, $line, $size );
  }
  
  
  1;