bump version to 1.18
[gitmo/Moose.git] / lib / Moose / Meta / TypeCoercion / Union.pm
index d583e8c..cc5437c 100644 (file)
@@ -7,7 +7,7 @@ use metaclass;
 
 use Scalar::Util 'blessed';
 
-our $VERSION   = '0.96';
+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 }