01fb36371ac5b77f5bb430e380e5c45caeb3c5ee
[catagits/Catalyst-Runtime.git] / t / lib / TestApp / Controller / Action / Chained.pm
1 package TestApp::Controller::Action::Chained;
2
3 use strict;
4 use warnings;
5
6 use base qw/Catalyst::Controller/;
7
8 sub begin :Private { }
9
10 #
11 #   TODO
12 #   :Chained('') means what?
13 #
14
15 #
16 #   Simple parent/child action test
17 #
18 sub foo  :PathPart('chained/foo')  :Captures(1) :Chained('/') { }
19 sub endpoint  :PathPart('end')  :Chained('/action/chained/foo')  :Args(1) { }
20
21 #
22 #   Parent/child test with two args each
23 #
24 sub foo2 :PathPart('chained/foo2') :Captures(2) :Chained('/') { }
25 sub endpoint2 :PathPart('end2') :Chained('/action/chained/foo2') :Args(2) { }
26
27 #
28 #   Relative specification of parent action
29 #
30 sub bar :PathPart('chained/bar') :Chained('/') :Captures(0) { }
31 sub finale :PathPart('') :Chained('bar') :Args { }
32
33 #
34 #   three chain with concurrent endpoints
35 #
36 sub one   :PathPart('chained/one') :Chained('/')                   :Captures(1) { }
37 sub two   :PathPart('two')         :Chained('/action/chained/one') :Captures(2) { }
38 sub three_end :PathPart('three')       :Chained('two') :Args(3) { }
39 sub one_end   :PathPart('chained/one') :Chained('/')   :Args(1) { }
40 sub two_end   :PathPart('two')         :Chained('one') :Args(2) { }
41
42 #
43 #   Dispatch on number of arguments
44 #
45 sub multi1 :PathPart('chained/multi') :Chained('/') :Args(1) { }
46 sub multi2 :PathPart('chained/multi') :Chained('/') :Args(2) { }
47
48 #
49 #   Roots in an action defined in a higher controller
50 #
51 sub higher_root :PathPart('bar') :Chained('/action/chained/foo/higher_root') :Args(1) { }
52
53 #
54 #   Controller -> subcontroller -> controller
55 #
56 sub pcp1 :PathPart('chained/pcp1')  :Chained('/')                        :Captures(1) { }
57 sub pcp3 :Chained('/action/chained/foo/pcp2') :Args(1)     { }
58
59 #
60 #   Dispatch on capture number
61 #
62 sub multi_cap1 :PathPart('chained/multi_cap') :Chained('/') :Captures(1) { }
63 sub multi_cap2 :PathPart('chained/multi_cap') :Chained('/') :Captures(2) { }
64 sub multi_cap_end1 :PathPart('baz') :Chained('multi_cap1') :Args(0) { }
65 sub multi_cap_end2 :PathPart('baz') :Chained('multi_cap2') :Args(0) { }
66
67 #
68 #   Priority: Slurpy args vs. chained actions
69 #
70 sub priority_a1 :PathPart('chained/priority_a') :Chained('/') :Args { }
71 sub priority_a2 :PathPart('chained/priority_a') :Chained('/') :Captures(1) { }
72 sub priority_a2_end :PathPart('end') :Chained('priority_a2') :Args(1) { }
73
74 #
75 #   Priority: Fixed args vs. chained actions
76 #
77 sub priority_b1 :PathPart('chained/priority_b') :Chained('/') :Args(3) { }
78 sub priority_b2 :PathPart('chained/priority_b') :Chained('/') :Captures(1) { }
79 sub priority_b2_end :PathPart('end') :Chained('priority_b2') :Args(1) { }
80
81 #
82 #   Optional specification of :Args in endpoint
83 #
84 sub opt_args :PathPart('chained/opt_args') :Chained('/') { }
85
86 #
87 #   Optional PathPart test -> /chained/optpp/*/opt_pathpart/*
88 #
89 sub opt_pp_start :Chained('/') :PathPart('chained/optpp') :Captures(1) { }
90 sub opt_pathpart :Chained('opt_pp_start') :Args(1) { }
91
92 #
93 #   Optional Args *and* PathPart -> /chained/optall/*/oa/...
94 #
95 sub opt_all_start :Chained('/') :PathPart('chained/optall') :Captures(1) { }
96 sub oa :Chained('opt_all_start') { }
97
98 #
99 #   :Chained is the same as :Chained('/')
100 #
101 sub rootdef :Chained :PathPart('chained/rootdef') :Args(1) { }
102
103 #
104 #   the ParentChain controller chains to this action by
105 #   specifying :Chained('.')
106 #
107 sub parentchain :Chained('/') :PathPart('chained/parentchain') :Captures(1) { }
108
109 sub end :Private {
110   my ($self, $c) = @_;
111   my $out = join('; ', map { join(', ', @$_) }
112                          ($c->req->captures, $c->req->args));
113   $c->res->body($out);
114 }
115
116 1;