X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FUtil%2FTypeConstraints.pm;h=7947bfd034a73d6bfad886edeaa00ea1d5dab7ea;hb=0e8cddd7b18ca15aaa2773af593977618532dc8d;hp=d7edb022e48d9a3bd674ba213d4e34b47fb6b746;hpb=7afaa906c95bdb6f3582510f374ea1c9efd15371;p=gitmo%2FMoose.git diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index d7edb02..7947bfd 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -1045,8 +1045,33 @@ constraint fails, then the code block is run with the value provided in C<$_>. This reference should return a string, which will be used in the text of the exception thrown. +=item B + +This can be used to define a "hand optimized" inlinable version of your type +constraint. + +You provide a subroutine which will be called I on a +L object. It will receive a single parameter, the +name of the variable to check, typically something like C<"$_"> or C<"$_[0]">. + +The subroutine should return a code string suitable for inlining. You can +assume that the check will be wrapped in parenthese when it is inlined. + +The inlined code should include any checks that your type's parent type's +do. For example, the C type's inlining sub looks like this: + + sub { + '!ref(' . $_[1] . ') ' + . '&& Scalar::Util::looks_like_number(' . $_[1] . ')' + } + +Note that it checks if the variable is a reference, since it is a subtype of +the C type. + =item B +B instead.> + This can be used to define a "hand optimized" version of your type constraint which can be used to avoid traversing a subtype constraint hierarchy. @@ -1065,7 +1090,7 @@ parameters: type( 'Foo', { where => ..., message => ... } ); -The valid hashref keys are C, C, and C. +The valid hashref keys are C, C, and C. =back