Skip to content

Instantly share code, notes, and snippets.

@karupanerura
Created August 4, 2011 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karupanerura/1124954 to your computer and use it in GitHub Desktop.
Save karupanerura/1124954 to your computer and use it in GitHub Desktop.
get_all_dispatch.pl
use strict;
use warnings;
use Data::Dumper;
use Class::Load;
my $wantclass = shift(@ARGV) or die;
Class::Load::load_class($wantclass);
print Dumper[grep { /^dispatch_/ } get_all_methods($wantclass)];
sub get_all_methods {
my $class = shift;
my @methods = ();
my @class_isa;
{
no strict 'refs';
@class_isa = @{"${class}::ISA"};
}
foreach my $parent (@class_isa) {
push(@methods, get_all_methods($parent));
}
push(@methods, get_all_subs($class));
wantarray ? @methods : \@methods;
}
sub get_all_subs {
my $class = shift;
{
no strict 'refs'; ## no critic
my $symbol_table = \%{"${class}::"};
my @subs =
grep { defined(*{$symbol_table->{$_}}{CODE}) }
(keys %$symbol_table);
wantarray ? @subs : \@subs;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment