[Templates-cvs] cvs commit: TT3/lib/Template/TT3/Tag Comment.pm Escape.pm

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


cvs         03/12/11 15:12:48

  Added:       lib/Template/TT3/Tag Comment.pm Escape.pm
  Log:
  added Tag/Comment.pm and Tag/Escape.pm
  
  Revision  Changes    Path
  1.1                  TT3/lib/Template/TT3/Tag/Comment.pm
  
  Index: Comment.pm
  ===================================================================
  #========================================================================
  #
  # Template::TT3::Tag::Comment
  #
  # DESCRIPTION
  #   Module implementing a specialised tag object for handling escaped
  #   characters.
  # 
  # AUTHOR
  #   Andy Wardley <abw@wardley.org>
  #
  # COPYRIGHT
  #   Copyright (C) 1996-2003 Andy Wardley.  All Rights Reserved.
  #   Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
  #
  #   This module is free software; you can redistribute it and/or
  #   modify it under the same terms as Perl itself.
  #
  # REVISION
  #   $Id: Comment.pm,v 1.1 2003/12/11 15:12:48 abw Exp $
  #
  #========================================================================
  
  package Template::TT3::Tag::Comment;
  
  use strict;
  use warnings;
  use Template::TT3::Tag;
  use vars qw( $VERSION $DEBUG $ERROR $WARNING $TAG );
  use base qw( Template::TT3::Tag );
  
  $VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);
  $DEBUG   = 0 unless defined $DEBUG;
  $ERROR   = '';
  $TAG     = {
      name  => 'comment',
      start => qr/(?m:^#)/,
      end   => qr/(?m:\n|$)/,
  };
  
  
  sub parse {
      my ($self, $textref, $document) = @_;
  
      $self->debug("scanned comment: $$textref\n") if $DEBUG;
      return 1;
  }
  
  
  1;
  __END__
  
  =head1 NAME
  
  Template::TT3::Tag::Comment - tag module for scanning comments
  
  =head1 SYNOPSIS
  
      package Template::TT3::Tag::Comment;
  
      # TODO
  
  =head1 DESCRIPTION
  
  # TODO
  
  =head1 METHODS
  
  =head2 new()
  
  # TODO
  
  =head1 AUTHOR
  
  Andy Wardley  E<lt>abw@wardley.orgE<gt>
  
  =head1 VERSION
  
  $Revision: 1.1 $
  
  =head1 COPYRIGHT
  
    Copyright (C) 1996-2003 Andy Wardley.  All Rights Reserved.
    Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
  
  This module is free software; you can redistribute it and/or
  modify it under the same terms as Perl itself.
  
  =cut
  
  # Local Variables:
  # mode: perl
  # perl-indent-level: 4
  # indent-tabs-mode: nil
  # End:
  #
  # vim: expandtab shiftwidth=4:
  
  
  
  1.1                  TT3/lib/Template/TT3/Tag/Escape.pm
  
  Index: Escape.pm
  ===================================================================
  #========================================================================
  #
  # Template::TT3::Tag::Escape
  #
  # DESCRIPTION
  #   Module implementing a specialised tag object for handling escaped
  #   characters.
  # 
  # AUTHOR
  #   Andy Wardley <abw@wardley.org>
  #
  # COPYRIGHT
  #   Copyright (C) 1996-2003 Andy Wardley.  All Rights Reserved.
  #   Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
  #
  #   This module is free software; you can redistribute it and/or
  #   modify it under the same terms as Perl itself.
  #
  # REVISION
  #   $Id: Escape.pm,v 1.1 2003/12/11 15:12:48 abw Exp $
  #
  #========================================================================
  
  package Template::TT3::Tag::Escape;
  
  use strict;
  use warnings;
  use Template::TT3::Tag;
  use vars qw( $VERSION $DEBUG $ERROR $WARNING $TAG $ESCAPE $RANGE );
  use base qw( Template::TT3::Tag );
  
  $VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);
  $DEBUG   = 0 unless defined $DEBUG;
  $ERROR   = '';
  $ESCAPE  = qr/\\/;      # backslash is escape character, e.g. \$foo
  $RANGE   = qr/./;       # any character can be escaped
  $TAG     = {
      name   => 'escape',
      escape => $ESCAPE,
      range  => $RANGE,
  };
  
  
  sub init {
      my ($self, $config) = @_;
  
      my $escape = $config->{ escape };
      $escape = $ESCAPE unless defined $escape;
      $escape = ref $escape ? $escape : quotemeta($escape);
  
      my $range = $config->{ range  };
      $range = $RANGE unless defined $range;
      $range = ref $range ? $range : quotemeta($range);
  
      $config->{ start } = qr/$escape(?:$range)/
          unless defined $config->{ start };
  
      $config->{ strip } = qr/^$escape/
          unless defined $config->{ strip };
  
      $self->debug("start regex: $config->{ start }\n")
          if $DEBUG;
      $self->debug("strip regex: $config->{ strip }\n")
          if $DEBUG;
  
      
      return $self->SUPER::init($config);
  }
  
  sub scan {
      my ($self, $start, $textref, $document) = @_;
  
      $self->debug("scanned escape: $start\n") if $DEBUG;
      $start =~ s/$self->{ strip }//;
  
      return $document->text($start);
  }
  
  
  1;
  __END__
  
  =head1 NAME
  
  Template::TT3::Tag - base class scanner for embedded tags
  
  =head1 SYNOPSIS
  
      package Template::TT3::Tag;
  
      # TODO
  
  =head1 DESCRIPTION
  
  # TODO
  
  =head1 METHODS
  
  =head2 new()
  
  # TODO
  
  =head1 AUTHOR
  
  Andy Wardley  E<lt>abw@wardley.orgE<gt>
  
  =head1 VERSION
  
  $Revision: 1.1 $
  
  =head1 COPYRIGHT
  
    Copyright (C) 1996-2003 Andy Wardley.  All Rights Reserved.
    Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
  
  This module is free software; you can redistribute it and/or
  modify it under the same terms as Perl itself.
  
  =cut
  
  # Local Variables:
  # mode: perl
  # perl-indent-level: 4
  # indent-tabs-mode: nil
  # End:
  #
  # vim: expandtab shiftwidth=4: