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

cvs@template-toolkit.org cvs@template-toolkit.org
Wed, 10 Nov 2004 18:25:25 +0000


cvs         04/11/10 18:25:25

  Added:       lib/Template Directive.pm
  Log:
  * added Template::Directive
  
  Revision  Changes    Path
  1.1                  TT3/lib/Template/Directive.pm
  
  Index: Directive.pm
  ===================================================================
  #========================================================================
  #
  # Template::Directive
  #
  # DESCRIPTION
  #   This module implements a base class directive object.  This is then
  #   configured at runtime or subclassed to implement specific directives
  #   such as INCLUDE, IF, FOREACH, etc.
  # 
  # AUTHOR
  #   Andy Wardley <abw@wardley.org>
  #
  # COPYRIGHT
  #   Copyright (C) 1996-2004 Andy Wardley.  All Rights Reserved.
  #   Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
  #   Copyright (C) 2003-2004 Fotango Ltd.
  #
  #   This module is free software; you can redistribute it and/or
  #   modify it under the same terms as Perl itself.
  #
  # REVISION
  #   $Id: Directive.pm,v 1.1 2004/11/10 18:25:24 abw Exp $
  #
  #========================================================================
  
  package Template::Directive;
  
  use strict;
  use warnings;
  use Template::Parser;
  use base qw( Template::Parser );
  
  our $VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);
  our $DEBUG   = 0 unless defined $DEBUG;
  our $ERROR   = '';
  our $ELEMENT = 'Template::Element';   # TODO
  
  
  
  sub init {
      my ($self, $config) = @_;
  
      # copy all $config items into $self
      @$self{ keys %$config } = values %$config;
  
      return $self;
  }
  
  
  sub keyword {
      my $self  = shift;
      my $class = ref($self) || $self;
      
      if (ref $self) {
          # called as an object method - return internal value
          # or fetch it by calling keyword() as class method and 
          # cache internally for next time
          return $self->{ keyword } ||= $class->keyword();
      }
      else {
          # called as a class method - first look for $KEYWORD package
          # variable in subclass, failing that we intuit it from the 
          # class name, using the upper case version of the last part
          return $self->pkgvar( KEYWORD => do { 
              my ($keyword) = ($class =~ /(\w+)$/); 
              uc($keyword);
          });
      }
  }
  
  sub extend {
      # create new object with parent link to $self, expanding directives
      # out into keywords according to some map or other
      die "Template::Directive extend() not yet implemented\n";
  }
  
  sub parse {
      my $self = shift;
      $self->throw( directive => 'parse() method not yet implemented' );
  }
  
  
  sub element {
      my $self = shift;
      $self->throw( directive => 'element() method not yet implemented' );
  }
  
  
  
  
  
  1;
  __END__
  
  =head1 NAME
  
  Template::Directive - base class directive module
  
  =head1 SYNOPSIS
  
      # TODO
  
  =head1 DESCRIPTION
  
      # TODO
  
  =head1 METHODS
  
      # TODO
  
  =head1 AUTHOR
  
  Andy Wardley  E<lt>abw@wardley.orgE<gt>
  
  =head1 VERSION
  
  $Revision: 1.1 $
  
  =head1 COPYRIGHT
  
    Copyright (C) 1996-2004 Andy Wardley.  All Rights Reserved.
    Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
    Copyright (C) 2003-2004 Fotango 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: