diff options
author | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2005-03-03 18:27:34 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2005-03-03 18:27:34 +0000 |
commit | 18592d64f2500d3ad1a9da4535c78adf607159d1 (patch) | |
tree | bad8ba86a26c5157ea2c9172fe59008a335ea5be /lib/Tie | |
parent | 296b60dd8987f12ccbda0d2499a3bcf09b3ab304 (diff) | |
download | perl-18592d64f2500d3ad1a9da4535c78adf607159d1.tar.gz |
Add a regression test for bug #32193, and make the
fix a bit more robust
p4raw-id: //depot/perl@24002
Diffstat (limited to 'lib/Tie')
-rw-r--r-- | lib/Tie/RefHash.pm | 4 | ||||
-rw-r--r-- | lib/Tie/RefHash.t | 11 |
2 files changed, 12 insertions, 3 deletions
diff --git a/lib/Tie/RefHash.pm b/lib/Tie/RefHash.pm index 3920dfd2da..cfcdd5b5a1 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 c0fad915f7..3415cecef1 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; } - |