Created
August 4, 2011 10:52
-
-
Save karupanerura/1124954 to your computer and use it in GitHub Desktop.
get_all_dispatch.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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