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

cvs@template-toolkit.org cvs@template-toolkit.org
Fri, 26 Mar 2004 13:19:01 +0000


cvs         04/03/26 13:19:01

  Added:       lib/Template/Plugin Hello.pm
  Log:
  * added Plugin base class, Plugins manager and example Plugin
  
  Revision  Changes    Path
  1.1                  TT3/lib/Template/Plugin/Hello.pm
  
  Index: Hello.pm
  ===================================================================
  #========================================================================
  #
  # Template::Plugin::Hello
  #
  # DESCRIPTION
  #   Simple example of a plugin which says hello.
  # 
  # 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) 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: Hello.pm,v 1.1 2004/03/26 13:19:01 abw Exp $
  #
  #========================================================================
  
  package Template::Plugin::Hello;
  
  use strict;
  use warnings;
  use Template::Plugin;
  use base qw( Template::Plugin );
  use vars qw( $VERSION $DEBUG $ERROR $THROW );
  
  $VERSION   = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);
  $DEBUG     = 0 unless defined $DEBUG;
  $ERROR     = '';
  $THROW     = 'hello';
  
  my $GREETINGS = {
      czech     => 'Ahoj, svet!',
      bengali   => 'Shagatam Prithivi!',
      english   => 'Hello World!',
      french    => 'Salut le Monde!',
      german    => 'Hallo Welt!',
      hindi     => 'Shwagata Prithvi!',
      italian   => 'Ciao Mondo!',
      norwegian => 'Hallo Verden!',
      portugese => 'Ola mundo!',
      spanish   => '!Hola mundo!',
      swedish   => 'Hejsan värld!',
      turkish   => 'Merhaba Dünya!',
  };
  
  
  sub new {
      my ($class, $context, @args) = @_;
  
      # last argument is hash of named args
      my $params = pop(@args);
  
      # TODO: search context for 'language' if not defined as param
  
      bless {
          language => $params->{ language } || 'english',
      }, $class;
  }
  
  
  sub hello {
      my ($self, @args) = @_;
      my $params = @args && UNIVERSAL::isa($args[-1], 'HASH') ? pop(@args) : { @args };
      my $language = $params->{ language } || $self->{ language };
  
      return $GREETINGS->{ $language }
          || $self->error("Sorry, we don't know how to say 'Hello World' in $language");
  }
  
  
  1;
  
  __END__
  
  =head1 NAME
  
  Template::Plugin::Hello - example plugin that says "hello"
  
  =head1 SYNOPSIS
  
      TODO
  
  =head1 DESCRIPTION
  
  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) 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: