X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FTypes%2FTypeDecorator.pm;h=fdbaf9fcabec4fad88dbcb2f6e061f39a7f50434;hb=0d07f026067efc017e030c8c9a8e0faad6f55166;hp=12c7f4803b3bacd785f2913b07d38b3d41203974;hpb=442e42ba3e90b69452a0c8c2a78cd55d2304262a;p=gitmo%2FMooseX-Types.git diff --git a/lib/MooseX/Types/TypeDecorator.pm b/lib/MooseX/Types/TypeDecorator.pm index 12c7f48..fdbaf9f 100644 --- a/lib/MooseX/Types/TypeDecorator.pm +++ b/lib/MooseX/Types/TypeDecorator.pm @@ -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);