Dancer...Mutable(3pm)
π Dancer::Serializer::Mutable π
okay bestie, welcome to Dancer::Serializer::Mutable (yes that's the full name, she's from the Dancer::Serializer family, and she's a 3pm perl module π
). She's the one who figures out what format your content should be in, then serializes and deserializes it using the appropriate HTTP header. no cap. β¨
πΈ VERSION πΈ
so this is version 1.3522 π
β¨ SYNOPSIS β¨
okay so here's the whole vibe:
# in config.yml
serializer: Mutable
# in the app
put '/something' => sub {
# deserialized from request
my $name = param( 'name' );
...
# will be serialized to the most
# fitting format
return { message => "user $name added" };
};
that's literally it. you set it in config.yml, you go about your business, and she handles the rest π«Ά
π« DESCRIPTION π«
so what she does is, she tries to find the best (de)serializer for any given request π¦. to do that, she goes down this list and picks the first content type she finds, then uses its related serializer:
- the
content_typefrom the request headers - the
content_typeparameter from the URL - the
acceptfrom the request headers - and if nothing else shows up, the default is
application/json
and here's the content-type to serializer mapping that Dancer::Serializer::Mutable uses, bestie, look at her:
serializer | content types
----------------------------------------------------------
Dancer::Serializer::YAML | text/x-yaml, text/html
Dancer::Serializer::XML | text/xml
Dancer::Serializer::JSON | text/x-json, application/json
π EXPORTABLE FUNCTIONS π
π template_or_serialize( $template, $data, $options ) π
for those moments when you want to render a template for normal browser requests, but return serialized content for AJAX calls. two moods, one function, iconic π§
if the requested content-type is text/html, template_or_serialize returns the rendered template. otherwise it returns $data unmodified β and then that gets serialized as usual π
heads up: template_or_serialize is not exported by default. so you gotta ask for her by name, like:
use Dancer::Serializer::Mutable qw/ template_or_serialize /;
get '/greetings' => sub {
...;
return template_or_serialize 'greetings' => {
title => $title,
name => $name,
};
};
slay π
π₯ INTERNAL METHODS π₯
these are the methods that Dancer uses internally, and they are not accessible via the DSL. so like, you can look, but they're not for you to call directly, iykyk π
β serialize
serialize a data structure β¨. the format she serializes it to is determined automatically, as described above π. it can be one of YAML, XMLβ¦ wait, YAML, XML, JSON β and she defaults to JSON if there's no clear preference from the request π
β deserialize
deserialize the provided serialized data into a data structure π. the type of serialization format depends on the request's content-type. for now, it can be one of YAML, XML, JSON π
β content_type
returns the content-type that was used during the last serialize / deserialize call π
β οΈ WARNING: you must callserialize/deserializebefore callingcontent_type. otherwise the return value will beundefπ
π«Ά AUTHOR π«Ά
Dancer Core Developers β legends, honestly π
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2010 by Alexis Sukrieh πΈ
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself β¨
and that's the whole page, bestie! this doc shipped with perl v5.40.1 on 2026-05-05, so that's when this little icon got her glow-up π¦π mwah, go serialize something cute π
π¦ where this page comes from
- ubuntu stonking: libdancer-perl 1.3522-2 Β· 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