1use strict; 2use warnings; 3use lib 't/lib'; 4use Test::More; 5use Test::Fatal; 6 7{ 8 package Foo; 9 open *foo, "<", $0; 10 11 sub foo { } 12} 13 14{ 15 package Bar; 16 open *bar, "<", $0; 17 18 sub bar { } 19} 20 21use Package::Stash; 22 23{ 24 my $stash = Package::Stash->new('Foo'); 25 ok($stash->has_symbol('&foo'), "has &foo"); 26 ok($stash->has_symbol('foo'), "has foo"); 27 $stash->remove_symbol('&foo'); 28 ok(!$stash->has_symbol('&foo'), "has &foo"); 29 ok($stash->has_symbol('foo'), "has foo"); 30} 31 32{ 33 my $stash = Package::Stash->new('Bar'); 34 ok($stash->has_symbol('&bar'), "has &bar"); 35 ok($stash->has_symbol('bar'), "has bar"); 36 $stash->remove_symbol('bar'); 37 ok($stash->has_symbol('&bar'), "has &bar"); 38 ok(!$stash->has_symbol('bar'), "has bar"); 39} 40 41{ 42 my $stash = Package::Stash->new('Baz'); 43 is(exception { 44 $stash->add_symbol('baz', *Foo::foo{IO}); 45 }, undef, "can add an IO symbol"); 46 ok($stash->has_symbol('baz'), "has baz"); 47 is($stash->get_symbol('baz'), *Foo::foo{IO}, "got the right baz"); 48} 49 50done_testing; 51