Commit | Line | Data |
8748abc5 |
1 | use warnings; |
2 | use strict; |
3 | use HTTP::Request::Common; |
4 | use utf8; |
5 | |
6 | BEGIN { |
7 | use Test::More; |
8 | eval "use Type::Tiny 1.000005; 1" || do { |
9 | plan skip_all => "Trouble loading Type::Tiny and friends => $@"; |
10 | }; |
11 | } |
12 | |
13 | BEGIN { |
14 | package MyApp::Types; |
15 | $INC{'MyApp/Types.pm'} = __FILE__; |
16 | |
17 | use strict; |
18 | use warnings; |
19 | |
20 | use Type::Utils -all; |
21 | use Types::Standard -types; |
22 | use Type::Library |
23 | -base, |
24 | -declare => qw( UserId Heart ); |
25 | |
26 | extends "Types::Standard"; |
27 | |
28 | declare UserId, |
29 | as Int, |
30 | where { $_ < 5 }; |
31 | |
32 | declare Heart, |
33 | as Str, |
34 | where { $_ eq '♥' }; |
35 | |
36 | } |
37 | |
38 | { |
39 | package MyApp::Controller::Root; |
40 | $INC{'MyApp/Controller/Root.pm'} = __FILE__; |
41 | |
42 | use Moose; |
43 | use MooseX::MethodAttributes; |
44 | use MyApp::Types qw/Tuple Int Str StrMatch ArrayRef Enum UserId Heart/; |
45 | |
46 | extends 'Catalyst::Controller'; |
47 | |
48 | sub user :Local Args(1) |
49 | Query(page=>Int,user=>Tuple[Enum['a','b'],Int]) { |
50 | my ($self, $c, $int) = @_; |
51 | $c->res->body("page ${\$c->req->query_parameters->{page}}, user ${\$c->req->query_parameters->{user}[1]}"); |
52 | } |
53 | |
54 | sub default :Default { |
55 | my ($self, $c, $int) = @_; |
56 | $c->res->body('default'); |
57 | } |
58 | |
59 | MyApp::Controller::Root->config(namespace=>''); |
60 | |
61 | package MyApp; |
62 | use Catalyst; |
63 | |
64 | MyApp->setup; |
65 | } |
66 | |
67 | use Catalyst::Test 'MyApp'; |
68 | |
69 | { |
70 | my $res = request '/user/1?page=10&user=a&user=100'; |
71 | is $res->content, 'page 10, user 100'; |
72 | } |
73 | |
74 | done_testing; |