From: John Napiorkowski Date: Fri, 28 May 2010 20:01:57 +0000 (-0400) Subject: fix and test related to breakage in MX:Types and others when we made the TC->equals... X-Git-Tag: 1.06~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ed90007bbf809739645439d7f47bafaffecf384c;p=gitmo%2FMoose.git fix and test related to breakage in MX:Types and others when we made the TC->equals test more exclusive in release 1.05 --- diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index bac571a..d292bcc 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -5,7 +5,8 @@ use strict; use warnings; use metaclass; -use overload '""' => sub { shift->name }, # stringify to tc name +use overload '0+' => sub { refaddr(shift) }, # id an object + '""' => sub { shift->name }, # stringify to tc name fallback => 1; use Scalar::Util qw(blessed refaddr); @@ -133,7 +134,7 @@ sub equals { my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; - return 1 if refaddr($self) == refaddr($other); + return 1 if 0+$self == 0+$other; if ( $self->has_hand_optimized_type_constraint and $other->has_hand_optimized_type_constraint ) { return 1 if $self->hand_optimized_type_constraint == $other->hand_optimized_type_constraint; diff --git a/t/040_type_constraints/010_misc_type_tests.t b/t/040_type_constraints/010_misc_type_tests.t index 04bc642..6915ddf 100644 --- a/t/040_type_constraints/010_misc_type_tests.t +++ b/t/040_type_constraints/010_misc_type_tests.t @@ -5,6 +5,7 @@ use warnings; use Test::More; use Test::Exception; +use Scalar::Util qw(refaddr); BEGIN { use_ok('Moose::Util::TypeConstraints'); @@ -78,7 +79,9 @@ ok $subtype2 => 'made a subtype of our subtype'; my $foo = Moose::Util::TypeConstraints::find_type_constraint('Foo'); my $bar = Moose::Util::TypeConstraints::find_type_constraint('Bar'); - ok(! $foo->equals($bar), "Foo type is not equal to Bar type"); + ok(!$foo->equals($bar), "Foo type is not equal to Bar type"); + ok( $foo->equals($foo), "Foo equals Foo"); + ok( 0+$foo == refaddr($foo), "overloading works"); } done_testing;