This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
new perldelta
[perl5.git] / cpan / Scalar-List-Utils / t / reftype.t
CommitLineData
1bfb5477
GB
1#!./perl
2
b823713c
CBW
3use strict;
4use warnings;
f4a2945e 5
3630f57e 6use Test::More tests => 32;
1bfb5477 7
f4a2945e 8use Scalar::Util qw(reftype);
b823713c 9use vars qw(*F);
f4a2945e
JH
10use Symbol qw(gensym);
11
12# Ensure we do not trigger and tied methods
13tie *F, 'MyTie';
2ff28616 14my $RE = $] < 5.011 ? 'SCALAR' : 'REGEXP';
f4a2945e 15
3630f57e
CBW
16my $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
19my $t;
20my @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 35foreach 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
48package MyTie;
49
50sub TIEHANDLE { bless {} }
51sub DESTROY {}
52
53sub AUTOLOAD {
b823713c 54 our $AUTOLOAD;
f4a2945e
JH
55 warn "$AUTOLOAD called";
56 exit 1; # May be in an eval
57}