As a first approximation (with all the caveats already mentioned by halley):

{ no strict 'refs'; @my_subs = grep exists &{ 'Some::Module::' . $_ }, keys %Some::Modul +e::; }
This only tells you the subs in Some::Module's symbol table at the time. For one thing it does not differentiate between instance methods and class methods. Neither does it differentiate betweeen "methods" (i.e. functions that are expected to be called through a -> notation) and regular functions. In fact, if Some::Module imported some random function (e.g. croak or floor), it will be listed in @my_subs. It also doesn't show subs stored in lexicals.

Try it with a module you know (or think you know) and see what you get.

Update: Also, the above does not take into account inheritance. You'd need to adapt it to travel up @ISA's to get inherited methods.

Here's a stab at it:

use strict; use warnings; sub get_subs { my $pkg = shift; my $subs = shift || +{}; my $seen = shift || +{}; return if $seen->{ $pkg }++; my $pkg_and_dots = $pkg . '::'; my @ancestors; { no strict 'refs'; $subs->{ $_ } ||= $pkg for grep exists &{ "$pkg_and_dots$_" }, keys %{ $pkg_and_dots }; @ancestors = @{ "${pkg_and_dots}ISA" }; } @ancestors = 'UNIVERSAL' unless @ancestors || $seen->{ UNIVERSAL }; get_subs( $_, $subs, $seen ) for @ancestors; return $subs; } sub Foo::baz { 1 } @Bar::ISA = 'Foo'; my $subs = get_subs( 'Bar' ); __END__
Now $subs points to a hash whose contents are:
'VERSION' => 'UNIVERSAL' 'baz' => 'Foo' 'can' => 'UNIVERSAL' 'isa' => 'UNIVERSAL'

the lowliest monk


In reply to Re: Reflecting on Object by tlm
in thread Reflecting on Object by tomazos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.