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);
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;
use Test::More;
use Test::Exception;
+use Scalar::Util qw(refaddr);
BEGIN {
use_ok('Moose::Util::TypeConstraints');
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;