Upgrade to Attribute::Handlers 0.70.
[p5sagit/p5-mst-13.2.git] / t / lib / u-reftype.t
CommitLineData
f4a2945e 1BEGIN {
2 chdir 't' if -d 't';
3 @INC = '../lib';
6b05f64e 4 require Config; import Config;
5 if ($Config{extensions} !~ /\bList\/Util\b/) {
6 print "1..0 # Skip: List::Util was not built\n";
7 exit 0;
8 }
f4a2945e 9}
10
11use Scalar::Util qw(reftype);
12use vars qw($t $y $x *F);
13use Symbol qw(gensym);
14
15# Ensure we do not trigger and tied methods
16tie *F, 'MyTie';
17
18@test = (
19 [ undef, 1],
20 [ undef, 'A'],
21 [ HASH => {} ],
22 [ ARRAY => [] ],
23 [ SCALAR => \$t ],
24 [ REF => \(\$t) ],
25 [ GLOB => \*F ],
26 [ GLOB => gensym ],
27 [ CODE => sub {} ],
28# [ IO => *STDIN{IO} ] the internal sv_reftype returns UNKNOWN
29);
30
31print "1..", @test*4, "\n";
32
33my $i = 1;
34foreach $test (@test) {
35 my($type,$what) = @$test;
36 my $pack;
37 foreach $pack (undef,"ABC","0",undef) {
38 print "# $what\n";
39 my $res = reftype($what);
40 printf "# %s - %s\n", map { defined($_) ? $_ : 'undef' } $type,$res;
41 print "not " if $type ? $res ne $type : defined($res);
42 bless $what, $pack if $type && defined $pack;
43 print "ok ",$i++,"\n";
44 }
45}
46
47package MyTie;
48
49sub TIEHANDLE { bless {} }
50sub DESTROY {}
51
52sub AUTOLOAD {
53 warn "$AUTOLOAD called";
54 exit 1; # May be in an eval
55}