From: Jesse Luehrs Date: Wed, 12 May 2010 00:11:09 +0000 (-0500) Subject: initialize the ARRAY and HASH slots on get X-Git-Tag: 0.01~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=30d1a0987f7c01aad0c45be6b6cf6eada670007a;p=gitmo%2FPackage-Stash.git 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 --- 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};