From: John Napiorkowski Date: Fri, 5 Dec 2008 21:49:20 +0000 (+0000) Subject: changes to the way Moose::Meta::TypeConstraint passed arguments to the compiled type... X-Git-Tag: 0.63~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a125746004b00e978de096e9de12d1cbdaf8eb35;p=gitmo%2FMoose.git changes to the way Moose::Meta::TypeConstraint passed arguments to the compiled type constraint coderef so that I can support MooseX::Types::Structured::Optional --- diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index 5337cd6..2aec261 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -419,6 +419,8 @@ not particularly useful. =item B +=item B + =item B =item B diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index 1c83eab..fa12aea 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -72,7 +72,13 @@ sub new { sub coerce { ((shift)->coercion || Moose->throw_error("Cannot coerce without a type coercion"))->coerce(@_) } -sub check { $_[0]->_compiled_type_constraint->($_[1]) ? 1 : undef } + +sub check { + my ($self, @args) = @_; + my $constraint_subref = $self->_compiled_type_constraint; + return $constraint_subref->(@args) ? 1 : undef; +} + sub validate { my ($self, $value) = @_; if ($self->_compiled_type_constraint->($value)) { @@ -210,8 +216,9 @@ sub _compile_subtype { } else { return Class::MOP::subname($self->name, sub { return undef unless $optimized_parent->($_[0]); - local $_ = $_[0]; - $check->($_[0]); + my (@args) = @_; + local $_ = $args[0]; + $check->(@args); }); } } else { @@ -219,9 +226,10 @@ sub _compile_subtype { my @checks = @parents; push @checks, $check if $check != $null_constraint; return Class::MOP::subname($self->name => sub { - local $_ = $_[0]; + my (@args) = @_; + local $_ = $args[0]; foreach my $check (@checks) { - return undef unless $check->($_[0]); + return undef unless $check->(@args); } return 1; }); @@ -234,8 +242,9 @@ sub _compile_type { return $check if $check == $null_constraint; # Item, Any return Class::MOP::subname($self->name => sub { - local $_ = $_[0]; - $check->($_[0]); + my (@args) = @_; + local $_ = $args[0]; + $check->(@args); }); }