perlquestion
ribasushi
Hello fellow monks,<br><br>
I have a situation in which I have a 3rd party module which exports some subroutines which I need to redefine (lets not delve into a discussion of why this is bad, etc.). Here is an example:<br><br>
<b>module.pm</b><code>
package module;
use warnings;
use strict;
use base qw/Exporter/;
our @EXPORT = qw/function/;
sub function {
print "old\n";
}
1;
</code>
<b>redefine.pm</b><code>
package redefine;
use warnings;
use strict;
no warnings qw/redefine/;
use module;
sub module::function {
print "new\n";
}
1;
</code><br>
Now unless 'use redefine' preceeds _any_ 'use module' - everything works as expected. However if I do this:<code>
use module;
use redefine;
function();
</code>
I still get 'old', because the symbol table is still referencing the first version of function().<br><br>Is there a way to truly redefine a subroutine, or the only way to do this right is to ensure redefine.pm is the very first one use()d in any circumstances?<br><br>
Thanks