3 SV *mop_method_metaclass;
4 SV *mop_associated_metaclass;
8 mop_update_method_map(pTHX_ SV *const self, SV *const class_name, HV *const stash, HV *const map)
10 const char *const class_name_pv = HvNAME(stash); /* must be HvNAME(stash), not SvPV_nolen_const(class_name) */
11 SV *method_metaclass_name;
18 symbols = mop_get_all_package_symbols(stash, TYPE_FILTER_CODE);
19 sv_2mortal((SV*)symbols);
20 (void)hv_iterinit(symbols);
21 while ( (coderef = hv_iternextsv(symbols, &method_name, &method_name_len)) ) {
22 CV *cv = (CV *)SvRV(coderef);
28 if (!mop_get_code_info(coderef, &cvpkg_name, &cv_name)) {
32 /* this checks to see that the subroutine is actually from our package */
33 if ( !(strEQ(cvpkg_name, "constant") && strEQ(cv_name, "__ANON__")) ) {
34 if ( strNE(cvpkg_name, class_name_pv) ) {
39 method_slot = *hv_fetch(map, method_name, method_name_len, TRUE);
40 if ( SvOK(method_slot) ) {
43 if ( sv_isobject(method_slot) ) {
44 body = mop_call0(aTHX_ method_slot, KEY_FOR(body)); /* $method_object->body() */
50 if ( SvROK(body) && ((CV *) SvRV(body)) == cv ) {
55 method_metaclass_name = mop_call0(aTHX_ self, mop_method_metaclass); /* $self->method_metaclass() */
58 $method_object = $method_metaclass->wrap(
60 associated_metaclass => $self,
61 package_name => $class_name,
70 PUSHs(method_metaclass_name); /* invocant */
71 mPUSHs(newRV_inc((SV *)cv));
72 PUSHs(mop_associated_metaclass);
74 PUSHs(KEY_FOR(package_name));
77 mPUSHs(newSVpv(method_name, method_name_len));
80 call_sv(mop_wrap, G_SCALAR | G_METHOD);
84 /* $map->{$method_name} = $method_object */
85 sv_setsv(method_slot, method_object);
92 MODULE = Class::MOP::Mixin::HasMethods PACKAGE = Class::MOP::Mixin::HasMethods
97 _full_method_map(self)
100 HV *const obj = (HV *)SvRV(self);
101 SV *const class_name = HeVAL( hv_fetch_ent(obj, KEY_FOR(package), 0, HASH_FOR(package)) );
102 HV *const stash = gv_stashsv(class_name, 0);
108 mXPUSHs(newRV_noinc((SV *)newHV()));
112 current = mop_check_package_cache_flag(aTHX_ stash);
113 cache_flag = HeVAL( hv_fetch_ent(obj, KEY_FOR(package_cache_flag), TRUE, HASH_FOR(package_cache_flag)));
114 map_ref = HeVAL( hv_fetch_ent(obj, KEY_FOR(methods), TRUE, HASH_FOR(methods)));
116 /* $self->{methods} does not yet exist (or got deleted) */
117 if ( !SvROK(map_ref) || SvTYPE(SvRV(map_ref)) != SVt_PVHV ) {
118 SV *new_map_ref = newRV_noinc((SV *)newHV());
119 sv_2mortal(new_map_ref);
120 sv_setsv(map_ref, new_map_ref);
123 if ( !SvOK(cache_flag) || SvUV(cache_flag) != current ) {
124 mop_update_method_map(aTHX_ self, class_name, stash, (HV *)SvRV(map_ref));
125 sv_setuv(cache_flag, mop_check_package_cache_flag(aTHX_ stash)); /* update_cache_flag() */
131 mop_method_metaclass = newSVpvs("method_metaclass");
132 mop_associated_metaclass = newSVpvs("associated_metaclass");
133 mop_wrap = newSVpvs("wrap");