Can just use the fully qualified name to overwrite the sub.
Unfortunately not - the change is visible within your script, but not within the module.
Foo.pm
package Foo; use warnings; use strict; sub ONE () { 111 } sub TWO { 222 } my $three = 333; sub THREE () { $three } sub go { print "One=", ONE, ", Two=", TWO, ", Three=", THREE, "\n"; } 1;
test.pl
use warnings; use strict; use lib '.'; use Foo; #BEGIN { #*Foo::ONE = sub () { 444 }; #*Foo::TWO = sub { 555 }; #*Foo::THREE = sub () { 666 }; sub Foo::ONE () { 444 } sub Foo::TWO { 555 } sub Foo::THREE () { 666 } #} Foo::go; print "One=", Foo::ONE, ", Two=", Foo::TWO, ", Three=", Foo::THREE, "\ +n";
See also perl -MO=Deparse Foo.pm.
In reply to Re^2: How to redefine a modules private function?
by haukex
in thread How to redefine a modules private function?
by sectokia
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |