summaryrefslogtreecommitdiff
path: root/cpan/Test-Simple/t/Test-Stream-PackageUtil.t
blob: 76d80d87ed99eee608d7a16b9ba568615b142f83 (plain)
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
use strict;
use warnings;

use Test::Stream;
use Test::More;

use ok 'Test::Stream::PackageUtil';

can_ok(__PACKAGE__, qw/package_sym package_purge_sym/);

my $ok = package_sym(__PACKAGE__, CODE => 'ok');
is($ok, \&ok, "package sym gave us the code symbol");

my $todo = package_sym(__PACKAGE__, SCALAR => 'TODO');
is($todo, \$TODO, "got the TODO scalar");

our $foo = 'foo';
our @foo = ('f', 'o', 'o');
our %foo = (f => 'oo');
sub foo { 'foo' };

is(foo(), 'foo', "foo() is defined");
is($foo, 'foo', '$foo is defined');
is_deeply(\@foo, [ 'f', 'o', 'o' ], '@foo is defined');
is_deeply(\%foo, { f => 'oo' }, '%foo is defined');

package_purge_sym(__PACKAGE__, CODE => 'foo');

is($foo, 'foo', '$foo is still defined');
is_deeply(\@foo, [ 'f', 'o', 'o' ], '@foo is still defined');
is_deeply(\%foo, { f => 'oo' }, '%foo is still defined');
my $r = eval { __PACKAGE__->foo() };
my $e = $@;
ok(!$r, "Failed to call foo()");
like($e, qr/Can't locate object method "foo" via package "main"/, "foo() is not defined anymore");
ok(!__PACKAGE__->can('foo'), "can() no longer thinks we can do foo()");

done_testing;