From: Stevan Little Date: Sun, 19 Mar 2006 19:51:10 +0000 (+0000) Subject: uploadin X-Git-Tag: 0_05~86 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6b8bd8d3bc7470493af007431efe7b70e1eb7970;p=gitmo%2FMoose.git uploadin --- diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index f9fa401..a4a02f4 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -65,7 +65,6 @@ sub type ($$) { my ($name, $check) = @_; my $full_name = caller() . "::${name}"; register_type_constraint($name => subname $full_name => sub { - return find_type_constraint($name) unless defined $_[0]; local $_ = $_[0]; return undef unless $check->($_[0]); $_[0]; @@ -78,8 +77,7 @@ sub subtype ($$;$) { my $full_name = caller() . "::${name}"; $parent = find_type_constraint($parent) unless $parent && ref($parent) eq 'CODE'; - register_type_constraint($name => subname $full_name => sub { - return find_type_constraint($name) unless defined $_[0]; + register_type_constraint($name => subname $full_name => sub { local $_ = $_[0]; return undef unless defined $parent->($_[0]) && $check->($_[0]); $_[0]; @@ -168,6 +166,10 @@ Moose::Util::TypeConstraints - Type constraint system for Moose subtype NaturalLessThanTen => as Natural => where { $_ < 10 }; + + coerce Num + => as Str + => to { 0+$_ }; =head1 DESCRIPTION @@ -177,10 +179,6 @@ validation. This is B a type system for Perl 5. -The type and subtype constraints are basically functions which will -validate their first argument. If called with no arguments, they will -return themselves (this is syntactic sugar for Moose attributes). - This module also provides a simple hierarchy for Perl 5 types, this could probably use some work, but it works for me at the moment.