Tweaks
[gitmo/Mouse.git] / xs-src / MouseTypeConstraints.xs
index 09cf92c..1001fbd 100644 (file)
@@ -4,12 +4,6 @@
 
 #include "mouse.h"
 
-#if PERL_BCDVERSION >= 0x5008005
-#define LooksLikeNumber(sv) looks_like_number(sv)
-#else
-#define LooksLikeNumber(sv) ( SvPOKp(sv) ? looks_like_number(sv) : SvNIOKp(sv) )
-#endif
-
 #ifndef SvRXOK
 #define SvRXOK(sv) (SvROK(sv) && SvMAGICAL(SvRV(sv)) && mg_find(SvRV(sv), PERL_MAGIC_qr))
 #endif
@@ -117,7 +111,7 @@ mouse_tc_Num(pTHX_ SV* const data PERL_UNUSED_DECL, SV* const sv) {
     return LooksLikeNumber(sv);
 }
 
-int
+static int
 S_nv_is_integer(pTHX_ NV const nv) {
     if(nv == (NV)(IV)nv){
         return TRUE;
@@ -125,7 +119,7 @@ S_nv_is_integer(pTHX_ NV const nv) {
     else {
         char buf[64];  /* Must fit sprintf/Gconvert of longest NV */
         char* p;
-        Gconvert(nv, NV_DIG, 0, buf);
+        (void)Gconvert(nv, NV_DIG, 0, buf);
         p = &buf[0];
 
         /* -?[0-9]+ */
@@ -392,7 +386,7 @@ mouse_lookup_isa(pTHX_ HV* const instance_stash, const char* const klass_pv){
 #define find_method_pvn(a, b, c) mouse_stash_find_method(aTHX_ a, b, c)
 #define find_method_pvs(a, b)    mouse_stash_find_method(aTHX_ a, STR_WITH_LEN(b))
 
-static inline GV*
+STATIC_INLINE GV*
 mouse_stash_find_method(pTHX_ HV* const stash, const char* const name, I32 const namelen){
     GV** const gvp = (GV**)hv_fetch(stash, name, namelen, FALSE);
     if(gvp && isGV(*gvp) && GvCV(*gvp)){ /* shortcut */
@@ -553,13 +547,15 @@ XS(XS_Mouse_constraint_check) {
     dVAR;
     dXSARGS;
     MAGIC* const mg = (MAGIC*)XSANY.any_ptr;
+    SV* sv;
 
     if(items < 1){
         croak("Too few arguments for type constraint check functions");
     }
 
-    SvGETMAGIC( ST(0) );
-    ST(0) = boolSV( CALL_FPTR((check_fptr_t)mg->mg_ptr)(aTHX_ mg->mg_obj, ST(0)) );
+    sv = ST(0);
+    SvGETMAGIC(sv);
+    ST(0) = boolSV( CALL_FPTR((check_fptr_t)mg->mg_ptr)(aTHX_ mg->mg_obj, sv) );
     XSRETURN(1);
 }
 
@@ -725,8 +721,7 @@ CODE:
             SV* const tc = *av_fetch(types, i, TRUE);
             SV* const c  = get_slots(tc, "compiled_type_constraint");
             if(!(c && mouse_tc_CodeRef(aTHX_ NULL, c))){
-                sv_dump(self);
-                croak("'%"SVf"' has no compiled type constraint", self);
+                mouse_throw_error(self, c, "'%"SVf"' has no compiled type constraint", self);
             }
             av_push(union_checks, newSVsv(c));
         }
@@ -744,3 +739,16 @@ CODE:
     (void)set_slots(self, "compiled_type_constraint", check);
 }
 
+bool
+check(SV* self, SV* sv)
+CODE:
+{
+    SV* const check = get_slots(self, "compiled_type_constraint");
+    if(!(check && mouse_tc_CodeRef(aTHX_ NULL, check))){
+        mouse_throw_error(self, check, "'%"SVf"' has no compiled type constraint", self);
+    }
+    RETVAL = mouse_tc_check(aTHX_ check, sv) ? TRUE : FALSE;
+}
+OUTPUT:
+    RETVAL
+