support imported types (types-tiny, MXT)
John Napiorkowski [Tue, 17 Mar 2015 14:52:11 +0000 (09:52 -0500)]
lib/Catalyst/Action.pm
t/arg_constraints.t

index 58693af..274ffd9 100644 (file)
@@ -100,13 +100,19 @@ has args_constraints => (
       return \@args;
     } else {
       @args =
-        map { Moose::Util::TypeConstraints::find_or_parse_type_constraint($_) || die "$_ is not a constraint!" } 
+        map {  $self->resolve_type_constraint($_) || die "$_ is not a constraint!" }
         @arg_protos;
     }
 
     return \@args;
   }
 
+sub resolve_type_constraint {
+  my ($self, $name) = @_;
+  my $tc = eval "package ${\$self->class}; $name" || undef;
+  return $tc || Moose::Util::TypeConstraints::find_or_parse_type_constraint($name);
+}
+
 use overload (
 
     # Stringify to reverse for debug output etc.
index e4a2593..2a43a87 100644 (file)
@@ -1,7 +1,12 @@
 use warnings;
 use strict;
-use Test::More;
-use HTTP::Request::Common;
+
+BEGIN {
+  use Test::More;
+  eval "use Types::Standard; 1;" || do {
+    plan skip_all => "Trouble loading Types::Standard => $@";
+  };
+}
 
 {
   package MyApp::Controller::Root;
@@ -9,6 +14,7 @@ use HTTP::Request::Common;
 
   use Moose;
   use MooseX::MethodAttributes;
+  use Types::Standard qw/Tuple Int Str/;
 
   extends 'Catalyst::Controller';
 
@@ -22,7 +28,14 @@ use HTTP::Request::Common;
     $c->res->body('many_ints');
   }
 
+  sub tuple :Local Args(Tuple[Str,Int]) {
+    my ($self, $c, $int) = @_;
+    $c->res->body('tuple');
+  }
+
+
   sub any_priority :Path('priority_test') Args(1) { $_[1]->res->body('any_priority') }
+
   sub int_priority :Path('priority_test') Args(Int) { $_[1]->res->body('int_priority') }
 
   sub default :Default {
@@ -75,10 +88,21 @@ use Catalyst::Test 'MyApp';
   my $res = request '/priority_test/1';
   is $res->content, 'int_priority';
 }
+
 {
   my $res = request '/priority_test/a';
   is $res->content, 'any_priority';
 }
 
+{
+  my $res = request '/tuple/aaa/111';
+  is $res->content, 'tuple';
+}
+
+{
+  my $res = request '/tuple/aaa/aaa';
+  is $res->content, 'default';
+}
+
 done_testing;