From: Dave Rolsky Date: Sat, 14 Aug 2010 17:28:33 +0000 (+0200) Subject: Add _get_local_methods method that returns method objects directly. X-Git-Tag: 1.05~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fe1b970ae7d324629fd8848c1c640940c87ecfb5;p=gitmo%2FClass-MOP.git Add _get_local_methods method that returns method objects directly. Using this in various places can make our code much more efficient, since we avoid calling get_method twice. --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index d383e20..b1678a9 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -944,8 +944,7 @@ sub get_all_methods { for my $class ( reverse $self->linearized_isa ) { my $meta = Class::MOP::Class->initialize($class); - $methods{$_} = $meta->get_method($_) - for $meta->get_method_list; + $methods{ $_->name } = $_ for $meta->_get_local_methods; } return values %methods; diff --git a/lib/Class/MOP/Mixin/HasMethods.pm b/lib/Class/MOP/Mixin/HasMethods.pm index bc5b09c..b8ea9ff 100644 --- a/lib/Class/MOP/Mixin/HasMethods.pm +++ b/lib/Class/MOP/Mixin/HasMethods.pm @@ -156,6 +156,18 @@ sub get_method_list { keys %{$namespace}; } +# This should probably be what get_method_list actually does, instead of just +# returning names. This was created as a much faster alternative to +# $meta->get_method($_) for $meta->get_method_list +sub _get_local_methods { + my $self = shift; + + my $namespace = $self->namespace; + + return map { $self->get_method($_) } grep { *{ $namespace->{$_} }{CODE} } + keys %{$namespace}; +} + 1; __END__