This node is duplicate. Please ignore.


Have you searched CPAN for modules that walk the symbol table? The following will find all subs currently existing in a package. It can be expanded to walk the entire symbol table. It can be expanded to look at @ISA. There's no way to know whether the subs it finds are methods or not.

use strict; use warnings; use Scalar::Util qw( reftype ); sub is_glob { for (@_ ? $_[0] : $_) { return reftype(\$_) eq 'GLOB'; } } sub get_subs { my ($pkg) = @_; my $symtab = \%::; for (split /::/, $pkg) { $symtab = $symtab->{"${_}::"} or return; } return grep is_glob($symtab->{$_}) && *{$symtab->{$_}}{CODE}, keys %$symtab; } print "$_\n" for sort +get_subs('Foo::Bar');

Interesting tidbit: 'Foo::Bar' can be written as Foo::Bar::.

What other kind of code (besides string eval) can generate methods on the fly? Can we recognize them in a reasonable way?

Assignment of a sub ref to a glob.


In reply to (DUP) Re: How to find all the available functions in a file or methods in a module? by ikegami
in thread How to find all the available functions in a file or methods in a module? by szabgab

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.