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


in reply to Identify subs and their source

Always search PerlMonks. I did a brief search and found:

Tabulate sub defs, sub calls in Perl code by graff.

It'll work on a script, a module, modules, a directory, or directories. It uses B::Deparse, so I think that it meets your constraints. Here's the link for scan-source.perl.

A cool little tool that I use to analyse subs is Sub::Mutate. It can tell you if a sub is a method, function, XSUB, STANDALONE, etc. For example, I took the Dumper sub from Data::Dumper:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper::Simple; use Sub::Mutate qw( sub_body_type sub_closure_role sub_is_lvalue sub_is_constant sub_is_method mutate_sub_is_method sub_is_debuggable mutate_sub_is_debuggable sub_prototype mutate_sub_prototype ); my $sub = \&Dumper; print my $type = sub_body_type($sub), "\n"; print $type = sub_closure_role($sub), "\n"; if ( sub_is_lvalue($sub) ) { print "sub is an lvalue\n"; } else { print "sub is not an lvalue\n"; } if ( sub_is_constant($sub)) { print "sub is a constant\n"; } else { print "sub is not a constant\n"; } if ( sub_is_method($sub)) { print "sub is a method\n"; } else { print "sub is not a method\n"; } if ( sub_is_debuggable($sub)) { print "sub is debuggable\n"; } else { print "sub is not debuggable\n"; } my $proto = sub_prototype($sub); print Dumper($proto); sub Dumper { return Data::Dumper->Dump([@_]); }