Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Identify subs and their source

by Khen1950fx (Canon)
on May 25, 2011 at 07:30 UTC ( #906609=note: print w/ replies, xml ) Need Help??


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([@_]); }


Comment on Re: Identify subs and their source
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://906609]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2015-07-06 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (71 votes), past polls