[Chicago-talk] Asking an class for its method list

Steven Lembark lembark at wrkhors.com
Sun Jan 25 18:06:10 CST 2004

> How can I get back a list of methods available in an class?

$ perldoc Module::Name;

I don't know if the Module::Info gives you all of the
inherited methods; I certianly know that it cannot
extrapolate AUTOLOAD results a-priori (except for auto
split, and even that can be problematic).

Q: why would you want to use undocumented methods in
   any class?

If you need to sanity check the calls before making
them then use "can":

	sub dispatch
		my $obj = shift;
		my $method = shift;

		if( my $sub = $obj->can($method) )
			# caller gets back the result of calling a
			# method with passed in arguments...

			$method->$sub( @_ )
			# or an excption.

			my $ref = ref $obj || 'unblessed';

			die "Bogus object '$obj': $ref cannot $method";

Steven Lembark                               2930 W. Palmer
Workhorse Computing                       Chicago, IL 60647
                                            +1 888 359 3508

More information about the Chicago-talk mailing list