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 🫢


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