Subject: | MooseX::Type provided type is mutated when UNION'd with a regular Moose type (represented as a string) |
See attached for failing unit test and corresponding patch to make it
work.
The code that exposes the bug:
use MooseX::Types -declare => [qw( MyUnionType MyStr )];
use MooseX::Types::Moose qw(Str Item);
subtype MyUnionType, as Str | 'Int';
subtype MyStr, as Str;
# this will fail because the Str is now a union type and coercions can
not be added to a UNION type
coerce MyStr, from Item, via {"$_"};
Subject: | 0001-underlying-type-is-converted-to-UNION.patch |
diff --git a/lib/MooseX/Types/TypeDecorator.pm b/lib/MooseX/Types/TypeDecorator.pm
index 46a3fbd..5e6f951 100644
--- a/lib/MooseX/Types/TypeDecorator.pm
+++ b/lib/MooseX/Types/TypeDecorator.pm
@@ -18,7 +18,7 @@ use overload(
## is needed for syntax compatibility. Maybe someday we'll all just do
## Or[Str,Str,Int]
- my @tc = grep {blessed $_} @_;
+ my @tc = map { blessed $_ ? $_ : Moose::Util::TypeConstraints::find_or_parse_type_constraint($_) } @_;
my $union = Moose::Meta::TypeConstraint::Union->new(type_constraints=>\@tc);
return Moose::Util::TypeConstraints::register_type_constraint($union);
},
diff --git a/t/16_union_with_simple_type.t b/t/16_union_with_simple_type.t
new file mode 100644
index 0000000..8de6fff
--- /dev/null
+++ b/t/16_union_with_simple_type.t
@@ -0,0 +1,10 @@
+use Test::More tests => 1;
+use MooseX::Types -declare => [qw( MyUnionType MyStr )];
+use MooseX::Types::Moose qw(Str Item);
+
+subtype MyUnionType, as Str | 'Int';
+subtype MyStr, as Str;
+
+eval { coerce MyStr, from Item, via {"$_"} };
+
+ok(!$@, 'no error thrown on coerce for Union') or diag $@;
--
1.6.2.1