Dear Monks,
I have several scripts that I would like to be able to run on a variety of systems where I don't control the main installation directories. In particular, one of them is a perl 5.8.0 where the List::Util version is "1.07_00" and therefore refaddr is missing.
I tried creating my own override of the whole List::Util package, but the XS part was not portable to all systems.
Instead, to fill in the missing function, I created the following module:
package PatchPackages;
use strict;
use version; our $VERSION = qv/0.0.1/;
sub import {
require Scalar::Util;
if (! Scalar::Util->can('refaddr')) {
# Copied from more recent Scalar::Util code.
# Makes up for this function being missing on some
# of our 5.8.0 installations.
*Scalar::Util::refaddr =
sub ($) {
my $pkg = ref($_[0]) or return undef;
if (Scalar::Util::blessed($_[0])) {
bless $_[0], 'Scalar::Util::Fake';
}
else {
$pkg = undef;
}
"$_[0]" =~ /0x(\w+)/;
my $i = do { local $^W; hex $1 };
bless $_[0], $pkg if defined $pkg;
$i;
}
}
}
1;
This seems a little messy, but it works. Does anyone know of a cleaner way to do this?