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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.