#define is_an_instance_of(klass, sv) mouse_is_an_instance_of(aTHX_ gv_stashpvs(klass, GV_ADD), (sv))
-#define IsObject(sv) (SvROK(sv) && SvOBJECT(SvRV(sv)))
+#define IsObject(sv) (SvROK(sv) && SvOBJECT(SvRV(sv)))
+#define IsArrayRef(sv) (SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) == SVt_PVAV)
+#define IsHashRef(sv) (SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) == SVt_PVHV)
+#define IsCodeRef(sv) (SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) == SVt_PVCV)
#define mcall0(invocant, m) mouse_call0(aTHX_ (invocant), (m))
#define mcall1(invocant, m, arg1) mouse_call1(aTHX_ (invocant), (m), (arg1))
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)) == SVt_PVCV)){
+ if(!IsCodeRef(tc_code)){
mouse_throw_error(MOUSE_xa_attribute(xa), tc, "Not a CODE reference");
}
}
}
if(flags & MOUSEf_TC_IS_ARRAYREF){
- AV* const av = (AV*)SvRV(value);
+ AV* av;
I32 len;
I32 i;
- if(SvTYPE(av) != SVt_PVAV){
+ if(!IsArrayRef(value)){
croak("Mouse-panic: Not an ARRAY reference");
}
+ av = (AV*)SvRV(value);
len = av_len(av) + 1;
EXTEND(SP, len);
for(i = 0; i < len; i++){
}
}
else if(flags & MOUSEf_TC_IS_HASHREF){
- HV* const hv = (HV*)SvRV(value);
+ HV* hv;
HE* he;
- if(SvTYPE(hv) != SVt_PVHV){
+ if(!IsHashRef(value)){
croak("Mouse-panic: Not a HASH reference");
}
+ hv = (HV*)SvRV(value);
hv_iterinit(hv);
while((he = hv_iternext(hv))){
EXTEND(SP, 2);
else {
value = mcall0s(attr, "default");
- if(SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVCV){
+ if(IsCodeRef(value)){
value = mcall0(self, value);
}
}
int
mouse_tc_ArrayRef(pTHX_ SV* const data PERL_UNUSED_DECL, SV* const sv) {
assert(sv);
- return SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) == SVt_PVAV;
+ return IsArrayRef(sv);
}
int
mouse_tc_HashRef(pTHX_ SV* const data PERL_UNUSED_DECL, SV* const sv) {
assert(sv);
- return SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) == SVt_PVHV;
+ return IsHashRef(sv);
}
int
mouse_tc_CodeRef(pTHX_ SV* const data PERL_UNUSED_DECL, SV* const sv) {
assert(sv);
- return SvROK(sv) && !SvOBJECT(SvRV(sv))&& SvTYPE(SvRV(sv)) == SVt_PVCV;
+ return IsCodeRef(sv);
}
int
static int
mouse_parameterized_ArrayRef(pTHX_ SV* const param, SV* const sv) {
- if(mouse_tc_ArrayRef(aTHX_ NULL, sv)){
+ if(IsArrayRef(sv)){
AV* const av = (AV*)SvRV(sv);
I32 const len = av_len(av) + 1;
I32 i;
{
check_fptr_t fptr;
SV* const tc_code = mcall0s(param, "_compiled_type_constraint");
- if(!(SvROK(tc_code) && SvTYPE(SvRV(tc_code)) == SVt_PVCV)){
+ if(!IsCodeRef(tc_code)){
croak("_compiled_type_constraint didn't return a CODE reference");
}
I32 len;
I32 i;
- if(!mouse_tc_ArrayRef(aTHX_ NULL, types_ref)){
+ if(!IsArrayRef(types_ref)){
croak("Not an ARRAY reference");
}
types = (AV*)SvRV(types_ref);
avref = POPs;
PUTBACK;
- if(SvROK(avref) && SvTYPE(SvRV(avref)) == SVt_PVAV){
+ if(IsArrayRef(avref)){
AV* const av = (AV*)SvRV(avref);
I32 const len = AvFILLp(av) + 1;
I32 i;