From: Jesse Luehrs Date: Fri, 12 Nov 2010 02:09:58 +0000 (-0600) Subject: preserve existing behavior here i guess X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FPackage-Stash-PP.git;a=commitdiff_plain;h=f75437398a7a18f7852b0151f7cb808dbeb06d0a preserve existing behavior here i guess --- diff --git a/lib/Package/Stash.pm b/lib/Package/Stash.pm index 88f921e..132f687 100644 --- a/lib/Package/Stash.pm +++ b/lib/Package/Stash.pm @@ -204,7 +204,16 @@ sub has_package_symbol { my $entry_ref = \$namespace->{$name}; if (reftype($entry_ref) eq 'GLOB') { - return defined *{$entry_ref}{$type}; + # XXX: assigning to any typeglob slot also initializes the SCALAR slot, + # and saying that an undef scalar variable doesn't exist is probably + # vaguely less surprising than a scalar variable popping into existence + # without anyone defining it + if ($type eq 'SCALAR') { + return defined ${ *{$entry_ref}{$type} }; + } + else { + return defined *{$entry_ref}{$type}; + } } else { # a symbol table entry can be -1 (stub), string (stub with prototype), diff --git a/t/07-edge-cases.t b/t/07-edge-cases.t index 85944d5..e544c7a 100755 --- a/t/07-edge-cases.t +++ b/t/07-edge-cases.t @@ -18,12 +18,16 @@ use Package::Stash; sub stub_with_proto (); our $SCALAR; + our $SCALAR_WITH_VALUE = 1; our @ARRAY; our %HASH; } my $stash = Package::Stash->new('Foo'); +{ local $TODO = "i think this is a perl bug (see comment in has_package_symbol)"; ok($stash->has_package_symbol('$SCALAR'), '$SCALAR'); +} +ok($stash->has_package_symbol('$SCALAR_WITH_VALUE'), '$SCALAR_WITH_VALUE'); ok($stash->has_package_symbol('@ARRAY'), '@ARRAY'); ok($stash->has_package_symbol('%HASH'), '%HASH'); is_deeply( @@ -32,4 +36,9 @@ is_deeply( "can see all code symbols" ); +$stash->add_package_symbol('%added', {}); +ok(!$stash->has_package_symbol('$added'), '$added'); +ok(!$stash->has_package_symbol('@added'), '@added'); +ok($stash->has_package_symbol('%added'), '%added'); + done_testing;