Move is_valid_class_name into XS
[gitmo/Mouse.git] / xs-src / MouseUtil.xs
index 93160fc..8704d89 100644 (file)
@@ -202,8 +202,7 @@ mouse_call1 (pTHX_ SV* const self, SV* const method, SV* const arg1) {
 
 int
 mouse_predicate_call(pTHX_ SV* const self, SV* const method) {
-    SV* const value = mcall0(self, method);
-    return SvTRUE(value);
+    return sv_true( mcall0(self, method) );
 }
 
 SV*
@@ -286,6 +285,29 @@ CODE:
 }
 
 bool
+is_valid_class_name(SV* sv)
+CODE:
+{
+    SvGETMAGIC(sv);
+    if(SvPOKp(sv) && SvCUR(sv) > 0){
+        UV i;
+        RETVAL = TRUE;
+        for(i = 0; i < SvCUR(sv); i++){
+            char const c = SvPVX(sv)[i];
+            if(!(isALNUM(c) || c == ':')){
+                RETVAL = FALSE;
+                break;
+            }
+        }
+    }
+    else{
+        RETVAL = SvNIOKp(sv) ? TRUE : FALSE;
+    }
+}
+OUTPUT:
+    RETVAL
+
+bool
 is_class_loaded(SV* sv)
 
 void
@@ -378,6 +400,6 @@ PPCODE:
     }
 
     if(predicate_name == NULL){ /* anonymous predicate */
-        XPUSHs( newRV_noinc((SV*)xsub) );
+        mXPUSHs( newRV_inc((SV*)xsub) );
     }
 }