Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: 'extract' subs from source code

by tobyink (Canon)
on Oct 24, 2012 at 16:23 UTC ( [id://1000664]=note: print w/replies, xml ) Need Help??


in reply to 'extract' subs from source code

So let's use perl to parse Perl...

use v5.10; use strict; use warnings; { package SubLister; use Class::Inspector; sub list_subs { my $number = int rand 999_999_999; our @SUBS = (); eval qq{ package Random$number; }.shift.q{ BEGIN { @SubLister::SUBS = @{Class::Inspector->functions(__PAC +KAGE__)}; die; } }; return @SUBS; } } my $source_code = <<'SRC'; sub foo { 1 } sub bar { 2 } sub baz { 3 } CORE::say("We don't want to execute this!"); SRC say("Got: $_") for SubLister::list_subs($source_code);
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (9)
As of 2024-04-23 17:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found