summaryrefslogtreecommitdiffstats
path: root/lib/Stash/Manip.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-05-11 19:11:09 -0500
committerJesse Luehrs <doy@tozt.net>2010-05-11 19:11:09 -0500
commit30d1a0987f7c01aad0c45be6b6cf6eada670007a (patch)
tree7f3d5a8ea78587482c0b00010fba3ee09624bf24 /lib/Stash/Manip.pm
parentb1a00d0e626e61c80bdcd71b550d3e24eefc9e0b (diff)
downloadpackage-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
Diffstat (limited to 'lib/Stash/Manip.pm')
-rw-r--r--lib/Stash/Manip.pm8
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};