From: Lukas Mai Date: Wed, 21 Nov 2012 04:37:49 +0000 (+0100) Subject: make M:M:TC:Parameterized->equals("Unregistered") work X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=46f2b34a7630a949348044912609d3aa17791150;p=gitmo%2FMoose.git make M:M:TC:Parameterized->equals("Unregistered") work --- diff --git a/lib/Moose/Meta/TypeConstraint/Parameterized.pm b/lib/Moose/Meta/TypeConstraint/Parameterized.pm index 175c9ab..65bf696 100644 --- a/lib/Moose/Meta/TypeConstraint/Parameterized.pm +++ b/lib/Moose/Meta/TypeConstraint/Parameterized.pm @@ -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 index 0000000..5dac87f --- /dev/null +++ b/t/type_constraints/type_constraint_equals.t @@ -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;