}
my $stash = Package::Stash->new('Foo');
-{ local $TODO = ($] < 5.010 || $Package::Stash::IMPLEMENTATION eq 'PP')
- ? "undef scalars aren't visible on 5.8, or from pure perl at all"
+{ local $TODO = $] < 5.010
+ ? "undef scalars aren't visible on 5.8"
: undef;
ok($stash->has_symbol('$SCALAR'), '$SCALAR');
}
is(ref($stash->get_symbol('$glob')), '', "nothing yet");
is(ref($stash->get_or_add_symbol('$glob')), 'SCALAR', "got an empty scalar");
-my $Bar = Package::Stash->new('Bar');
-my $foo = 3;
-$foo =~ s/3/4/;
-my $bar = 4.5;
-$bar =~ s/4/5/;
+SKIP: {
+ skip "PP doesn't support anon stashes before 5.14", 4
+ if $] < 5.014 && $Package::Stash::IMPLEMENTATION eq 'PP';
+ local $TODO = "don't know how to properly inflate a stash entry";
-is(exception { $Bar->add_symbol('$foo', \$foo) }, undef,
- "can add PVIV values");
-is(exception { $Bar->add_symbol('$bar', \$bar) }, undef,
- "can add PVNV values");
-is(exception { bless \$bar, 'Foo'; $Bar->add_symbol('$bar2', $bar) }, undef,
- "can add PVMG values");
-is(exception { $Bar->add_symbol('$baz', qr/foo/) }, undef,
- "can add regex values");
-is(exception { undef $bar; $Bar->add_symbol('$quux', \$bar) }, undef,
- "can add undef values that aren't NULL");
+ my $anon = {}; # not using Package::Anon
+ $anon->{foo} = -1; # stub
+ $anon->{bar} = '$&'; # stub with prototype
+ $anon->{baz} = \"foo"; # constant
-use_ok('CompileTime');
-
-{
- package Gets::Deleted;
- sub bar { }
+ my $stash = Package::Stash->new($anon);
+ is(
+ exception {
+ is(ref($stash->get_symbol('&foo')), 'CODE',
+ "stub expanded into a glob");
+ is(ref($stash->get_symbol('&bar')), 'CODE',
+ "stub with prototype expanded into a glob");
+ is(ref($stash->get_symbol('&baz')), 'CODE',
+ "constant expanded into a glob");
+ },
+ undef,
+ "can call get_symbol on weird stash entries"
+ );
}
{
- my $delete = Package::Stash->new('Gets::Deleted');
- ok($delete->has_symbol('&bar'), "sees the method");
- {
- no strict 'refs';
- delete ${'main::Gets::'}{'Deleted::'};
- }
- ok(!$delete->has_symbol('&bar'), "method goes away when stash is deleted");
+ my $warning;
+ local $SIG{__WARN__} = sub { $warning = $_[0] };
+ my $stash = Package::Stash->new('Bar');
+ $stash->add_symbol('&foo' => sub { });
+ $stash->add_symbol('&foo' => sub { });
+ is($warning, undef, "no redefinition warnings");
}
done_testing;