From: Stevan Little Date: Mon, 20 Mar 2006 21:33:41 +0000 (+0000) Subject: getting-there X-Git-Tag: 0_05~79 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=01bf41120a30b2360c0f544a044467ab26731459;p=gitmo%2FMoose.git getting-there --- diff --git a/lib/Moose.pm b/lib/Moose.pm index fdc0903..d8444b5 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -83,7 +83,7 @@ sub import { } else { # otherwise assume it is a constraint - my $constraint = Moose::Util::TypeConstraints::find_type_constraint($options{isa}); + my $constraint = Moose::Util::TypeConstraints::find_type_constraint($options{isa})->constraint_code; # if the constraing it not found .... unless (defined $constraint) { # assume it is a foreign class, and make diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index b2c5db7..eb5524d 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -26,7 +26,7 @@ sub import { my %TYPES; sub find_type_constraint { my $type_name = shift; - $TYPES{$type_name}->constraint_code; + $TYPES{$type_name}; } sub register_type_constraint { @@ -82,7 +82,7 @@ sub subtype ($$;$) { my ($name, $parent, $check) = @_; if (defined $check) { my $full_name = caller() . "::${name}"; - $parent = find_type_constraint($parent) + $parent = find_type_constraint($parent)->constraint_code unless $parent && ref($parent) eq 'CODE'; register_type_constraint($name => subname $full_name => sub { local $_ = $_[0]; @@ -92,7 +92,7 @@ sub subtype ($$;$) { } else { ($parent, $check) = ($name, $parent); - $parent = find_type_constraint($parent) + $parent = find_type_constraint($parent)->constraint_code unless $parent && ref($parent) eq 'CODE'; return subname '__anon_subtype__' => sub { local $_ = $_[0]; @@ -109,7 +109,7 @@ sub coerce ($@) { my @coercions; while (@coercion_map) { my ($constraint_name, $action) = splice(@coercion_map, 0, 2); - my $constraint = find_type_constraint($constraint_name); + my $constraint = find_type_constraint($constraint_name)->constraint_code; (defined $constraint) || confess "Could not find the type constraint ($constraint_name)"; push @coercions => [ $constraint, $action ]; diff --git a/t/053_util_find_type_constraint.t b/t/053_util_find_type_constraint.t index b3dc1e0..00e584a 100644 --- a/t/053_util_find_type_constraint.t +++ b/t/053_util_find_type_constraint.t @@ -3,11 +3,27 @@ use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 12; use Test::Exception; BEGIN { use_ok('Moose::Util::TypeConstraints', (':no_export')); } -#diag Moose::Util::TypeConstraints::dump_type_constraints(); \ No newline at end of file +*find_type_constraint = \&Moose::Util::TypeConstraints::find_type_constraint; + +foreach my $type_name (qw( + Any + Value + Int + Str + Ref + ScalarRef + ArrayRef + HashRef + CodeRef + RegexpRef + Object + )) { + is(find_type_constraint($type_name)->name, $type_name, '... got the right name for ' . $type_name); +} \ No newline at end of file