in reply to Module Subs and Methods

Try saving this to a file in your perl/lib/Devel/ directory as SubCheck.pm

use strict; package DB; CHECK{ print "$_ => $DB::sub{$_}" for sort keys %DB::sub; die 'Done'; +} sub DB{ return; } 1;

Then invoke a program that uses the modules you are interested in exploring using the following syntax:

perl -d:SubCheck yourscript.

You will get output that looks something like this (for a very simple program).

D:\Perl\test>perl58 -d:SubCheck HorL.pl8 AutoLoader::AUTOLOAD => d:/Perl/lib/AutoLoader.pm:22-116 AutoLoader::BEGIN => d:/Perl/lib/AutoLoader.pm:11-20 AutoLoader::__ANON__[d:/Perl/lib/AutoLoader.pm:96] => d:/Perl/lib/Auto +Loader.pm:96-96 AutoLoader::import => d:/Perl/lib/AutoLoader.pm:118-166 AutoLoader::unimport => d:/Perl/lib/AutoLoader.pm:168-171 Carp::carp => d:/Perl/lib/Carp.pm:193-193 Carp::cluck => d:/Perl/lib/Carp.pm:194-194 Carp::confess => d:/Perl/lib/Carp.pm:192-192 Carp::croak => d:/Perl/lib/Carp.pm:191-191 Carp::export_fail => d:/Perl/lib/Carp.pm:144-148 Carp::longmess => d:/Perl/lib/Carp.pm:157-168 Carp::shortmess => d:/Perl/lib/Carp.pm:177-183 Config::BEGIN => d:/Perl/lib/Config.pm:2-2 Config::CLEAR => d:/Perl/lib/Config.pm:1147-1147 Config::DELETE => d:/Perl/lib/Config.pm:1146-1146 Config::DESTROY => d:/Perl/lib/Config.pm:1172-1172 Config::EXISTS => d:/Perl/lib/Config.pm:1135-1143 Config::FETCH => d:/Perl/lib/Config.pm:1029-1115 Config::FIRSTKEY => d:/Perl/lib/Config.pm:1119-1124 Config::NEXTKEY => d:/Perl/lib/Config.pm:1126-1133 Config::STORE => d:/Perl/lib/Config.pm:1145-1145 Config::TIEHASH => d:/Perl/lib/Config.pm:1169-1169 Config::config_re => d:/Perl/lib/Config.pm:1154-1158 Config::config_sh => d:/Perl/lib/Config.pm:1150-1152 Config::config_vars => d:/Perl/lib/Config.pm:1160-1167 Config::import => d:/Perl/lib/Config.pm:7-16 Config::myconfig => d:/Perl/lib/Config.pm:1021-1027 DynaLoader::BEGIN => d:/Perl/lib/DynaLoader.pm:25-25 DynaLoader::bootstrap => d:/Perl/lib/DynaLoader.pm:130-250 DynaLoader::bootstrap_inherit => d:/Perl/lib/DynaLoader.pm:119-125 DynaLoader::croak => d:/Perl/lib/DynaLoader.pm:117-117 DynaLoader::dl_load_flags => d:/Perl/lib/DynaLoader.pm:48-48 Exporter::__ANON__[d:/Perl/lib/Exporter.pm:57] => d:/Perl/lib/Exporter +.pm:57-57 Exporter::as_heavy => d:/Perl/lib/Exporter.pm:15-22 Exporter::export => d:/Perl/lib/Exporter.pm:24-26 Exporter::export_fail => d:/Perl/lib/Exporter.pm:64-67 Exporter::export_ok_tags => d:/Perl/lib/Exporter.pm:81-83 Exporter::export_tags => d:/Perl/lib/Exporter.pm:77-79 Exporter::export_to_level => d:/Perl/lib/Exporter.pm:73-75 Exporter::import => d:/Perl/lib/Exporter.pm:28-60 Exporter::require_version => d:/Perl/lib/Exporter.pm:85-87 main::BEGIN => HorL.pl8:3-3 main::card_value => HorL.pl8:5-5 main::show_card => HorL.pl8:7-13 strict::bits => d:/Perl/lib/strict.pm:101-105 strict::import => d:/Perl/lib/strict.pm:107-110 strict::unimport => d:/Perl/lib/strict.pm:112-115 vars::BEGIN => d:/Perl/lib/vars.pm:8-8 vars::import => d:/Perl/lib/vars.pm:10-44 warnings::BEGIN => d:/Perl/lib/warnings.pm:130-130 warnings::Croaker => d:/Perl/lib/warnings.pm:292-295 warnings::__chk => d:/Perl/lib/warnings.pm:396-441 warnings::bits => d:/Perl/lib/warnings.pm:298-327 warnings::enabled => d:/Perl/lib/warnings.pm:444-453 warnings::import => d:/Perl/lib/warnings.pm:330-365 warnings::register::import => d:/Perl/lib/warnings/register.pm:36-49 warnings::register::mkMask => d:/Perl/lib/warnings/register.pm:27-33 warnings::unimport => d:/Perl/lib/warnings.pm:368-393 warnings::warn => d:/Perl/lib/warnings.pm:457-467 warnings::warnif => d:/Perl/lib/warnings.pm:470-487 Done at d:/Perl/lib/Devel/SubCheck.pm line 4. CHECK failed--call queue aborted.

The output is of the form packagename::subname => sourcefile:startline-endline.

The list should include all the subs the compiler knows about just prior to running the program. The program will not be run.

I guess this could be a candidate for uploading to CPAN if anyone would find it useful. Hardly seems worth it for 6 lines of code though?


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


Replies are listed 'Best First'.
Re: Re: Module Subs and Methods
by Arguile (Hermit) on Jun 19, 2003 at 21:50 UTC

    The list should include all the subs the compiler knows about just prior to running the program. The program will not be run.**

    That's a very important distinction, as nothing dynamic (ie. run-time evaluated) will be listed.

    For example, CGI is probably the most well known example of dynamic autoloading. If you were to use CGI in your program and then run this, you’d see only a very small selection of the function available. However with use CGI qw(-compile :all) it would list them all. That's because, by default, CGI only compiles a function when it’s requested.

    Update: A simpler example is require Module::Name if $foo

    Any method to list functions will always be suspect due to dynamic evaluation. Add in anonymous subs and the waters are even murkier. This isn't a failing in BrowserUK’s method (which is pretty damn cool), it’s a reality of Perl.


    ** Not completely correct as the BEGIN{} block will be run. (Yes I’m picking nits :)

Re^2: Module Subs and Methods
by adrianh (Chancellor) on Jun 20, 2003 at 12:46 UTC

    If you want to play with the symbol table then Devel::Symdump provides lots of potential amusement.