in reply to Re: Working Around Missing Modules (KISS)
in thread Working Around Missing Modules

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;

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^3: Working Around Missing Modules (KISS)
by tye (Sage) on Dec 02, 2006 at 15:36 UTC

    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] }; } } } ...

    - tye        

      Duh. I don't see that as a big problem, frankly.

      Might I suggest the use of Acme::UNIVERSAL::new then? It works in some cases and fails in some known cases, but I suppose the latter is fine.