2 package Moose::Meta::TypeCoercion::Union;
8 use Scalar::Util 'blessed';
10 use base 'Moose::Meta::TypeCoercion';
12 sub compile_type_coercion {
14 my $type_constraint = $self->type_constraint;
16 (blessed $type_constraint && $type_constraint->isa('Moose::Meta::TypeConstraint::Union'))
17 || Moose->throw_error("You can only create a Moose::Meta::TypeCoercion::Union for a " .
18 "Moose::Meta::TypeConstraint::Union, not a $type_constraint");
20 $self->_compiled_type_coercion(
24 foreach my $type ( grep { $_->has_coercion }
25 @{ $type_constraint->type_constraints } ) {
26 my $temp = $type->coerce($value);
27 return $temp if $type_constraint->check($temp);
35 sub has_coercion_for_type { 0 }
37 sub add_type_coercions {
39 Moose->throw_error("Cannot add additional type coercions to Union types");
44 # ABSTRACT: The Moose Type Coercion metaclass for Unions
52 This is a subclass of L<Moose::Meta::TypeCoercion> that is used for
53 L<Moose::Meta::TypeConstraint::Union> objects.
58 =item B<< $coercion->has_coercion_for_type >>
60 This method always returns false.
62 =item B<< $coercion->add_type_coercions >>
64 This method always throws an error. You cannot add coercions to a
67 =item B<< $coercion->coerce($value) >>
69 This method will coerce by trying the coercions for each type in the
76 See L<Moose/BUGS> for details on reporting bugs.