From: Dave Rolsky Date: Wed, 25 Mar 2009 22:27:06 +0000 (-0500) Subject: Small refactoring of Union type to remove some wacky code X-Git-Tag: 0.72_01~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=816ef2e26e148154bd091d9636b526a4d8e55ed2;p=gitmo%2FMoose.git Small refactoring of Union type to remove some wacky code --- diff --git a/lib/Moose/Meta/TypeConstraint/Union.pm b/lib/Moose/Meta/TypeConstraint/Union.pm index 74f23d9..c4508b2 100644 --- a/lib/Moose/Meta/TypeConstraint/Union.pm +++ b/lib/Moose/Meta/TypeConstraint/Union.pm @@ -20,21 +20,15 @@ __PACKAGE__->meta->add_attribute('type_constraints' => ( sub new { my ($class, %options) = @_; + + my $name = join '|' => sort { $a cmp $b } + map { $_->name } @{ $options{type_constraints} }; + my $self = $class->SUPER::new( - name => (join '|' => sort {$a cmp $b} - map { $_->name } @{$options{type_constraints}}), - parent => undef, - message => undef, - hand_optimized_type_constraint => undef, - compiled_type_constraint => sub { - my $value = shift; - foreach my $type (@{$options{type_constraints}}) { - return 1 if $type->check($value); - } - return undef; - }, - %options + name => $name, + %options, ); + $self->_set_constraint(sub { $self->check($_[0]) }); $self->coercion(Moose::Meta::TypeCoercion::Union->new( type_constraint => $self @@ -42,6 +36,21 @@ sub new { return $self; } +sub _actually_compile_type_constraint { + my $self = shift; + + my @constraints = @{ $self->type_constraints }; + + return sub { + my $value = shift; + foreach my $type (@constraints) { + return 1 if $type->check($value); + } + return undef; + }; +} + + sub equals { my ( $self, $type_or_name ) = @_;