summaryrefslogtreecommitdiffstats
path: root/t/bare-anon.t
blob: f42dce8e0473a4628a476bdbedc4afd75af3c166 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use lib 't/lib';

use Package::Stash;

BEGIN {
    plan skip_all => "Anonymous stashes in PP need at least perl 5.14"
        if $] < 5.014
        && $Package::Stash::IMPLEMENTATION eq 'PP';

    plan skip_all => "This isn't really going to work yet, probably";
}

use Symbol;

my $anon = {};
my $stash = Package::Stash->new($anon);
# no way to bless something into a hashref yet
# my $obj = $anon->bless({});

{
    my $code = sub { 'FOO' };
    $stash->add_symbol('&foo' => $code);
    is($stash->get_symbol('&foo'), $code);
    # is($obj->foo, 'FOO');
}

{
    local $TODO = "can't inflate weird stash entries";
    $anon->{bar} = \123;

    is(
        exception {
            my $code = $stash->get_symbol('&bar');
            is(ref($code), 'CODE');
            is($code->(), 123);

            # is($obj->bar, 123);
        },
        undef
    );
}

{
    local $TODO = "can't inflate weird stash entries";
    $anon->{baz} = -1;

    is(
        exception {
            my $code = $stash->get_symbol('&baz');
            is(ref($code), 'CODE');
            like(
                exception { $code->() },
                qr/Undefined subroutine \&__ANON__::baz called/
            );
        },
        undef
    );
}

done_testing;