X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeCoercion%2FUnion.pm;h=007c0eb37cef14aeb53a01fb6732ef34485d115e;hb=bb8ef15197850184a45acade3e8f387fd6b63829;hp=73e3c9f21ef19d07e3c7e600b6a1d0b3f92e89f9;hpb=9e4ed568f2e5c1041e6fea8d0cbde420562ab5df;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeCoercion/Union.pm b/lib/Moose/Meta/TypeCoercion/Union.pm index 73e3c9f..007c0eb 100644 --- a/lib/Moose/Meta/TypeCoercion/Union.pm +++ b/lib/Moose/Meta/TypeCoercion/Union.pm @@ -7,7 +7,7 @@ use metaclass; use Scalar::Util 'blessed'; -our $VERSION = '0.84'; +our $VERSION = '1.9900'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -18,26 +18,22 @@ sub compile_type_coercion { my $type_constraint = $self->type_constraint; (blessed $type_constraint && $type_constraint->isa('Moose::Meta::TypeConstraint::Union')) - || Moose->throw_error("You can only a Moose::Meta::TypeCoercion::Union for a " . + || Moose->throw_error("You can only create 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 undef; - }); + ); } sub has_coercion_for_type { 0 } @@ -83,9 +79,7 @@ union. =head1 BUGS -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. +See L for details on reporting bugs. =head1 AUTHOR @@ -93,7 +87,7 @@ Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE -Copyright 2006-2009 by Infinity Interactive, Inc. +Copyright 2006-2010 by Infinity Interactive, Inc. L