X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeCoercion%2FUnion.pm;h=6e6f7da4473e0d35ab99d53f24eb730b0f6da72b;hb=0031c50c1ba39e702417ee2bc1cb6a00b7af2cfa;hp=8fd4affe8036d2098cc5417fc5c41f2dc36662dd;hpb=8b5074ce1a5038824f1e1177cd00d1bcfec5a9fb;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeCoercion/Union.pm b/lib/Moose/Meta/TypeCoercion/Union.pm index 8fd4aff..6e6f7da 100644 --- a/lib/Moose/Meta/TypeCoercion/Union.pm +++ b/lib/Moose/Meta/TypeCoercion/Union.pm @@ -7,10 +7,6 @@ use metaclass; use Scalar::Util 'blessed'; -our $VERSION = '0.97'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - use base 'Moose::Meta::TypeCoercion'; sub compile_type_coercion { @@ -18,26 +14,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 } @@ -49,14 +41,12 @@ sub add_type_coercions { 1; +# ABSTRACT: The Moose Type Coercion metaclass for Unions + __END__ =pod -=head1 NAME - -Moose::Meta::TypeCoercion::Union - The Moose Type Coercion metaclass for Unions - =head1 DESCRIPTION This is a subclass of L that is used for @@ -85,17 +75,4 @@ union. See L for details on reporting bugs. -=head1 AUTHOR - -Stevan Little Estevan@iinteractive.comE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006-2010 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - =cut