2 package Moose::Meta::TypeCoercion::Union;
8 use Scalar::Util 'blessed';
10 our $VERSION = '1.11';
11 $VERSION = eval $VERSION;
12 our $AUTHORITY = 'cpan:STEVAN';
14 use base 'Moose::Meta::TypeCoercion';
16 sub compile_type_coercion {
18 my $type_constraint = $self->type_constraint;
20 (blessed $type_constraint && $type_constraint->isa('Moose::Meta::TypeConstraint::Union'))
21 || Moose->throw_error("You can only create a Moose::Meta::TypeCoercion::Union for a " .
22 "Moose::Meta::TypeConstraint::Union, not a $type_constraint");
24 $self->_compiled_type_coercion(
28 foreach my $type ( grep { $_->has_coercion }
29 @{ $type_constraint->type_constraints } ) {
30 my $temp = $type->coerce($value);
31 return $temp if $type_constraint->check($temp);
39 sub has_coercion_for_type { 0 }
41 sub add_type_coercions {
43 Moose->throw_error("Cannot add additional type coercions to Union types");
54 Moose::Meta::TypeCoercion::Union - The Moose Type Coercion metaclass for Unions
58 This is a subclass of L<Moose::Meta::TypeCoercion> that is used for
59 L<Moose::Meta::TypeConstraint::Union> objects.
64 =item B<< $coercion->has_coercion_for_type >>
66 This method always returns false.
68 =item B<< $coercion->add_type_coercions >>
70 This method always throws an error. You cannot add coercions to a
73 =item B<< $coercion->coerce($value) >>
75 This method will coerce by trying the coercions for each type in the
82 See L<Moose/BUGS> for details on reporting bugs.
86 Stevan Little E<lt>stevan@iinteractive.comE<gt>
88 =head1 COPYRIGHT AND LICENSE
90 Copyright 2006-2010 by Infinity Interactive, Inc.
92 L<http://www.iinteractive.com>
94 This library is free software; you can redistribute it and/or modify
95 it under the same terms as Perl itself.