#include "mouse.h"
-#define CHECK_INSTANCE(instance) STMT_START{ \
- if(!(SvROK(instance) && SvTYPE(SvRV(instance)) == SVt_PVHV)){ \
- croak("Invalid object instance"); \
- } \
+#define CHECK_INSTANCE(instance) STMT_START{ \
+ if(!IsHashRef(instance)){ \
+ croak("Invalid object instance"); \
+ } \
} STMT_END
PUSHs(svp ? *svp : &PL_sv_undef);
}
}
- else if(flags & MOUSEf_TC_IS_HASHREF){
+ else{
HV* hv;
HE* he;
+ assert(flags & MOUSEf_TC_IS_HASHREF);
+
if(!IsHashRef(value)){
croak("Mouse-panic: Not a HASH reference");
}
value = mouse_xa_apply_type_constraint(aTHX_ MOUSE_mg_xa(mg), value, flags);
}
- set_slot(self, slot, value);
+ value = set_slot(self, slot, value);
if(flags & MOUSEf_ATTR_IS_WEAK_REF){
weaken_slot(self, slot);
return xsub;
}
-XS(XS_Mouse_simple_accessor)
-{
- dVAR; dXSARGS;
- dMOUSE_self;
- MAGIC* const mg = (MAGIC*)XSANY.any_ptr;
- SV* value;
-
- if(items == 1){ /* reader */
- value = get_slot(self, MOUSE_mg_slot(mg));
- if(!value){
- value = &PL_sv_undef;
- }
- }
- else if(items == 2){ /* writer */
- value = set_slot(self, MOUSE_mg_slot(mg), ST(1));
- }
- else {
- croak("Expected exactly one or two argument for an accessor for '%"SVf"'", MOUSE_mg_slot(mg));
- }
-
- ST(0) = value;
- XSRETURN(1);
-}
-
XS(XS_Mouse_simple_reader)
{
dVAR; dXSARGS;
sv_rvweaken(HeVAL(he));
}
}
-\r
+
MODULE = Mouse::Meta::Method::Accessor::XS PACKAGE = Mouse::Meta::Method::Accessor::XS
PROTOTYPES: DISABLE
_generate_clearer(klass, SV* attr, metaclass)
CODE:
{
- SV* const slot = mcall0s(attr, "name");
+ SV* const slot = mcall0(attr, mouse_name);
STRLEN len;
const char* const pv = SvPV_const(slot, len);
RETVAL = mouse_simple_accessor_generate(aTHX_ NULL, pv, len, XS_Mouse_simple_clearer, NULL, 0);
_generate_predicate(klass, SV* attr, metaclass)
CODE:
{
- SV* const slot = mcall0s(attr, "name");
+ SV* const slot = mcall0(attr, mouse_name);
STRLEN len;
const char* const pv = SvPV_const(slot, len);
RETVAL = mouse_simple_accessor_generate(aTHX_ NULL, pv, len, XS_Mouse_simple_predicate, NULL, 0);