In this area of introspection, Perl is quite good. Each package has a hash that contains all global names ("globs"). If you iterate over the code slots of these globs, you find all code that is connected to a name in that package.

This approach will not find stuff that has been declared lexically, you can't get at it in a convenient way. For that, you have to look at PadWalker, or hit the module author until they make globally accessible what in fact is a variable with (module) global scope.

#!perl -wl use strict; use File::Basename; print "Subroutines in File::Basename"; print $_ for keys %File::Basename::;

If you want to make this more parametric, the easiest approach is to switch off strict for the section where you go through the namespace:

use strict; use File::Basename; sub dump_keys { my($package)= @_; print "Subroutines in $package"; no strict 'refs'; print $_ for keys %{"$package\::"}; } dump_keys('File::Basename');

I think you can also work your way down the namespace hierarchy by starting at the %:: hash and going to the File:: entry and then to the Basename:: entry, but I find this too much hassle compared to switching off strict for a small block.


In reply to Re: Optree for entire module by Corion
in thread Optree for entire module by wanna_code_perl

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.