actually, this isn't our fault, this is just generic 5.8 brokenness
[gitmo/Package-Stash-XS.git] / t / bare-anon.t
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 plan skip_all => "This isn't really going to work yet, probably";
16
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 = "can't inflate weird stash entries";
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 = "can't inflate weird stash entries";
47     $anon->{baz} = -1;
48
49     is(
50         exception {
51             my $code = $stash->get_symbol('&baz');
52             is(ref($code), 'CODE');
53             like(
54                 exception { $code->() },
55                 qr/Undefined subroutine \&__ANON__::baz called/
56             );
57         },
58         undef
59     );
60 }
61
62 done_testing;