I find a module, that I want to change.
My problem have some features like this:
- I want to add functionality and flexibility to this module.
- Now this module solves tasks, but web-service, for what it was written, change API
- And also, I want to use code of this module.
- It is not my module
- Fix some bugs
How i should be in this situation?
- Inheriting from this module and add functionality and upload to CPAN?
- Ask author about my modifications (and reload module)?
- Something else?
There are various ways to modify a module as you use it, and I cover most of them in Mastering Perl.
- As Dave Cross mentions, send fixes upstream or become part of that project. It sounds like you have the ambition to be a significant contributor. :)
- Create a subclass to replace methods
- Override or overload subroutines or methods
- Wrap subroutines to modify or adapt either inputs or outputs (e.g. Hook::LexWrap)
- Create a locally patched version, and store it separately from the main code so it doesn't disappear in an upgrade
For example, this is something I often do directly in program code while I wait for an upstream fix:
use Some::Module; # load the original first
BEGIN {
package Some::Module;
no warnings 'redefine';
if( $VERSION > 1.23 and $VERSION < 1.45 ) {
*broken = sub { ... fixed version ... };
}
}
This way, I have the fix even if the target module is upgraded.