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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |