From: Dave Rolsky Date: Thu, 25 Jun 2009 17:45:02 +0000 (-0500) Subject: Deprecated the Role type (use role_type instead). X-Git-Tag: 0.84~23^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4831e2de2a702a3b2eee09a8bdd5feafa681bf67;p=gitmo%2FMoose.git Deprecated the Role type (use role_type instead). --- diff --git a/Changes b/Changes index 5215de1..5370688 100644 --- a/Changes +++ b/Changes @@ -9,6 +9,11 @@ for, noteworthy changes. associated_methods. (hdp) * Moose::Util::TypeConstraints + - Deprecated the totally useless Role type name, which just + checked if $object->can('does'). Note that this is _not_ the + same as a type created by calling role_type('RoleName'). + + * Moose::Util::TypeConstraints * Moose::Meta::TypeConstraint::DuckType - Reify duck type from a regular subtype into an actual class (Sartak) diff --git a/lib/Moose/Manual/Delta.pod b/lib/Moose/Manual/Delta.pod index e12d1f2..5cfee58 100644 --- a/lib/Moose/Manual/Delta.pod +++ b/lib/Moose/Manual/Delta.pod @@ -16,6 +16,13 @@ feature. If you encounter a problem and have a solution but don't see it documented here, or think we missed an important feature, please send us a patch. +=head1 Version 0.84 + +The C type has been deprecated. On its own, it was useless, +since it just checked C<< $object->can('does') >>. If you were using +it as a parent type, just call C to create an +appropriate type instead. + =head1 Version 0.78 C now imports C and C into packages diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index ac3b7b1..52603fd 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -657,6 +657,7 @@ subtype 'Object' => as 'Ref' => where { blessed($_) && blessed($_) ne 'Regexp' } => optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Object; +# This type is deprecated. subtype 'Role' => as 'Object' => where { $_->can('does') } => optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Role; @@ -861,7 +862,6 @@ that hierarchy represented visually. GlobRef FileHandle Object - Role B Any type followed by a type parameter C<[`a]> can be parameterized, this means you can say: @@ -887,8 +887,7 @@ existence check. This means that your class B be loaded for this type constraint to pass. B The C constraint checks a string is a I which is a role, like C<'MyApp::Role::Comparable'>. The C -constraint checks that an I has a C method. +name> which is a role, like C<'MyApp::Role::Comparable'>. =head2 Type Constraint Naming diff --git a/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm index 461f53d..45ac73c 100644 --- a/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm +++ b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm @@ -31,7 +31,7 @@ sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or bles sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' } -sub Role { blessed($_[0]) && $_[0]->can('does') } +sub Role { Carp::cluck('The Role type is deprecated.'); blessed($_[0]) && $_[0]->can('does') } sub ClassName { return Class::MOP::is_class_loaded( $_[0] ); diff --git a/t/020_attributes/005_attribute_does.t b/t/020_attributes/005_attribute_does.t index 01145f8..b0ef886 100644 --- a/t/020_attributes/005_attribute_does.t +++ b/t/020_attributes/005_attribute_does.t @@ -19,7 +19,7 @@ use Test::Exception; has 'bar' => (is => 'rw', does => 'Bar::Role'); has 'baz' => ( is => 'rw', - does => subtype('Role', where { $_->does('Bar::Role') }) + does => role_type('Bar::Role') ); package Bar::Role; diff --git a/t/040_type_constraints/003_util_std_type_constraints.t b/t/040_type_constraints/003_util_std_type_constraints.t index 2457d50..bb1ded0 100644 --- a/t/040_type_constraints/003_util_std_type_constraints.t +++ b/t/040_type_constraints/003_util_std_type_constraints.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 291; +use Test::More tests => 277; use Test::Exception; use Scalar::Util (); @@ -283,26 +283,6 @@ ok(!defined Object(qr/../), '... Object rejects anything which is not ok(defined Object(bless {}, 'Foo'), '... Object accepts anything which is blessed'); ok(!defined Object(undef), '... Object accepts anything which is blessed'); -{ - package My::Role; - sub does { 'fake' } -} - -ok(!defined Role(0), '... Role rejects anything which is not a Role'); -ok(!defined Role(100), '... Role rejects anything which is not a Role'); -ok(!defined Role(''), '... Role rejects anything which is not a Role'); -ok(!defined Role('Foo'), '... Role rejects anything which is not a Role'); -ok(!defined Role([]), '... Role rejects anything which is not a Role'); -ok(!defined Role({}), '... Role rejects anything which is not a Role'); -ok(!defined Role(sub {}), '... Role rejects anything which is not a Role'); -ok(!defined Role($SCALAR_REF), '... Role rejects anything which is not a Role'); -ok(!defined Role($GLOB_REF), '... Role rejects anything which is not a Role'); -ok(!defined Role($fh), '... Role rejects anything which is not a Role'); -ok(!defined Role(qr/../), '... Role rejects anything which is not a Role'); -ok(!defined Role(bless {}, 'Foo'), '... Role rejects anything which is not a Role'); -ok(defined Role(bless {}, 'My::Role'), '... Role accepts anything which is a Role'); -ok(!defined Role(undef), '... Role rejects anything which is not a Role'); - ok(!defined ClassName(0), '... ClassName rejects anything which is not a ClassName'); ok(!defined ClassName(100), '... ClassName rejects anything which is not a ClassName'); ok(!defined ClassName(''), '... ClassName rejects anything which is not a ClassName');