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


in reply to Re: A general method of locally overriding subroutines
in thread A general method of locally overriding subroutines

Clever. It just needs one more goto to handle the empty case (no overrides) gracefully:
sub localize { my $real = pop; no strict 'refs'; goto CALL unless @_; AGAIN: local *{shift@_} = sub { 'changed' }; goto AGAIN if @_; CALL: $real->(); }
Even so, it's easier to understand than the nested-subroutines solution.

I wonder if anybody out there has got something even simpler.