From: Hugo van der Sanden Date: Tue, 8 Aug 2000 03:02:03 +0000 (+0100) Subject: Augment #6539 a bit: don't croak if there's magic in the air. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=016a42f39635e4e96555aee41f820c77d820b582;p=p5sagit%2Fp5-mst-13.2.git Augment #6539 a bit: don't croak if there's magic in the air. Subject: Re: [PATCH bleadperl-6530] bless, REF, and bless(REF, REF) Message-Id: <200008080202.DAA09147@crypt.compulink.co.uk> p4raw-id: //depot/perl@6545 --- diff --git a/pp.c b/pp.c index c6bb0a5..5371f31 100644 --- a/pp.c +++ b/pp.c @@ -563,9 +563,7 @@ PP(pp_bless) STRLEN len; char *ptr; - if (ssv && SvGMAGICAL(ssv)) - mg_get(ssv); - if (SvROK(ssv)) + if (ssv && !SvGMAGICAL(ssv) && !SvAMAGIC(ssv) && SvROK(ssv)) Perl_croak(aTHX_ "Attempt to bless into a reference"); ptr = SvPV(ssv,len); if (ckWARN(WARN_MISC) && len == 0) diff --git a/t/op/bless.t b/t/op/bless.t index ccabcb8..46bf6c3 100644 --- a/t/op/bless.t +++ b/t/op/bless.t @@ -1,6 +1,6 @@ #!./perl -print "1..29\n"; +print "1..31\n"; BEGIN { chdir 't' if -d 't'; @@ -28,7 +28,7 @@ $b1 = bless [], "B"; print expected($b1, "B", "ARRAY"), "ok 2\n"; $c1 = bless \(map "$_", "test"), "C"; print expected($c1, "C", "SCALAR"), "ok 3\n"; -$test = "foo"; $d1 = bless \*test, "D"; +our $test = "foo"; $d1 = bless \*test, "D"; print expected($d1, "D", "GLOB"), "ok 4\n"; $e1 = bless sub { 1 }, "E"; print expected($e1, "E", "CODE"), "ok 5\n"; @@ -44,7 +44,7 @@ print expected($a1, "A", "HASH"), "ok 9\n"; # reblessing does modify object -my $a2 = bless $a1, "A2"; +bless $a1, "A2"; print expected($a1, "A2", "HASH"), "ok 10\n"; # local and my @@ -52,7 +52,7 @@ print expected($a1, "A2", "HASH"), "ok 10\n"; local $a1 = bless $a1, "A3"; # should rebless outer $a1 local $b1 = bless [], "B3"; my $c1 = bless $c1, "C3"; # should rebless outer $c1 - $test2 = ""; my $d1 = bless \*test2, "D3"; + our $test2 = ""; my $d1 = bless \*test2, "D3"; print expected($a1, "A3", "HASH"), "ok 11\n"; print expected($b1, "B3", "ARRAY"), "ok 12\n"; print expected($c1, "C3", "SCALAR"), "ok 13\n"; @@ -115,3 +115,13 @@ print expected(bless([]), 'main', "ARRAY"), "ok 22\n"; $a1 = bless {}, "A4"; $b1 = eval { bless {}, $a1 }; print $@ ? "ok 29\n" : "not ok 29\t# $b1\n"; + +# class is an overloaded ref +{ + package H4; + use overload '""' => sub { "C4" }; +} +$h1 = bless {}, "H4"; +$c4 = eval { bless \$test, $h1 }; +print expected($c4, 'C4', "SCALAR"), "ok 30\n"; +print $@ ? "not ok 31\t# $@" : "ok 31\n";