Is there a way to overload / intercept function calls for overloaded objects in Perl?

By analogy with what is possible with overloaded operators, is there a way to apply some kind 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_functionit wasnโ€™t defined, I could just use sub AUTOLOADto catch the call, but when itโ€™s defined, I donโ€™t know how to intercept the call (without something crazy, for example, for injection wrappers around all the callers or temporarily disinfect all the subsites) .

Another way to express this: I would like to write use overload sin => \&my_sin;, but have to sinbe some kind of function and call it as nomethoda sub when an overloaded object is used in a function call.

EDIT:

, , , Perl5 Perl6, . , Perl6 , , , Whatever, , ( ).

- , CPAN: Whatever.

/ .

+3
1
+1

Source: https://habr.com/ru/post/1774388/


All Articles