make M:M:TC:Parameterized->equals("Unregistered") work topic/tc-equals-autocreate
Lukas Mai [Wed, 21 Nov 2012 04:37:49 +0000 (05:37 +0100)]
lib/Moose/Meta/TypeConstraint/Parameterized.pm
t/type_constraints/type_constraint_equals.t [new file with mode: 0644]

index 175c9ab..65bf696 100644 (file)
@@ -25,7 +25,7 @@ __PACKAGE__->meta->add_attribute('parameterized_from' => (
 sub equals {
     my ( $self, $type_or_name ) = @_;
 
-    my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
+    my $other = Moose::Util::TypeConstraints::find_or_create_type_constraint($type_or_name) or return;
 
     return unless $other->isa(__PACKAGE__);
 
diff --git a/t/type_constraints/type_constraint_equals.t b/t/type_constraints/type_constraint_equals.t
new file mode 100644 (file)
index 0000000..5dac87f
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::Fatal qw(lives_ok);
+use Test::More;
+
+use Moose::Util::TypeConstraints ();
+
+lives_ok {
+       ok !Moose::Util::TypeConstraints::find_or_create_type_constraint('Int')->equals('Str');
+};
+
+lives_ok {
+       ok !Moose::Util::TypeConstraints::find_or_create_type_constraint('Int')->equals('NoSuchType');
+};
+
+lives_ok {
+       ok !Moose::Util::TypeConstraints::find_or_create_type_constraint('ArrayRef[Int]')->equals('ArrayRef[Str]');
+};
+
+lives_ok {
+       ok !Moose::Util::TypeConstraints::find_or_create_type_constraint('ArrayRef[Int]')->equals('SomeNonType');
+};
+
+my $tc = Moose::Util::TypeConstraints::find_type_constraint('HashRef')->parameterize('Int');
+lives_ok {
+       ok $tc->equals('HashRef[Int]');
+};
+
+done_testing;