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

cvs@template-toolkit.org cvs@template-toolkit.org
Thu, 11 Dec 2003 15:11:38 +0000


cvs         03/12/11 15:11:37

  Modified:    lib/Template/TT3 Scanner.pm
  Log:
  * added sort_tags flags to allow automatic lengthwise sorting of tags
    to be disabled
  
  Revision  Changes    Path
  1.3       +14 -8     TT3/lib/Template/TT3/Scanner.pm
  
  Index: Scanner.pm
  ===================================================================
  RCS file: /template-toolkit/TT3/lib/Template/TT3/Scanner.pm,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Scanner.pm	2003/12/10 15:13:20	1.2
  +++ Scanner.pm	2003/12/11 15:11:37	1.3
  @@ -18,7 +18,7 @@
   #   modify it under the same terms as Perl itself.
   #
   # REVISION
  -#   $Id: Scanner.pm,v 1.2 2003/12/10 15:13:20 abw Exp $
  +#   $Id: Scanner.pm,v 1.3 2003/12/11 15:11:37 abw Exp $
   #
   #========================================================================
   
  @@ -30,7 +30,7 @@
   use vars qw( $VERSION $DEBUG $ERROR $WARNING $TAGS );
   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   = '';
   $TAGS    = [ ];
  @@ -48,6 +48,10 @@
       my $cfgtags = $config->{ tags } || $config->{ TAGS } || [ ];
       $cfgtags = [ $cfgtags ] unless UNIVERSAL::isa($cfgtags, 'ARRAY');
    
  +    $self->{ sort_tags } = exists $config->{ sort_tags } 
  +                                ? $config->{ sort_tags }
  +                                : 1;
  +
       $self->tags([ @$pkgtags, @$cfgtags ]) || return;
   
       return $self;
  @@ -125,11 +129,13 @@
           # gives them longer string representations (e.g. "(?-xism:<FOO)" vs 
           # "<FOOBAR") so we map them all to regex before sorting by length and
           # bulding a composite regex to match any of the start tags
  -        my $regex = join( '|',
  -                          reverse 
  -                          sort { length $a <=> length $b }  
  -                          map { ref($_) ? $_ : qr/$_/ } 
  -                          @build );
  +        if ($self->{ sort_tags }) {
  +            @build = reverse 
  +                     sort { length $a <=> length $b }  
  +                     map { ref($_) ? $_ : qr/$_/ } 
  +                     @build;
  +        }
  +        my $regex = join( '|', @build );
           $self->{ regex } = qr/ \G (.*?) ($regex) /sx;
           $self->debug("tags regex: $regex\n") if $DEBUG;
       }
  @@ -254,7 +260,7 @@
   
   =head1 VERSION
   
  -$Revision: 1.2 $
  +$Revision: 1.3 $
   
   =head1 COPYRIGHT