#!/usr/bin/perl use strict; use warnings; use feature 'say'; use Path::Tiny; use File::Temp qw(tempfile); sub hotpatch { if ($_[1] eq 'AnyEvent/DNS.pm') { for my $inc (@INC) { next if ref $inc; my $fn = path($inc)->child($_[1]); if (open my $in, '<', $fn) { my ($out) = tempfile(UNLINK => 1); while (<$in>) { s/sub\s+DOMAIN_PORT\b/sub DOMAIN_PORT () { 1053 } +sub FORMER_DOMAIN_PORT/; print {$out} $_; } seek($out, 0, 0); return $out; } } warn "couldn't patch AnyEvent::DNS"; } return undef; } BEGIN { unshift @INC, \&hotpatch } use AnyEvent::DNS; BEGIN { @INC = grep not(ref and $_ eq \&hotpatch), @INC } say AnyEvent::DNS::DOMAIN_PORT(); say AnyEvent::DNS::FORMER_DOMAIN_PORT();
In reply to Re^2: How to redefine a modules private function?
by salva
in thread How to redefine a modules private function?
by sectokia
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |