Is it possible to redefine the _function_used_by_exported_function
only for the exported_function
call in the second_routine
?
#!/usr/bin/env perl
use warnings;
use strict;
use Needed::Module qw(exported_function);
sub first_routine {
return exported_function( 2 );
}
no warnings 'redefine';
sub Needed::Module::_function_used_by_exported_function {
return 'B';
}
sub second_routine {
return exported_function( 5 );
}
say first_routine();
say second_routine();
You can locally redefine the
sub _function_used_by_exported_function
inside yoursub second_routine
.I lifted the typeglob assignment inside
sub second_routine
from brian d foy's Mastering Perl, Chapter 10 on page 161. The sub is redefined by assigning to the typeglob, which only replaces the coderef part of it. I uselocal
to only do that inside the current block. That way, the outside world is not affected by the change, as you can see in the output.