Let's say we have a CPAN module that we desperately need fixed, but the author isn't responding. How do we handle this? There seem to be several strategies.

  1. Abandon it (not always possible)
  2. Fork it (we all know the problems here)
  3. Hack it (then when a new version gets released, watch your hack break)
  4. Subclass it (might be procedural or not designed for subclassing)
  5. Override it (externally replace the functions which break)

The last method seems to have the lowest impact.

use Broken::Module; use Sub::Override; my $broken = Sub::Override->new; $broken->replace( 'Broken::Module::foo' => \&fixed_foo );

With that, you just make sure that $broken stays in scope and Broken::Module now exhibits your desired behavior. But what happens if you upgrade Broken::Module? Your override might break.

I'm thinking of a couple of strategies, but the simplest one seems to be to override a subroutine if an only if a module's version is a particular version or range I specify (the check won't be made if I don't ask for it). I'm thinking of something similar to the syntax of only.

use Broken::Module; use Sub::Override; my $override = Sub::Override->new; $override->version( 'Broken::Module' => '0.30-0.50 !0.36 0.55-'); $override->replace( 'Broken::Module::foo' => \&fixed_foo );

If the version method is called, the replace will die loudly if the version does not match. Thus, an external patch to a module will fail if that module is upgraded. This seems much safer than our current alternatives. Is this a reasonable approach or am I missing something?

Cheers,
Ovid

New address of my CGI Course.


In reply to Upgrade-proofing overridden subroutines by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.