diff options
author | Jesse Luehrs <doy@tozt.net> | 2010-05-11 19:11:09 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2010-05-11 19:11:09 -0500 |
commit | 30d1a0987f7c01aad0c45be6b6cf6eada670007a (patch) | |
tree | 7f3d5a8ea78587482c0b00010fba3ee09624bf24 | |
parent | b1a00d0e626e61c80bdcd71b550d3e24eefc9e0b (diff) | |
download | package-stash-30d1a0987f7c01aad0c45be6b6cf6eada670007a.tar.gz package-stash-30d1a0987f7c01aad0c45be6b6cf6eada670007a.zip |
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
-rw-r--r-- | lib/Stash/Manip.pm | 8 |
1 files changed, 6 insertions, 2 deletions
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}; |