From: John Napiorkowski Date: Wed, 29 Oct 2008 17:37:11 +0000 (+0000) Subject: moved name attribute normalization out of Moose::Util::TypeConstraints into Moose... X-Git-Tag: 0.61~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8534c69ae0617132aab6fffcbfcd3832a34b7e8a;p=gitmo%2FMoose.git moved name attribute normalization out of Moose::Util::TypeConstraints into Moose::Meta::TypeConstraint --- diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index 9c445ae..ae37ab0 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -59,12 +59,18 @@ __PACKAGE__->meta->add_attribute('package_defined_in' => ( sub new { my $class = shift; - my $self = $class->_new(@_); + my ($first, @rest) = @_; + my %args = ref $first ? %$first : $first ? ($first, @rest) : (); + $args{name} = $args{name} ? "$args{name}" : "__ANON__"; + + my $self = $class->_new(%args); $self->compile_type_constraint() unless $self->_has_compiled_type_constraint; return $self; } + + sub coerce { ((shift)->coercion || Moose->throw_error("Cannot coerce without a type coercion"))->coerce(@_) } sub check { $_[0]->_compiled_type_constraint->($_[1]) ? 1 : undef } sub validate { diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 86caaa4..c7665fd 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -373,8 +373,6 @@ sub _create_type_constraint ($$$;$$) { . $pkg_defined_in ) if defined $type; } - - $name = $name ? "$name" : "__ANON__"; my %opts = ( name => $name,