10 use open qw( :utf8 :std );
14 my($object, $package, $type) = @_;
15 print "# $object $package $type\n";
16 is(ref($object), $package);
17 my $r = qr/^\Q$package\E=(\w+)\(0x([0-9a-f]+)\)$/u;
19 if ("$object" =~ $r) {
21 # in 64-bit platforms hex warns for 32+ -bit values
22 cmp_ok(do {no warnings 'portable'; hex($2)}, '==', $object);
29 # test blessing simple types
32 expected($a1, "ዐ", "HASH");
34 expected($b1, "B", "ARRAY");
35 $c1 = bless \(map "$_", "test"), "ᶜ";
36 expected($c1, "ᶜ", "SCALAR");
37 $tèst = "foo"; $d1 = bless \*tèst, "ɖ";
38 expected($d1, "ɖ", "GLOB");
39 $e1 = bless sub { 1 }, "ಎ";
40 expected($e1, "ಎ", "CODE");
42 expected($f1, "ḟ", "REF");
43 $g1 = bless \substr("test", 1, 2), "ㄍ";
44 expected($g1, "ㄍ", "LVALUE");
46 # blessing ref to object doesn't modify object
48 expected(bless(\$a1, "ḟ"), "ḟ", "REF");
49 expected($a1, "ዐ", "HASH");
51 # reblessing does modify object
54 expected($a1, "ዐ2", "HASH");
58 local $a1 = bless $a1, "ዐ3"; # should rebless outer $a1
59 local $b1 = bless [], "B3";
60 my $c1 = bless $c1, "ᶜ3"; # should rebless outer $c1
61 our $test2 = ""; my $d1 = bless \*test2, "ɖ3";
62 expected($a1, "ዐ3", "HASH");
63 expected($b1, "B3", "ARRAY");
64 expected($c1, "ᶜ3", "SCALAR");
65 expected($d1, "ɖ3", "GLOB");
67 expected($a1, "ዐ3", "HASH");
68 expected($b1, "B", "ARRAY");
69 expected($c1, "ᶜ3", "SCALAR");
70 expected($d1, "ɖ", "GLOB");
74 expected(bless({}, $1), "ಎ", "HASH");
78 $! = 2; # attempt to avoid cached string
80 expected(bless({}, $!), $string, "HASH");
86 sub test { main::is(${$_[0]}, $string) }
99 $b1 = eval { bless {}, $a1 };
100 isnt ($@, '', "class is a ref");
102 # class is an overloaded ref
104 $TODO = "Package not yet clean";
107 use overload '""' => sub { "ᶜ4" };
109 $h1 = bless {}, "ᚺ4";
110 $c4 = eval { bless \$test, $h1 };
111 is ($@, '', "class is an overloaded ref");
112 expected($c4, 'ᶜ4', "SCALAR");
122 my $a = bless \(keys %h), 'zàp';