don't rely on the ::PP BROKEN_ constants existing in tests
[gitmo/Package-Stash.git] / t / bare-anon.t
CommitLineData
c6ddb1d1 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5use Test::Fatal;
6use lib 't/lib';
7
8use Package::Stash;
9use Symbol;
10
11plan 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
15my $anon = {};
16my $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
64done_testing;