Fix a typo
[gitmo/Mouse.git] / xs-src / MouseUtil.xs
index 3e97648..92fa676 100644 (file)
@@ -91,8 +91,6 @@ mouse_throw_error(SV* const metaobject, SV* const data /* not used */, const cha
     va_list args;
     SV* message;
 
-    PERL_UNUSED_ARG(data); /* for moose-compat */
-
     assert(metaobject);
     assert(fmt);
 
@@ -103,13 +101,17 @@ mouse_throw_error(SV* const metaobject, SV* const data /* not used */, const cha
     {
         dSP;
         PUSHMARK(SP);
-        EXTEND(SP, 4);
+        EXTEND(SP, 6);
 
         PUSHs(metaobject);
         mPUSHs(message);
 
-        mPUSHs(newSVpvs("depth"));
-        mPUSHi(-1);
+        if(data){ /* extra arg, might be useful for debugging */
+            mPUSHs(newSVpvs("data"));
+            PUSHs(data);
+            mPUSHs(newSVpvs("depth"));
+            mPUSHi(-1);
+        }
 
         PUTBACK;
 
@@ -202,8 +204,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 +287,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
@@ -347,29 +371,37 @@ OUTPUT:
     RETVAL
 
 void
-generate_isa_predicate_for(SV* klass, SV* predicate_name = NULL)
+generate_isa_predicate_for(SV* arg, SV* predicate_name = NULL)
+ALIAS:
+    generate_isa_predicate_for = 0
+    generate_can_predicate_for = 1
 PPCODE:
 {
     const char* name_pv = NULL;
     CV* xsub;
 
-    SvGETMAGIC(klass);
+    SvGETMAGIC(arg);
 
-    if(!SvOK(klass)){
-        croak("You must define a class name");
+    if(!SvOK(arg)){
+        croak("You must define %s", ix == 0 ? "a class name" : "method names");
     }
 
     if(predicate_name){
         SvGETMAGIC(predicate_name);
         if(!SvOK(predicate_name)){
-            croak("You must define a predicate_name");
+            croak("You must define %s", "a predicate name");
         }
         name_pv = SvPV_nolen_const(predicate_name);
     }
 
-    xsub = mouse_generate_isa_predicate_for(aTHX_ klass, name_pv);
+    if(ix == 0){
+        xsub = mouse_generate_isa_predicate_for(aTHX_ arg, name_pv);
+    }
+    else{
+        xsub = mouse_generate_can_predicate_for(aTHX_ arg, name_pv);
+    }
 
     if(predicate_name == NULL){ /* anonymous predicate */
-        XPUSHs( newRV_noinc((SV*)xsub) );
+        mXPUSHs( newRV_inc((SV*)xsub) );
     }
 }