Dancer2...rializer(3)
β¨ Dancer2::Core::Role::Serializer β¨
okay bestie, so this is a page from the User Contributed Perl Documentation (the whole thing lives in section 3 of the manual, that's the "library calls" zone, iykyk) π
πΈ NAME πΈ
Dancer2::Core::Role::Serializer β literally the Role for Serializer engines π
π VERSION π
version 2.2.1 β she's serving, she's current π«Ά
π¦ DESCRIPTION π¦
So here's the tea: any class that consumes this role gets to be a serializer under Dancer2. That's the whole point of the role, she's a job description for serializers π
But listen, it's not a free ride. If you wanna implement this role, you must implement the methods serialize and deserialize, and you should also define the value of the content_type attribute. No cap, those are the rules π
β¨ ATTRIBUTES β¨
content_type
This is the content type of the object after it's been serialized. Like, example: a JSON serializer would have a application/json content type defined. Simple as that π
π METHODS π
serialize($content, [\%options])
okay so this one is on you to implement, bestie β the consumer has to write it. It receives the serializer class object and a reference to the object that's getting serialized. It should return the object after being serialized, in whatever content type the content_type attribute says π¦
There's a third, optional argument: a hash reference of options that get passed to the serializer. Slay, options π
β οΈ And this part is important: the serialize method must return bytes and therefore has to handle any encoding. Do not skip this, do not be cute about it, handle your encoding fr fr π
deserialize($content, [\%options])
The inverse method of serialize β the uno reverse card π She receives the serializer class object and a string that should be deserialized. The method should return a reference to the deserialized Perl data structure.
Third optional argument again: a hash reference of options to the serializer π
β οΈ And same energy on this side: deserialize receives encoded bytes and must therefore handle any decoding required. You got this, just don't forget π§
π CONFIGURATION π
The serializer configuration variable is the one that tells Dancer2 which engine to use. She's the main character of this section π
You can change it either in your config.yml file:
#Set JSON engine
serializer: "JSON"
# Prettify JSON output
engines:
serializer:
JSON:
pretty: 1
And if you wanna know which engines are available, go peek at "Serializers" in Dancer2::Manual π
π AUTHOR π
Dancer Core Developers β iconic, legendary, no notes π«Ά
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2026 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. Free software bestie, we love to see it πΈ
and that's the whole page, periodt π this was perl v5.42.3, dated 2026-09-20, and it was a User Contributed Perl Documentation moment π β¨
π¦ where this page comes from
- fedora 44: perl-Dancer2 2.2.1-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms