Commit | Line | Data |
---|---|---|
1bfb5477 GB |
1 | #!./perl |
2 | ||
b823713c CBW |
3 | use strict; |
4 | use warnings; | |
f4a2945e | 5 | |
3630f57e | 6 | use Test::More tests => 32; |
1bfb5477 | 7 | |
f4a2945e | 8 | use Scalar::Util qw(reftype); |
b823713c | 9 | use vars qw(*F); |
f4a2945e JH |
10 | use Symbol qw(gensym); |
11 | ||
12 | # Ensure we do not trigger and tied methods | |
13 | tie *F, 'MyTie'; | |
2ff28616 | 14 | my $RE = $] < 5.011 ? 'SCALAR' : 'REGEXP'; |
f4a2945e | 15 | |
3630f57e CBW |
16 | my $s = []; # SvTYPE($s) is SVt_RV, and SvROK($s) is true |
17 | $s = undef; # SvTYPE($s) is SVt_RV, but SvROK($s) is false | |
18 | ||
b823713c CBW |
19 | my $t; |
20 | my @test = ( | |
cac6698e S |
21 | [ undef, 1, 'number' ], |
22 | [ undef, 'A', 'string' ], | |
23 | [ HASH => {}, 'HASH ref' ], | |
24 | [ ARRAY => [], 'ARRAY ref' ], | |
25 | [ SCALAR => \$t, 'SCALAR ref' ], | |
26 | [ SCALAR => \$s, 'SCALAR ref (but SVt_RV)' ], | |
27 | [ REF => \(\$t), 'REF ref' ], | |
28 | [ GLOB => \*F, 'tied GLOB ref' ], | |
29 | [ GLOB => gensym, 'GLOB ref' ], | |
30 | [ CODE => sub {}, 'CODE ref' ], | |
31 | [ IO => *STDIN{IO}, 'IO ref' ], | |
32 | [ $RE => qr/x/, 'REGEEXP' ], | |
f4a2945e JH |
33 | ); |
34 | ||
b823713c | 35 | foreach my $test (@test) { |
cf083cf9 GB |
36 | my($type,$what, $n) = @$test; |
37 | ||
38 | is( reftype($what), $type, $n); | |
39 | next unless ref($what); | |
40 | ||
41 | bless $what, "ABC"; | |
42 | is( reftype($what), $type, $n); | |
43 | ||
44 | bless $what, "0"; | |
45 | is( reftype($what), $type, $n); | |
f4a2945e JH |
46 | } |
47 | ||
48 | package MyTie; | |
49 | ||
50 | sub TIEHANDLE { bless {} } | |
51 | sub DESTROY {} | |
52 | ||
53 | sub AUTOLOAD { | |
b823713c | 54 | our $AUTOLOAD; |
f4a2945e JH |
55 | warn "$AUTOLOAD called"; |
56 | exit 1; # May be in an eval | |
57 | } |