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 slot to CvXSUBANY slot for efficiency (gfx)
29 CvXSUBANY(xsub).any_ptr = (void*)slot;
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 = (SV*)XSANY.any_ptr;
62 croak("Expected exactly one argument");
65 value = mouse_instance_get_slot(self, slot);
66 ST(0) = value ? value : &PL_sv_undef;
71 XS(mouse_xs_simple_writer)
75 SV* const slot = (SV*)XSANY.any_ptr;
78 croak("Expected exactly two argument");
81 ST(0) = mouse_instance_set_slot(self, slot, ST(1));
86 XS(mouse_xs_simple_predicate)
90 SV* const slot = (SV*)XSANY.any_ptr;
93 croak("Expected exactly one argument");
96 ST(0) = boolSV( mouse_instance_has_slot(self, slot) );