Commit | Line | Data |
8642531f |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
4 | use Test::More; |
5 | use Test::Fatal; |
6 | use lib 't/lib'; |
7 | |
8 | use Test::Requires 'Package::Anon'; |
9 | |
10 | use Package::Stash; |
11 | use Symbol; |
12 | |
d93368f6 |
13 | plan skip_all => "Anonymous stashes in PP need at least perl 5.14" |
acbc69c4 |
14 | if $] < 5.014 |
ace6563d |
15 | && $Package::Stash::IMPLEMENTATION eq 'PP'; |
d93368f6 |
16 | |
8642531f |
17 | my $anon = Package::Anon->new; |
18 | my $stash = Package::Stash->new($anon); |
19 | my $obj = $anon->bless({}); |
20 | |
21 | { |
22 | my $code = sub { 'FOO' }; |
23 | $stash->add_symbol('&foo' => $code); |
24 | is($stash->get_symbol('&foo'), $code); |
25 | is($obj->foo, 'FOO'); |
26 | } |
27 | |
28 | { |
29 | $anon->{bar} = \123; |
30 | |
31 | my $code = $stash->get_symbol('&bar'); |
32 | is(ref($code), 'CODE'); |
33 | is($code->(), 123); |
34 | |
35 | is($obj->bar, 123); |
36 | } |
37 | |
38 | { |
39 | $anon->{baz} = -1; |
40 | |
41 | my $code = $stash->get_symbol('&baz'); |
42 | is(ref($code), 'CODE'); |
43 | like( |
44 | exception { $code->() }, |
45 | qr/Undefined subroutine \&__ANON__::baz called/ |
46 | ); |
47 | } |
48 | |
49 | done_testing; |