Fix is_subtype_of to handle not-yet-defined role
[gitmo/Moose.git] / lib / Moose / Meta / TypeCoercion / Union.pm
index 74b2ed8..6e6f7da 100644 (file)
@@ -7,10 +7,6 @@ use metaclass;
 
 use Scalar::Util 'blessed';
 
-our $VERSION   = '0.80';
-$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<Moose::Meta::TypeCoercion> that is used for
@@ -83,21 +73,6 @@ 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.
-
-=head1 AUTHOR
-
-Stevan Little E<lt>stevan@iinteractive.comE<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright 2006-2009 by Infinity Interactive, Inc.
-
-L<http://www.iinteractive.com>
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
+See L<Moose/BUGS> for details on reporting bugs.
 
 =cut