From: John Napiorkowski Date: Fri, 28 May 2010 20:05:26 +0000 (-0400) Subject: added some overloading so that we can properly perform equality tests between a TC... X-Git-Tag: 0.22~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Types.git;a=commitdiff_plain;h=1f0716010cd80a4a4c192e16034c69caa6b01606 added some overloading so that we can properly perform equality tests between a TC and a TC wrapped by a decorator (fix needed for 1.05 Mooses and later). --- diff --git a/lib/MooseX/Types/TypeDecorator.pm b/lib/MooseX/Types/TypeDecorator.pm index 6e71c43..66e0d90 100644 --- a/lib/MooseX/Types/TypeDecorator.pm +++ b/lib/MooseX/Types/TypeDecorator.pm @@ -11,6 +11,11 @@ use Moose::Meta::TypeConstraint::Union; use Scalar::Util qw(blessed); use overload( + '0+' => sub { + my $self = shift @_; + my $tc = $self->{__type_constraint}; + return 0+$tc; + }, '""' => sub { my $self = shift @_; if(blessed $self) { @@ -19,6 +24,7 @@ use overload( return "$self"; } }, + bool => sub { 1 }, '|' => sub { ## It's kind of ugly that we need to know about Union Types, but this diff --git a/t/regressions/01-is_subtype_of.t b/t/regressions/01-is_subtype_of.t index 1f2f000..d1a7054 100644 --- a/t/regressions/01-is_subtype_of.t +++ b/t/regressions/01-is_subtype_of.t @@ -1,27 +1,34 @@ use strict; use warnings; -use Test::More tests=>6; +use Test::More tests=>5; use MooseX::Types; use MooseX::Types::Moose qw(Any Item ); my $item = subtype as 'Item'; +ok Item->equals('Item'); +ok Item->equals(Item); + ok ( $item->is_subtype_of('Any'), q[$item is subtype of 'Any']); ok ( Item->is_subtype_of('Any'), q[Item is subtype of 'Any']); -ok ( $item->is_subtype_of(Any), - q[Item is subtype of Any]); - ok ( Item->is_subtype_of(Any), q[Item is subtype of Any]); + +__END__ + + my $any = subtype as 'Any'; +ok ( $item->is_subtype_of(Any), + q[Item is subtype of Any]); + ok ( $item->is_subtype_of($any), q[$item is subtype of $any]);