1 package Catalyst::ActionRole::Scheme;
5 requires 'match', 'match_captures', 'list_extra_info';
7 around ['match','match_captures'] => sub {
8 my ($orig, $self, $ctx, @args) = @_;
9 my $request_scheme = lc($ctx->req->env->{'psgi.url_scheme'});
10 my $match_scheme = lc($self->scheme||'');
12 return $request_scheme eq $match_scheme ? $self->$orig($ctx, @args) : 0;
15 around 'list_extra_info' => sub {
16 my ($orig, $self, @args) = @_;
18 %{ $self->$orig(@args) },
19 Scheme => $self->attributes->{Scheme}[0]||'',
27 Catalyst::ActionRole::ConsumesContent - Match on HTTP Request Content-Type
31 package MyApp::Web::Controller::MyController;
33 use base 'Catalyst::Controller';
35 sub start : POST Chained('/') CaptureArg(0) { ... }
37 sub is_json : Chained('start') Consumes('application/json') { ... }
38 sub is_urlencoded : Chained('start') Consumes('application/x-www-form-urlencoded') { ... }
39 sub is_multipart : Chained('start') Consumes('multipart/form-data') { ... }
41 ## Alternatively, for common types...
43 sub is_json : Chained('start') Consume(JSON) { ... }
44 sub is_urlencoded : Chained('start') Consumes(UrlEncoded) { ... }
45 sub is_multipart : Chained('start') Consumes(Multipart) { ... }
47 ## Or allow more than one type
51 : Consumes('application/x-www-form-urlencoded')
52 : Consumes('multipart/form-data')
61 This is an action role that lets your L<Catalyst::Action> match on the content
62 type of the incoming request.
64 Generally when there's a PUT or POST request, there's a request content body
65 with a matching MIME content type. Commonly this will be one of the types
66 used with classic HTML forms ('application/x-www-form-urlencoded' for example)
67 but there's nothing stopping you specifying any valid content type.
69 For matching purposes, we match strings but the casing is insensitive.
73 This role requires the following methods in the consuming class.
79 Returns 1 if the action matches the existing request and zero if not.
83 This role defines the following methods
89 Around method modifier that return 1 if the request content type matches one of the
90 allowed content types (see L</http_methods>) and zero otherwise.
92 =head2 allowed_content_types
94 An array of strings that are the allowed content types for matching this action.
98 Boolean. Does the current request match content type with what this actionrole
101 =head2 list_extra_info
103 Add the accepted content type to the debug screen.
107 Catalyst Contributors, see Catalyst.pm
111 This library is free software. You can redistribute it and/or modify it under
112 the same terms as Perl itself.