Garlands of YAML and JSON
Gluggagægir the Elf had to admit that the myriad of IT systems that worked together at the North Pole was amazing. All built different, in different languages, and with different technologies. Luckily, the Elves had decided that everyone should use a universal serialization format so that all the different systems could talk to each other. Unfortunately, however, none of the elves could agree what that should be, and they'd all ended up using a different universal serialization format.
While some elves are working at Santa's Gift Factories for a Holidays season or two before they move to greener pastures (usually quite literally greener, as the Easter Bunny is notoriously known to be the biggest elf poacher around) Gluggagægir is one of your long-term commitment type of elf. He's been around and worked in most departments, and expects to be around longer still, slowly moving up the yuletide ladder until — who knows? — he makes it as Cheers Chief Officer.
So Glugg has made the decision not to argue with the trend du jour, whatever that might be. Why can't we just accept input in any of the contested serialization formats and have the computer, which is pretty smart at processing data, figure it all out?
The current hot debate was should the elves be serializing data in either YAML or JSON, both of which are readable and fairly easy to manipulate. Either was perfectly fine with Glugg, as he's an old-hand to the serialization/deserialization dance. And happens to have one more handy tool on his belt for those tasks: File::Serialize.
Keep it short, keep it sweet
The main raison d'être of File::Serialize is to encapsulate and take care of all the boring, repetitive details that come with serialization. Before using File::Serialize, Glugg used to have two scripts that looked like
In other words, almost the same, except for the serialization engine. But with File::Serialize, he now can just hide that difference under the blanket:
And it goes the other way around as well. The module can also figure out the right output format and deal with common options (pretty-printing, utf8 output, canonical representation) based on the filename the script is writing to:
With, of course, always the possibility to explicitly choose a specific format, for those special cases.
Keep it magic, when you need to be l33t
And then there is the module's carefully guarded little hidden bonus: it also has a function called
transerialize_file, which allows to implement a small pipeline (or, in develfoper lingo, a garland) of transformations. For example, Glugg's real script is even shorter than the snippets given above, and looks something like this:
Short and efficient. That's how elves are, and that's how they like their code to be.