Permalink
Browse files

Resolve aliased type names when asked to.

This also requires MX::Types 0.17, so has_available_type_export won't blow up
when introspecting a code symbol that exists, but is not a type constraint.
  • Loading branch information...
1 parent 77fd5ae commit ec619ea01786a93fa76cf1fab13fe71efc21a619 @rafl rafl committed Aug 17, 2009
Showing with 17 additions and 7 deletions.
  1. +1 −1 Makefile.PL
  2. +16 −6 lib/Parse/Method/Signatures/TypeConstraint.pm
View
@@ -9,7 +9,7 @@ all_from 'lib/Parse/Method/Signatures.pm';
requires 'List::MoreUtils';
requires 'Moose';
requires 'MooseX::Traits' => '0.06';
-requires 'MooseX::Types' => '0.10';
+requires 'MooseX::Types' => '0.17';
requires 'MooseX::Types::Moose';
requires 'MooseX::Types::Structured';
requires 'namespace::clean' => '0.10';
@@ -41,12 +41,22 @@ sub find_registered_constraint {
my $type;
if ($self->has_from_namespace) {
-
- $type = has_available_type_export($self->from_namespace, $name);
- croak "The type '$name' was found in " . $self->from_namespace . " " .
- "but it hasn't yet been defined. Perhaps you need to move the " .
- "definition into a type library or a BEGIN block.\n"
- if $type && $type->isa('MooseX::Types::UndefinedType');
+ my $pkg = $self->from_namespace;
+
+ if ($type = has_available_type_export($pkg, $name)) {
+ croak "The type '$name' was found in $pkg " .
+ "but it hasn't yet been defined. Perhaps you need to move the " .
+ "definition into a type library or a BEGIN block.\n"
+ if $type && $type->isa('MooseX::Types::UndefinedType');
+ }
+ else {
+ my $meta = Class::MOP::class_of($pkg) || Class::MOP::Class->initialize($pkg);
+ my $func = $meta->get_package_symbol('&' . $name);
+ my $proto = prototype $func if $func;
+
+ $name = $func->()
+ if $func && defined $proto && !length $proto;
+ }
}
my $registry = Moose::Util::TypeConstraints->get_type_constraint_registry;

0 comments on commit ec619ea

Please sign in to comment.