in reply to Re: How to redefine a modules private function?
in thread How to redefine a modules private function?
I tried my best.
I was capable to intercept the warning, but it doesn't seem like it's even possible to redefine a constant. (or to be more precise: the once stored constant can't be changed)°
Other may have more success:
use strict; use warnings; use Data::Dump qw/pp dd/; $|=1; BEGIN { $\="\n"; my $old = $SIG{__WARN__}; $SIG{__WARN__} = sub { my ( $msg ) = @_ ; if ($msg =~ /Constant subroutine DOMAIN_PORT redefined/ ) { $SIG{__WARN__} = $old; print "REDEFINED", pp caller; package ALIEN; no warnings "redefine"; sub DOMAIN_PORT() { 666 } } } } sub ALIEN::DOMAIN_PORT() { "DUMMY" } package ALIEN; sub DOMAIN_PORT() { 53 } BEGIN { print "pre compile"; } sub test { print "Inside test: ", DOMAIN_PORT; } BEGIN { test(); print DOMAIN_PORT; }
REDEFINED("main", "d:/tmp/pm/patch_constant.pl", 42) pre compile Inside test: 53 53
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
°) not sure what is going wrong here, maybe it's a timimg issue
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: How to redefine a modules private function?
by LanX (Saint) on Mar 09, 2022 at 00:25 UTC | |
by LanX (Saint) on Mar 09, 2022 at 13:30 UTC | |
by LanX (Saint) on Mar 09, 2022 at 13:46 UTC |