From: Karen Etheridge Date: Tue, 31 May 2011 21:00:25 +0000 (+0000) Subject: update docs to show how to call into parent checks X-Git-Tag: 2.0100~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0578d5ce8425586373f878c7998fceb49743cdbd;p=gitmo%2FMoose.git update docs to show how to call into parent checks --- diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index a671af9..805a3d1 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -1058,15 +1058,20 @@ The subroutine should return a code string suitable for inlining. You can assume that the check will be wrapped in parentheses when it is inlined. The inlined code should include any checks that your type's parent types -do. For example, the C type's inlining sub looks like this: +do. For example, the C type's inlining sub looks like this: sub { - '!ref(' . $_[1] . ') ' - . '&& Scalar::Util::looks_like_number(' . $_[1] . ')' + 'defined(' . $_[1] . ')' + . ' && !ref(' . $_[1] . ')' } -Note that it checks if the variable is a reference, since it is a subtype of -the C type. +Note that it checks if the variable is defined, since it is a subtype of +the C type. However, to avoid repeating code, this can be optimized as: + + sub { + $_[0]->parent()->_inline_check($_[1]) + . ' && !ref(' . $_[1] . ')' + } =item B