Cataly...rialize(3pm)
π Catalyst::Action::Serialize β bestie edition π
okay so real talk, this is Catalyst::Action::Serialize, a Perl manual page from the 3pm section of the perl docs (yes the title got chopped to Cataly...rialize which is honestly so dramatic of it π
). It does one job and it does it gorgeously: it serializes the body of an HTTP Response. Let's get into it π¦
β¨ NAME β¨
Catalyst::Action::Serialize β Serialize Data in a Response π
πΈ SYNOPSIS πΈ
package Foo::Controller::Bar;
__PACKAGE__->config(
'default' => 'text/x-yaml',
'stash_key' => 'rest',
'map' => {
'text/html' => [ 'View', 'TT', ],
'text/x-yaml' => 'YAML',
'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
}
);
sub end :ActionClass('Serialize') {}
likeβ¦ look at it. that's the whole vibe. you set up a map, you slap :ActionClass('Serialize') on your end method, and the serializing just happens. ate. π₯
π DESCRIPTION π
This action will serialize the body of an HTTP Response. The serializer is selected by introspecting the HTTP Requests content-type header. (so it literally looks at what the client asked for and goes "say less, I got you" π)
It requires that your Catalyst controller is properly configured to set up the mapping between Content Type's and Serialization classes. No map, no magic β the configuration is the whole plot, bestie.
The specifics of serializing each content-type is implemented as a plugin to Catalyst::Action::Serialize. So each content type gets its own lil specialist π€
Typically, you would use this ActionClass on your end method. However, nothing is stopping you from choosing specific methods to Serialize:
sub foo :Local :ActionClass('Serialize') {
.. populate stash with data ..
}
main character energy honestly. pick whichever methods you want serialized, it's your world π
When you use this module, the request class will be changed to Catalyst::Request::REST. not a suggestion, that's just what happens π«Ά
π CONFIGURATION π
π map
Takes a hashref, mapping Content-Types to a given serializer plugin. that's the whole thing. content type in, serializer plugin out π
π default
This is the 'fall-back' Content-Type if none of the requested or acceptable types is found in the map. It must be an entry in the map.
β οΈ bestie listen: it must be an entry in themap. don't be out here pointingdefaultat something that isn't in there, okay? π
π stash_key
Specifies the key of the stash entry holding the data that is to be serialized. So if the value is rest, we will serialize the data under:
$c->stash->{'rest'}
lowkey the most important setting and everyone forgets it π
π content_type_stash_key
Specifies the key of the stash entry that optionally holds an overriding Content-Type. If set, and if the specified stash entry has a valid value, then it takes priority over the requested content types.
This can be useful if you want to dynamically force a particular content type, perhaps for debugging. obsessed with a good override tbh π
π«Ά HELPFUL PEOPLE π«Ά
Daisuke Maki pointed out that early versions of this Action did not play well with others, or generally behave in a way that was very consistent with the rest of Catalyst.
(real ones remember. thank you Daisuke, genuinely iconic of you to say something πβ¨)
π CUSTOM ERRORS π
For building custom error responses when serialization fails, you can create an ActionRole (and use Catalyst::Controller::ActionRole to apply it to the end action) which overrides unsupported_media_type and/or serialize_bad_request methods.
so when it all goes sideways β and sometimes it will, no cap β you can build your own cute error responses instead of vibing with the default ones π
π SEE ALSO π
You likely want to look at Catalyst::Controller::REST, which implements a sensible set of defaults for doing a REST controller. fr fr, start there.
Catalyst::Action::Deserialize, Catalyst::Action::REST β the rest of the friend group π
π AUTHORS π
See Catalyst::Action::REST for authors. (they're over there, go say hi π)
π LICENSE π
You may distribute this code under the same terms as Perl itself. slay, generous, we love to see it β¨
aaaand that's the page!! this was shipped as part of perl v5.40.1, dated 2026-05-07, and it lives in the User Contributed Perl Documentation collection (the 3pm section, iykyk) π
πΈ mwah, go serialize something gorgeous bestie π¦π
π¦ where this page comes from
- ubuntu stonking: libcatalyst-action-rest-perl 1.22-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