4 mop_update_method_map(pTHX_ SV *const self, SV *const class_name, HV *const stash, HV *const map)
6 const char *const class_name_pv = HvNAME(stash); /* must be HvNAME(stash), not SvPV_nolen_const(class_name) */
7 SV *method_metaclass_name;
14 symbols = mop_get_all_package_symbols(stash, TYPE_FILTER_CODE);
15 sv_2mortal((SV*)symbols);
16 (void)hv_iterinit(symbols);
17 while ( (coderef = hv_iternextsv(symbols, &method_name, &method_name_len)) ) {
18 CV *cv = (CV *)SvRV(coderef);
24 if (!mop_get_code_info(coderef, &cvpkg_name, &cv_name)) {
28 /* this checks to see that the subroutine is actually from our package */
29 if ( !(strEQ(cvpkg_name, "constant") && strEQ(cv_name, "__ANON__")) ) {
30 if ( strNE(cvpkg_name, class_name_pv) ) {
35 method_slot = *hv_fetch(map, method_name, method_name_len, TRUE);
36 if ( SvOK(method_slot) ) {
39 if ( sv_isobject(method_slot) ) {
40 body = mop_call0(aTHX_ method_slot, KEY_FOR(body)); /* $method_object->body() */
46 if ( SvROK(body) && ((CV *) SvRV(body)) == cv ) {
51 method_metaclass_name = mop_call0(aTHX_ self, mop_method_metaclass); /* $self->method_metaclass() */
54 $method_object = $method_metaclass->wrap(
56 associated_metaclass => $self,
57 package_name => $class_name,
66 PUSHs(method_metaclass_name); /* invocant */
67 mPUSHs(newRV_inc((SV *)cv));
68 PUSHs(mop_associated_metaclass);
70 PUSHs(KEY_FOR(package_name));
73 mPUSHs(newSVpv(method_name, method_name_len));
76 call_sv(mop_wrap, G_SCALAR | G_METHOD);
80 /* $map->{$method_name} = $method_object */
81 sv_setsv(method_slot, method_object);
88 MODULE = Class::MOP::Package PACKAGE = Class::MOP::Package
93 get_all_package_symbols(self, filter=TYPE_FILTER_NONE)
101 if ( ! SvROK(self) ) {
102 die("Cannot call get_all_package_symbols as a class method");
105 if (GIMME_V == G_VOID) {
111 if ( (he = hv_fetch_ent((HV *)SvRV(self), KEY_FOR(package), 0, HASH_FOR(package))) ) {
112 stash = gv_stashsv(HeVAL(he), 0);
120 symbols = mop_get_all_package_symbols(stash, filter);
121 PUSHs(sv_2mortal(newRV_noinc((SV *)symbols)));
124 _full_method_map(self)
127 HV *const obj = (HV *)SvRV(self);
128 SV *const class_name = HeVAL( hv_fetch_ent(obj, KEY_FOR(package), 0, HASH_FOR(package)) );
129 HV *const stash = gv_stashsv(class_name, 0);
135 mXPUSHs(newRV_noinc((SV *)newHV()));
139 current = mop_check_package_cache_flag(aTHX_ stash);
140 cache_flag = HeVAL( hv_fetch_ent(obj, KEY_FOR(package_cache_flag), TRUE, HASH_FOR(package_cache_flag)));
141 map_ref = HeVAL( hv_fetch_ent(obj, KEY_FOR(methods), TRUE, HASH_FOR(methods)));
143 /* $self->{methods} does not yet exist (or got deleted) */
144 if ( !SvROK(map_ref) || SvTYPE(SvRV(map_ref)) != SVt_PVHV ) {
145 SV *new_map_ref = newRV_noinc((SV *)newHV());
146 sv_2mortal(new_map_ref);
147 sv_setsv(map_ref, new_map_ref);
150 if ( !SvOK(cache_flag) || SvUV(cache_flag) != current ) {
151 mop_update_method_map(aTHX_ self, class_name, stash, (HV *)SvRV(map_ref));
152 sv_setuv(cache_flag, mop_check_package_cache_flag(aTHX_ stash)); /* update_cache_flag() */
158 INSTALL_SIMPLE_READER_WITH_KEY(Package, name, package);