I'm a little new to perl, so bear with me if my lingo is wrong. :)
I'm working with a large legacy code base and looking for a way to be able to "generate" new functions implicitly and dispatch them to existing functions via an algorithm at runtime. It's akin to an AOP thing.
For example, I might want to take a function like:
... and provide a "logged" version of that call in the form:$value = Foo::bar($x);
... without writing the wrapper for every single function.$value = Logged::Foo::bar("/tmp/log", $x);
Originally I had a version that worked using AUTOLOAD. This was almost EXACTLY what I wanted, except that I couldn't figure out how to get one AUTOLOAD function to dispatch for multiple packages.
Enter: UNIVERSAL::AUTOLOAD. :)
So UNIVERSAL::AUTOLOAD works like a charm except that I get a warning that using this to dispatch non-methods is deprecated (perl 5.8.3) and that the workaround is to, you guessed it, explicitly define the AUTOLOAD in each package that does any dispatching.
Is there another way to do this? To summarize, I need to be able to write a single function that's deferred to as the "last resort" for name-based dispatch so that I can shim in code that can rewrite the requests in order to augment them and dispatch them to other functions.
I'm looking forward to working this out to provide some generalized predicate-dispatch type notions in some later projects, but I don't want to go too far down an unsupported path if I can possibly find a supported one.
Thanks in advance!
zonk
In reply to Dynamic function dispatching... by zonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |