From: Yuval Kogman Date: Wed, 20 Aug 2008 13:56:55 +0000 (+0000) Subject: TC checker subs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3c63e75d0d5e48433d2a4da1c989b5e9f1a8fdbd;p=gitmo%2FMoose.git TC checker subs --- diff --git a/Moose.xs b/Moose.xs index 6bcb2d3..4d334fe 100644 --- a/Moose.xs +++ b/Moose.xs @@ -459,8 +459,11 @@ STATIC bool check_sv_type (TC type, SV *sv) { case GlobRef: return check_reftype(type, sv); break; + case RegexpRef: + return ( sv_isobject(sv) && ( strEQ("Regexp", HvNAME_get(SvSTASH(SvRV(sv)))) ) ); + break; case Object: - return sv_isobject(sv); + return ( sv_isobject(sv) && ( strNE("Regexp", HvNAME_get(SvSTASH(SvRV(sv)))) ) ); break; case ClassName: if ( SvOK(sv) && !SvROK(sv) ) { @@ -471,9 +474,6 @@ STATIC bool check_sv_type (TC type, SV *sv) { } return 0; break; - case RegexpRef: - return sv_isa(sv, "Regexp"); - break; case FileHandle: croak("todo"); break; @@ -1237,3 +1237,48 @@ DESTROY(self) if ( mi ) delete_mi(aTHX_ mi); + +MODULE = Moose PACKAGE = Moose::XS::TypeConstraints +PROTOTYPES: ENABLE + +bool +_check_type(sv) + INPUT: + SV* sv + ALIAS: + Any = Any + Item = Any + Bool = Any + Undef = Undef + Defined = Defined + Str = Str + Value = Str + Num = Num + Int = Int + GlobRef = GlobRef + ArrayRef = ArrayRef + HashRef = HashRef + CodeRef = CodeRef + Ref = Ref + ScalarRef = ScalarRef + FileHandle = FileHandle + RegexpRef = RegexpRef + Object = Object + Role = Role + ClassName = ClassName + CODE: + RETVAL = check_sv_type(ix, sv); + OUTPUT: + RETVAL + +bool +ObjectOfType(sv, class) + INPUT: + SV* sv + SV* class + PREINIT: + HV *stash = gv_stashsv(class, 0); + CODE: + RETVAL = check_sv_class(aTHX_ stash, sv); + OUTPUT: + RETVAL