Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/Package/Stash/PP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ sub has_symbol {
if (reftype($entry_ref) eq 'GLOB') {
if ($type eq 'SCALAR') {
if (BROKEN_SCALAR_INITIALIZATION) {
{
my $package = $self->name;

# Turning off warnings does not silence this, so intercept it instead.
local $SIG{__WARN__} = sub {1};
return 1 if eval "package $package; my \$y = ${sigil}${name}; 1";
}

return defined ${ *{$entry_ref}{$type} };
}
else {
Expand Down
22 changes: 22 additions & 0 deletions t/pp_imported_scalars.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;

BEGIN { $Package::Stash::IMPLEMENTATION = 'PP' }

use Package::Stash;

{
package Foo::Test::Scalar;
use vars qw/$xyz/;

sub xyz { 1 };
sub abc { 1 };
}

my $ps = Package::Stash->new('Foo::Test::Scalar');
Test::More::ok($ps->has_symbol('$xyz'), "Found imported scalar, even though it is undef.");
Test::More::ok(!$ps->has_symbol('$abc'), "did not find undeclared scalar");

done_testing;