Note that it will exclude constants in the specified package and oddballs like BEGIN blocks. This was modified from clever source I saw in CPAN module Package::Constants. Note that it will list also all imported subs from packages use'd by the target package.sub get_coderefs_href ($) { # get hashref of all coderefs in package my $pkg=shift; my $rv; no strict 'refs'; my $stash = $pkg . '::'; for my $name (keys %$stash ) { my $sub = $pkg->can( $name ); # use UNIVERSAL::can next unless defined $sub; my $proto = prototype( $sub ); next if defined $proto and length($proto)==0; $rv->{$name}++; } $rv; }
Hope that helps a fellow Perl monk!
SSF
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: list all subs in a package
by ikegami (Patriarch) on Jan 01, 2009 at 23:44 UTC | |
by sflitman (Hermit) on Jan 02, 2009 at 02:04 UTC | |
by ikegami (Patriarch) on Jan 02, 2009 at 02:56 UTC | |
by sflitman (Hermit) on Jan 02, 2009 at 09:55 UTC | |
by ikegami (Patriarch) on Jan 02, 2009 at 10:26 UTC | |
|
Re: list all subs in a package
by tilly (Archbishop) on Jan 02, 2009 at 08:31 UTC | |
|
Re: list all subs in a package
by tdlewis77 (Sexton) on Aug 06, 2017 at 14:49 UTC |