new match and match captutres for http methods, plus tests, docs
[catagits/Catalyst-Runtime.git] / t / lib / TestApp / Controller / HTTPMethods.pm
1 package TestApp::Controller::HTTPMethods;
2
3 use Moose;
4 use MooseX::MethodAttributes;
5  
6 extends 'Catalyst::Controller';
7  
8 sub default : Path Args {
9     my ($self, $ctx) = @_;
10     $ctx->response->body('default');
11 }
12  
13 sub get : Path('foo') Method('GET') {
14     my ($self, $ctx) = @_;
15     $ctx->response->body('get');
16 }
17  
18 sub post : Path('foo') Method('POST') {
19     my ($self, $ctx) = @_;
20     $ctx->response->body('post');
21 }
22  
23 sub get_or_post : Path('bar') Method('GET') Method('POST') {
24     my ($self, $ctx) = @_;
25     $ctx->response->body('get or post');
26 }
27  
28 sub any_method : Path('baz') {
29     my ($self, $ctx) = @_;
30     $ctx->response->body('any');
31 }
32
33 sub base :Chained('/') PathPrefix CaptureArgs(0) { }
34
35   sub chained_get :Chained('base') Args(0) GET {
36     pop->res->body('chained_get');
37   }
38
39   sub chained_post :Chained('base') Args(0) POST {
40     pop->res->body('chained_post');
41   }
42
43   sub chained_put :Chained('base') Args(0) PUT {
44     pop->res->body('chained_put');
45   }
46
47   sub chained_delete :Chained('base') Args(0) DELETE {
48     pop->res->body('chained_delete');
49   }
50
51   sub get_or_put :Chained('base') PathPart('get_put_post_delete')
52     : CaptureArgs(0) GET PUT { }
53
54     sub get2 :Chained('get_or_put') PathPart('') Args(0) GET {
55       pop->res->body('get2');
56     }
57     
58     sub put2 :Chained('get_or_put') PathPart('') Args(0) PUT {
59       pop->res->body('put2');
60     }
61
62   sub post_or_delete :Chained('base') PathPart('get_put_post_delete')
63     : CaptureArgs(0) POST DELETE { }
64
65     sub post2 :Chained('post_or_delete') PathPart('') Args(0) POST {
66       pop->res->body('post2');
67     }
68     
69     sub delete2 :Chained('post_or_delete') PathPart('') Args(0) DELETE {
70       pop->res->body('delete2');
71     }
72
73   sub check_default :Chained('base') CaptureArgs(0) { }
74
75     sub default_get :Chained('check_default') PathPart('') Args(0) GET {
76       pop->res->body('get3');
77     }
78
79     sub default_post :Chained('check_default') PathPart('') Args(0) POST {
80       pop->res->body('post3');
81     }
82
83     sub chain_default :Chained('check_default') PathPart('') Args(0) {
84       pop->res->body('chain_default');
85     }
86
87
88 __PACKAGE__->meta->make_immutable;