in reply to How to find all the available functions in a file or methods in a module?
use strict; use warnings; use Scalar::Util qw( reftype ); sub is_glob { for (@_ ? $_[0] : $_) { return reftype(\$_) eq 'GLOB'; } } sub get_subs { my ($pkg) = @_; my $symtab = \%::; for (split /::/, $pkg) { $symtab = $symtab->{"${_}::"} or return; } return grep is_glob($symtab->{$_}) && *{$symtab->{$_}}{CODE}, keys %$symtab; } print "$_\n" for sort +get_subs('Foo::Bar');
Interesting tidbit: 'Foo::Bar' can be written as Foo::Bar::.
What other kind of code (besides string eval) can generate methods on the fly? Can we recognize them in a reasonable way?
Assignment of a sub ref to a glob.
|
---|