X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeCoercion%2FUnion.pm;h=cc5437c813705b5a05d93476e35e4e54218084a6;hb=aff6aafcfff96c2a91bd044e35010757feae584c;hp=3fab43b7869e750228d3ffbd3884b84b5f64e4cb;hpb=0f8380b0cdbda1e13ed7c456edd3f0d1c0315ec9;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeCoercion/Union.pm b/lib/Moose/Meta/TypeCoercion/Union.pm index 3fab43b..cc5437c 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.86'; +our $VERSION = '1.18'; $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