[Templates-cvs] cvs commit: Template2/lib/Template Stash.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
cvs 06/05/14 07:12:21
Modified: lib/Template Stash.pm
Log:
* added $PRIVATE package variable containing regex to match hidden or
private variables, set to match any starting '_' or '.' by default
Revision Changes Path
2.101 +15 -12 Template2/lib/Template/Stash.pm
Index: Stash.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Stash.pm,v
retrieving revision 2.100
retrieving revision 2.101
diff -u -r2.100 -r2.101
--- Stash.pm 2006/02/10 10:54:07 2.100
+++ Stash.pm 2006/05/14 07:12:20 2.101
@@ -18,7 +18,7 @@
#
#----------------------------------------------------------------------------
#
-# $Id: Stash.pm,v 2.100 2006/02/10 10:54:07 abw Exp $
+# $Id: Stash.pm,v 2.101 2006/05/14 07:12:20 abw Exp $
#
#============================================================================
@@ -27,9 +27,10 @@
require 5.004;
use strict;
-use vars qw( $VERSION $DEBUG $ROOT_OPS $SCALAR_OPS $HASH_OPS $LIST_OPS );
-$VERSION = sprintf("%d.%02d", q$Revision: 2.100 $ =~ /(\d+)\.(\d+)/);
+our $VERSION = sprintf("%d.%02d", q$Revision: 2.101 $ =~ /(\d+)\.(\d+)/);
+our $DEBUG = 0 unless defined $DEBUG;
+our $PRIVATE = qr/^[_.]/;
#========================================================================
@@ -43,14 +44,14 @@
# respectively for LIST_OPS and HASH_OPS
#------------------------------------------------------------------------
-$ROOT_OPS = {
+our $ROOT_OPS = {
'inc' => sub { local $^W = 0; my $item = shift; ++$item },
'dec' => sub { local $^W = 0; my $item = shift; --$item },
# import => \&hash_import,
defined $ROOT_OPS ? %$ROOT_OPS : (),
};
-$SCALAR_OPS = {
+our $SCALAR_OPS = {
'item' => sub { $_[0] },
'list' => sub { [ $_[0] ] },
'hash' => sub { { value => $_[0] } },
@@ -164,11 +165,11 @@
defined $SCALAR_OPS ? %$SCALAR_OPS : (),
};
-$HASH_OPS = {
+our $HASH_OPS = {
'item' => sub {
my ($hash, $item) = @_;
$item = '' unless defined $item;
- return if $item =~ /^[_.]/;
+ return if $PRIVATE && $item =~ /$PRIVATE/;
$hash->{ $item };
},
'hash' => sub { $_[0] },
@@ -215,7 +216,7 @@
defined $HASH_OPS ? %$HASH_OPS : (),
};
-$LIST_OPS = {
+our $LIST_OPS = {
'item' => sub { $_[0]->[ $_[1] || 0 ] },
'list' => sub { $_[0] },
'hash' => sub {
@@ -679,9 +680,10 @@
# if $DEBUG;
# return undef without an error if either side of the dot is unviable
+ return undef unless defined($root) and defined($item);
+
# or if an attempt is made to access a private member, starting _ or .
- return undef
- unless defined($root) and defined($item) and $item !~ /^[\._]/;
+ return undef if $PRIVATE && $item =~ /$PRIVATE/;
if ($atroot || $rootref eq 'HASH') {
# if $root is a regular HASH or a Template::Stash kinda HASH (the
@@ -835,9 +837,10 @@
$default ||= 0;
# return undef without an error if either side of the dot is unviable
+ return undef unless $root and defined $item;
+
# or if an attempt is made to update a private member, starting _ or .
- return undef ## RETURN
- unless $root and defined $item and $item !~ /^[\._]/;
+ return undef if $PRIVATE && $item =~ /$PRIVATE/;
if ($rootref eq 'HASH' || $atroot) {
# if the root is a hash we set the named key