X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=xs-src%2FMouseUtil.xs;h=d8e3f4cf5f59fdd128c3cc74ae2e6364696906e2;hp=3e97648a3a108fec0c46d85435efc9ac4a57ba2c;hb=431e4817af5380b349d562cafde91777db982a2a;hpb=a5c683f611022dcabb13169162fa2f57ba72b200 diff --git a/xs-src/MouseUtil.xs b/xs-src/MouseUtil.xs index 3e97648..d8e3f4c 100644 --- a/xs-src/MouseUtil.xs +++ b/xs-src/MouseUtil.xs @@ -108,8 +108,12 @@ mouse_throw_error(SV* const metaobject, SV* const data /* not used */, const cha PUSHs(metaobject); mPUSHs(message); - mPUSHs(newSVpvs("depth")); - mPUSHi(-1); + if(data){ /* extra arg, might be useful for debugging */ + mPUSHs(newSVpsv("data")); + PUSHs(data); + mPUSHs(newSVpvs("depth")); + mPUSHi(-1); + } PUTBACK; @@ -202,8 +206,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 +289,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 +373,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) ); } }