| 1 |
|
| #include "mouse.h" |
| 2 |
|
| |
| 3 |
|
| /* keywords for methods/keys */ |
| 4 |
|
| SV* mouse_package; |
| 5 |
|
| SV* mouse_namespace; |
| 6 |
|
| SV* mouse_methods; |
| 7 |
|
| SV* mouse_name; |
| 8 |
|
| SV* mouse_get_attribute; |
| 9 |
|
| SV* mouse_get_attribute_list; |
| 10 |
|
| SV* mouse_coerce; |
| 11 |
|
| |
| 12 |
|
| #define MOUSE_xc_flags(a) SvUVX(MOUSE_av_at((a), MOUSE_XC_FLAGS)) |
| 13 |
|
| #define MOUSE_xc_gen(a) MOUSE_av_at((a), MOUSE_XC_GEN) |
| 14 |
|
| #define MOUSE_xc_stash(a) ( (HV*)MOUSE_av_at((a), MOUSE_XC_STASH) ) |
| 15 |
|
| #define MOUSE_xc_attrall(a) ( (AV*)MOUSE_av_at((a), MOUSE_XC_ATTRALL) ) |
| 16 |
|
| #define MOUSE_xc_buildall(a) ( (AV*)MOUSE_av_at((a), MOUSE_XC_BUILDALL) ) |
| 17 |
|
| #define MOUSE_xc_demolishall(a) ( (AV*)MOUSE_av_at((a), MOUSE_XC_DEMOLISHALL) ) |
| 18 |
|
| |
| 19 |
|
| enum mouse_xc_flags_t { |
| 20 |
|
| MOUSEf_XC_IS_IMMUTABLE = 0x0001, |
| 21 |
|
| MOUSEf_XC_IS_ANON = 0x0002, |
| 22 |
|
| MOUSEf_XC_HAS_BUILDARGS = 0x0004, |
| 23 |
|
| MOUSEf_XC_CONSTRUCTOR_IS_STRICT |
| 24 |
|
| = 0x0008, |
| 25 |
|
| |
| 26 |
|
| MOUSEf_XC_mask = 0xFFFF /* not used */ |
| 27 |
|
| }; |
| 28 |
|
| |
| 29 |
|
| /* Mouse XS Metaclass object */ |
| 30 |
|
| enum mouse_xc_ix_t{ |
| 31 |
|
| MOUSE_XC_FLAGS, |
| 32 |
|
| |
| 33 |
|
| MOUSE_XC_GEN, /* class generation */ |
| 34 |
|
| MOUSE_XC_STASH, /* symbol table hash */ |
| 35 |
|
| |
| 36 |
|
| MOUSE_XC_ATTRALL, /* all the attributes */ |
| 37 |
|
| MOUSE_XC_BUILDALL, /* all the BUILD methods */ |
| 38 |
|
| MOUSE_XC_DEMOLISHALL, /* all the DEMOLISH methods */ |
| 39 |
|
| |
| 40 |
|
| MOUSE_XC_last |
| 41 |
|
| }; |
| 42 |
|
| |
| 43 |
|
| enum mouse_modifier_t { |
| 44 |
|
| MOUSE_M_BEFORE, |
| 45 |
|
| MOUSE_M_AROUND, |
| 46 |
|
| MOUSE_M_AFTER, |
| 47 |
|
| }; |
| 48 |
|
| |
| 49 |
|
| static MGVTBL mouse_xc_vtbl; /* for identity */ |
| 50 |
|
| |
| 51 |
|
| HV* |
| 52 |
2501 |
| mouse_get_namespace(pTHX_ SV* const meta) { |
| 53 |
2501 |
| SV* const package = get_slot(meta, mouse_package); |
| 54 |
2501 |
▶ | if(!(package && SvOK(package))){ |
Branch: 2 branches
| Branch | True | False | Total |
| if(!(package && SvOK(package))){ |
2501 |
0 |
2501 |
| if(!(package && SvOK(package))){ |
0 |
2501 |
2501 |
|
| 55 |
0 |
| croak("No package name defined for metaclass"); |
| 56 |
|
| } |
| 57 |
2501 |
| return gv_stashsv(package, GV_ADDMULTI); |
| 58 |
|
| } |
| 59 |
|
| |
| 60 |
|
| static AV* |
| 61 |
504 |
| mouse_calculate_all_attributes(pTHX_ SV* const metaclass) { |
| 62 |
504 |
| SV* const avref = mcall0s(metaclass, "_calculate_all_attributes"); |
| 63 |
504 |
▶ | if(!(SvROK(avref) && SvTYPE(SvRV(avref)) == SVt_PVAV)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(!(SvROK(avref) && SvTYPE(SvRV(avref)) == SVt_PVAV)) { |
504 |
0 |
504 |
| if(!(SvROK(avref) && SvTYPE(SvRV(avref)) == SVt_PVAV)) { |
0 |
504 |
504 |
|
| 64 |
0 |
| croak("$meta->_calculate_all_attributes did not return an ARRAY reference"); |
| 65 |
|
| } |
| 66 |
504 |
| return (AV*)SvRV(avref); |
| 67 |
|
| } |
| 68 |
|
| |
| 69 |
|
| XS(XS_Mouse__Object_BUILDARGS); /* prototype */ |
| 70 |
|
| |
| 71 |
|
| static int |
| 72 |
504 |
| mouse_class_has_custom_buildargs(pTHX_ HV* const stash) { |
| 73 |
504 |
| GV* const buildargs = gv_fetchmeth_autoload(stash, "BUILDARGS", sizeof("BUILDARGS")-1, 0); |
| 74 |
|
| |
| 75 |
504 |
▶ | return buildargs && CvXSUB(GvCV(buildargs)) != XS_Mouse__Object_BUILDARGS; |
Branch: 2 branches
| Branch | True | False | Total |
| return buildargs && CvXSUB(GvCV(buildargs)) != XS_Mouse__Object_BUILDARGS; |
399 |
105 |
504 |
| return buildargs && CvXSUB(GvCV(buildargs)) != XS_Mouse__Object_BUILDARGS; |
11 |
388 |
399 |
|
| 76 |
|
| } |
| 77 |
|
| |
| 78 |
|
| static AV* |
| 79 |
504 |
| mouse_class_update_xc(pTHX_ SV* const metaclass PERL_UNUSED_DECL, AV* const xc) { |
| 80 |
504 |
▶ | HV* const stash = MOUSE_xc_stash(xc); |
Branch: 1 branch
| Branch | True | False | Total |
| HV* const stash = MOUSE_xc_stash(xc); |
504 |
0 |
504 |
|
| 81 |
504 |
| AV* const linearized_isa = mro_get_linear_isa(stash); |
| 82 |
504 |
| I32 const len = AvFILLp(linearized_isa) + 1; |
| 83 |
|
| I32 i; |
| 84 |
504 |
| U32 flags = 0x00; |
| 85 |
504 |
| AV* const buildall = newAV(); |
| 86 |
504 |
| AV* const demolishall = newAV(); |
| 87 |
|
| AV* attrall; |
| 88 |
|
| |
| 89 |
504 |
| ENTER; |
| 90 |
504 |
| SAVETMPS; |
| 91 |
|
| |
| 92 |
|
| /* old data will be delete at the end of the perl scope */ |
| 93 |
504 |
| av_delete(xc, MOUSE_XC_DEMOLISHALL, 0x00); |
| 94 |
504 |
| av_delete(xc, MOUSE_XC_BUILDALL, 0x00); |
| 95 |
504 |
| av_delete(xc, MOUSE_XC_ATTRALL, 0x00); |
| 96 |
|
| |
| 97 |
504 |
| SvREFCNT_inc_simple_void_NN(linearized_isa); |
| 98 |
504 |
| sv_2mortal((SV*)linearized_isa); |
| 99 |
|
| |
| 100 |
|
| /* update */ |
| 101 |
|
| |
| 102 |
504 |
| av_store(xc, MOUSE_XC_BUILDALL, (SV*)buildall); |
| 103 |
504 |
| av_store(xc, MOUSE_XC_DEMOLISHALL, (SV*)demolishall); |
| 104 |
|
| |
| 105 |
504 |
| attrall = mouse_calculate_all_attributes(aTHX_ metaclass); |
| 106 |
504 |
| SvREFCNT_inc_simple_void_NN(attrall); |
| 107 |
504 |
| av_store(xc, MOUSE_XC_ATTRALL, (SV*)attrall); |
| 108 |
|
| |
| 109 |
504 |
▶ | if(predicate_calls(metaclass, "is_immutable")){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(predicate_calls(metaclass, "is_immutable")){ |
57 |
447 |
504 |
|
| 110 |
57 |
| flags |= MOUSEf_XC_IS_IMMUTABLE; |
| 111 |
|
| } |
| 112 |
|
| |
| 113 |
504 |
▶ | if(predicate_calls(metaclass, "is_anon_class")){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(predicate_calls(metaclass, "is_anon_class")){ |
62 |
442 |
504 |
|
| 114 |
62 |
| flags |= MOUSEf_XC_IS_ANON; |
| 115 |
|
| } |
| 116 |
|
| |
| 117 |
504 |
▶ | if(mouse_class_has_custom_buildargs(aTHX_ stash)){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(mouse_class_has_custom_buildargs(aTHX_ stash)){ |
11 |
493 |
504 |
|
| 118 |
11 |
| flags |= MOUSEf_XC_HAS_BUILDARGS; |
| 119 |
|
| } |
| 120 |
|
| |
| 121 |
504 |
▶ | if(predicate_calls(metaclass, "strict_constructor")){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(predicate_calls(metaclass, "strict_constructor")){ |
4 |
500 |
504 |
|
| 122 |
4 |
| flags |= MOUSEf_XC_CONSTRUCTOR_IS_STRICT; |
| 123 |
|
| } |
| 124 |
|
| |
| 125 |
504 |
| av_store(xc, MOUSE_XC_FLAGS, newSVuv(flags)); |
| 126 |
|
| |
| 127 |
1673 |
▶ | for(i = 0; i < len; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < len; i++){ |
1169 |
504 |
1673 |
|
| 128 |
1169 |
▶ | SV* const klass = MOUSE_av_at(linearized_isa, i); |
Branch: 1 branch
| Branch | True | False | Total |
| SV* const klass = MOUSE_av_at(linearized_isa, i); |
1169 |
0 |
1169 |
|
| 129 |
1169 |
| HV* const st = gv_stashsv(klass, TRUE); |
| 130 |
|
| GV* gv; |
| 131 |
|
| |
| 132 |
1169 |
| gv = stash_fetchs(st, "BUILD", FALSE); |
| 133 |
1169 |
▶ | if(gv && GvCVu(gv)){ |
Branch: 3 branches
| Branch | True | False | Total |
| if(gv && GvCVu(gv)){ |
31 |
1138 |
1169 |
| if(gv && GvCVu(gv)){ |
31 |
0 |
31 |
| if(gv && GvCVu(gv)){ |
31 |
0 |
31 |
|
| 134 |
31 |
| av_unshift(buildall, 1); |
| 135 |
31 |
| av_store(buildall, 0, newRV_inc((SV*)GvCV(gv))); |
| 136 |
|
| } |
| 137 |
|
| |
| 138 |
1169 |
| gv = stash_fetchs(st, "DEMOLISH", FALSE); |
| 139 |
1169 |
▶ | if(gv && GvCVu(gv)){ |
Branch: 3 branches
| Branch | True | False | Total |
| if(gv && GvCVu(gv)){ |
29 |
1140 |
1169 |
| if(gv && GvCVu(gv)){ |
29 |
0 |
29 |
| if(gv && GvCVu(gv)){ |
29 |
0 |
29 |
|
| 140 |
29 |
| av_push(demolishall, newRV_inc((SV*)GvCV(gv))); |
| 141 |
|
| } |
| 142 |
|
| } |
| 143 |
|
| |
| 144 |
504 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
504 |
0 |
504 |
|
| 145 |
504 |
| LEAVE; |
| 146 |
|
| |
| 147 |
504 |
▶ | sv_setuv(MOUSE_xc_gen(xc), mro_get_pkg_gen(stash)); |
Branch: 2 branches
| Branch | True | False | Total |
| sv_setuv(MOUSE_xc_gen(xc), mro_get_pkg_gen(stash)); |
504 |
0 |
504 |
| sv_setuv(MOUSE_xc_gen(xc), mro_get_pkg_gen(stash)); |
504 |
0 |
504 |
|
| 148 |
504 |
| return xc; |
| 149 |
|
| } |
| 150 |
|
| |
| 151 |
|
| static AV* |
| 152 |
6432 |
| mouse_get_xc_wo_check(pTHX_ SV* const metaclass) { |
| 153 |
|
| AV* xc; |
| 154 |
|
| MAGIC* mg; |
| 155 |
|
| |
| 156 |
6432 |
▶ | if(!IsObject(metaclass)){ |
Branch: 2 branches
| Branch | True | False | Total |
| if(!IsObject(metaclass)){ |
6432 |
0 |
6432 |
| if(!IsObject(metaclass)){ |
0 |
6432 |
6432 |
|
| 157 |
0 |
| croak("Not a Mouse metaclass"); |
| 158 |
|
| } |
| 159 |
|
| |
| 160 |
6432 |
| mg = mouse_mg_find(aTHX_ SvRV(metaclass), &mouse_xc_vtbl, 0x00); |
| 161 |
6432 |
▶ | if(!mg){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(!mg){ |
509 |
5923 |
6432 |
|
| 162 |
|
| /* cache stash for performance */ |
| 163 |
509 |
| HV* const stash = mouse_get_namespace(aTHX_ metaclass); |
| 164 |
509 |
| xc = newAV(); |
| 165 |
|
| |
| 166 |
509 |
| mg = sv_magicext(SvRV(metaclass), (SV*)xc, PERL_MAGIC_ext, |
| 167 |
|
| &mouse_xc_vtbl, NULL, 0); |
| 168 |
509 |
| SvREFCNT_dec(xc); /* refcnt++ in sv_magicext */ |
| 169 |
|
| |
| 170 |
509 |
| av_extend(xc, MOUSE_XC_last - 1); |
| 171 |
|
| |
| 172 |
509 |
| av_store(xc, MOUSE_XC_GEN, newSVuv(0U)); |
| 173 |
509 |
| av_store(xc, MOUSE_XC_STASH, (SV*)stash); |
| 174 |
509 |
| SvREFCNT_inc_simple_void_NN(stash); |
| 175 |
|
| } |
| 176 |
|
| else{ |
| 177 |
5923 |
| xc = (AV*)MOUSE_mg_obj(mg); |
| 178 |
|
| |
| 179 |
|
| assert(xc); |
| 180 |
|
| assert(SvTYPE(xc) == SVt_PVAV); |
| 181 |
|
| } |
| 182 |
6432 |
| return xc; |
| 183 |
|
| } |
| 184 |
|
| |
| 185 |
|
| static int |
| 186 |
6432 |
| mouse_xc_is_fresh(pTHX_ AV* const xc) { |
| 187 |
6432 |
▶ | HV* const stash = MOUSE_xc_stash(xc); |
Branch: 1 branch
| Branch | True | False | Total |
| HV* const stash = MOUSE_xc_stash(xc); |
6432 |
0 |
6432 |
|
| 188 |
6432 |
▶ | SV* const gen = MOUSE_xc_gen(xc); |
Branch: 1 branch
| Branch | True | False | Total |
| SV* const gen = MOUSE_xc_gen(xc); |
6432 |
0 |
6432 |
|
| 189 |
6432 |
▶ | if(SvUVX(gen) != 0U && MOUSE_xc_flags(xc) & MOUSEf_XC_IS_IMMUTABLE) { |
Branch: 3 branches
| Branch | True | False | Total |
| if(SvUVX(gen) != 0U && MOUSE_xc_flags(xc) & MOUSEf_XC_IS_IMMUTABLE) { |
5389 |
1043 |
6432 |
| if(SvUVX(gen) != 0U && MOUSE_xc_flags(xc) & MOUSEf_XC_IS_IMMUTABLE) { |
5389 |
0 |
5389 |
| if(SvUVX(gen) != 0U && MOUSE_xc_flags(xc) & MOUSEf_XC_IS_IMMUTABLE) { |
235 |
5154 |
5389 |
|
| 190 |
235 |
| return TRUE; |
| 191 |
|
| } |
| 192 |
6197 |
▶ | return SvUVX(gen) == mro_get_pkg_gen(stash); |
Branch: 1 branch
| Branch | True | False | Total |
| return SvUVX(gen) == mro_get_pkg_gen(stash); |
6197 |
0 |
6197 |
|
| 193 |
|
| } |
| 194 |
|
| |
| 195 |
|
| STATIC_INLINE AV* |
| 196 |
3978 |
| mouse_get_xc(pTHX_ SV* const metaclass) { |
| 197 |
3978 |
| AV* const xc = mouse_get_xc_wo_check(aTHX_ metaclass); |
| 198 |
3978 |
| return mouse_xc_is_fresh(aTHX_ xc) |
| 199 |
|
| ? xc |
| 200 |
3978 |
▶ | : mouse_class_update_xc(aTHX_ metaclass, xc); |
Branch: 1 branch
| Branch | True | False | Total |
| : mouse_class_update_xc(aTHX_ metaclass, xc); |
504 |
3474 |
3978 |
|
| 201 |
|
| } |
| 202 |
|
| |
| 203 |
|
| static AV* |
| 204 |
2454 |
| mouse_get_xc_if_fresh(pTHX_ SV* const metaclass) { |
| 205 |
2454 |
| AV* const xc = mouse_get_xc_wo_check(aTHX_ metaclass); |
| 206 |
2454 |
| return mouse_xc_is_fresh(aTHX_ xc) |
| 207 |
|
| ? xc |
| 208 |
2454 |
▶ | : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| : NULL; |
1853 |
601 |
2454 |
|
| 209 |
|
| } |
| 210 |
|
| |
| 211 |
|
| static HV* |
| 212 |
2907 |
| mouse_buildargs(pTHX_ SV* metaclass, SV* const klass, I32 ax, I32 items) { |
| 213 |
|
| HV* args; |
| 214 |
|
| |
| 215 |
|
| /* shift @_ */ |
| 216 |
2907 |
| ax++; |
| 217 |
2907 |
| items--; |
| 218 |
|
| |
| 219 |
2907 |
▶ | if(items == 1){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(items == 1){ |
69 |
2838 |
2907 |
|
| 220 |
69 |
| SV* const args_ref = ST(0); |
| 221 |
69 |
▶ | if(!IsHashRef(args_ref)){ |
Branch: 3 branches
| Branch | True | False | Total |
| if(!IsHashRef(args_ref)){ |
63 |
6 |
69 |
| if(!IsHashRef(args_ref)){ |
62 |
1 |
63 |
| if(!IsHashRef(args_ref)){ |
4 |
58 |
62 |
|
| 222 |
11 |
▶ | if(!metaclass){ metaclass = get_metaclass(klass); } |
Branch: 1 branch
| Branch | True | False | Total |
| if(!metaclass){ metaclass = get_metaclass(klass); } |
2 |
9 |
11 |
|
| 223 |
11 |
| mouse_throw_error(metaclass, NULL, "Single parameters to new() must be a HASH ref"); |
| 224 |
|
| } |
| 225 |
58 |
| args = newHVhv((HV*)SvRV(args_ref)); |
| 226 |
58 |
| sv_2mortal((SV*)args); |
| 227 |
|
| } |
| 228 |
|
| else{ |
| 229 |
|
| I32 i; |
| 230 |
|
| |
| 231 |
2838 |
▶ | if( (items % 2) != 0 ){ |
Branch: 1 branch
| Branch | True | False | Total |
| if( (items % 2) != 0 ){ |
0 |
2838 |
2838 |
|
| 232 |
0 |
▶ | if(!metaclass){ metaclass = get_metaclass(klass); } |
Branch: 1 branch
| Branch | True | False | Total |
| if(!metaclass){ metaclass = get_metaclass(klass); } |
0 |
0 |
0 |
|
| 233 |
0 |
| mouse_throw_error(metaclass, NULL, "Odd number of parameters to new()"); |
| 234 |
|
| } |
| 235 |
|
| |
| 236 |
2838 |
| args = newHV_mortal(); |
| 237 |
5475 |
▶ | for(i = 0; i < items; i += 2){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < items; i += 2){ |
2637 |
2838 |
5475 |
|
| 238 |
2637 |
| (void)hv_store_ent(args, ST(i), newSVsv(ST(i+1)), 0U); |
| 239 |
|
| } |
| 240 |
|
| |
| 241 |
|
| } |
| 242 |
2896 |
| return args; |
| 243 |
|
| } |
| 244 |
|
| |
| 245 |
|
| static void |
| 246 |
8 |
| mouse_report_unknown_args(pTHX_ SV* const meta, AV* const attrs, HV* const args) { |
| 247 |
8 |
| HV* const attr_map = newHV_mortal(); |
| 248 |
8 |
| SV* const unknown = newSVpvs_flags("", SVs_TEMP); |
| 249 |
8 |
| I32 const len = AvFILLp(attrs) + 1; |
| 250 |
|
| I32 i; |
| 251 |
|
| HE* he; |
| 252 |
|
| |
| 253 |
32 |
▶ | for(i = 0; i < len; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < len; i++){ |
24 |
8 |
32 |
|
| 254 |
24 |
▶ | SV* const attr = MOUSE_av_at(attrs, i); |
Branch: 1 branch
| Branch | True | False | Total |
| SV* const attr = MOUSE_av_at(attrs, i); |
24 |
0 |
24 |
|
| 255 |
24 |
| AV* const xa = mouse_get_xa(aTHX_ attr); |
| 256 |
24 |
▶ | SV* const init_arg = MOUSE_xa_init_arg(xa); |
Branch: 1 branch
| Branch | True | False | Total |
| SV* const init_arg = MOUSE_xa_init_arg(xa); |
24 |
0 |
24 |
|
| 257 |
24 |
▶ | if(SvOK(init_arg)){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvOK(init_arg)){ |
16 |
8 |
24 |
|
| 258 |
16 |
| (void)hv_store_ent(attr_map, init_arg, &PL_sv_undef, 0U); |
| 259 |
|
| } |
| 260 |
|
| } |
| 261 |
|
| |
| 262 |
8 |
| hv_iterinit(args); |
| 263 |
36 |
▶ | while((he = hv_iternext(args))){ |
Branch: 1 branch
| Branch | True | False | Total |
| while((he = hv_iternext(args))){ |
20 |
8 |
28 |
|
| 264 |
20 |
| SV* const key = hv_iterkeysv(he); |
| 265 |
20 |
▶ | if(!hv_exists_ent(attr_map, key, 0U)){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(!hv_exists_ent(attr_map, key, 0U)){ |
4 |
16 |
20 |
|
| 266 |
16 |
| sv_catpvf(unknown, "%"SVf", ", key); |
| 267 |
|
| } |
| 268 |
|
| } |
| 269 |
|
| |
| 270 |
8 |
▶ | if(SvCUR(unknown) > 0){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvCUR(unknown) > 0){ |
8 |
0 |
8 |
|
| 271 |
8 |
| SvCUR(unknown) -= 2; /* chop "," */ |
| 272 |
|
| } |
| 273 |
|
| else{ |
| 274 |
0 |
| sv_setpvs(unknown, "(unknown)"); |
| 275 |
|
| } |
| 276 |
|
| |
| 277 |
8 |
| mouse_throw_error(meta, NULL, |
| 278 |
|
| "Unknown attribute passed to the constructor of %"SVf": %"SVf, |
| 279 |
|
| mcall0(meta, mouse_name), unknown); |
| 280 |
0 |
| } |
| 281 |
|
| |
| 282 |
|
| |
| 283 |
|
| |
| 284 |
|
| static void |
| 285 |
2060 |
| mouse_class_initialize_object(pTHX_ SV* const meta, SV* const object, HV* const args, bool const is_cloning) { |
| 286 |
2060 |
| AV* const xc = mouse_get_xc(aTHX_ meta); |
| 287 |
2060 |
▶ | AV* const attrs = MOUSE_xc_attrall(xc); |
Branch: 1 branch
| Branch | True | False | Total |
| AV* const attrs = MOUSE_xc_attrall(xc); |
2060 |
0 |
2060 |
|
| 288 |
2060 |
| I32 const len = AvFILLp(attrs) + 1; |
| 289 |
|
| I32 i; |
| 290 |
2060 |
| AV* triggers_queue = NULL; |
| 291 |
2060 |
| I32 used = 0; |
| 292 |
|
| |
| 293 |
|
| assert(meta || object); |
| 294 |
|
| assert(args); |
| 295 |
|
| assert(SvTYPE(args) == SVt_PVHV); |
| 296 |
|
| |
| 297 |
2060 |
▶ | if(mg_find((SV*)args, PERL_MAGIC_tied)){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(mg_find((SV*)args, PERL_MAGIC_tied)){ |
0 |
2060 |
2060 |
|
| 298 |
0 |
| croak("You cannot use tied HASH reference as initializing arguments"); |
| 299 |
|
| } |
| 300 |
|
| |
| 301 |
|
| /* for each attribute */ |
| 302 |
19305 |
▶ | for(i = 0; i < len; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < len; i++){ |
17710 |
1595 |
19305 |
|
| 303 |
17710 |
▶ | SV* const attr = MOUSE_av_at(attrs, i); |
Branch: 1 branch
| Branch | True | False | Total |
| SV* const attr = MOUSE_av_at(attrs, i); |
17710 |
0 |
17710 |
|
| 304 |
17710 |
| AV* const xa = mouse_get_xa(aTHX_ attr); |
| 305 |
|
| |
| 306 |
17710 |
▶ | SV* const slot = MOUSE_xa_slot(xa); |
Branch: 1 branch
| Branch | True | False | Total |
| SV* const slot = MOUSE_xa_slot(xa); |
17710 |
0 |
17710 |
|
| 307 |
17710 |
▶ | U16 const flags = (U16)MOUSE_xa_flags(xa); |
Branch: 1 branch
| Branch | True | False | Total |
| U16 const flags = (U16)MOUSE_xa_flags(xa); |
17710 |
0 |
17710 |
|
| 308 |
17710 |
▶ | SV* const init_arg = MOUSE_xa_init_arg(xa); |
Branch: 1 branch
| Branch | True | False | Total |
| SV* const init_arg = MOUSE_xa_init_arg(xa); |
17710 |
0 |
17710 |
|
| 309 |
|
| HE* he; |
| 310 |
|
| |
| 311 |
17710 |
▶ | if(SvOK(init_arg) && ( he = hv_fetch_ent(args, init_arg, FALSE, 0U) ) ){ |
Branch: 2 branches
| Branch | True | False | Total |
| if(SvOK(init_arg) && ( he = hv_fetch_ent(args, init_arg, FALSE, 0U) ) ){ |
17685 |
25 |
17710 |
| if(SvOK(init_arg) && ( he = hv_fetch_ent(args, init_arg, FALSE, 0U) ) ){ |
1195 |
16490 |
17685 |
|
| 312 |
1195 |
| SV* value = HeVAL(he); |
| 313 |
1195 |
▶ | if(flags & MOUSEf_ATTR_HAS_TC){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(flags & MOUSEf_ATTR_HAS_TC){ |
1035 |
160 |
1195 |
|
| 314 |
1035 |
| value = mouse_xa_apply_type_constraint(aTHX_ xa, value, flags); |
| 315 |
|
| } |
| 316 |
778 |
| value = set_slot(object, slot, value); |
| 317 |
778 |
▶ | if(flags & MOUSEf_ATTR_IS_WEAK_REF){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(flags & MOUSEf_ATTR_IS_WEAK_REF){ |
8 |
770 |
778 |
|
| 318 |
8 |
| weaken_slot(object, slot); |
| 319 |
|
| } |
| 320 |
778 |
▶ | if(flags & MOUSEf_ATTR_HAS_TRIGGER){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(flags & MOUSEf_ATTR_HAS_TRIGGER){ |
30 |
748 |
778 |
|
| 321 |
30 |
| AV* const pair = newAV(); |
| 322 |
30 |
| av_push(pair, newSVsv( mcall0s(attr, "trigger") )); |
| 323 |
30 |
| av_push(pair, newSVsv(value)); |
| 324 |
|
| |
| 325 |
30 |
▶ | if(!triggers_queue) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!triggers_queue) { |
26 |
4 |
30 |
|
| 326 |
26 |
| triggers_queue = newAV_mortal(); |
| 327 |
|
| } |
| 328 |
30 |
| av_push(triggers_queue, (SV*)pair); |
| 329 |
|
| } |
| 330 |
778 |
| used++; |
| 331 |
|
| } |
| 332 |
|
| else { /* no init arg */ |
| 333 |
16515 |
▶ | if(flags & (MOUSEf_ATTR_HAS_DEFAULT | MOUSEf_ATTR_HAS_BUILDER)){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(flags & (MOUSEf_ATTR_HAS_DEFAULT | MOUSEf_ATTR_HAS_BUILDER)){ |
279 |
16236 |
16515 |
|
| 334 |
|
| /* skip if the object has the slot (it occurs on cloning/reblessing) */ |
| 335 |
279 |
▶ | if(!(flags & MOUSEf_ATTR_IS_LAZY) && !has_slot(object, slot)){ |
Branch: 2 branches
| Branch | True | False | Total |
| if(!(flags & MOUSEf_ATTR_IS_LAZY) && !has_slot(object, slot)){ |
175 |
104 |
279 |
| if(!(flags & MOUSEf_ATTR_IS_LAZY) && !has_slot(object, slot)){ |
175 |
0 |
175 |
|
| 336 |
175 |
| mouse_xa_set_default(aTHX_ xa, object); |
| 337 |
|
| } |
| 338 |
|
| } |
| 339 |
16236 |
▶ | else if(is_cloning) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if(is_cloning) { |
10 |
16226 |
16236 |
|
| 340 |
10 |
▶ | if(flags & MOUSEf_ATTR_IS_WEAK_REF){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(flags & MOUSEf_ATTR_IS_WEAK_REF){ |
1 |
9 |
10 |
|
| 341 |
1 |
| weaken_slot(object, slot); |
| 342 |
|
| } |
| 343 |
|
| } |
| 344 |
|
| /* don't check "required" while cloning (or reblesseing) */ |
| 345 |
16226 |
▶ | else if(flags & MOUSEf_ATTR_IS_REQUIRED) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if(flags & MOUSEf_ATTR_IS_REQUIRED) { |
44 |
16182 |
16226 |
|
| 346 |
44 |
| mouse_throw_error(attr, NULL, "Attribute (%"SVf") is required", slot); |
| 347 |
|
| } |
| 348 |
|
| } |
| 349 |
|
| } /* for each attribute */ |
| 350 |
|
| |
| 351 |
1595 |
▶ | if(MOUSE_xc_flags(xc) & MOUSEf_XC_CONSTRUCTOR_IS_STRICT |
Branch: 2 branches
| Branch | True | False | Total |
| if(MOUSE_xc_flags(xc) & MOUSEf_XC_CONSTRUCTOR_IS_STRICT |
1595 |
0 |
1595 |
| if(MOUSE_xc_flags(xc) & MOUSEf_XC_CONSTRUCTOR_IS_STRICT |
12 |
1583 |
1595 |
|
| 352 |
12 |
▶ | && used < (I32)HvUSEDKEYS(args)){ |
Branch: 2 branches
| Branch | True | False | Total |
| && used < (I32)HvUSEDKEYS(args)){ |
0 |
12 |
12 |
| && used < (I32)HvUSEDKEYS(args)){ |
8 |
4 |
12 |
|
| 353 |
8 |
| mouse_report_unknown_args(aTHX_ meta, attrs, args); |
| 354 |
|
| } |
| 355 |
|
| |
| 356 |
1587 |
▶ | if(triggers_queue){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(triggers_queue){ |
26 |
1561 |
1587 |
|
| 357 |
26 |
| I32 const len = AvFILLp(triggers_queue) + 1; |
| 358 |
54 |
▶ | for(i = 0; i < len; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < len; i++){ |
30 |
24 |
54 |
|
| 359 |
30 |
| AV* const pair = (AV*)AvARRAY(triggers_queue)[i]; |
| 360 |
30 |
| SV* const trigger = AvARRAY(pair)[0]; |
| 361 |
30 |
| SV* const value = AvARRAY(pair)[1]; |
| 362 |
|
| |
| 363 |
30 |
| mcall1(object, trigger, value); |
| 364 |
|
| } |
| 365 |
|
| } |
| 366 |
|
| |
| 367 |
1585 |
▶ | if(MOUSE_xc_flags(xc) & MOUSEf_XC_IS_ANON){ |
Branch: 2 branches
| Branch | True | False | Total |
| if(MOUSE_xc_flags(xc) & MOUSEf_XC_IS_ANON){ |
1585 |
0 |
1585 |
| if(MOUSE_xc_flags(xc) & MOUSEf_XC_IS_ANON){ |
73 |
1512 |
1585 |
|
| 368 |
73 |
| (void)set_slot(object, newSVpvs_flags("__METACLASS__", SVs_TEMP), meta); |
| 369 |
|
| } |
| 370 |
1585 |
| } |
| 371 |
|
| |
| 372 |
|
| STATIC_INLINE SV* |
| 373 |
1869 |
| mouse_initialize_metaclass(pTHX_ SV* const klass) { |
| 374 |
1869 |
| SV* const meta = get_metaclass(klass); |
| 375 |
1869 |
▶ | if(LIKELY(SvOK(meta))){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(LIKELY(SvOK(meta))){ |
1868 |
1 |
1869 |
|
| 376 |
1868 |
| return meta; |
| 377 |
|
| } |
| 378 |
1 |
| return mcall1s(newSVpvs_flags("Mouse::Meta::Class", SVs_TEMP), |
| 379 |
|
| "initialize", klass); |
| 380 |
|
| } |
| 381 |
|
| |
| 382 |
|
| static void |
| 383 |
1396 |
| mouse_buildall(pTHX_ AV* const xc, SV* const object, SV* const args) { |
| 384 |
1396 |
▶ | AV* const buildall = MOUSE_xc_buildall(xc); |
Branch: 1 branch
| Branch | True | False | Total |
| AV* const buildall = MOUSE_xc_buildall(xc); |
1396 |
0 |
1396 |
|
| 385 |
1396 |
| I32 const len = AvFILLp(buildall) + 1; |
| 386 |
|
| I32 i; |
| 387 |
1439 |
▶ | for(i = 0; i < len; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < len; i++){ |
52 |
1387 |
1439 |
|
| 388 |
52 |
| dSP; |
| 389 |
|
| |
| 390 |
52 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
52 |
52 |
|
| 391 |
52 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
52 |
52 |
|
| 392 |
52 |
| PUSHs(object); |
| 393 |
52 |
| PUSHs(args); |
| 394 |
52 |
| PUTBACK; |
| 395 |
|
| |
| 396 |
52 |
| call_sv_safe(AvARRAY(buildall)[i], G_VOID | G_DISCARD); |
| 397 |
|
| } |
| 398 |
1387 |
| } |
| 399 |
|
| |
| 400 |
|
| static AV* |
| 401 |
58 |
| mouse_get_modifier_storage(pTHX_ |
| 402 |
|
| SV* const meta, |
| 403 |
|
| enum mouse_modifier_t const m, SV* const name) { |
| 404 |
|
| static const char* const keys[] = { |
| 405 |
|
| "before", |
| 406 |
|
| "around", |
| 407 |
|
| "after", |
| 408 |
|
| }; |
| 409 |
58 |
| SV* const key = sv_2mortal(Perl_newSVpvf(aTHX_ "%s_method_modifiers", keys[m])); |
| 410 |
|
| SV* table; |
| 411 |
|
| SV* storage_ref; |
| 412 |
|
| |
| 413 |
58 |
| must_defined(name, "a method name"); |
| 414 |
|
| |
| 415 |
58 |
| table = get_slot(meta, key); |
| 416 |
|
| |
| 417 |
58 |
▶ | if(!table){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(!table){ |
45 |
13 |
58 |
|
| 418 |
|
| /* $meta->{$key} = {} */ |
| 419 |
45 |
| table = sv_2mortal(newRV_noinc((SV*)newHV())); |
| 420 |
45 |
| set_slot(meta, key, table); |
| 421 |
|
| } |
| 422 |
|
| |
| 423 |
58 |
| storage_ref = get_slot(table, name); |
| 424 |
|
| |
| 425 |
58 |
▶ | if(!storage_ref){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(!storage_ref){ |
47 |
11 |
58 |
|
| 426 |
47 |
| storage_ref = sv_2mortal(newRV_noinc((SV*)newAV())); |
| 427 |
47 |
| set_slot(table, name, storage_ref); |
| 428 |
|
| } |
| 429 |
|
| else{ |
| 430 |
11 |
▶ | if(!IsArrayRef(storage_ref)){ |
Branch: 3 branches
| Branch | True | False | Total |
| if(!IsArrayRef(storage_ref)){ |
11 |
0 |
11 |
| if(!IsArrayRef(storage_ref)){ |
11 |
0 |
11 |
| if(!IsArrayRef(storage_ref)){ |
0 |
11 |
11 |
|
| 431 |
0 |
| croak("Modifier strorage for '%s' is not an ARRAY reference", keys[m]); |
| 432 |
|
| } |
| 433 |
|
| } |
| 434 |
|
| |
| 435 |
58 |
| return (AV*)SvRV(storage_ref); |
| 436 |
|
| } |
| 437 |
|
| |
| 438 |
|
| static |
| 439 |
168 |
| XSPROTO(XS_Mouse_value_holder) { |
| 440 |
168 |
| dVAR; dXSARGS; |
| 441 |
168 |
| SV* const value = (SV*)XSANY.any_ptr; |
| 442 |
|
| assert(value); |
| 443 |
|
| PERL_UNUSED_VAR(items); |
| 444 |
168 |
| ST(0) = value; |
| 445 |
168 |
| XSRETURN(1); |
| 446 |
|
| } |
| 447 |
|
| |
| 448 |
|
| DECL_BOOT(Mouse__Util); |
| 449 |
|
| DECL_BOOT(Mouse__Util__TypeConstraints); |
| 450 |
|
| DECL_BOOT(Mouse__Meta__Method__Accessor__XS); |
| 451 |
|
| DECL_BOOT(Mouse__Meta__Attribute); |
| 452 |
|
| |
| 453 |
|
| MODULE = Mouse PACKAGE = Mouse |
| 454 |
|
| |
| 455 |
|
| PROTOTYPES: DISABLE |
| 456 |
|
| |
| 457 |
|
| BOOT: |
| 458 |
|
| { |
| 459 |
286 |
| mouse_package = newSVpvs("package"); |
| 460 |
286 |
| mouse_namespace = newSVpvs("namespace"); |
| 461 |
286 |
| mouse_methods = newSVpvs("methods"); |
| 462 |
286 |
| mouse_name = newSVpvs("name"); |
| 463 |
286 |
| mouse_coerce = newSVpvs("coerce"); |
| 464 |
|
| |
| 465 |
286 |
| mouse_get_attribute = newSVpvs("get_attribute"); |
| 466 |
286 |
| mouse_get_attribute_list = newSVpvs("get_attribute_list"); |
| 467 |
|
| |
| 468 |
286 |
▶ | CALL_BOOT(Mouse__Util); |
Branch: 1 branch
| Branch | True | False | Total |
| CALL_BOOT(Mouse__Util); |
0 |
286 |
286 |
|
| 469 |
286 |
▶ | CALL_BOOT(Mouse__Util__TypeConstraints); |
Branch: 1 branch
| Branch | True | False | Total |
| CALL_BOOT(Mouse__Util__TypeConstraints); |
0 |
286 |
286 |
|
| 470 |
286 |
▶ | CALL_BOOT(Mouse__Meta__Method__Accessor__XS); |
Branch: 1 branch
| Branch | True | False | Total |
| CALL_BOOT(Mouse__Meta__Method__Accessor__XS); |
0 |
286 |
286 |
|
| 471 |
286 |
▶ | CALL_BOOT(Mouse__Meta__Attribute); |
Branch: 1 branch
| Branch | True | False | Total |
| CALL_BOOT(Mouse__Meta__Attribute); |
0 |
286 |
286 |
|
| 472 |
|
| } |
| 473 |
|
| |
| 474 |
|
| MODULE = Mouse PACKAGE = Mouse::Meta::Module |
| 475 |
|
| |
| 476 |
|
| BOOT: |
| 477 |
286 |
| INSTALL_SIMPLE_READER_WITH_KEY(Module, name, package); |
| 478 |
286 |
| INSTALL_SIMPLE_READER_WITH_KEY(Module, _method_map, methods); |
| 479 |
286 |
| INSTALL_SIMPLE_READER_WITH_KEY(Module, _attribute_map, attributes); |
| 480 |
|
| |
| 481 |
|
| HV* |
| 482 |
|
| namespace(SV* self) |
| 483 |
|
| CODE: |
| 484 |
|
| { |
| 485 |
396 |
| RETVAL = mouse_get_namespace(aTHX_ self); |
| 486 |
|
| } |
| 487 |
|
| OUTPUT: |
| 488 |
|
| RETVAL |
| 489 |
|
| |
| 490 |
|
| # ignore extra arguments for extensibility |
| 491 |
|
| void |
| 492 |
|
| add_method(SV* self, SV* name, SV* code, ...) |
| 493 |
|
| CODE: |
| 494 |
|
| { |
| 495 |
2079 |
| SV* const package = get_slot(self, mouse_package); /* $self->{package} */ |
| 496 |
2079 |
| SV* const methods = get_slot(self, mouse_methods); /* $self->{methods} */ |
| 497 |
|
| GV* gv; |
| 498 |
|
| SV* code_ref; |
| 499 |
|
| |
| 500 |
2079 |
▶ | if(!(package && SvOK(package))){ |
Branch: 2 branches
| Branch | True | False | Total |
| if(!(package && SvOK(package))){ |
2079 |
0 |
2079 |
| if(!(package && SvOK(package))){ |
0 |
2079 |
2079 |
|
| 501 |
0 |
| croak("No package name defined"); |
| 502 |
|
| } |
| 503 |
|
| |
| 504 |
2079 |
| must_defined(name, "a method name"); |
| 505 |
2079 |
| must_ref (code, "a CODE reference", SVt_NULL); /* any reftype is OK */ |
| 506 |
|
| |
| 507 |
2079 |
| code_ref = code; |
| 508 |
2079 |
▶ | if(SvTYPE(SvRV(code_ref)) != SVt_PVCV){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvTYPE(SvRV(code_ref)) != SVt_PVCV){ |
0 |
2079 |
2079 |
|
| 509 |
0 |
| SV* sv = code_ref; /* used in tryAMAGICunDEREF */ |
| 510 |
0 |
| SV** sp = &sv; /* used in tryAMAGICunDEREF */ |
| 511 |
0 |
| tryAMAGICunDEREF(to_cv); /* try \&{$code} */ |
| 512 |
0 |
| must_ref(code, "a CODE reference", SVt_PVCV); |
| 513 |
0 |
| code_ref = sv; |
| 514 |
|
| } |
| 515 |
|
| |
| 516 |
|
| /* *{$package . '::' . $name} -> *gv */ |
| 517 |
2079 |
| gv = gv_fetchpv(form("%"SVf"::%"SVf, package, name), GV_ADDMULTI, SVt_PVCV); |
| 518 |
2079 |
| mouse_install_sub(aTHX_ gv, code_ref); |
| 519 |
|
| /* CvMETHOD_on((CV*)SvRV(code_ref)); */ |
| 520 |
2079 |
| (void)set_slot(methods, name, code); /* $self->{methods}{$name} = $code */ |
| 521 |
|
| } |
| 522 |
|
| |
| 523 |
|
| MODULE = Mouse PACKAGE = Mouse::Meta::Class |
| 524 |
|
| |
| 525 |
|
| BOOT: |
| 526 |
|
| { |
| 527 |
|
| CV* xsub; |
| 528 |
|
| |
| 529 |
286 |
| INSTALL_SIMPLE_READER(Class, roles); |
| 530 |
286 |
| INSTALL_SIMPLE_PREDICATE_WITH_KEY(Class, is_anon_class, anon_serial_id); |
| 531 |
286 |
| INSTALL_SIMPLE_READER(Class, is_immutable); |
| 532 |
|
| |
| 533 |
286 |
| INSTALL_INHERITABLE_CLASS_ACCESSOR(strict_constructor); |
| 534 |
|
| |
| 535 |
286 |
| INSTALL_CLASS_HOLDER(Class, method_metaclass, "Mouse::Meta::Method"); |
| 536 |
286 |
| INSTALL_CLASS_HOLDER(Class, attribute_metaclass, "Mouse::Meta::Attribute"); |
| 537 |
286 |
| INSTALL_CLASS_HOLDER(Class, constructor_class, "Mouse::Meta::Method::Constructor::XS"); |
| 538 |
286 |
| INSTALL_CLASS_HOLDER(Class, destructor_class, "Mouse::Meta::Method::Destructor::XS"); |
| 539 |
|
| |
| 540 |
286 |
| xsub = newXS("Mouse::Meta::Method::Constructor::XS::_generate_constructor", |
| 541 |
|
| XS_Mouse_value_holder, file); |
| 542 |
286 |
| CvXSUBANY(xsub).any_ptr |
| 543 |
286 |
| = newRV_inc((SV*)get_cvs("Mouse::Object::new", GV_ADD)); |
| 544 |
|
| |
| 545 |
286 |
| xsub = newXS("Mouse::Meta::Method::Destructor::XS::_generate_destructor", |
| 546 |
|
| XS_Mouse_value_holder, file); |
| 547 |
286 |
| CvXSUBANY(xsub).any_ptr |
| 548 |
286 |
| = newRV_inc((SV*)get_cvs("Mouse::Object::DESTROY", GV_ADD)); |
| 549 |
|
| } |
| 550 |
|
| |
| 551 |
|
| |
| 552 |
|
| void |
| 553 |
|
| linearized_isa(SV* self) |
| 554 |
|
| PPCODE: |
| 555 |
|
| { |
| 556 |
|
| /* MOUSE_xc_stash() is not available because the xc system depends on |
| 557 |
|
| linearized_isa() */ |
| 558 |
1091 |
| HV* const stash = mouse_get_namespace(aTHX_ self); |
| 559 |
1091 |
| AV* const linearized_isa = mro_get_linear_isa(stash); |
| 560 |
1091 |
| I32 const len = AvFILLp(linearized_isa) + 1; |
| 561 |
|
| I32 i; |
| 562 |
1091 |
▶ | EXTEND(SP, len); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, len); |
1091 |
0 |
1091 |
| EXTEND(SP, len); |
0 |
1091 |
1091 |
|
| 563 |
3671 |
▶ | for(i = 0; i < len; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < len; i++){ |
2580 |
1091 |
3671 |
|
| 564 |
2580 |
| PUSHs(AvARRAY(linearized_isa)[i]); |
| 565 |
|
| } |
| 566 |
|
| } |
| 567 |
|
| |
| 568 |
|
| void |
| 569 |
|
| get_all_attributes(SV* self) |
| 570 |
|
| PPCODE: |
| 571 |
|
| { |
| 572 |
32 |
| AV* const xc = mouse_get_xc(aTHX_ self); |
| 573 |
32 |
▶ | AV* const all_attrs = MOUSE_xc_attrall(xc); |
Branch: 1 branch
| Branch | True | False | Total |
| AV* const all_attrs = MOUSE_xc_attrall(xc); |
32 |
0 |
32 |
|
| 574 |
32 |
| I32 const len = AvFILLp(all_attrs) + 1; |
| 575 |
|
| I32 i; |
| 576 |
|
| |
| 577 |
32 |
▶ | EXTEND(SP, len); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, len); |
32 |
0 |
32 |
| EXTEND(SP, len); |
0 |
32 |
32 |
|
| 578 |
112 |
▶ | for(i = 0; i < len; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < len; i++){ |
80 |
32 |
112 |
|
| 579 |
80 |
▶ | PUSHs( MOUSE_av_at(all_attrs, i) ); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHs( MOUSE_av_at(all_attrs, i) ); |
80 |
0 |
80 |
|
| 580 |
|
| } |
| 581 |
|
| } |
| 582 |
|
| |
| 583 |
|
| void |
| 584 |
|
| new_object(SV* meta, ...) |
| 585 |
|
| CODE: |
| 586 |
|
| { |
| 587 |
9 |
| AV* const xc = mouse_get_xc(aTHX_ meta); |
| 588 |
9 |
| HV* const args = mouse_buildargs(aTHX_ meta, NULL, ax, items); |
| 589 |
|
| SV* object; |
| 590 |
|
| |
| 591 |
9 |
▶ | object = mouse_instance_create(aTHX_ MOUSE_xc_stash(xc)); |
Branch: 1 branch
| Branch | True | False | Total |
| object = mouse_instance_create(aTHX_ MOUSE_xc_stash(xc)); |
9 |
0 |
9 |
|
| 592 |
9 |
| mouse_class_initialize_object(aTHX_ meta, object, args, FALSE); |
| 593 |
9 |
| mouse_buildall(aTHX_ xc, object, sv_2mortal(newRV_inc((SV*)args))); |
| 594 |
9 |
| ST(0) = object; /* because object is mortal, we should return it as is */ |
| 595 |
9 |
| XSRETURN(1); |
| 596 |
|
| } |
| 597 |
|
| |
| 598 |
|
| void |
| 599 |
|
| clone_object(SV* meta, SV* object, ...) |
| 600 |
|
| CODE: |
| 601 |
|
| { |
| 602 |
6 |
| AV* const xc = mouse_get_xc(aTHX_ meta); |
| 603 |
6 |
| HV* const args = mouse_buildargs(aTHX_ meta, NULL, ax + 1, items - 1); |
| 604 |
|
| SV* proto; |
| 605 |
|
| |
| 606 |
6 |
▶ | if(!mouse_is_an_instance_of(aTHX_ MOUSE_xc_stash(xc), object)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(!mouse_is_an_instance_of(aTHX_ MOUSE_xc_stash(xc), object)) { |
6 |
0 |
6 |
| if(!mouse_is_an_instance_of(aTHX_ MOUSE_xc_stash(xc), object)) { |
2 |
4 |
6 |
|
| 607 |
2 |
| mouse_throw_error(meta, object, |
| 608 |
|
| "You must pass an instance of the metaclass (%"SVf"), not (%"SVf")", |
| 609 |
|
| mcall0(meta, mouse_name), object); |
| 610 |
|
| } |
| 611 |
|
| |
| 612 |
4 |
| proto = mouse_instance_clone(aTHX_ object); |
| 613 |
4 |
| mouse_class_initialize_object(aTHX_ meta, proto, args, TRUE); |
| 614 |
4 |
| ST(0) = proto; /* because object is mortal, we should return it as is */ |
| 615 |
4 |
| XSRETURN(1); |
| 616 |
|
| } |
| 617 |
|
| |
| 618 |
|
| void |
| 619 |
|
| _initialize_object(SV* meta, SV* object, HV* args, bool is_cloning = FALSE) |
| 620 |
|
| CODE: |
| 621 |
|
| { |
| 622 |
187 |
| mouse_class_initialize_object(aTHX_ meta, object, args, is_cloning); |
| 623 |
|
| } |
| 624 |
|
| |
| 625 |
|
| void |
| 626 |
|
| _invalidate_metaclass_cache(SV* meta) |
| 627 |
|
| CODE: |
| 628 |
|
| { |
| 629 |
583 |
| AV* const xc = mouse_get_xc_if_fresh(aTHX_ meta); |
| 630 |
583 |
▶ | if(xc) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(xc) { |
0 |
583 |
583 |
|
| 631 |
0 |
▶ | SV* const gen = MOUSE_xc_gen(xc); |
Branch: 1 branch
| Branch | True | False | Total |
| SV* const gen = MOUSE_xc_gen(xc); |
0 |
0 |
0 |
|
| 632 |
0 |
| sv_setuv(gen, 0U); |
| 633 |
|
| } |
| 634 |
583 |
| delete_slot(meta, newSVpvs_flags("_mouse_cache_", SVs_TEMP)); |
| 635 |
|
| } |
| 636 |
|
| |
| 637 |
|
| |
| 638 |
|
| MODULE = Mouse PACKAGE = Mouse::Meta::Role |
| 639 |
|
| |
| 640 |
|
| BOOT: |
| 641 |
286 |
| INSTALL_SIMPLE_READER_WITH_KEY(Role, get_roles, roles); |
| 642 |
286 |
| INSTALL_SIMPLE_PREDICATE_WITH_KEY(Role, is_anon_role, anon_serial_id); |
| 643 |
|
| |
| 644 |
286 |
| INSTALL_CLASS_HOLDER(Role, method_metaclass, "Mouse::Meta::Role::Method"); |
| 645 |
|
| |
| 646 |
|
| void |
| 647 |
|
| add_before_modifier(SV* self, SV* name, SV* modifier) |
| 648 |
|
| CODE: |
| 649 |
|
| { |
| 650 |
47 |
| av_push(mouse_get_modifier_storage(aTHX_ self, (enum mouse_modifier_t)ix, name), newSVsv(modifier)); |
| 651 |
|
| } |
| 652 |
|
| ALIAS: |
| 653 |
|
| add_before_method_modifier = MOUSE_M_BEFORE |
| 654 |
|
| add_around_method_modifier = MOUSE_M_AROUND |
| 655 |
|
| add_after_method_modifier = MOUSE_M_AFTER |
| 656 |
|
| |
| 657 |
|
| void |
| 658 |
|
| get_before_modifiers(SV* self, SV* name) |
| 659 |
|
| ALIAS: |
| 660 |
|
| get_before_method_modifiers = MOUSE_M_BEFORE |
| 661 |
|
| get_around_method_modifiers = MOUSE_M_AROUND |
| 662 |
|
| get_after_method_modifiers = MOUSE_M_AFTER |
| 663 |
|
| PPCODE: |
| 664 |
|
| { |
| 665 |
11 |
| AV* const storage = mouse_get_modifier_storage(aTHX_ self, |
| 666 |
|
| (enum mouse_modifier_t)ix, name); |
| 667 |
11 |
| I32 const len = av_len(storage) + 1; |
| 668 |
11 |
▶ | if(GIMME_V == G_ARRAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(GIMME_V == G_ARRAY) { |
11 |
0 |
11 |
|
| 669 |
|
| I32 i; |
| 670 |
11 |
▶ | EXTEND(SP, len); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, len); |
11 |
0 |
11 |
| EXTEND(SP, len); |
0 |
11 |
11 |
|
| 671 |
21 |
▶ | for(i = 0; i < len; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < len; i++){ |
10 |
11 |
21 |
|
| 672 |
10 |
| PUSHs(*av_fetch(storage, i, TRUE)); |
| 673 |
|
| } |
| 674 |
|
| } |
| 675 |
|
| else{ |
| 676 |
0 |
| mPUSHi(len); |
| 677 |
|
| } |
| 678 |
|
| } |
| 679 |
|
| |
| 680 |
|
| void |
| 681 |
|
| add_metaclass_accessor(SV* self, SV* name) |
| 682 |
|
| CODE: |
| 683 |
|
| { |
| 684 |
0 |
| SV* const klass = mcall0(self, mouse_name); |
| 685 |
0 |
| const char* fq_name = form("%"SVf"::%"SVf, klass, name); |
| 686 |
|
| STRLEN keylen; |
| 687 |
0 |
| const char* const key = SvPV_const(name, keylen); |
| 688 |
0 |
| mouse_simple_accessor_generate(aTHX_ fq_name, key, keylen, |
| 689 |
|
| XS_Mouse_inheritable_class_accessor, NULL, 0); |
| 690 |
|
| } |
| 691 |
|
| |
| 692 |
|
| MODULE = Mouse PACKAGE = Mouse::Object |
| 693 |
|
| |
| 694 |
|
| void |
| 695 |
|
| new(SV* klass, ...) |
| 696 |
|
| CODE: |
| 697 |
|
| { |
| 698 |
1869 |
| SV* const meta = mouse_initialize_metaclass(aTHX_ klass); |
| 699 |
1869 |
| AV* const xc = mouse_get_xc(aTHX_ meta); |
| 700 |
1869 |
▶ | UV const flags = MOUSE_xc_flags(xc); |
Branch: 1 branch
| Branch | True | False | Total |
| UV const flags = MOUSE_xc_flags(xc); |
1869 |
0 |
1869 |
|
| 701 |
|
| SV* args; |
| 702 |
|
| SV* object; |
| 703 |
|
| |
| 704 |
|
| /* BUILDARGS */ |
| 705 |
1869 |
▶ | if(flags & MOUSEf_XC_HAS_BUILDARGS){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(flags & MOUSEf_XC_HAS_BUILDARGS){ |
26 |
1843 |
1869 |
|
| 706 |
|
| I32 i; |
| 707 |
26 |
| SPAGAIN; |
| 708 |
|
| |
| 709 |
26 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
26 |
26 |
|
| 710 |
26 |
▶ | EXTEND(SP, items); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, items); |
26 |
0 |
26 |
| EXTEND(SP, items); |
0 |
26 |
26 |
|
| 711 |
95 |
▶ | for(i = 0; i < items; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < items; i++){ |
69 |
26 |
95 |
|
| 712 |
69 |
| PUSHs(ST(i)); |
| 713 |
|
| } |
| 714 |
|
| |
| 715 |
26 |
| PUTBACK; |
| 716 |
26 |
| call_method_safes("BUILDARGS", G_SCALAR); |
| 717 |
|
| |
| 718 |
26 |
| SPAGAIN; |
| 719 |
26 |
| args = POPs; |
| 720 |
26 |
| PUTBACK; |
| 721 |
|
| |
| 722 |
26 |
▶ | if(!IsHashRef(args)){ |
Branch: 3 branches
| Branch | True | False | Total |
| if(!IsHashRef(args)){ |
26 |
0 |
26 |
| if(!IsHashRef(args)){ |
26 |
0 |
26 |
| if(!IsHashRef(args)){ |
0 |
26 |
26 |
|
| 723 |
0 |
| croak("BUILDARGS did not return a HASH reference"); |
| 724 |
|
| } |
| 725 |
|
| } |
| 726 |
|
| else{ |
| 727 |
1843 |
| args = newRV_inc((SV*)mouse_buildargs(aTHX_ meta, klass, ax, items)); |
| 728 |
1834 |
| sv_2mortal(args); |
| 729 |
|
| } |
| 730 |
|
| |
| 731 |
|
| /* new_object */ |
| 732 |
1860 |
▶ | object = mouse_instance_create(aTHX_ MOUSE_xc_stash(xc)); |
Branch: 1 branch
| Branch | True | False | Total |
| object = mouse_instance_create(aTHX_ MOUSE_xc_stash(xc)); |
1860 |
0 |
1860 |
|
| 733 |
1860 |
| mouse_class_initialize_object(aTHX_ meta, object, (HV*)SvRV(args), FALSE); |
| 734 |
|
| /* BUILDALL */ |
| 735 |
1385 |
| mouse_buildall(aTHX_ xc, object, args); |
| 736 |
1376 |
| ST(0) = object; /* because object is mortal, we should return it as is */ |
| 737 |
1376 |
| XSRETURN(1); |
| 738 |
|
| } |
| 739 |
|
| |
| 740 |
|
| void |
| 741 |
|
| DESTROY(SV* object) |
| 742 |
|
| ALIAS: |
| 743 |
|
| DESTROY = 0 |
| 744 |
|
| DEMOLISHALL = 1 |
| 745 |
|
| CODE: |
| 746 |
|
| { |
| 747 |
1872 |
| SV* const meta = get_metaclass(object); |
| 748 |
|
| AV* xc; |
| 749 |
|
| AV* demolishall; |
| 750 |
|
| I32 len; |
| 751 |
|
| I32 i; |
| 752 |
|
| |
| 753 |
1872 |
▶ | if(!IsObject(object)){ |
Branch: 2 branches
| Branch | True | False | Total |
| if(!IsObject(object)){ |
1872 |
0 |
1872 |
| if(!IsObject(object)){ |
0 |
1872 |
1872 |
|
| 754 |
0 |
▶ | croak("You must not call %s as a class method", |
Branch: 1 branch
| Branch | True | False | Total |
| croak("You must not call %s as a class method", |
0 |
0 |
0 |
|
| 755 |
|
| ix == 0 ? "DESTROY" : "DEMOLISHALL"); |
| 756 |
|
| } |
| 757 |
|
| |
| 758 |
1872 |
▶ | if(SvOK(meta) && (xc = mouse_get_xc_if_fresh(aTHX_ meta))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(SvOK(meta) && (xc = mouse_get_xc_if_fresh(aTHX_ meta))) { |
1871 |
1 |
1872 |
| if(SvOK(meta) && (xc = mouse_get_xc_if_fresh(aTHX_ meta))) { |
1853 |
18 |
1871 |
|
| 759 |
1853 |
▶ | demolishall = MOUSE_xc_demolishall(xc); |
Branch: 1 branch
| Branch | True | False | Total |
| demolishall = MOUSE_xc_demolishall(xc); |
1853 |
0 |
1853 |
|
| 760 |
|
| } |
| 761 |
|
| else { /* The metaclass is already destroyed */ |
| 762 |
19 |
| AV* const linearized_isa = mro_get_linear_isa(SvSTASH(SvRV(object))); |
| 763 |
|
| |
| 764 |
19 |
| len = AvFILLp(linearized_isa) + 1; |
| 765 |
|
| |
| 766 |
19 |
| demolishall = newAV_mortal(); |
| 767 |
59 |
▶ | for(i = 0; i < len; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < len; i++){ |
40 |
19 |
59 |
|
| 768 |
40 |
▶ | SV* const klass = MOUSE_av_at(linearized_isa, i); |
Branch: 1 branch
| Branch | True | False | Total |
| SV* const klass = MOUSE_av_at(linearized_isa, i); |
40 |
0 |
40 |
|
| 769 |
40 |
| HV* const st = gv_stashsv(klass, TRUE); |
| 770 |
40 |
| GV* const gv = stash_fetchs(st, "DEMOLISH", FALSE); |
| 771 |
40 |
▶ | if(gv && GvCVu(gv)){ |
Branch: 3 branches
| Branch | True | False | Total |
| if(gv && GvCVu(gv)){ |
1 |
39 |
40 |
| if(gv && GvCVu(gv)){ |
1 |
0 |
1 |
| if(gv && GvCVu(gv)){ |
1 |
0 |
1 |
|
| 772 |
1 |
| av_push(demolishall, newRV_inc((SV*)GvCV(gv))); |
| 773 |
|
| } |
| 774 |
|
| } |
| 775 |
|
| } |
| 776 |
|
| |
| 777 |
1872 |
| len = AvFILLp(demolishall) + 1; |
| 778 |
1872 |
▶ | if(len > 0){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(len > 0){ |
72 |
1800 |
1872 |
|
| 779 |
72 |
▶ | SV* const in_global_destruction = boolSV(PL_dirty); |
Branch: 1 branch
| Branch | True | False | Total |
| SV* const in_global_destruction = boolSV(PL_dirty); |
2 |
70 |
72 |
|
| 780 |
72 |
| SAVEI32(PL_statusvalue); /* local $? */ |
| 781 |
72 |
| PL_statusvalue = 0; |
| 782 |
|
| |
| 783 |
72 |
▶ | SAVEGENERICSV(ERRSV); /* local $@ */ |
Branch: 1 branch
| Branch | True | False | Total |
| SAVEGENERICSV(ERRSV); /* local $@ */ |
72 |
0 |
72 |
|
| 784 |
72 |
▶ | ERRSV = newSV(0); |
Branch: 1 branch
| Branch | True | False | Total |
| ERRSV = newSV(0); |
72 |
0 |
72 |
|
| 785 |
|
| |
| 786 |
72 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
72 |
72 |
|
| 787 |
|
| |
| 788 |
155 |
▶ | for(i = 0; i < len; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < len; i++){ |
83 |
72 |
155 |
|
| 789 |
83 |
| SPAGAIN; |
| 790 |
|
| |
| 791 |
83 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
83 |
83 |
|
| 792 |
83 |
| PUSHs(object); |
| 793 |
83 |
| PUSHs(in_global_destruction); |
| 794 |
83 |
| PUTBACK; |
| 795 |
|
| |
| 796 |
83 |
| call_sv(AvARRAY(demolishall)[i], G_VOID | G_EVAL | G_DISCARD); |
| 797 |
|
| |
| 798 |
83 |
▶ | if(sv_true(ERRSV)){ |
Branch: 2 branches
| Branch | True | False | Total |
| if(sv_true(ERRSV)){ |
83 |
0 |
83 |
| if(sv_true(ERRSV)){ |
0 |
83 |
83 |
|
| 799 |
0 |
▶ | SV* const e = sv_mortalcopy(ERRSV); |
Branch: 1 branch
| Branch | True | False | Total |
| SV* const e = sv_mortalcopy(ERRSV); |
0 |
0 |
0 |
|
| 800 |
0 |
| LEAVE; |
| 801 |
0 |
▶ | sv_setsv(ERRSV, e); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setsv(ERRSV, e); |
0 |
0 |
0 |
|
| 802 |
0 |
| croak(NULL); /* rethrow */ |
| 803 |
|
| } |
| 804 |
|
| } |
| 805 |
|
| } |
| 806 |
|
| } |
| 807 |
|
| |
| 808 |
|
| HV* |
| 809 |
|
| BUILDARGS(SV* klass, ...) |
| 810 |
|
| CODE: |
| 811 |
|
| { |
| 812 |
1049 |
| RETVAL = mouse_buildargs(aTHX_ NULL, klass, ax, items); |
| 813 |
|
| } |
| 814 |
|
| OUTPUT: |
| 815 |
|
| RETVAL |
| 816 |
|
| |
| 817 |
|
| |
| 818 |
|
| void |
| 819 |
|
| BUILDALL(SV* self, SV* args) |
| 820 |
|
| CODE: |
| 821 |
|
| { |
| 822 |
2 |
| SV* const meta = get_metaclass(self); |
| 823 |
2 |
| AV* const xc = mouse_get_xc(aTHX_ meta); |
| 824 |
|
| |
| 825 |
2 |
| must_ref(args, "a HASH reference to BUILDALL", SVt_PVHV); |
| 826 |
2 |
| mouse_buildall(aTHX_ xc, self, args); |
| 827 |
|
| } |