Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Saturday December 02, 2006
05:56 AM

Working around a lack of Scalar::Util::refaddr with AS Perl

[ #31786 ]

I was all ready to use the following bit of code in one of my modules to let it build properly with ActivePerl:

use Scalar::Util;

BEGIN {
    if ( defined &Scalar::Util::refaddr ) {
        *_ident = \&Scalar::Util::refaddr;
    }
    else {
        require overload;
        *_ident = sub {
            my ( $object ) = @_;
            if ( overload::Method($object, '""') ) {
                croak "Overloaded stringification requires &Scalar::Util::refaddr (version 1.08 or greater)";
            }
            return "$object";
        };
    }
}

Then I double-checked and saw that refaddr is a pure Perl function. Regrettably, I copied it into my code:

sub _refaddr($) {
    my $pkg = ref( $_[0] ) or return undef;
    if ( blessed( $_[0] ) ) {
        bless $_[0], 'Class::BuildMethods::Fake';
    }
    else {
        $pkg = undef;
    }
    "$_[0]" =~ /0x(\w+)/;
    my $i = do { local $^W; hex $1 };
    bless $_[0], $pkg if defined $pkg;
    $i;
}

This raises an interesting, but ugly, question. What about a module which provides functionality which core modules have, but only in upgraded versions which AS does not provide? For example:

use Module::Substitute
    'Scalar::Util' => [qw/refaddr openhandle/];

That's a terrible name, but this would be something designed to not go into core, thus allowing people to use these extra functions if they want to build on ActiveState. I really hate the idea of duplicating this code, but this might be a way to get around some of the AS build problems.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • One of the problems that might happen with a Module::Substitute is that implementation for THAT gets as bad as for others.

    I'd like to see special-purpose single function modules.

    i.e. Scalar::Refaddr etc etc