Commit | Line | Data |
c803b921 |
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 Package::Stash; |
9 | use Symbol; |
10 | |
11 | plan skip_all => "Anonymous stashes in PP need at least perl 5.14" |
12 | if $] < 5.014 |
13 | && $Package::Stash::IMPLEMENTATION eq 'PP'; |
14 | |
15 | my $anon = {}; |
16 | my $stash = Package::Stash->new($anon); |
17 | # no way to bless something into a hashref yet |
18 | # my $obj = $anon->bless({}); |
19 | |
20 | { |
21 | my $code = sub { 'FOO' }; |
22 | $stash->add_symbol('&foo' => $code); |
23 | is($stash->get_symbol('&foo'), $code); |
24 | # is($obj->foo, 'FOO'); |
25 | } |
26 | |
27 | { |
e0cd2c90 |
28 | local $TODO = "can't inflate weird stash entries"; |
c803b921 |
29 | $anon->{bar} = \123; |
30 | |
31 | is( |
32 | exception { |
33 | my $code = $stash->get_symbol('&bar'); |
34 | is(ref($code), 'CODE'); |
35 | is($code->(), 123); |
36 | |
37 | # is($obj->bar, 123); |
38 | }, |
39 | undef |
40 | ); |
41 | } |
42 | |
43 | { |
e0cd2c90 |
44 | local $TODO = "can't inflate weird stash entries"; |
c803b921 |
45 | $anon->{baz} = -1; |
46 | |
47 | is( |
48 | exception { |
49 | my $code = $stash->get_symbol('&baz'); |
50 | is(ref($code), 'CODE'); |
51 | like( |
52 | exception { $code->() }, |
53 | qr/Undefined subroutine \&__ANON__::baz called/ |
54 | ); |
55 | }, |
56 | undef |
57 | ); |
58 | } |
59 | |
60 | done_testing; |