From 30d1a0987f7c01aad0c45be6b6cf6eada670007a Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 11 May 2010 19:11:09 -0500 Subject: initialize the ARRAY and HASH slots on get otherwise you have to explicitly initialize a package global array or hash with some value if you want to get a reference to its contents, if it's empty on first access --- lib/Stash/Manip.pm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/Stash/Manip.pm') diff --git a/lib/Stash/Manip.pm b/lib/Stash/Manip.pm index 3b9bcff..38177c7 100644 --- a/lib/Stash/Manip.pm +++ b/lib/Stash/Manip.pm @@ -184,8 +184,12 @@ sub get_package_symbol { my $namespace = $self->namespace; # FIXME - $self->add_package_symbol($variable) - unless exists $namespace->{$name}; + if (!exists $namespace->{$name}) { + my $initial = $type eq 'ARRAY' ? [] + : $type eq 'HASH' ? {} + : \undef; + $self->add_package_symbol($variable, $initial) + } my $entry_ref = \$namespace->{$name}; -- cgit v1.2.3-54-g00ecf