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