.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Dancer2::Serializer::Mutable 3pm" .TH Dancer2::Serializer::Mutable 3pm "2023-02-10" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Dancer2::Serializer::Mutable \- Serialize and deserialize content based on HTTP header .SH "VERSION" .IX Header "VERSION" version 0.400001 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& # in config.yml \& serializer: Mutable \& \& engines: \& serializer: \& Mutable: \& mapping: \& \*(Aqtext/x\-yaml\*(Aq : YAML \& \*(Aqtext/html\*(Aq : YAML \& \*(Aqtext/x\-data\-dumper\*(Aq : Dumper \& \*(Aqtext/x\-json\*(Aq : JSON \& \*(Aqapplication/json\*(Aq : JSON \& \& # in the app \& put \*(Aq/something\*(Aq => sub { \& # deserialized from request \& my $name = param( \*(Aqname\*(Aq ); \& \& ... \& \& # will be serialized to the most \& # fitting format \& return { message => "user $name added" }; \& }; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This serializer will try find the best (de)serializer for a given request. For this, it will pick the first valid content type found from the following list and use its related serializer. .IP "\(bu" 4 The \fBcontent_type\fR from the request headers .IP "\(bu" 4 the \fBaccept\fR from the request headers .IP "\(bu" 4 The default is \fBapplication/json\fR .PP The content\-type/serializer mapping that \f(CW\*(C`Dancer2::Serializer::Mutable\*(C'\fR uses is .PP .Vb 5 \& serializer | content types \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& Dancer2::Serializer::YAML | text/x\-yaml, text/html \& Dancer2::Serializer::Dumper | text/x\-data\-dumper \& Dancer2::Serializer::JSON | text/x\-json, application/json .Ve .PP A different mapping can be provided via the config file. For example, the default mapping would be configured as .PP .Vb 9 \& engines: \& serializer: \& Mutable: \& mapping: \& \*(Aqtext/x\-yaml\*(Aq : YAML \& \*(Aqtext/html\*(Aq : YAML \& \*(Aqtext/x\-data\-dumper\*(Aq : Dumper \& \*(Aqtext/x\-json\*(Aq : JSON \& \*(Aqapplication/json\*(Aq : JSON .Ve .PP The keys of the mapping are the content-types to serialize, and the values the serializers to use. Serialization for \f(CW\*(C`YAML\*(C'\fR, \f(CW\*(C`Dumper\*(C'\fR and \f(CW\*(C`JSON\*(C'\fR are done using internal Dancer mechanisms. Any other serializer will be taken to be as Dancer2 serialization class (minus the \f(CW\*(C`Dancer2::Serializer::\*(C'\fR prefix) and an instance of it will be used to serialize/deserialize data. For example, adding Dancer2::Serializer::XML to the mapping would be: .PP .Vb 9 \& engines: \& serializer: \& Mutable: \& mapping: \& \*(Aqtext/x\-yaml\*(Aq : YAML \& \*(Aqtext/html\*(Aq : YAML \& \*(Aqtext/x\-data\-dumper\*(Aq : Dumper \& \*(Aqtext/x\-json\*(Aq : JSON \& \*(Aqtext/xml\*(Aq : XML .Ve .SS "\s-1INTERNAL METHODS\s0" .IX Subsection "INTERNAL METHODS" The following methods are used internally by \f(CW\*(C`Dancer2\*(C'\fR and are not made accessible via the \s-1DSL.\s0 .SS "serialize" .IX Subsection "serialize" Serialize a data structure. The format it is serialized to is determined automatically as described above. It can be one of \s-1YAML,\s0 Dumper, \s-1JSON,\s0 defaulting to \s-1JSON\s0 if there's no clear preference from the request. .SS "deserialize" .IX Subsection "deserialize" Deserialize the provided serialized data to a data structure. The type of serialization format depends on the request's content-type. For now, it can be one of \s-1YAML,\s0 Dumper, \s-1JSON.\s0 .SS "content_type" .IX Subsection "content_type" Returns the content-type that was used during the last \f(CW\*(C`serialize\*(C'\fR / \&\f(CW\*(C`deserialize\*(C'\fR call. \fB\s-1WARNING\s0\fR : you must call \f(CW\*(C`serialize\*(C'\fR / \f(CW\*(C`deserialize\*(C'\fR before calling \f(CW\*(C`content_type\*(C'\fR. Otherwise the return value will be \f(CW\*(C`undef\*(C'\fR. .SH "AUTHOR" .IX Header "AUTHOR" Dancer Core Developers .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2023 by Alexis Sukrieh. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.