this is only going to work on 5.14
[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"
14 if Package::Stash::BROKEN_GLOB_ASSIGNMENT;
15
8642531f 16my $anon = Package::Anon->new;
17my $stash = Package::Stash->new($anon);
18my $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 $anon->{bar} = \123;
29
30 my $code = $stash->get_symbol('&bar');
31 is(ref($code), 'CODE');
32 is($code->(), 123);
33
34 is($obj->bar, 123);
35}
36
37{
38 $anon->{baz} = -1;
39
40 my $code = $stash->get_symbol('&baz');
41 is(ref($code), 'CODE');
42 like(
43 exception { $code->() },
44 qr/Undefined subroutine \&__ANON__::baz called/
45 );
46}
47
48done_testing;