|| Moose->throw_error("You can only a Moose::Meta::TypeCoercion::Union for a " .
"Moose::Meta::TypeConstraint::Union, not a $type_constraint");
- $self->_compiled_type_coercion(sub {
- my $value = shift;
- # go through all the type constraints
- # in the union, and check em ...
- foreach my $type (@{$type_constraint->type_constraints}) {
- # if they have a coercion first
- if ($type->has_coercion) {
- # then try to coerce them ...
+ $self->_compiled_type_coercion(
+ sub {
+ my $value = shift;
+
+ foreach my $type ( grep { $_->has_coercion }
+ @{ $type_constraint->type_constraints } ) {
my $temp = $type->coerce($value);
- # and if they get something
- # make sure it still fits within
- # the union type ...
return $temp if $type_constraint->check($temp);
}
+
+ return $value;
}
- return $value;
- });
+ );
}
sub has_coercion_for_type { 0 }