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