From: Dave Rolsky Date: Wed, 14 Jul 2010 16:30:45 +0000 (-0500) Subject: Deprecation warning for calling type() or subtype() with a list of params X-Git-Tag: 1.09~40 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=44193bdade986814e12e5ddf5a7e35e080e75c91;p=gitmo%2FMoose.git Deprecation warning for calling type() or subtype() with a list of params --- diff --git a/lib/Moose/Deprecated.pm b/lib/Moose/Deprecated.pm index a51f072..71ac437 100644 --- a/lib/Moose/Deprecated.pm +++ b/lib/Moose/Deprecated.pm @@ -11,6 +11,8 @@ use Package::DeprecationManager -deprecations => { 'pre-0.94 MetaRole API' => '0.93', 'Moose::Exporter with_caller' => '0.89', 'Role type' => '0.84', + 'subtype without sugar' => '0.72', + 'type without sugar' => '0.72', }, -ignore => [qw( Moose Moose::Exporter Moose::Util::MetaRole )], ; diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 7784a8c..127b453 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -275,6 +275,12 @@ 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' + ); + return _create_type_constraint( $_[0], undef, $_[1] ); } @@ -294,6 +300,12 @@ sub subtype { # # 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' + ); + return _create_type_constraint( undef, @_ ); } @@ -301,11 +313,23 @@ sub subtype { # 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' + ); + 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' + ); + return _create_type_constraint(@_); } diff --git a/t/040_type_constraints/001_util_type_constraints.t b/t/040_type_constraints/001_util_type_constraints.t index e4e8119..c7c611e 100644 --- a/t/040_type_constraints/001_util_type_constraints.t +++ b/t/040_type_constraints/001_util_type_constraints.t @@ -194,6 +194,11 @@ throws_ok {$r->add_type_constraint(bless {}, 'SomeClass')} qr/not a valid type c # sugar was indistinguishable from calling directly. { + no warnings 'redefine'; + *Moose::Deprecated::deprecated = sub { return }; +} + +{ my $type = type( 'Number2', sub { Scalar::Util::looks_like_number($_) } ); ok( $type->check(5), '... this is a Num' );