in reply to Altering subroutine parameters using Hook::LexWrap

Update: As tye points out below, I was wrong.

You have to return a reference to the modifed @_ from the pre wrapper sub, if you want that to be passed to the original sub.

use strict; use Hook::LexWrap; sub some_sub{ print "@_"; } sub before{ # inject a new arg unshift @_, 'new arg'; return \@_; } wrap some_sub, pre => \&before; some_sub(1,2,3);

Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.

Replies are listed 'Best First'.
Re^2: Altering subroutine parameters using Hook::LexWrap (nope)
by tye (Sage) on Jan 19, 2005 at 03:51 UTC

    This produces "1 2 3" for me using Hook-LexWrap-0.20. (That is, it doesn't work.)

    - tye