From: Jesse Luehrs Date: Fri, 12 Nov 2010 02:11:38 +0000 (-0600) Subject: cache the full method map where possible X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=39e3013b71e122e0e309e62b7c5cfd1e02d860cb;p=gitmo%2FClass-MOP.git cache the full method map where possible --- diff --git a/lib/Class/MOP/Mixin/HasMethods.pm b/lib/Class/MOP/Mixin/HasMethods.pm index a593125..d08d273 100644 --- a/lib/Class/MOP/Mixin/HasMethods.pm +++ b/lib/Class/MOP/Mixin/HasMethods.pm @@ -167,17 +167,7 @@ sub remove_method { sub get_method_list { my $self = shift; - my $namespace = $self->namespace; - - # Constants may show up as some sort of non-GLOB reference in the - # namespace hash ref, depending on the Perl version. - return grep { - defined $namespace->{$_} - && ( ref( \$namespace->{$_} ) ne 'GLOB' - || *{ $namespace->{$_} }{CODE} ) - && $self->has_method($_) - } - keys %{$namespace}; + return keys %{ $self->_full_method_map }; } # This should probably be what get_method_list actually does, instead of just @@ -186,15 +176,7 @@ sub get_method_list { sub _get_local_methods { my $self = shift; - my $namespace = $self->namespace; - - return map { $self->get_method($_) } - grep { - defined $namespace->{$_} - && ( ref $namespace->{$_} - || *{ $namespace->{$_} }{CODE} ) - } - keys %{$namespace}; + return values %{ $self->_full_method_map }; } sub _restore_metamethods_from { @@ -219,6 +201,21 @@ sub update_package_cache_flag { $self->{'_package_cache_flag'} = Class::MOP::check_package_cache_flag($self->name); } +sub _full_method_map { + my $self = shift; + + my $pkg_gen = Class::MOP::check_package_cache_flag($self->name); + + if (($self->{_package_cache_flag_full} || -1) != $pkg_gen) { + # forcibly reify all method map entries + $self->get_method($_) + for $self->list_all_package_symbols('CODE'); + $self->{_package_cache_flag_full} = $pkg_gen; + } + + return $self->_method_map; +} + 1; __END__