Perl getting every object invoked function

perl

Solution

You might want to check AUTOLOADING

If you call a subroutine that is undefined, you would ordinarily get an immediate, fatal error complaining that the subroutine doesn't exist. (Likewise for subroutines being used as methods, when the method doesn't exist in any base class of the class's package.) However, if an AUTOLOAD subroutine is defined in the package or packages used to locate the original subroutine, then that AUTOLOAD subroutine is called with the arguments that would have been passed to the original subroutine

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

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

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

}

outputs `Foo::blah`

Problem

I am new to Perl so I don't know whether it is doable or not. I am interested in creating an module which would catch all calls performed on it. The usage of it would be as follows : ``` $object = new Foo; $object->blah; ``` the function name (so in this case "blah" would be cough by Foo and returned as string to a screen). The bit I don't know how to do is catching the called function name as string.

Original source