diff options
author | Jesse Luehrs <doy@tozt.net> | 2011-11-29 14:27:30 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2011-11-29 14:27:30 -0600 |
commit | c6ddb1d1e19b3e23d64840dd62e2f9c777b5eb09 (patch) | |
tree | e9013e18959d19fc53ff7d358f8c1dc4dc2cf88b /t/bare-anon.t | |
parent | e88665a5772fd94a541366c984ecbade0b39fc95 (diff) | |
download | package-stash-c6ddb1d1e19b3e23d64840dd62e2f9c777b5eb09.tar.gz package-stash-c6ddb1d1e19b3e23d64840dd62e2f9c777b5eb09.zip |
add some tests for bare anon stashes
Diffstat (limited to 't/bare-anon.t')
-rw-r--r-- | t/bare-anon.t | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/t/bare-anon.t b/t/bare-anon.t new file mode 100644 index 0000000..3c96ec8 --- /dev/null +++ b/t/bare-anon.t @@ -0,0 +1,63 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use Test::Fatal; +use lib 't/lib'; + +use Package::Stash; +use Symbol; + +plan skip_all => "Anonymous stashes in PP need at least perl 5.14" + if Package::Stash::BROKEN_GLOB_ASSIGNMENT; + +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 = ($Package::Stash::IMPLEMENTATION eq 'PP') + ? "can't inflate weird stash entries" + : undef; + $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 = ($Package::Stash::IMPLEMENTATION eq 'PP') + ? "can't inflate weird stash entries" + : undef; + $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; |