Perl:CPAN-模块修改和添加功能 [英] Perl: CPAN - Module modifying and adding functionality
本文介绍了Perl:CPAN-模块修改和添加功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找到了要更改的模块。
I find a module, that I want to change.
我的问题有以下特征:
- 我要向该模块添加功能和灵活性。
- 现在,该模块可以解决任务,但是网络服务(针对其编写的内容)可以更改API
- 而且,我想使用此模块的代码。
- 这不是我的模块不是
- 修复一些错误
- 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?
- 要继承此模块并添加功能并上传到CPAN吗?
- 问作者我的修改(和重新加载模块)吗?
- 还有什么?
推荐答案
在使用模块时,有很多种修改模块的方法,我将介绍大部分其中的精通Perl 。
There are various ways to modify a module as you use it, and I cover most of them in Mastering Perl.
- 戴夫·克罗斯提到 ,向上游发送修复程序或成为该项目的一部分。听起来您有成为重要贡献者的雄心。 :)
- 创建一个子类来替换方法
- 覆盖或重载子例程或方法
- 将子例程包装为修改或调整输入或输出(例如 Hook :: LexWrap )
- 创建本地修补版本,并将其与主代码分开存储,这样它就不会在升级中消失
- 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.
这篇关于Perl:CPAN-模块修改和添加功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文