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 | |
e068010b |
15 | plan skip_all => "This isn't really going to work yet, probably"; |
16 | |
c6ddb1d1 |
17 | my $anon = {}; |
18 | my $stash = Package::Stash->new($anon); |
19 | # no way to bless something into a hashref yet |
20 | # my $obj = $anon->bless({}); |
21 | |
22 | { |
23 | my $code = sub { 'FOO' }; |
24 | $stash->add_symbol('&foo' => $code); |
25 | is($stash->get_symbol('&foo'), $code); |
26 | # is($obj->foo, 'FOO'); |
27 | } |
28 | |
29 | { |
30 | local $TODO = ($Package::Stash::IMPLEMENTATION eq 'PP') |
31 | ? "can't inflate weird stash entries" |
32 | : undef; |
33 | $anon->{bar} = \123; |
34 | |
35 | is( |
36 | exception { |
37 | my $code = $stash->get_symbol('&bar'); |
38 | is(ref($code), 'CODE'); |
39 | is($code->(), 123); |
40 | |
41 | # is($obj->bar, 123); |
42 | }, |
43 | undef |
44 | ); |
45 | } |
46 | |
47 | { |
48 | local $TODO = ($Package::Stash::IMPLEMENTATION eq 'PP') |
49 | ? "can't inflate weird stash entries" |
50 | : undef; |
51 | $anon->{baz} = -1; |
52 | |
53 | is( |
54 | exception { |
55 | my $code = $stash->get_symbol('&baz'); |
56 | is(ref($code), 'CODE'); |
57 | like( |
58 | exception { $code->() }, |
59 | qr/Undefined subroutine \&__ANON__::baz called/ |
60 | ); |
61 | }, |
62 | undef |
63 | ); |
64 | } |
65 | |
66 | done_testing; |