[Templates-cvs] cvs commit: Template2/lib/Template Stash.pm

cvs@template-toolkit.org cvs@template-toolkit.org
Thu, 24 Jul 2003 13:13:32 +0100


cvs         03/07/24 12:13:32

  Modified:    lib/Template Stash.pm
  Log:
  * merged in Darren's branch to add define_vmethod() to stash and context
  
  Revision  Changes    Path
  2.78      +15 -7     Template2/lib/Template/Stash.pm
  
  Index: Stash.pm
  ===================================================================
  RCS file: /template-toolkit/Template2/lib/Template/Stash.pm,v
  retrieving revision 2.77
  retrieving revision 2.78
  diff -u -r2.77 -r2.78
  --- Stash.pm	2003/07/24 11:32:35	2.77
  +++ Stash.pm	2003/07/24 12:13:32	2.78
  @@ -7,10 +7,10 @@
   #   variables for the Template Toolkit. 
   #
   # AUTHOR
  -#   Andy Wardley   <abw@kfs.org>
  +#   Andy Wardley   <abw@wardley.org>
   #
   # COPYRIGHT
  -#   Copyright (C) 1996-2000 Andy Wardley.  All Rights Reserved.
  +#   Copyright (C) 1996-2003 Andy Wardley.  All Rights Reserved.
   #   Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
   #
   #   This module is free software; you can redistribute it and/or
  @@ -18,7 +18,7 @@
   #
   #----------------------------------------------------------------------------
   #
  -# $Id: Stash.pm,v 2.77 2003/07/24 11:32:35 abw Exp $
  +# $Id: Stash.pm,v 2.78 2003/07/24 12:13:32 abw Exp $
   #
   #============================================================================
   
  @@ -29,7 +29,7 @@
   use strict;
   use vars qw( $VERSION $DEBUG $ROOT_OPS $SCALAR_OPS $HASH_OPS $LIST_OPS );
   
  -$VERSION = sprintf("%d.%02d", q$Revision: 2.77 $ =~ /(\d+)\.(\d+)/);
  +$VERSION = sprintf("%d.%02d", q$Revision: 2.78 $ =~ /(\d+)\.(\d+)/);
   
   
   #========================================================================
  @@ -250,6 +250,7 @@
       return '';
   }
   
  +
   #------------------------------------------------------------------------
   # define_vmethod($type, $name, \&sub)
   #
  @@ -257,21 +258,28 @@
   # name $name, that invokes &sub when called.  It is expected that &sub
   # be able to handle the type that it will be called upon.
   #------------------------------------------------------------------------
  +
   sub define_vmethod {
       my ($class, $type, $name, $sub) = @_;
       my $op;
  +    $type = lc $type;
   
  -    if (($type = lc $type) eq 'scalar') {
  +    if ($type =~ /^scalar|item$/) {
           $op = $SCALAR_OPS;
       }
       elsif ($type eq 'hash') {
           $op = $HASH_OPS;
       }
  -    elsif ($type eq 'array') {
  +    elsif ($type =~ /^list|array$/) {
           $op = $LIST_OPS;
       }
  +    else {
  +        die "invalid vmethod type: $type\n";
  +    }
  +
  +    $op->{ $name } = $sub;
   
  -    $op->{ $name } = $sub if $op;
  +    return 1;
   }