From: Rafael Garcia-Suarez Date: Thu, 3 Mar 2005 18:27:34 +0000 (+0000) Subject: Add a regression test for bug #32193, and make the X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=18592d64f2500d3ad1a9da4535c78adf607159d1;p=p5sagit%2Fp5-mst-13.2.git Add a regression test for bug #32193, and make the fix a bit more robust p4raw-id: //depot/perl@24002 --- diff --git a/lib/Tie/RefHash.pm b/lib/Tie/RefHash.pm index 3920dfd..cfcdd5b 100644 --- a/lib/Tie/RefHash.pm +++ b/lib/Tie/RefHash.pm @@ -115,7 +115,9 @@ sub STORE { sub DELETE { my($s, $k) = @_; - (ref $k) ? delete($s->[0]{overload::StrVal($k)})->[1] : delete($s->[1]{$k}); + (ref $k) + ? (delete($s->[0]{overload::StrVal($k)}) || [])->[1] + : delete($s->[1]{$k}); } sub EXISTS { diff --git a/lib/Tie/RefHash.t b/lib/Tie/RefHash.t index c0fad91..3415cec 100644 --- a/lib/Tie/RefHash.t +++ b/lib/Tie/RefHash.t @@ -23,7 +23,7 @@ BEGIN { use strict; use Tie::RefHash; use Data::Dumper; -my $numtests = 37; +my $numtests = 39; my $currtest = 1; print "1..$numtests\n"; @@ -129,6 +129,14 @@ test((keys %h)[0] eq $ref); test((keys %{$h{$ref}}) == 1); test((keys %{$h{$ref}})[0] eq $ref1); +{ + # Tests that delete returns the deleted element [perl #32193] + my $ref = \(my $var = "oink"); + tie my %oink, 'Tie::RefHash'; + $oink{$ref} = "ding"; + test($oink{$ref} eq "ding"); + test(delete($oink{$ref}) eq "ding"); +} die "expected to run $numtests tests, but ran ", $currtest - 1 if $currtest - 1 != $numtests; @@ -318,4 +326,3 @@ END return @r; } -