|No such thing as a small change|
How to change the symbol table to wrap a sub in another sub ?by Withigo (Friar)
|on Sep 21, 2006 at 18:25 UTC||Need Help??|
Withigo has asked for the
wisdom of the Perl Monks concerning the following question:
In the pursuit of Laziness, I am attempting to wrap a sub with another sub, and thought that manipulating the symbol table of the package would be the way to go. Since it should only be a couple of lines of code, I'd rather not use a module. Besides, it's nice to know how to do this.
The sub I am wrapping is CGI's param(), and the reason is so that I can call Encode::decode_utf8() on everything returned from param(). Instead of modifying hundreds of individual calls to param(), I'll just hook param() in one place. But I can't quite get it to work, and I couldn't find very many clear explanations with examples here in the monastery.
My code so far:
But it doesn't work. I'm finding the syntax a bit tricky for getting a typeglob out of CGI's symbol table hash and into a scalar reference, and then putting that sub reference into a new typeglob that can be called as a sub. What am I doing wrong and what is a better way?