Perl 上的 Monkey Patch

這整個週末都在跟 Net::DNS 奮戰 edns-client-subnet,遇到模組內的一小段程式有 bug,先用 monkey patch 硬上,之後再看看要怎麼丟 patch 回 upstream。

monkey patch 的方法主要是參考「How can I monkey-patch an instance method in Perl?」這邊提供的方法而來的。

由於實際的行為是 subroutine redefined (會產生警告訊息),所以要局部關掉 warnings,然後再把整個 subroutine 換掉:

use BugPackage;

    no warnings;
    local *BugPackage::bug_function = sub {
        # new code


This entry was posted in Computer, DNS, Murmuring, Network, Programming and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *