diff options
author | Jesse Luehrs <doy@tozt.net> | 2011-11-29 03:04:56 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2011-11-29 03:04:56 -0600 |
commit | 0f40e41f356af017fc3ff3a2c685c61ff648b4c0 (patch) | |
tree | 923ea4c567ebaa5f70e733d56609f1228ae70b6d | |
parent | c049a789b0ccb2734ee8c8f1b8a6bb80b575c19b (diff) | |
download | package-stash-0f40e41f356af017fc3ff3a2c685c61ff648b4c0.tar.gz package-stash-0f40e41f356af017fc3ff3a2c685c61ff648b4c0.zip |
don't initialize the slot unless a value is provided
-rw-r--r-- | lib/Package/Stash/PP.pm | 7 | ||||
-rw-r--r-- | t/basic.t | 2 |
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/Package/Stash/PP.pm b/lib/Package/Stash/PP.pm index 121a57e..67e4658 100644 --- a/lib/Package/Stash/PP.pm +++ b/lib/Package/Stash/PP.pm @@ -160,8 +160,11 @@ sub add_symbol { my $namespace = $self->namespace; $namespace->{$name} ||= *{ Symbol::gensym() }; - *{ $namespace->{$name} } = ref $initial_value - ? $initial_value : \$initial_value; + + if (@_ > 2) { + *{ $namespace->{$name} } = ref $initial_value + ? $initial_value : \$initial_value; + } } sub remove_glob { @@ -252,6 +252,8 @@ is($foo_stash->get_symbol('@foo'), $ARRAY, '... got the right values for @Foo::f { $foo_stash->add_symbol('%zork'); + ok(!$foo_stash->has_symbol('$zork'), + "add_symbol with single argument doesn't vivify scalar slot"); my $syms = $foo_stash->get_all_symbols('HASH'); |