In a manner similar to what is possible with overloaded operators, is there a way to apply some sort of magic to a variable so that the following:
my $magic_var = ...;
some_function($magic_var);
will result in something like this:
call_function(\&some_function, $magic_var)
If some_function was not defined, I could just use an AUTOLOAD sub to catch the call, but when it is defined, I am not aware of a way to intercept the call (without something crazy like injecting wrappers around all of the caller's subs, or temporarily undefining all the subs).
Another way to put it is I would like to write use overload sin => \&my_sin; but have sin be any function, and have it call a nomethod like sub whenever the overloaded object is used in a function call.
EDIT:
By popular request, the reason that I was looking into this was because I am working on a Perl5 version of the Perl6 whatever star. However, after looking into the Perl6 implementation more, it seems that it also does not deal with functions being called on Whatever, so it seems like I won't have to try and deal with function calls (just operators and method calls).
If anyone is interested, the module is up on CPAN: Whatever.
Feedback / Comments are welcome.
Can you use the tie mechanism?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With