X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Farg_constraints.t;h=05278d1f5bb6c03d3850dbff278cd139732d9810;hp=cb4d8cf03a24100558a449c8241d1199617e04d8;hb=4e93cdb6d9403718baff430bc1bdc3245aa5236f;hpb=afa7a6c9f9b0b788c6c165231fbb571a9d8b7a37 diff --git a/t/arg_constraints.t b/t/arg_constraints.t index cb4d8cf..05278d1 100644 --- a/t/arg_constraints.t +++ b/t/arg_constraints.t @@ -16,14 +16,14 @@ BEGIN { use strict; use warnings; - + use Type::Utils -all; use Types::Standard -types; use Type::Library -base, -declare => qw( UserId Heart User ContextLike ); - extends "Types::Standard"; + extends "Types::Standard"; class_type User, { class => "MyApp::Model::User::user" }; duck_type ContextLike, [qw/model/]; @@ -152,7 +152,7 @@ BEGIN { sub any_priority_link_any :Chained(link_any) PathPart('') Args(1) { $_[1]->res->body('any_priority_link_any') } sub int_priority_link_any :Chained(link_any) PathPart('') Args(Int) { $_[1]->res->body('int_priority_link_any') } - + sub link_int :Chained(chain_base) PathPart('') CaptureArgs(Int) { } sub any_priority_link :Chained(link_int) PathPart('') Args(1) { $_[1]->res->body('any_priority_link') } @@ -198,10 +198,71 @@ BEGIN { MyApp::Controller::Root->config(namespace=>''); + package MyApp::Controller::Autoclean; + $INC{'MyApp/Controller/Autoclean.pm'} = __FILE__; + + use Moose; + use MooseX::MethodAttributes; + use namespace::clean -except => [ 'meta' ]; + + use MyApp::Types qw/Int/; + + extends 'Catalyst::Controller'; + + sub an_int :Local Args(Int) { + my ($self, $c, $int) = @_; + $c->res->body('an_int (autoclean)'); + } + + MyApp::Controller::Autoclean->config(namespace=>'autoclean'); + + package MyApp::Role; + $INC{'MyApp/Role.pm'} = __FILE__; + + use Moose::Role; + use MooseX::MethodAttributes::Role; + use MyApp::Types qw/Int/; + + sub an_int :Local Args(Int) { + my ($self, $c, $int) = @_; + $c->res->body('an_int (withrole)'); + } + + sub an_int_ns :Local Args(MyApp::Types::Int) { + my ($self, $c, $int) = @_; + $c->res->body('an_int (withrole)'); + } + + package MyApp::BaseController; + $INC{'MyApp/BaseController.pm'} = __FILE__; + + use Moose; + use MooseX::MethodAttributes; + use MyApp::Types qw/Int/; + + extends 'Catalyst::Controller'; + + sub from_parent :Local Args(Int) { + my ($self, $c, $id) = @_; + $c->res->body("from_parent $id"); + } + + package MyApp::Controller::WithRole; + $INC{'MyApp/Controller/WithRole.pm'} = __FILE__; + + use Moose; + use MooseX::MethodAttributes; + + extends 'MyApp::BaseController'; + + with 'MyApp::Role'; + + MyApp::Controller::WithRole->config(namespace=>'withrole'); + package MyApp; use Catalyst; - MyApp->setup; + MyApp->setup('-Log=fatal'); } use Catalyst::Test 'MyApp'; @@ -508,4 +569,28 @@ SKIP: { } +{ + my $res = request '/autoclean/an_int/1'; + is $res->content, 'an_int (autoclean)'; +} + +{ + my $res = request '/withrole/an_int_ns/S'; + is $res->content, 'default'; +} + +{ + my $res = request '/withrole/an_int_ns/111'; + is $res->content, 'an_int (withrole)'; +} + +{ + my $res = request '/withrole/an_int/1'; + is $res->content, 'an_int (withrole)'; +} + +{ + my $res = request '/withrole/from_parent/1'; + is $res->content, 'from_parent 1'; +} done_testing;