This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #71998] overload::Method can die with blessed methods
authorFather Chrysostomos <sprout@cpan.org>
Tue, 28 Sep 2010 20:53:51 +0000 (13:53 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 28 Sep 2010 20:53:51 +0000 (13:53 -0700)
If an overload method is itself blessed into a class that has
overloaded operators but does not have fallback enabled, then an error
is produced:

$ perl5.10.0
use overload '+' => sub{};
bless overload::Method main => '+';
overload::Method main => '+';
^D
Operation "ne": no method found,
left argument in overloaded package main,
right argument has no overloaded magic at /usr/local/lib/perl5/5.10.0/
overload.pm line 59.

The attached patch fixes this.

lib/overload.pm
lib/overload.t
pod/perldelta.pod

index 7d09d69..31c88b7 100644 (file)
@@ -1,6 +1,6 @@
 package overload;
 
-our $VERSION = '1.10';
+our $VERSION = '1.11';
 
 sub nil {}
 
@@ -57,7 +57,9 @@ sub ov_method {
   my $globref = shift;
   return undef unless $globref;
   my $sub = \&{*$globref};
-  return $sub if $sub ne \&nil;
+  require Scalar::Util;
+  return $sub
+    if Scalar::Util::refaddr($sub) != Scalar::Util::refaddr(\&nil);
   return shift->can($ {*$globref});
 }
 
index 417c1cb..ef65ea5 100644 (file)
@@ -48,7 +48,7 @@ package main;
 
 $| = 1;
 BEGIN { require './test.pl' }
-plan tests => 4881;
+plan tests => 4882;
 
 use Scalar::Util qw(tainted);
 
@@ -1999,4 +1999,12 @@ fresh_perl_is
  'use overload from the main package'
 ;
 
+{
+    package blessed_methods;
+    use overload '+' => sub {};
+    bless overload::Method __PACKAGE__,'+';
+    eval { overload::Method __PACKAGE__,'+' };
+    ::is($@, '', 'overload::Method and blessed overload methods');
+}
+
 # EOF
index a1430ad..73a90d2 100644 (file)
@@ -244,6 +244,14 @@ C<NEXT> has been upgraded from version 0.64 to 0.65.
 
 =item *
 
+C<overload> has been upgraded from version 1.10 to 1.11.
+
+C<overload::Method> can now handle subroutines that are themselves blessed
+into overloaded classes
+L<[perl #71998]|http://rt.perl.org/rt3//Public/Bug/Display.html?id=71998>.
+
+=item *
+
 C<PathTools> has been upgraded from version 3.31_01 to 3.33.
 
 =item *