Benoît Benoît - 1 month ago 6
Perl Question

How do I list available methods on a given object or package in Perl?

How do I list available methods on a given object or package in Perl?

Answer

If you have a package called Foo, this should do it:

no strict 'refs';
for(keys %Foo::) { # All the symbols in Foo's symbol table
  print "$_\n" if exists &{"Foo::$_"}; # check if symbol is method
}
use strict 'refs';

Alternatively, to get a list of all methods:

no strict 'refs';
my @methods = grep { defined &{$_} } keys %Foo::;
use strict 'refs';