1Catalyst::Action::SeriaUlsiezre(C3o)ntributed Perl DocumCeanttaaltyisotn::Action::Serialize(3)
2
3
4

NAME

6       Catalyst::Action::Serialize - Serialize Data in a Response
7

SYNOPSIS

9           package Foo::Controller::Bar;
10
11           __PACKAGE__->config(
12               'default'   => 'text/x-yaml',
13               'stash_key' => 'rest',
14               'map'       => {
15                   'text/html'          => [ 'View', 'TT', ],
16                   'text/x-yaml'        => 'YAML',
17                   'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
18               }
19           );
20
21           sub end :ActionClass('Serialize') {}
22

DESCRIPTION

24       This action will serialize the body of an HTTP Response.  The
25       serializer is selected by introspecting the HTTP Requests content-type
26       header.
27
28       It requires that your Catalyst controller is properly configured to set
29       up the mapping between Content Type's and Serialization classes.
30
31       The specifics of serializing each content-type is implemented as a
32       plugin to Catalyst::Action::Serialize.
33
34       Typically, you would use this ActionClass on your "end" method.
35       However, nothing is stopping you from choosing specific methods to
36       Serialize:
37
38         sub foo :Local :ActionClass('Serialize') {
39            .. populate stash with data ..
40         }
41
42       When you use this module, the request class will be changed to
43       Catalyst::Request::REST.
44

CONFIGURATION

46   map
47       Takes a hashref, mapping Content-Types to a given serializer plugin.
48
49   default
50       This is the 'fall-back' Content-Type if none of the requested or
51       acceptable types is found in the "map". It must be an entry in the
52       "map".
53
54   stash_key
55       Specifies the key of the stash entry holding the data that is to be
56       serialized.  So if the value is "rest", we will serialize the data
57       under:
58
59         $c->stash->{'rest'}
60
61   content_type_stash_key
62       Specifies the key of the stash entry that optionally holds an
63       overriding Content-Type. If set, and if the specified stash entry has a
64       valid value, then it takes priority over the requested content types.
65
66       This can be useful if you want to dynamically force a particular
67       content type, perhaps for debugging.
68

HELPFUL PEOPLE

70       Daisuke Maki pointed out that early versions of this Action did not
71       play well with others, or generally behave in a way that was very
72       consistent with the rest of Catalyst.
73

CUSTOM ERRORS

75       For building custom error responses when serialization fails, you can
76       create an ActionRole (and use Catalyst::Controller::ActionRole to apply
77       it to the "end" action) which overrides "unsupported_media_type" and/or
78       "serialize_bad_request" methods.
79

SEE ALSO

81       You likely want to look at Catalyst::Controller::REST, which implements
82       a sensible set of defaults for doing a REST controller.
83
84       Catalyst::Action::Deserialize, Catalyst::Action::REST
85

AUTHORS

87       See Catalyst::Action::REST for authors.
88

LICENSE

90       You may distribute this code under the same terms as Perl itself.
91
92
93
94perl v5.34.0                      2022-01-20    Catalyst::Action::Serialize(3)
Impressum