X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FUtil%2FTypeConstraints.pm;h=4ab0006902304a5a835adea991b9e8d9794e4ffb;hb=eea9eb4d0a9d6d7453cfb6fca6bb6aae618254c4;hp=d7edb022e48d9a3bd674ba213d4e34b47fb6b746;hpb=7afaa906c95bdb6f3582510f374ea1c9efd15371;p=gitmo%2FMoose.git diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index d7edb02..4ab0006 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -269,18 +269,6 @@ sub register_type_constraint { # type constructors sub type { - - # back-compat version, called without sugar - if ( !any { ( reftype($_) || '' ) eq 'HASH' } @_ ) { - Moose::Deprecated::deprecated( - feature => 'type without sugar', - message => - 'Calling type() with a simple list of parameters is deprecated. This will be an error in Moose 2.0200.' - ); - - return _create_type_constraint( $_[0], undef, $_[1] ); - } - my $name = shift; my %p = map { %{$_} } @_; @@ -292,44 +280,6 @@ sub type { } sub subtype { - - # crazy back-compat code for being called without sugar ... - # - # subtype 'Parent', sub { where }; - if ( scalar @_ == 2 && ( reftype( $_[1] ) || '' ) eq 'CODE' ) { - Moose::Deprecated::deprecated( - feature => 'subtype without sugar', - message => - 'Calling subtype() with a simple list of parameters is deprecated. This will be an error in Moose 2.0200.' - ); - - return _create_type_constraint( undef, @_ ); - } - - # subtype 'Parent', sub { where }, sub { message }; - # subtype 'Parent', sub { where }, sub { message }, sub { optimized }; - if ( scalar @_ >= 3 && all { ( reftype($_) || '' ) eq 'CODE' } - @_[ 1 .. $#_ ] ) { - Moose::Deprecated::deprecated( - feature => 'subtype without sugar', - message => - 'Calling subtype() with a simple list of parameters is deprecated. This will be an error in Moose 2.0200.' - ); - - return _create_type_constraint( undef, @_ ); - } - - # subtype 'Name', 'Parent', ... - if ( scalar @_ >= 2 && all { !ref } @_[ 0, 1 ] ) { - Moose::Deprecated::deprecated( - feature => 'subtype without sugar', - message => - 'Calling subtype() with a simple list of parameters is deprecated. This will be an error in Moose 2.0200.' - ); - - return _create_type_constraint(@_); - } - if ( @_ == 1 && !ref $_[0] ) { __PACKAGE__->_throw_error( 'A subtype cannot consist solely of a name, it must have a parent' @@ -1045,8 +995,38 @@ 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 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: + + sub { + 'defined(' . $_[1] . ')' + . ' && !ref(' . $_[1] . ')' + } + +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 +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 +1045,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