http://qs321.pair.com?node_id=535919


in reply to A general method of locally overriding subroutines

Are the functions to be overridden all in the same package? If they are, you can do the localisation with a single hash slice:

sub localise_and_call { my($fn, @args) = @_; my $stash = \%::; # assuming main package # I forgot the local here @$stash{@args} = (sub { "changed" }) x @args; $fn->(@args); }

Update: oops, doesn't work when I add the "local" where it's supposed to go. I'm not sure why not though, maybe a bug.

Update: now reported as bug #38710.

Hugo