From: Nicholas Clark Date: Wed, 15 Mar 2006 17:57:14 +0000 (+0000) Subject: Test for reblessing objects with weak references. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2372186ae65ad0411bfab65604891fae243522b7;p=p5sagit%2Fp5-mst-13.2.git Test for reblessing objects with weak references. p4raw-id: //depot/perl@27508 --- diff --git a/lib/overload.t b/lib/overload.t index cf553ce..b12cf27 100644 --- a/lib/overload.t +++ b/lib/overload.t @@ -47,7 +47,7 @@ sub numify { 0 + "${$_[0]}" } # Not needed, additional overhead package main; $| = 1; -use Test::More tests=>503; +use Test::More tests => 509; $a = new Oscalar "087"; @@ -1225,3 +1225,32 @@ foreach my $op (qw(<=> == != < <= > >=)) { ok(!$b, "Expect overloaded boolean"); ok(!$a, "Expect overloaded boolean"); } +{ + use Scalar::Util 'weaken'; + + package Shklitza; + use overload '""' => sub {"CLiK KLAK"}; + + package Ksshfwoom; + use overload '""' => sub {"OOOKK AWK"}; + + package main; + + my ($obj, $ref); + $obj = bless do {my $a; \$a}, 'Shklitza'; + $ref = $obj; + + is ($obj, "CLiK KLAK"); + is ($ref, "CLiK KLAK"); + + weaken $ref; + is ($ref, "CLiK KLAK"); + + bless $obj, 'Ksshfwoom'; + + is ($obj, "OOOKK AWK"); + is ($ref, "OOOKK AWK"); + + undef $obj; + is ($ref, undef); +}