in reply to List of subs defined by a file?
I need a list of all the subs brought in by the file, not all the subs in the current or main package, and file.pm does not conatin any package declarations.
You can require that file in an ad-hoc package and inspect its symbol table:
#!/usr/bin/perl # file.pm use strict; our ($baz, $quux); sub blorf; $quux = sub { 3 }; sub foo { 1 } sub bar { 2 }
#!/usr/bin/perl # main script use strict; { package Query; require "file.pm"; } print "in package ", __PACKAGE__, $/; for my $sym ( keys %Query:: ) { no strict 'refs'; print "file.pm: $sym\n" if defined *{'Query::'.$sym}{CODE}; print "file.pm: subref \$$sym\n" if ref ${*{'Query::'.$sym}{SCALAR}} + eq 'CODE'; }
Output:
in package main file.pm: sub bar file.pm: subref $quux file.pm: sub blorf file.pm: sub foo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: List of subs defined by a file?
by sflitman (Hermit) on Dec 21, 2008 at 09:00 UTC | |
by shmem (Chancellor) on Dec 21, 2008 at 16:57 UTC |