don't rely on the ::PP BROKEN_ constants existing in tests
[gitmo/Package-Stash.git] / t / anon.t
CommitLineData
8642531f 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5use Test::Fatal;
6use lib 't/lib';
7
8use Test::Requires 'Package::Anon';
9
10use Package::Stash;
11use Symbol;
12
d93368f6 13plan skip_all => "Anonymous stashes in PP need at least perl 5.14"
acbc69c4 14 if $] < 5.014
ace6563d 15 && $Package::Stash::IMPLEMENTATION eq 'PP';
d93368f6 16
8642531f 17my $anon = Package::Anon->new;
18my $stash = Package::Stash->new($anon);
19my $obj = $anon->bless({});
20
21{
22 my $code = sub { 'FOO' };
23 $stash->add_symbol('&foo' => $code);
24 is($stash->get_symbol('&foo'), $code);
25 is($obj->foo, 'FOO');
26}
27
28{
29 $anon->{bar} = \123;
30
31 my $code = $stash->get_symbol('&bar');
32 is(ref($code), 'CODE');
33 is($code->(), 123);
34
35 is($obj->bar, 123);
36}
37
38{
39 $anon->{baz} = -1;
40
41 my $code = $stash->get_symbol('&baz');
42 is(ref($code), 'CODE');
43 like(
44 exception { $code->() },
45 qr/Undefined subroutine \&__ANON__::baz called/
46 );
47}
48
49done_testing;