From: Jesse Luehrs Date: Tue, 29 Nov 2011 09:04:56 +0000 (-0600) Subject: don't initialize the slot unless a value is provided X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0f40e41f356af017fc3ff3a2c685c61ff648b4c0;p=gitmo%2FPackage-Stash.git don't initialize the slot unless a value is provided --- 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 { diff --git a/t/basic.t b/t/basic.t index f20e055..ded3d77 100644 --- a/t/basic.t +++ b/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');