From: Fergal Daly Date: Sat, 21 Jun 2003 19:02:30 +0000 (+0000) Subject: [perl #22753] overload::StrVal() fails for regexp refs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b3c0ec7c1220f243dffb147d13728e1cc44420cc;p=p5sagit%2Fp5-mst-13.2.git [perl #22753] overload::StrVal() fails for regexp refs From: "fergal@esatclear.ie (via RT)" Message-ID: p4raw-id: //depot/perl@19840 --- diff --git a/lib/overload.pm b/lib/overload.pm index 81c8598..05a3567 100644 --- a/lib/overload.pm +++ b/lib/overload.pm @@ -84,10 +84,13 @@ sub Method { sub AddrRef { my $package = ref $_[0]; return "$_[0]" unless $package; - bless $_[0], overload::Fake; # Non-overloaded package - my $str = "$_[0]"; - bless $_[0], $package; # Back - $package . substr $str, index $str, '='; + + require Scalar::Util; + my $class = Scalar::Util::blessed($_[0]); + my $class_prefix = defined($class) ? "$class=" : ""; + my $type = Scalar::Util::reftype($_[0]); + my $addr = Scalar::Util::refaddr($_[0]); + return sprintf("$class_prefix$type(0x%x)", $addr); } sub StrVal { diff --git a/lib/overload.t b/lib/overload.t index 0798a91..0aba79f 100644 --- a/lib/overload.t +++ b/lib/overload.t @@ -1085,5 +1085,7 @@ print $a->xet('b') == 42 ? "ok 225\n" : "not ok 225\n"; print defined eval { $a->{b} } ? "not ok 226\n" : "ok 226\n"; print $@ =~ /zap/ ? "ok 227\n" : "not ok 227\n"; +print overload::StrVal(qr/a/) =~ /^Regexp=SCALAR\(0x[0-9a-f]+\)$/ ? "ok 228\n" : "not ok 228\n"; + # Last test is: -sub last {227} +sub last {228}