| 1 |
|
| #include "mop.h" |
| 2 |
|
| #include "ppport.h" |
| 3 |
|
| |
| 4 |
|
| SV *mop_method_metaclass; |
| 5 |
|
| SV *mop_associated_metaclass; |
| 6 |
|
| SV *mop_wrap; |
| 7 |
|
| |
| 8 |
|
| static void |
| 9 |
44585 |
| mop_update_method_map(pTHX_ HV *const stash, HV *const map) |
| 10 |
|
| { |
| 11 |
|
| char *method_name; |
| 12 |
|
| I32 method_name_len; |
| 13 |
|
| SV *method; |
| 14 |
|
| HV *symbols; |
| 15 |
|
| |
| 16 |
44585 |
| symbols = mop_get_all_package_symbols(stash, TYPE_FILTER_CODE); |
| 17 |
44585 |
| sv_2mortal((SV*)symbols); |
| 18 |
|
| |
| 19 |
44585 |
| (void)hv_iterinit(map); |
| 20 |
88948 |
▶ | while ((method = hv_iternextsv(map, &method_name, &method_name_len))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((method = hv_iternextsv(map, &method_name, &method_name_len))) { |
44363 |
44585 |
88948 |
|
| 21 |
|
| SV *body; |
| 22 |
|
| SV *stash_slot; |
| 23 |
|
| |
| 24 |
44363 |
▶ | if (!SvROK(method)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(method)) { |
0 |
44363 |
44363 |
|
| 25 |
0 |
| continue; |
| 26 |
|
| } |
| 27 |
|
| |
| 28 |
44363 |
▶ | if (sv_derived_from(method, "Class::MOP::Method")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_derived_from(method, "Class::MOP::Method")) { |
44333 |
30 |
44363 |
|
| 29 |
|
| /* $method_object->body() */ |
| 30 |
44333 |
| body = mop_call0(aTHX_ method, KEY_FOR(body)); |
| 31 |
|
| } |
| 32 |
|
| else { |
| 33 |
30 |
| body = method; |
| 34 |
|
| } |
| 35 |
|
| |
| 36 |
44363 |
| stash_slot = *hv_fetch(symbols, method_name, method_name_len, TRUE); |
| 37 |
44363 |
▶ | if (SvROK(stash_slot) && ((CV*)SvRV(body)) == ((CV*)SvRV(stash_slot))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(stash_slot) && ((CV*)SvRV(body)) == ((CV*)SvRV(stash_slot))) { |
44361 |
2 |
44363 |
| if (SvROK(stash_slot) && ((CV*)SvRV(body)) == ((CV*)SvRV(stash_slot))) { |
44358 |
3 |
44361 |
|
| 38 |
44358 |
| continue; |
| 39 |
|
| } |
| 40 |
|
| |
| 41 |
|
| /* delete $map->{$method_name} */ |
| 42 |
5 |
| (void)hv_delete(map, method_name, method_name_len, G_DISCARD); |
| 43 |
|
| } |
| 44 |
44585 |
| } |
| 45 |
|
| |
| 46 |
|
| MODULE = Class::MOP::Mixin::HasMethods PACKAGE = Class::MOP::Mixin::HasMethods |
| 47 |
|
| |
| 48 |
|
| PROTOTYPES: DISABLE |
| 49 |
|
| |
| 50 |
|
| void |
| 51 |
|
| _method_map(self) |
| 52 |
|
| SV *self |
| 53 |
|
| PREINIT: |
| 54 |
453198 |
| HV *const obj = (HV *)SvRV(self); |
| 55 |
453198 |
| SV *const class_name = HeVAL( hv_fetch_ent(obj, KEY_FOR(package), 0, HASH_FOR(package)) ); |
| 56 |
453198 |
| HV *const stash = gv_stashsv(class_name, 0); |
| 57 |
|
| UV current; |
| 58 |
|
| SV *cache_flag; |
| 59 |
|
| SV *map_ref; |
| 60 |
|
| PPCODE: |
| 61 |
453198 |
▶ | if (!stash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!stash) { |
13 |
453185 |
453198 |
|
| 62 |
13 |
▶ | mXPUSHs(newRV_noinc((SV *)newHV())); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newRV_noinc((SV *)newHV())); |
0 |
13 |
13 |
|
| 63 |
13 |
| return; |
| 64 |
|
| } |
| 65 |
|
| |
| 66 |
453185 |
| current = mop_check_package_cache_flag(aTHX_ stash); |
| 67 |
453185 |
| cache_flag = HeVAL( hv_fetch_ent(obj, KEY_FOR(package_cache_flag), TRUE, HASH_FOR(package_cache_flag))); |
| 68 |
453185 |
| map_ref = HeVAL( hv_fetch_ent(obj, KEY_FOR(methods), TRUE, HASH_FOR(methods))); |
| 69 |
|
| |
| 70 |
|
| /* $self->{methods} does not yet exist (or got deleted) */ |
| 71 |
453185 |
▶ | if ( !SvROK(map_ref) || SvTYPE(SvRV(map_ref)) != SVt_PVHV ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ( !SvROK(map_ref) || SvTYPE(SvRV(map_ref)) != SVt_PVHV ) { |
449172 |
4013 |
453185 |
| if ( !SvROK(map_ref) || SvTYPE(SvRV(map_ref)) != SVt_PVHV ) { |
0 |
449172 |
449172 |
|
| 72 |
4013 |
| SV *new_map_ref = newRV_noinc((SV *)newHV()); |
| 73 |
4013 |
| sv_2mortal(new_map_ref); |
| 74 |
4013 |
| sv_setsv(map_ref, new_map_ref); |
| 75 |
|
| } |
| 76 |
|
| |
| 77 |
453185 |
▶ | if ( !SvOK(cache_flag) || SvUV(cache_flag) != current ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ( !SvOK(cache_flag) || SvUV(cache_flag) != current ) { |
422244 |
30941 |
453185 |
| if ( !SvOK(cache_flag) || SvUV(cache_flag) != current ) { |
13644 |
408600 |
422244 |
|
| 78 |
44585 |
| mop_update_method_map(aTHX_ stash, (HV *)SvRV(map_ref)); |
| 79 |
44585 |
| sv_setuv(cache_flag, mop_check_package_cache_flag(aTHX_ stash)); /* update_cache_flag() */ |
| 80 |
|
| } |
| 81 |
|
| |
| 82 |
453185 |
▶ | XPUSHs(map_ref); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(map_ref); |
0 |
453185 |
453185 |
|
| 83 |
|
| |
| 84 |
|
| BOOT: |
| 85 |
459 |
| mop_method_metaclass = newSVpvs("method_metaclass"); |
| 86 |
459 |
| mop_associated_metaclass = newSVpvs("associated_metaclass"); |
| 87 |
459 |
| mop_wrap = newSVpvs("wrap"); |
| 88 |
459 |
| INSTALL_SIMPLE_READER(Mixin::HasMethods, method_metaclass); |
| 89 |
459 |
| INSTALL_SIMPLE_READER(Mixin::HasMethods, wrapped_method_metaclass); |