Skip to content
Browse files

don't initialize the slot unless a value is provided

  • Loading branch information...
1 parent c049a78 commit 0f40e41f356af017fc3ff3a2c685c61ff648b4c0 @doy committed
Showing with 7 additions and 2 deletions.
  1. +5 −2 lib/Package/Stash/PP.pm
  2. +2 −0 t/basic.t
View
7 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 {
View
2 t/basic.t
@@ -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');

0 comments on commit 0f40e41

Please sign in to comment.
Something went wrong with that request. Please try again.