[Templates-cvs] cvs commit: Template2/lib/Template Stash.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
cvs 06/01/30 18:34:56
Modified: lib/Template Stash.pm
Log:
* added defined() list and hash vmethods
Revision Changes Path
2.93 +14 -3 Template2/lib/Template/Stash.pm
Index: Stash.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Stash.pm,v
retrieving revision 2.92
retrieving revision 2.93
diff -u -r2.92 -r2.93
--- Stash.pm 2006/01/30 16:57:12 2.92
+++ Stash.pm 2006/01/30 18:34:56 2.93
@@ -18,7 +18,7 @@
#
#----------------------------------------------------------------------------
#
-# $Id: Stash.pm,v 2.92 2006/01/30 16:57:12 abw Exp $
+# $Id: Stash.pm,v 2.93 2006/01/30 18:34:56 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.92 $ =~ /(\d+)\.(\d+)/);
+$VERSION = sprintf("%d.%02d", q$Revision: 2.93 $ =~ /(\d+)\.(\d+)/);
#========================================================================
@@ -157,7 +157,12 @@
: [ %$hash ];
},
'exists' => sub { exists $_[0]->{ $_[1] } },
- 'defined' => sub { defined $_[0]->{ $_[1] } },
+ 'defined' => sub {
+ # return the item requested, or 1 if no argument
+ # to indicate that the hash itself is defined
+ my $hash = shift;
+ return @_ ? defined $hash->{ $_[0] } : 1;
+ },
'delete' => sub {
my $hash = shift;
delete $hash->{ $_ } for @_;
@@ -191,6 +196,12 @@
'shift' => sub { my $list = shift; shift(@$list) },
'max' => sub { local $^W = 0; my $list = shift; $#$list; },
'size' => sub { local $^W = 0; my $list = shift; $#$list + 1; },
+ 'defined' => sub {
+ # return the item requested, or 1 if no argument to
+ # indicate that the hash itself is defined
+ my $list = shift;
+ return @_ ? defined $list->[$_[0]] : 1;
+ },
'first' => sub {
my $list = shift;
return $list->[0] unless @_;