in reply to Altering subroutine parameters using Hook::LexWrap
Sorry for the false start. I encountered the problem when I played with it last year, and forgot how I got around it.
I 'fixed' it, by patching 3 lines/ 3 chars in the module:
use strict; use Hook::LexWrap; =comment With Hook::LexWrap patched as follows: 39: () = $wrapper{pre}->( \@_,$return) if $wrapper{pre}; 49: my $dummy = $wrapper{pre}->( \@_, $return) if $wrapper{ +pre}; 59: $wrapper{pre}->( \@_, $return) if $wrapper{pre}; =cut sub some_sub{ print "Got: @_\n"; print "Context: ", defined wantarray ? wantarray ? 'LIST' : 'SCALAR' : 'VOID', "\n"; } sub before{ # inject a new arg unshift @{ $_[ 0 ] }, 'new arg'; } wrap some_sub, pre => \&before; my @a = some_sub(1,2,3); my $a = some_sub(1,2,3); some_sub(1,2,3); __END__ P:\test>junk4.pl Got: new arg 1 2 3 Context: LIST Got: new arg 1 2 3 Context: SCALAR Got: new arg 1 2 3 Context: VOID
The caveat is that your wrappers have to expect a reference to @_ and deal with that. Not a major problem, if you need to make modifications.
|
|---|