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:
Even so, it's easier to understand than the nested-subroutines solution.sub localize { my $real = pop; no strict 'refs'; goto CALL unless @_; AGAIN: local *{shift@_} = sub { 'changed' }; goto AGAIN if @_; CALL: $real->(); }
I wonder if anybody out there has got something even simpler.
Tom Moertel : Blog / Talks / CPAN / LectroTest / PXSL / Coffee / Movie Rating Decoder
In Section
Meditations