in reply to Modifying subroutines and un-eval-ing

You might look into what Hook::LexWrap does to get its evil magic to work.

The cake is a lie.
The cake is a lie.
The cake is a lie.

  • Comment on Re: Modifying subroutines and un-eval-ing

Replies are listed 'Best First'.
Re^2: Modifying subroutines and un-eval-ing
by JadeNB (Chaplain) on Aug 06, 2009 at 17:51 UTC
    Actually, it looks to me like Hook::LexWrap might already do exactly what I want (which, of course, doesn't preclude my studying its evil ways source). The documentation is a little sparse about the scope in which the wrappers are executed, but the examples make it look like I might just pass my
    sub { BLAH }
    as a pre-wrapper to get the desired effect. Thanks so much!

    UPDATE: I've had a look at the source, and it seems that most of Hook::LexWrap's magic consists in fooling caller and installing subs in-place (a la memoize), not doing anything with lexical scope. My thoughts should probably have leapt immediately to PadWalker, though I'm not familiar enough with it to know if it'll do what I want. Binding is so so close, but it allows one to peek at bindings “the wrong way” for what I need.