Revision history for MooseX-Types-Structured
-{{NEXT}}
+0.25 28 December 2010
+ - fixed bug where ->is_subtype_of dies meaninglessly when the type we
+ are trying to check is not a type we can find. This makes our
+ handling consistent with core Moose. Also changed ->equals and
+ ->is_a_type_of to be consistent.
+ - Added test case for above
- The test suite now uses Test::Fatal instead of Test::Exception (Karen
Etheridge).
sub equals {
my ( $self, $type_or_name ) = @_;
- my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
+ my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name)
+ or return;
return unless $other->isa(__PACKAGE__);
sub is_a_type_of {
my ( $self, $type_or_name ) = @_;
- my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
+ my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name)
+ or return;
if ( $other->isa(__PACKAGE__) and @{ $other->type_constraints || [] }) {
if ( $self->parent->is_a_type_of($other->parent) ) {
sub is_subtype_of {
my ( $self, $type_or_name ) = @_;
- my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
+ my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name)
+ or return;
if ( $other->isa(__PACKAGE__) ) {
if ( $other->type_constraints and $self->type_constraints ) {
if ( $self->parent->is_a_type_of($other->parent) ) {
--- /dev/null
+use strict;
+use warnings;
+use Test::More;
+
+## Bug report was that if calling ->is_subtype on crap (not a type, etc) you
+## get a not very helpful error message. Fix was to make crap just return
+## boolean false to make this like the rest of Moose type constraints. I am
+## not convinced this is good, but at least is consistent.
+#
+# I also changed ->equals and ->is_a_type_of to be consistent
+
+{
+ package moosex::types::structured::bug_is_subtype;
+
+ use Moose;
+ use MooseX::Types -declare => [qw/ ThingType /];
+ use MooseX::Types::Moose qw/ Int Str /;
+ use MooseX::Types::Structured qw/ Dict /;
+
+ subtype ThingType, as Dict [ id => Int, name => Str, ];
+ has thing => ( is => 'ro', isa => ThingType, );
+}
+
+ok my $test = moosex::types::structured::bug_is_subtype->new,
+ 'created class';
+
+is(
+ moosex::types::structured::bug_is_subtype::ThingType,
+ 'moosex::types::structured::bug_is_subtype::ThingType',
+ 'correct type',
+);
+
+use MooseX::Types::Moose 'HashRef';
+
+is(
+ HashRef,
+ 'HashRef',
+ 'correct type',
+);
+
+ok(
+ moosex::types::structured::bug_is_subtype::ThingType->is_subtype_of(HashRef),
+ 'is a subtype',
+);
+
+ok(
+ !moosex::types::structured::bug_is_subtype::ThingType
+ ->is_subtype_of(moosex::types::structured::bug_is_subtype::ThingType),
+ 'is not a subtype',
+);
+
+ok(
+ !moosex::types::structured::bug_is_subtype::ThingType
+ ->is_subtype_of('SomeCrap'),
+ 'is not a subtype',
+);
+
+sub SomeCrap {}
+
+ok(
+ !moosex::types::structured::bug_is_subtype::ThingType
+ ->is_subtype_of(SomeCrap),
+ 'is not a subtype',
+);
+
+ok(
+ !moosex::types::structured::bug_is_subtype::ThingType
+ ->is_subtype_of(undef),
+ 'is not a subtype',
+);
+
+ok(
+ !moosex::types::structured::bug_is_subtype::ThingType
+ ->equal(undef),
+ 'is not a subtype',
+);
+
+ok(
+ !moosex::types::structured::bug_is_subtype::ThingType
+ ->is_a_type_of(undef),
+ 'is not a subtype',
+);
+
+
+done_testing;