-
Notifications
You must be signed in to change notification settings - Fork 6
/
05_get_stash.t
executable file
·52 lines (38 loc) · 1.25 KB
/
05_get_stash.t
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
#!perl -w
# get_stash(), is_invocant(), invocant()
use strict;
use warnings FATAL => 'all';
use Test::More tests => 40;
use Test::Exception;
use Tie::Scalar;
use Scalar::Util qw(blessed);
use Data::Util qw(:all);
#diag 'Testing ', $INC{'Data/Util/PurePerl.pm'} ? 'PurePerl' : 'XS';
sub get_stash_pp{
my($pkg) = @_;
no strict 'refs';
if(blessed $pkg){
$pkg = ref $pkg;
}
return \%{$pkg . '::'};
}
foreach my $pkg( qw(main strict Data::Util ::main::Data::Util), bless{}, 'Foo'){
is get_stash($pkg), get_stash_pp($pkg), sprintf 'get_stash(%s)', neat $pkg;
ok is_invocant($pkg), 'is_invocant()';
ok invocant($pkg)->isa('UNIVERSAL'), 'invocant()';
}
foreach my $pkg('not_exists', '', 1, undef, [], *ok){
ok !defined(get_stash $pkg), 'get_stash for ' . neat($pkg) . '(invalid value)';
ok !is_invocant($pkg), '!is_invocant()';
throws_ok{
invocant($pkg);
} qr/Validation failed/, 'invocant() throws fatal error';
}
my $x = tie my($ts), 'Tie::StdScalar', 'main';
is get_stash($ts), get_stash_pp('main'), 'for magic variable';
ok is_invocant($ts);
ok invocant($ts);
ok is_invocant($x), 'is_invocant() for an object';
is invocant($x), $x, 'invocant() for an object';
is invocant('::Data::Util'), 'Data::Util';
is invocant('main::Data::Util'), 'Data::Util';