From: Jesse Luehrs Date: Thu, 11 Nov 2010 21:22:14 +0000 (-0600) Subject: get rid of _full_method_map, and make _method_map do the cache checks X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=38bcde3fc28279a00afced7eb6f29304d66af962;hp=e59e2f1316c417cd3f131d30f6845eac0d94f759;p=gitmo%2FClass-MOP.git get rid of _full_method_map, and make _method_map do the cache checks --- diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index 69288bf..7707c61 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -187,7 +187,7 @@ Class::MOP::Mixin::HasMethods->meta->add_attribute( # NOTE: # we just alias the original method # rather than re-produce it here - '_full_method_map' => \&Class::MOP::Mixin::HasMethods::_full_method_map + '_method_map' => \&Class::MOP::Mixin::HasMethods::_method_map }, default => sub { {} } )) diff --git a/lib/Class/MOP/Deprecated.pm b/lib/Class/MOP/Deprecated.pm index ad2b553..4053c23 100644 --- a/lib/Class/MOP/Deprecated.pm +++ b/lib/Class/MOP/Deprecated.pm @@ -86,12 +86,7 @@ sub get_method_map { ); my $self = shift; - my $map = $self->_full_method_map; - - $map->{$_} = $self->get_method($_) - for grep { !blessed( $map->{$_} ) } keys %{$map}; - - return $map; + return { map { $_->name => $_ } $self->_get_local_methods }; } package diff --git a/lib/Class/MOP/Mixin/HasMethods.pm b/lib/Class/MOP/Mixin/HasMethods.pm index d27f396..d40d449 100644 --- a/lib/Class/MOP/Mixin/HasMethods.pm +++ b/lib/Class/MOP/Mixin/HasMethods.pm @@ -36,12 +36,6 @@ sub _add_meta_method { ); } -# This doesn't always get initialized in a constructor because there is a -# weird object construction path for subclasses of Class::MOP::Class. At one -# point, this always got initialized by calling into the XS code first, but -# that is no longer guaranteed to happen. -sub _method_map { $_[0]->{'methods'} ||= {} } - sub wrap_method_body { my ( $self, %args ) = @_; @@ -162,7 +156,7 @@ sub remove_method { ( defined $method_name && length $method_name ) || confess "You must define a method name"; - my $removed_method = delete $self->_full_method_map->{$method_name}; + my $removed_method = delete $self->_method_map->{$method_name}; $self->remove_package_symbol( { sigil => '&', type => 'CODE', name => $method_name } ); diff --git a/xs/HasMethods.xs b/xs/HasMethods.xs index 35f5168..88422ae 100644 --- a/xs/HasMethods.xs +++ b/xs/HasMethods.xs @@ -8,12 +8,10 @@ static void mop_update_method_map(pTHX_ SV *const self, SV *const class_name, HV *const stash, HV *const map) { const char *const class_name_pv = HvNAME(stash); /* must be HvNAME(stash), not SvPV_nolen_const(class_name) */ - SV *method_metaclass_name; char *method_name; I32 method_name_len; SV *coderef; HV *symbols; - dSP; symbols = mop_get_all_package_symbols(stash, TYPE_FILTER_CODE); sv_2mortal((SV*)symbols); @@ -23,7 +21,6 @@ mop_update_method_map(pTHX_ SV *const self, SV *const class_name, HV *const stas char *cvpkg_name; char *cv_name; SV *method_slot; - SV *method_object; if (!mop_get_code_info(coderef, &cvpkg_name, &cv_name)) { continue; @@ -50,42 +47,11 @@ mop_update_method_map(pTHX_ SV *const self, SV *const class_name, HV *const stas if ( SvROK(body) && ((CV *) SvRV(body)) == cv ) { continue; } + else { + /* $map->{$method_name} = undef */ + sv_setsv(method_slot, &PL_sv_undef); + } } - - method_metaclass_name = mop_call0(aTHX_ self, mop_method_metaclass); /* $self->method_metaclass() */ - - /* - $method_object = $method_metaclass->wrap( - $cv, - associated_metaclass => $self, - package_name => $class_name, - name => $method_name - ); - */ - ENTER; - SAVETMPS; - - PUSHMARK(SP); - EXTEND(SP, 8); - PUSHs(method_metaclass_name); /* invocant */ - mPUSHs(newRV_inc((SV *)cv)); - PUSHs(mop_associated_metaclass); - PUSHs(self); - PUSHs(KEY_FOR(package_name)); - PUSHs(class_name); - PUSHs(KEY_FOR(name)); - mPUSHs(newSVpv(method_name, method_name_len)); - PUTBACK; - - call_sv(mop_wrap, G_SCALAR | G_METHOD); - SPAGAIN; - method_object = POPs; - PUTBACK; - /* $map->{$method_name} = $method_object */ - sv_setsv(method_slot, method_object); - - FREETMPS; - LEAVE; } } @@ -94,7 +60,7 @@ MODULE = Class::MOP::Mixin::HasMethods PACKAGE = Class::MOP::Mixin::HasMethods PROTOTYPES: DISABLE void -_full_method_map(self) +_method_map(self) SV *self PREINIT: HV *const obj = (HV *)SvRV(self);