X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint.pm;h=eff4449ca6b98826d9c7b53a34d1fc28b8f479d4;hb=refs%2Ftags%2F0.66;hp=1c83eab5a8e8a716abd523369726ce9b93ab6428;hpb=e1737edc1aeb23724d9da1fec93ed82e900d8e00;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index 1c83eab..eff4449 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -12,7 +12,7 @@ use Scalar::Util qw(blessed refaddr); use base qw(Class::MOP::Object); -our $VERSION = '0.62_02'; +our $VERSION = '0.66'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -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); }); } @@ -335,7 +344,7 @@ The name of the type in the global type registry. =item B -This type's parent type. +This type's parent type. =item B @@ -343,18 +352,33 @@ Returns true if this type has a parent type. =item B +Synonym for C. + =item B +Returns this type's constraint. This is the value of C provided +when defining a type. + =item B +Returns true if this type has a message. + =item B +Returns this type's message. + =item B +Generate message for $value. + =item B +Returns true if this type has a coercion. + =item B +Returns this type's L if one exists. + =item B =item B @@ -386,7 +410,7 @@ Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE -Copyright 2006-2008 by Infinity Interactive, Inc. +Copyright 2006-2009 by Infinity Interactive, Inc. L