fix and test related to breakage in MX:Types and others when we made the TC->equals...
John Napiorkowski [Fri, 28 May 2010 20:01:57 +0000 (16:01 -0400)]
lib/Moose/Meta/TypeConstraint.pm
t/040_type_constraints/010_misc_type_tests.t

index bac571a..d292bcc 100644 (file)
@@ -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;
index 04bc642..6915ddf 100644 (file)
@@ -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;