in reply to Re^2: Packages with subs using fully qualified class names, not always their own. (monkey patch)
in thread Packages with subs using fully qualified class names, not always their own.
Simplified something like
sub my_func { local *OtherPackage::routine = sub { ... } # now use OtherPackage }
local will assure that the old code is restored when the scope is left and you have to keep full control over the code inside the scope.
This is not 100% safe because an exception could occur in the middle and a SIG handler could theoretically use OtherPackage.
in my case this is pretty impossible, but to be safe you could additionally check caller inside the patched routine.
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
|
|---|