Cataly...Content(3pm)
π Catalyst::ActionRole::ConsumesContent β Match on HTTP Request Content-Type π
okay bestie, so this page is Cataly...Content(3pm) from the User Contributed Perl Documentation collection, and honestly? it's giving tiny module, huge slay. it's a Catalyst::ActionRole that lets your action vibe-check the content type of whatever request just walked in. let's get into it π
β¨ NAME β¨
Catalyst::ActionRole::ConsumesContent β Match on HTTP Request Content-Type
like. that's literally the whole pitch. it matches on the HTTP request's Content-Type. periodt π
π¦ SYNOPSIS π¦
bestie here's the whole flex in code form, copy-paste ready:
package MyApp::Web::Controller::MyController;
use base 'Catalyst::Controller';
sub start : POST Chained('/') CaptureArg(0) { ... }
sub is_json : Chained('start') Consumes('application/json') { ... }
sub is_urlencoded : Chained('start') Consumes('application/x-www-form-urlencoded') { ... }
sub is_multipart : Chained('start') Consumes('multipart/form-data') { ... }
## Alternatively, for common types...
sub is_json : Chained('start') Consume(JSON) { ... }
sub is_urlencoded : Chained('start') Consumes(UrlEncoded) { ... }
sub is_multipart : Chained('start') Consumes(Multipart) { ... }
## Or allow more than one type
sub is_more_than_one
: Chained('start')
: Consumes('application/x-www-form-urlencoded')
: Consumes('multipart/form-data')
{
## ...
}
1;
β οΈ ok so heads up, bestie β notice how the second block writesConsume(JSON)(nos!) for the first one while the others sayConsumes(...). that's exactly how it is in the original, so i'm leaving it alone. copy it verbatim, don't get cute with it π
πΈ DESCRIPTION πΈ
so basically? this is an action role that lets your Catalyst::Action match on the content type of the incoming request. main character behavior fr fr π
ngl, generally when there's a PUT or a POST request, there's a request content body tagging along, and it's got a matching MIME content type. usually that's one of the types you'd see with classic HTML forms β like 'application/x-www-form-urlencoded', for example β but literally nothing is stopping you from specifying any valid content type. go off β¨
and for matching purposes? we match strings, but the casing is insensitive. so Application/JSON and application/json are the same vibe to us. iykyk π
π REQUIRES π
this role needs the following methods to exist in the consuming class, no cap:
match
match_captures
these return 1 if the action matches the existing request, and zero if it doesn't. that's it. that's the whole deal π«Ά
β METHODS β
this role defines the following methods, bestie, and i'm listing every single one:
match
match_captures
this is an around method modifier, and it returns 1 if the request content type matches one of the allowed content types (peep "http_methods") and zero otherwise. slay β
allowed_content_types
an array of strings β these are the allowed content types for matching this action. iconic π
can_consume
Boolean. does the current request's content type match what this actionrole can consume? yes or no, that's the tea π
list_extra_info
adds the accepted content type to the debug screen. so when you're debugging you can actually see it. obsessed π
π AUTHORS π
Catalyst Contributors, see Catalyst.pm. shoutout to the whole group chat, fr fr π«Ά
π COPYRIGHT π
this library is free software. you can redistribute it and/or modify it under the same terms as Perl itself. periodt, legally speaking π
and that's a wrap bestie!! this page came to you courtesy of perl v5.40.0 and it's dated 2024-11-15, so go forth, match some content types, and stay iconic β¨π¦π
π¦ where this page comes from
- debian trixie: libcatalyst-perl 5.90132-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcatalyst-perl 5.90132-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatalyst-perl 5.90132-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms