Perl gets every function called by an object

I am new to Perl, so I donโ€™t know if this is feasible or not. I am interested in creating a module that would catch all the calls made on it.

Its use will be as follows:

$object = new Foo;
$object->blah;

function name (so in this case "blah" will be a cough from Foo and returned as a string to the screen).

The bit that I donโ€™t know how to do is call the name of the called function as a string.

+4
source share
1 answer

You might want to check AUTOLOADING

undefined, , , , . (, , , - .) , , , AUTOLOAD, AUTOLOAD ,

my $object = new Foo;
print $object->blah, "\n";

package Foo;
sub new { return bless {}, shift }

# catch-all function
sub AUTOLOAD {
  return $AUTOLOAD;

}

Foo::blah

+5

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


All Articles