Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Listing all methods on an object

by dhosek (Beadle)
on Feb 05, 2009 at 19:43 UTC ( [id://741668]=perlquestion: print w/replies, xml ) Need Help??

dhosek has asked for the wisdom of the Perl Monks concerning the following question:

I know that I can use UNIVERSAL::can() to find out if an object supports a particular method, but I'm wondering if there's any way to get a complete list of the accessible methods on an object... so far I'm turning up blanks.

Replies are listed 'Best First'.
Re: Listing all methods on an object
by stvn (Monsignor) on Feb 05, 2009 at 21:46 UTC

    You can use Class::MOP to figure this out pretty easily.

    my @methods = Class::MOP::Class->initialize('My::Package')->get_all_me +thods;
    What is in @methods is an array of Class::MOP::Method objects which you can call the following methods on:
    • name - the local method name
    • package_name - the package where the method is defined
    • fully_qualified_name - the package name + name
    • body - returns the code ref
    It should be noted that unlike Class::Inspector and the newer Class::Sniff, this will honor the MRO (Method Resolution Order) you have chosen to use, so in 5.10 (or under Class::C3) it will return a correct method list if you use the c3 MRO instead of the standard dfs (depth-first-search) MRO.

    -stvn
Re: Listing all methods on an object
by jasonk (Parson) on Feb 05, 2009 at 21:14 UTC

    See Class::Inspector for one fairly easy method...

    use Class::Inspector; use Data::Dump qw( dump ); print dump( Class::Inspector->methods( 'Foo' ) )."\n";

    www.jasonkohles.com
    We're not surrounded, we're in a target-rich environment!
Re: Listing all methods on an object
by Corion (Patriarch) on Feb 05, 2009 at 21:16 UTC
Re: Listing all methods on an object
by toolic (Bishop) on Feb 05, 2009 at 19:55 UTC
Re: Listing all methods on an object
by Bloodnok (Vicar) on Feb 05, 2009 at 19:57 UTC
    Is list all subs in a package not of any use ? (found using Google search on the monastry)

    A user level that continues to overstate my experience :-))

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://741668]
Approved by toolic
Front-paged by almut
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-19 15:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found