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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |