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),
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(
"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;