Skip Menu |

This queue is for tickets about the Hook-LexWrap CPAN distribution.

Report information
The Basics
Id: 64498
Status: new
Priority: 0/
Queue: Hook-LexWrap

People
Owner: Nobody in particular
Requestors: grousse [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.24
Fixed in: (no value)



Subject: H::L should provide a way to access wrapped function directly from the wrappers
Hello. I've been using a pre-handler hook to transparently rewrite arguments list of a function (basically, turning command => 'foo' to 'file' => 'bar'). However, @_ values can't be affected directly: $_[$i] = 'file'; trigger this error message unexpected error: Modification of a read-only value attempted at t/FusionInventory/Test/MockSystem.pm line 35 Using splice instead doesn't trigger any error message, but isn't functional either, as the wrapped function is called with original arguments list The solution I've found has been to call the original function from the wrapper directly, and insert the result in $_[-1] to short-circuit original call. However, I had to retrieve the reference to the original function myself: my $original = \&{'function'}; wrap 'function', pre => sub { ... # short-circuit original call by calling function directly with # a modified argument list $_[-1] = $original->(@_[0 .. $#_ -1], file => $replacement); return; } This would have been easier if Hook::LexWrap provided automatically a way to call the original function. After a look in the code, maybe just making $original variable not lexically scoped, for instance.