From: gfx Date: Sat, 31 Oct 2009 06:23:41 +0000 (+0900) Subject: Refactor built-in type constraints X-Git-Tag: 0.40_04~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f6e3b8a91527e33b3952e77303231d1c6d1ad3e9;p=gitmo%2FMouse.git Refactor built-in type constraints --- diff --git a/xs-src/MouseTypeConstraints.xs b/xs-src/MouseTypeConstraints.xs index ca31b66..81d0811 100644 --- a/xs-src/MouseTypeConstraints.xs +++ b/xs-src/MouseTypeConstraints.xs @@ -86,11 +86,10 @@ mouse_builtin_tc_check(pTHX_ mouse_tc const tc, SV* const sv) { case MOUSE_TC_CLASS_NAME: return mouse_tc_ClassName(aTHX_ sv); case MOUSE_TC_ROLE_NAME: return mouse_tc_RoleName(aTHX_ sv); default: - /* custom type constraints */ NOOP; } - croak("Custom type constraint is not yet implemented"); + croak("Mouse-panic: unrecognized type constraint id: %d", (int)tc); return FALSE; /* not reached */ } @@ -109,22 +108,23 @@ mouse_tc_Any(pTHX_ SV* const sv PERL_UNUSED_DECL) { int mouse_tc_Bool(pTHX_ SV* const sv) { assert(sv); - if(SvOK(sv)){ + + if(SvTRUE(sv)){ if(SvIOKp(sv)){ - return SvIVX(sv) == 1 || SvIVX(sv) == 0; + return SvIVX(sv) == 1; } else if(SvNOKp(sv)){ - return SvNVX(sv) == 1.0 || SvNVX(sv) == 0.0; + return SvNVX(sv) == 1.0; } - else if(SvPOKp(sv)){ /* "" or "1" or "0" */ - return SvCUR(sv) == 0 - || ( SvCUR(sv) == 1 && ( SvPVX(sv)[0] == '1' || SvPVX(sv)[0] == '0' ) ); + else if(SvPOKp(sv)){ /* "1" */ + return SvCUR(sv) == 1 && SvPVX(sv)[0] == '1'; } else{ return FALSE; } } else{ + /* false must be boolean */ return TRUE; } }