K
kj
OK, there's this module XYZ (say, downloaded from CPAN), that is
*almost* perfectly fits my needs. Furthermore, all it would take
to make this fit perfect amounts to changing a couple of lines of
code in some ubiquitously used internal sub, XYZ::_pesky. Assume
that, for whatever reason, this is not a change that the author of
XYZ.pm would make.
What's a programmer to do? The most expedient workaround, of
course, would be to simply copy the contents of XYZ.pm to a new
file, give it a different name, and modify this clone to my heart's
content. But this sort of cut-and-paste programming is notoriously
problematic. For one thing, it would have to be repeated everytime
XYZ.pm is updated (assuming we want to remain always at the bleeding
edge of XYZ-tude). Plus, I feel queasy about lifting a fellow
programmer's work wholesale like that. (And here I'm completely
setting aside legal issues regarding intellectual property, licensing,
etc.)
An alternative to wholesale cut-and-paste would be to redefine the
function in question in my own code:
use XYZ ':all';
{
package XYZ;
no warnings 'redefine';
sub _pesky {
# ...
}
}
This approach may be a bit less of a chore when XYZ gets updated,
but it's still prety fragile. Plus, it doesn't work so well when
the function to be redesigned needs to access lexically-scoped data
in XYZ.pm. And, even when such redefinition is workable, it goes
too far, because it changes the behavior of XYZ everywhere; if some
other module we use happens to use XYZ, such redefinition is likely
to backfire on us...
Before I go off implementing some utterly insane scheme involving
File::Slurp, s///, and eval I thought I'd ask here if there's a
halfway decent "best practice" in these situations.
TIA!
kj
*almost* perfectly fits my needs. Furthermore, all it would take
to make this fit perfect amounts to changing a couple of lines of
code in some ubiquitously used internal sub, XYZ::_pesky. Assume
that, for whatever reason, this is not a change that the author of
XYZ.pm would make.
What's a programmer to do? The most expedient workaround, of
course, would be to simply copy the contents of XYZ.pm to a new
file, give it a different name, and modify this clone to my heart's
content. But this sort of cut-and-paste programming is notoriously
problematic. For one thing, it would have to be repeated everytime
XYZ.pm is updated (assuming we want to remain always at the bleeding
edge of XYZ-tude). Plus, I feel queasy about lifting a fellow
programmer's work wholesale like that. (And here I'm completely
setting aside legal issues regarding intellectual property, licensing,
etc.)
An alternative to wholesale cut-and-paste would be to redefine the
function in question in my own code:
use XYZ ':all';
{
package XYZ;
no warnings 'redefine';
sub _pesky {
# ...
}
}
This approach may be a bit less of a chore when XYZ gets updated,
but it's still prety fragile. Plus, it doesn't work so well when
the function to be redesigned needs to access lexically-scoped data
in XYZ.pm. And, even when such redefinition is workable, it goes
too far, because it changes the behavior of XYZ everywhere; if some
other module we use happens to use XYZ, such redefinition is likely
to backfire on us...
Before I go off implementing some utterly insane scheme involving
File::Slurp, s///, and eval I thought I'd ask here if there's a
halfway decent "best practice" in these situations.
TIA!
kj