File: Root.pm

package info (click to toggle)
libcatalyst-perl 5.90132-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: perl: 11,061; makefile: 7
file content (50 lines) | stat: -rw-r--r-- 1,684 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package TestContentNegotiation::Controller::Root;

use Moose;
use MooseX::MethodAttributes;

extends 'Catalyst::Controller';

sub start :Chained(/) PathPrefix CaptureArgs(0) { }

    sub is_json       : Chained('start') PathPart('') Consumes('application/json') Args(0) { pop->res->body('is_json1') }
    sub is_urlencoded : Chained('start') PathPart('') Consumes('application/x-www-form-urlencoded') Args(0) { pop->res->body('is_urlencoded1') }
    sub is_multipart  : Chained('start') PathPart('') Consumes('multipart/form-data') Args(0) { pop->res->body('is_multipart1') }

    sub under :Chained('start') CaptureArgs(0) { }

      sub is_json_under       : Chained('under') PathPart('') Consumes(JSON) Args(0) { pop->res->body('is_json2') }
      sub is_urlencoded_under : Chained('under') PathPart('') Consumes(UrlEncoded) Args(0) { pop->res->body('is_urlencoded2') }
      sub is_multipart_under  : Chained('under') PathPart('') Consumes(Multipart) Args(0) { pop->res->body('is_multipart2') }

      ## Or allow more than one type

    sub multi :Chained('start') PathPart('') CaptureArgs(0) { }

    sub is_more_than_one_1
      : Chained('multi')
      : Consumes('application/x-www-form-urlencoded')
      : Consumes('multipart/form-data')
      : Args(0)
    {
      pop->res->body('formdata1');
    }

    sub is_more_than_one_2
      : Chained('multi')
      : Consumes('HTMLForm')
      : Args(0)
    {
      pop->res->body('formdata2');
    }

    sub is_more_than_one_3
      : Chained('multi')
      : Consumes('application/x-www-form-urlencoded,multipart/form-data')
      : Args(0)
    {
      pop->res->body('formdata3');
    }


__PACKAGE__->meta->make_immutable;