more useful options | |
PerlMonks |
Re: Can a Perl module "inspect" itself and provide details about methods and parameters?by stevieb (Canon) |
on Sep 21, 2019 at 21:50 UTC ( [id://11106516]=note: print w/replies, xml ) | Need Help?? |
I think it'd be a futile effort to try to sort out what params each subroutine accepts because they can come in and be handled in a myriad of ways. However, using my Devel::Examine::Subs, you can at least get info about subroutines within a file, module or directory. Here's a code snip. In this case, I'm in a distribution directory (my Mock::Sub repository):
Output:
You can even get info about each sub. This example is reading just a single file (but it does work with directories and modules, it's just a bit different to extract the data. Docs contain this info.
Snip of output:
Works on in-memory modules as well. Send the module name to the file parameter. If the module is installed, we'll load it and read from there:
Output from my Logging::Simple distribution module:
Note that the _end() methods are simply placeholders; they allow my editor to fold all of my POD up into the last subroutine so when I go to bottom of the current file, it doesn't take me to the end of my POD. You could also use PPI to do the same thing. That's what my distribution uses, and added a whole slew of things around it.
In Section
Seekers of Perl Wisdom
|
|