That can fail with overloaded objects, thus forcing one back to reimplementing refaddr
#!/usr/bin/perl
use strict;
use warnings;
{
package Foo;
use overload '+' => sub { 'oops' };
sub new { bless {}, shift }
}
my $foo = Foo->new;
print 0+$foo;
| [reply] [d/l] |
Duh. I don't see that as a big problem, frankly.
My solution gets your module available from ActiveState as a PPM download (likely). Then for those who haven't learned the lesson of ETOOMUCHMAGIC and not only insist on using aliased.pm and overload.pm but using them together need only make sure they have a new enough Scalar::Util and everything works.
Yes, it'd be nice if you could encode into the automation tools "Require Scalar::Util, but if you use overload.pm on your aliased module, then require version X of it".
An improved version of my fix is:
package aliased;
BEGIN {
eval { require Scalar::Util };
if( defined &Scalar::Util::refaddr ) {
*refaddr= \&Scalar::Util::refaddr;
} else {
eval { require overload };
if( defined &overload::Overloaded ) {
*refaddr= sub {
if( overload::Overloaded( $_[0] ) ) {
require Carp;
Carp::confess( "Upgrade Scalar::Util ..." );
}
return 0+$_[0];
};
} else {
*refaddr= sub { 0+$_[0] };
}
}
}
...
| [reply] [d/l] |
| [reply] |