http://www.perlmonks.org?node_id=1225676


in reply to Re: Splitting program into modules
in thread Splitting program into modules

My Devel::Examine::Subs can list subs within files.

Single file example:

use warnings; use strict; use Devel::Examine::Subs; my $des = Devel::Examine::Subs->new(file => 'lib/Devel/Examine/Subs.pm +'); my $subs = $des->all; print "$_\n" for @$subs;

Output:

BEGIN new all has missing lines module objects search_replace replace inject_after inject remove order backup add_functionality engines pre_procs post_procs run valid_params _cache _cache_enabled _cache_safe _clean_config _clean_core_config _config _file _params _read_file _run_directory _run_end _write_file _core _pre_proc _proc _post_proc _engine _pod

You can also do entire directory structures:

use warnings; use strict; use Devel::Examine::Subs; my $des = Devel::Examine::Subs->new(file => '.'); my $data = $des->all; for my $file (keys %$data){ print "$file:\n"; for my $sub (@{ $data->{$file} }){ print "\t$sub\n"; } }

Snipped example output:

t/test/files/sample.pm: one one_inner one_inner_two two three four function five six seven eight examples/write_new_engine.pl: dumps lib/Devel/Examine/Subs/Sub.pm: BEGIN new name start end line_count lines code lib/Devel/Examine/Subs/Preprocessor.pm: BEGIN new _dt exists module inject replace remove _vim_placeholder

The software does a ton of useful things, but these are examples of the most basic functionality. It does not know how to see sub dependencies of other subs. However, I do have another software that does, however, it is intrusive (it actually writes into the Perl files, and you have to run the software to get usable trace information (ie. if you don't call all scenarios, it may not find all flows). I don't have the time at the moment to write a proper scenario for that, but have a look at Devel::Trace::Subs if you're interested. If you don't come up with anything else by morning, I'll create a good example.