Rolsky)
- Test firing behavior of triggers in relation to builder/default/
lazy_build. (t0m)
+ - Test behavior of equals/is_a_type_of/is_a_subtype_of for all
+ kinds of supported type. (t0m)
* Moose::Meta::Class
- In create(), do not pass "roles" option to the superclass
- added related test that creates an anon metaclass with
a required attribute
+ * Moose::Meta::TypeConstraint::Class
+ * Moose::Meta::TypeConstraint::Role
+ - Unify behavior of equals/is_a_type_of/is_a_subtype_of with
+ other types (as per change in 0.55_02). (t0m)
+ * Moose::Meta::TypeConstraint::Registry
+ - Fix warning when dealing with unknown type names (t0m)
0.58 Sat September 20, 2008
!! This release has an incompatible change regarding !!
my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
+ return unless defined $other;
return unless $other->isa(__PACKAGE__);
return $self->class eq $other->class;
}
my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_class);
+
+ return unless defined $type;
if ( $type->isa(__PACKAGE__) ) {
# if $type_or_name_or_class isn't a class, it might be the TC name of another ::Class type
sub has_type_constraint {
my ($self, $type_name) = @_;
- exists $self->type_constraints->{$type_name} ? 1 : 0
+ ($type_name and exists $self->type_constraints->{$type_name}) ? 1 : 0
}
sub get_type_constraint {
my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
+ return unless defined $other;
return unless $other->isa(__PACKAGE__);
return $self->role eq $other->role;
my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_role);
+ return unless defined $type;
+
if ( $type->isa(__PACKAGE__) ) {
# if $type_or_name_or_role isn't a role, it might be the TC name of another ::Role type
# or it could also just be a type object in this branch
use strict;
use warnings;
-use Test::More tests => 33;
+use Test::More tests => 35;
use Test::Exception;
BEGIN {
ok( $Str_or_Undef->equals(Moose::Meta::TypeConstraint::Union->new(type_constraints => [ $Str, $Undef ])), "equal to clone" );
ok( $Str_or_Undef->equals(Moose::Meta::TypeConstraint::Union->new(type_constraints => [ $Undef, $Str ])), "equal to reversed clone" );
+ok( !$Str_or_Undef->is_a_type_of("ThisTypeDoesNotExist"), "not type of non existant type" );
+ok( !$Str_or_Undef->is_subtype_of("ThisTypeDoesNotExist"), "not subtype of non existant type" );
+
# another ....
my $ArrayRef = find_type_constraint('ArrayRef');
plan tests => @valid_letters + @invalid_letters
+ @valid_languages + @invalid_languages
+ @valid_metacharacters + @invalid_metacharacters
- + @valid_languages + 6;
+ + @valid_languages + 10;
Moose::Util::TypeConstraints->export_type_constraints_as_functions();
ok( !$anon_enum->equals( enum [qw(foo bar)] ), "doesn't equal a diff enum" );
ok( $anon_enum->equals( $anon_enum ), "equals itself" );
ok( $anon_enum->equals( enum \@valid_languages ), "equals duplicate" );
+
+ok( !$anon_enum->is_subtype_of('Object'), 'enum not a subtype of Object');
+ok( !$anon_enum->is_a_type_of('Object'), 'enum not type of Object');
+
+ok( !$anon_enum->is_subtype_of('ThisTypeDoesNotExist'), 'enum not a subtype of nonexistant type');
+ok( !$anon_enum->is_a_type_of('ThisTypeDoesNotExist'), 'enum not type of nonexistant type');
+
use strict;
use warnings;
-use Test::More tests => 30;
+use Test::More tests => 32;
use Test::Exception;
BEGIN {
ok( $t->equals($t), "equals to self" );
ok( !$t->equals( $t->parent ), "not equal to parent" );
ok( $t->parent->equals( $t->parent ), "parent equals to self" );
+
+ ok( !$t->is_a_type_of("ThisTypeDoesNotExist"), "not a non existant type" );
+ ok( !$t->is_subtype_of("ThisTypeDoesNotExist"), "not a subtype of a non existant type" );
}
lives_ok {
use strict;
use warnings;
-use Test::More tests => 18;
+use Test::More tests => 20;
use Test::Exception;
BEGIN {
ok( $type->is_subtype_of("Object"), "subtype of Object" );
+ok( !$type->is_subtype_of("ThisTypeDoesNotExist"), "not subtype of undefined type" );
+ok( !$type->is_a_type_of("ThisTypeDoesNotExist"), "not type of undefined type" );
+
ok( find_type_constraint("Bar")->check(Foo->new), "Foo passes Bar" );
ok( find_type_constraint("Bar")->check(Bar->new), "Bar passes Bar" );
ok( !find_type_constraint("Gorch")->check(Bar->new), "but Bar doesn't pass Gorch");
use strict;
use warnings;
-use Test::More tests => 17;
+use Test::More tests => 19;
use Test::Exception;
BEGIN {
ok( $type->is_subtype_of("Object"), "subtype of Object" );
ok( $type->is_subtype_of("Role"), "subtype of Role" );
+ok( !$type->is_subtype_of("ThisTypeDoesNotExist"), "not subtype of unknown type name" );
+ok( !$type->is_a_type_of("ThisTypeDoesNotExist"), "not type of unknown type name" );
+
ok( find_type_constraint("Bar")->check(FooC->new), "Foo passes Bar" );
ok( find_type_constraint("Bar")->check(BarC->new), "Bar passes Bar" );
ok( !find_type_constraint("Gorch")->check(BarC->new), "but Bar doesn't pass Gorch");