more tests for the mixed string and perl type constraints in union type constraints...
[gitmo/MooseX-Types.git] / lib / MooseX / Types / TypeDecorator.pm
index 12c7f48..fdbaf9f 100644 (file)
@@ -24,10 +24,18 @@ use overload(
         ## is needed for syntax compatibility.  Maybe someday we'll all just do
         ## Or[Str,Str,Int]
 
-       my @tc = map {
-           blessed $_ ? $_ :
-             Moose::Util::TypeConstraints::find_or_parse_type_constraint($_)
-       } @_;
+        my @args = @_[0,1]; ## arg 3 is special,  see the overload docs.
+        my @tc = grep {blessed $_} map {
+            blessed $_ ? $_ :
+            Moose::Util::TypeConstraints::find_or_parse_type_constraint($_)
+              || croak "$_ is not a type constraint"
+        } @args;
+
+        ( scalar @tc == scalar @args)
+            || croak "one of your type constraints is bad.  Passed: ". join(', ', @args) ." Got: ". join(', ', @tc);
+
+        ( scalar @tc >= 2 )
+            || croak "You must pass in at least 2 type names to make a union";
 
         my $union = Moose::Meta::TypeConstraint::Union->new(type_constraints=>\@tc);
         return Moose::Util::TypeConstraints::register_type_constraint($union);