X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint%2FUnion.pm;h=1aa8354353cb0a04ed945e1adc9e82faeb68a2ef;hb=aead17e74252e3884f9f8e39912ca98fdf4b4dd5;hp=05c63daa2e3d7b3cdaf26964d9a34e494700098f;hpb=07b0f1a5599bf1a0ed99933200ca27290e9a468a;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint/Union.pm b/lib/Moose/Meta/TypeConstraint/Union.pm index 05c63da..1aa8354 100644 --- a/lib/Moose/Meta/TypeConstraint/Union.pm +++ b/lib/Moose/Meta/TypeConstraint/Union.pm @@ -7,7 +7,8 @@ use metaclass; use Moose::Meta::TypeCoercion::Union; -our $VERSION = '0.51'; +our $VERSION = '0.62'; +$VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::TypeConstraint'; @@ -20,7 +21,8 @@ __PACKAGE__->meta->add_attribute('type_constraints' => ( sub new { my ($class, %options) = @_; my $self = $class->SUPER::new( - name => (join ' | ' => map { $_->name } @{$options{type_constraints}}), + name => (join '|' => sort {$a cmp $b} + map { $_->name } @{$options{type_constraints}}), parent => undef, message => undef, hand_optimized_type_constraint => undef, @@ -98,6 +100,29 @@ sub is_subtype_of { return 0; } +sub create_child_type { + my ( $self, %opts ) = @_; + + my $constraint + = Moose::Meta::TypeConstraint->new( %opts, parent => $self ); + + # if we have a type constraint union, and no + # type check, this means we are just aliasing + # the union constraint, which means we need to + # handle this differently. + # - SL + if ( not( defined $opts{constraint} ) + && $self->has_coercion ) { + $constraint->coercion( + Moose::Meta::TypeCoercion::Union->new( + type_constraint => $self, + ) + ); + } + + return $constraint; +} + 1; __END__ @@ -111,7 +136,7 @@ Moose::Meta::TypeConstraint::Union - A union of Moose type constraints =head1 DESCRIPTION This metaclass represents a union of Moose type constraints. More -details to be explained later (possibly in a Cookbook::Recipe). +details to be explained later (possibly in a Cookbook recipe). This actually used to be part of Moose::Meta::TypeConstraint, but it is now better off in it's own file. @@ -180,6 +205,8 @@ anyway. They are here for completeness. =item B +=item B + =back =head1 BUGS