Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Listing the functions of a package / methods of an object

by moritz (Cardinal)
on Jul 15, 2008 at 14:00 UTC ( #697716=note: print w/replies, xml ) Need Help??


in reply to Listing the functions of a package / methods of an object

Use Moose or another OO framework that allows easy introspection.

Without having checked, I think your code will fail to list method in superclasses of $object

(And shouldn't $result be really $object?)

Replies are listed 'Best First'.
Re^2: Listing the functions of a package / methods of an object
by amir_e_a (Hermit) on Jul 15, 2008 at 14:22 UTC

    > Use Moose or another OO framework that allows easy introspection.

    Hmm ... but nothing for the old-fashioned plain blessed packages?..

    > Without having checked, I think your code will fail to list method in superclasses of $object

    You're right :(

    > And shouldn't $result be really <c>$object?

    Of course it should :)

      Class::MOP (which is the foundation of Moose) works well with the "old-fashioned" plain blessed hashref packages and has the functionality you are looking for. It is provided via Class::MOP::Class method_map.
      Hmm ... but nothing for the old-fashioned plain blessed packages?..

      I think you can do better (for example recurse into the classes @ISA, and filter out methods beginning with an underscore (which are private by convention), DESTROY etc.), but there are conceptual limits.

      Perl doesn't have different declarations for subs and methods, so it's impossible to distinguish these two automatically.

      Maybe there are better solutions to your problem. For example the thread Runtime introspection: What good is it? discusses (among a variety of other things) possible alternatives to to introspection.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://697716]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2023-06-01 15:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?