3 static MGVTBL mouse_simple_accessor_vtbl;
7 mouse_accessor_get_mg(pTHX_ CV* const xsub){
8 return moose_mg_find(aTHX_ (SV*)xsub, &mouse_simple_accessor_vtbl, MOOSEf_DIE_ON_FAIL);
13 mouse_install_simple_accessor(pTHX_ const char* const fq_name, const char* const key, I32 const keylen, XSUBADDR_t const accessor_impl){
14 CV* const xsub = newXS((char*)fq_name, accessor_impl, __FILE__);
15 SV* const slot = newSVpvn_share(key, keylen, 0U);
19 /* anonymous xsubs need sv_2mortal */
20 sv_2mortal((SV*)xsub);
23 mg = sv_magicext((SV*)xsub, slot, PERL_MAGIC_ext, &mouse_simple_accessor_vtbl, NULL, 0);
24 SvREFCNT_dec(slot); /* sv_magicext() increases refcnt in mg_obj */
27 * although we use MAGIC for gc, we also store mg to CvXSUBANY for efficiency (gfx)
29 CvXSUBANY(xsub).any_ptr = (void*)mg;
35 mouse_accessor_get_self(pTHX_ I32 const ax, I32 const items, CV* const cv) {
39 croak("Too few arguments for %s", GvNAME(CvGV(cv)));
42 /* NOTE: If self has GETMAGIC, $self->accessor will invoke GETMAGIC
43 * before calling methods, so SvGETMAGIC(self) is not necessarily needed here.
48 croak("Cant call %s as a class method", GvNAME(CvGV(cv)));
54 XS(mouse_xs_simple_reader)
58 SV* const slot = MOUSE_mg_slot((MAGIC*)XSANY.any_ptr);
62 croak("Expected exactly one argument for a reader for '%"SVf"'", slot);
65 value = mouse_instance_get_slot(aTHX_ self, slot);
66 ST(0) = value ? value : &PL_sv_undef;
71 XS(mouse_xs_simple_writer)
75 SV* const slot = MOUSE_mg_slot((MAGIC*)XSANY.any_ptr);
78 croak("Expected exactly two argument for a writer for '%"SVf"'", slot);
81 ST(0) = mouse_instance_set_slot(aTHX_ self, slot, ST(1));
85 XS(mouse_xs_simple_clearer)
89 SV* const slot = MOUSE_mg_slot((MAGIC*)XSANY.any_ptr);
93 croak("Expected exactly one argument for a clearer for '%"SVf"'", slot);
96 value = mouse_instance_delete_slot(aTHX_ self, slot);
97 ST(0) = value ? value : &PL_sv_undef;
101 XS(mouse_xs_simple_predicate)
105 SV* const slot = MOUSE_mg_slot((MAGIC*)XSANY.any_ptr);
108 croak("Expected exactly one argument for a predicate for '%"SVf"'", slot);
111 ST(0) = boolSV( mouse_instance_has_slot(aTHX_ self, slot) );