X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=xs-src%2FMouseAccessor.xs;h=dd89a007157314e2dc5a0d5a57dca0aaf36a3db4;hp=234e39507a4e7c3a133c59a9ec108e8fe57d4c8b;hb=6fe2272b04003d989c299dae495c4c6f9730dabc;hpb=76770976c9e76df52aeac5b171a0e9b62d127b38 diff --git a/xs-src/MouseAccessor.xs b/xs-src/MouseAccessor.xs index 234e395..dd89a00 100644 --- a/xs-src/MouseAccessor.xs +++ b/xs-src/MouseAccessor.xs @@ -52,8 +52,6 @@ static MGVTBL mouse_accessor_vtbl; /* MAGIC identity */ SV* mouse_accessor_get_self(pTHX_ I32 const ax, I32 const items, CV* const cv) { - SV* self; - if(items < 1){ croak("Too few arguments for %s", GvNAME(CvGV(cv))); } @@ -164,18 +162,11 @@ mouse_apply_type_constraint(pTHX_ AV* const xa, SV* value, U16 const flags){ } if(!SvOK(MOUSE_xa_tc_code(xa))){ - XS(XS_Mouse__Util__TypeConstraints_Item); /* prototype defined in Mouse.xs */ - tc_code = mcall0s(tc, "_compiled_type_constraint"); + av_store(xa, MOUSE_XA_TC_CODE, newSVsv(tc_code)); - if(SvROK(tc_code) && SvTYPE(SvRV(tc_code)) - && CvXSUB((CV*)SvRV(tc_code)) == XS_Mouse__Util__TypeConstraints_Item){ - /* built-in type constraints */ - mouse_tc const id = CvXSUBANY((CV*)SvRV(tc_code)).any_i32; - av_store(xa, MOUSE_XA_TC_CODE, newSViv(id)); - } - else{ - av_store(xa, MOUSE_XA_TC_CODE, newSVsv(tc_code)); + if(!(SvROK(tc_code) && SvTYPE(SvRV(tc_code)) == SVt_PVCV)){ + mouse_throw_error(MOUSE_xa_attribute(xa), tc, "Not a CODE reference"); } } else{ @@ -255,7 +246,7 @@ mouse_attr_get(pTHX_ SV* const self, MAGIC* const mg){ SV* const slot = MOUSE_mg_slot(mg); SV* value; - value = mouse_instance_get_slot(aTHX_ self, slot); + value = get_slot(self, slot); /* check_lazy */ if( !value && flags & MOUSEf_ATTR_IS_LAZY ){ @@ -285,7 +276,7 @@ mouse_attr_get(pTHX_ SV* const self, MAGIC* const mg){ } /* store value to slot */ - value = mouse_instance_set_slot(aTHX_ self, slot, value); + value = set_slot(self, slot, value); } PUSH_VALUE(value, flags); @@ -300,10 +291,10 @@ mouse_attr_set(pTHX_ SV* const self, MAGIC* const mg, SV* value){ value = mouse_apply_type_constraint(aTHX_ MOUSE_mg_xa(mg), value, flags); } - mouse_instance_set_slot(aTHX_ self, slot, value); + set_slot(self, slot, value); if(flags & MOUSEf_ATTR_IS_WEAK_REF){ - mouse_instance_weaken_slot(aTHX_ self, slot); + weaken_slot(self, slot); } if(flags & MOUSEf_ATTR_HAS_TRIGGER){ @@ -421,7 +412,7 @@ XS(mouse_xs_simple_reader) croak("Expected exactly one argument for a reader for '%"SVf"'", slot); } - value = mouse_instance_get_slot(aTHX_ self, slot); + value = get_slot(self, slot); ST(0) = value ? value : &PL_sv_undef; XSRETURN(1); } @@ -437,7 +428,7 @@ XS(mouse_xs_simple_writer) croak("Expected exactly two argument for a writer for '%"SVf"'", slot); } - ST(0) = mouse_instance_set_slot(aTHX_ self, slot, ST(1)); + ST(0) = set_slot(self, slot, ST(1)); XSRETURN(1); } @@ -452,7 +443,7 @@ XS(mouse_xs_simple_clearer) croak("Expected exactly one argument for a clearer for '%"SVf"'", slot); } - value = mouse_instance_delete_slot(aTHX_ self, slot); + value = delete_slot(self, slot); ST(0) = value ? value : &PL_sv_undef; XSRETURN(1); } @@ -467,7 +458,7 @@ XS(mouse_xs_simple_predicate) croak("Expected exactly one argument for a predicate for '%"SVf"'", slot); } - ST(0) = boolSV( mouse_instance_has_slot(aTHX_ self, slot) ); + ST(0) = boolSV( has_slot(self, slot) ); XSRETURN(1); }