Commit | Line | Data |
c6ddb1d1 |
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" |
acbc69c4 |
12 | if $] < 5.014 |
ace6563d |
13 | && $Package::Stash::IMPLEMENTATION eq 'PP'; |
c6ddb1d1 |
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 | { |
28 | local $TODO = ($Package::Stash::IMPLEMENTATION eq 'PP') |
29 | ? "can't inflate weird stash entries" |
30 | : undef; |
31 | $anon->{bar} = \123; |
32 | |
33 | is( |
34 | exception { |
35 | my $code = $stash->get_symbol('&bar'); |
36 | is(ref($code), 'CODE'); |
37 | is($code->(), 123); |
38 | |
39 | # is($obj->bar, 123); |
40 | }, |
41 | undef |
42 | ); |
43 | } |
44 | |
45 | { |
46 | local $TODO = ($Package::Stash::IMPLEMENTATION eq 'PP') |
47 | ? "can't inflate weird stash entries" |
48 | : undef; |
49 | $anon->{baz} = -1; |
50 | |
51 | is( |
52 | exception { |
53 | my $code = $stash->get_symbol('&baz'); |
54 | is(ref($code), 'CODE'); |
55 | like( |
56 | exception { $code->() }, |
57 | qr/Undefined subroutine \&__ANON__::baz called/ |
58 | ); |
59 | }, |
60 | undef |
61 | ); |
62 | } |
63 | |
64 | done_testing; |