Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl: CPAN - Module modifying and adding functionality

Tags:

module

perl

cpan

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?
like image 670
gaussblurinc Avatar asked Mar 15 '26 02:03

gaussblurinc


1 Answers

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.

like image 173
brian d foy Avatar answered Mar 17 '26 18:03

brian d foy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!