Re: How best to "fix" a bug in a standard module?



kj <socyl@xxxxxxxxxxxxxxxxx> wrote in comp.lang.perl.misc:



I frequently run into minor bugs in modules downloaded from CPAN.
Aside from the issue of reporting the bug to the modules' maintainers,
there's still the immediate problem of fixing the bug for our own
use.

AFAIC, it is out of the question to replace the installed module
with one I have fixed.

Why?

Therefore I have settled on just redefining
the buggy sub(s) in the calling code. For example, CGI::Carp::die
does not behave like CORE::die with respect to $@. To correct
this, I have this snippet at the beginning of my CGI script:

BEGIN {
no warnings 'redefine';
my $ccdie = \&CGI::Carp::die;
sub CGI::Carp::die {
@_ = $@ if !@_ and $@;
goto &$ccdie;
}
}

This seems to work fine, but somehow I'm not entirely comfortable
with doing something like this. What pitfalls am I overlooking?

I don't see any pitfalls. Under normal circumstances your approach
should work.

Is there a better approach?

I think there is. Use your own Perl library (~/lib/perl5/, for
instance), and make it known via $ENV{ PERL5LIB} or "use lib ...".
Then copy the broken module(s) to (an appropriate subdir of) your
lib and fix it there. Then send the author the diff. As they
say, "Patches speak louder than words".

If you want to be an even better member of the open source community,
add tests to the distributions .../t directory that discover the
behavior you have corrected, and also make sure that your fix
doesn't break any of the existing tests.

Anno
.



Relevant Pages

  • Re: HELP! RECENTLY ADDED ISSUES!
    ... Note that reporting a bug is useless without repro steps. ... largely precludes any advancement towards a fix at any point ever. ...
    (microsoft.public.windowsmedia.player)
  • Re: 2.6.18-rc6-mm2
    ... Will fix later. ... This kernel includes the patch to sort the PCI devices breadth-first. ... If you hit a bug in -mm and it is not obvious which patch caused it, ... When reporting bugs, please try to Cc: ...
    (Linux-Kernel)
  • please pull from the trivial tree
    ... Fix spelling in E1000_DISABLE_PACKET_SPLIT Kconfig description ... +- Finding patch that caused a bug ... +Always try the latest kernel from kernel.org and build from source. ... Length of input string in bytes ...
    (Linux-Kernel)
  • Subterrane v0.194 Alpha Released
    ... system, a character sheet, a ton of new spells, new monsters, item ... Added a character sheet that displays your character's ... Fix: Fixed a bug in the encumbrance calculation and status display ...
    (rec.games.roguelike.announce)
  • 2.6.18-rc6-mm2
    ... Will fix later. ... See the `hot-fixes' directory for any important updates to this patchset. ... If you hit a bug in -mm and it is not obvious which patch caused it, ... When reporting bugs, please try to Cc: ...
    (Linux-Kernel)