| Next | Hook::LexWrap | 6 |
my %cache;
wrap 'myfunction',
pre => sub { $_[-1] = $cache{$_[0]} if defined $cache{$_[0]} },
post => sub { $cache{$_[0]} = $_[-1] };
The regular function arguments are passed to the wrappers
An extra argument is appended to the end of @_
It contains the function's return value
Assigning to $_[-1] overwrites the return value
If you do this in a prewrapper, the original function is never called at all
| Next | ![]() |
Copyright © 2003 M. J. Dominus |