Templa...::YAML(3pm)

πŸ“¦
version 1.23 Β· 2 versions
  • 1.23 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.23 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Template::Plugin::YAML β€” bestie edition πŸ’–

okay so this is a page from the User Contributed Perl Documentation collection, and it's about Template::Plugin::YAML, the plugin that lets your Template Toolkit templates talk to YAML. Sit down, get comfy, we're doing this. 🫢


✨ NAME ✨

Template::Plugin::YAML β€” it's a plugin interface to YAML, that's literally the whole job description πŸ’…


🌸 SYNOPSIS 🌸

Here's the vibe, in template form:

[% USE YAML %]

[% YAML.dump(variable) %]
[% YAML.dump_html(variable) %]
[% value = YAML.undump(yaml_string) %]
[% YAML.dumpfile(filename, variable) %]
[% value = YAML.undumpfile(filename) %]

That's it. That's the whole energy. ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

So Template::Plugin::YAML is a simple Template Toolkit Plugin Interface to the YAML module. Like, simple simple. No drama, no chaos, just vibes. 🌈

You instantiate a YAML object with this directive, and boom, you're in business:

[% USE YAML %]

And because it's a standard plugin (they're all like this, no cap), you can also write its name in lowercase and it'll still work. Case? Not the moment. πŸ‘‘

[% USE yaml %]

πŸ’… METHODS πŸ’…

These are the methods the YAML object supports. One per section, keep scrolling bestie. πŸŽ€

⭐ dump( @variables )

Generates a raw text dump of the data structure(s) you pass in. Plural. Yes, you can pass more than one, we love a generous queen. πŸ™Œ

[% USE Dumper %]
[% yaml.dump(myvar) %]
[% yaml.dump(myvar, yourvar) %]
heads up β€” the example says USE Dumper, that's exactly what's written, don't come for me, I'm just the messenger πŸ’€

πŸ“ dump_html( @variables )

Generates a dump of the data structures β€” same deal as dump β€” but with a glow-up: the characters <, > and & get converted to their equivalent HTML entities, spaces become &nbsp;, and newlines become <br>. It's giving web-safe. 😌

[% USE yaml %]
[% yaml.dump_html(myvar) %]

🧚 undump( $string )

Takes a YAML-encoded string and converts it into the equivalent data structure. πŸͺ„

And here's the iconic trick β€” you can deep-copy a complex structure by completely serializing the data. Yes bestie, clone yourself:

[% USE yaml;
   yaml_string = yaml.dump(complex_data_structure);
   complex_copy = yaml.undump(yaml_string);
%]

πŸ”₯ dumpfile( $file, @variables )

Converts the data to YAML encoding and dumps it to the specified filepath. Writes to disk. Very main character of it. πŸ“

[% USE yaml; yaml.dumpfile(".storage", my_data) %]

πŸ’œ undumpfile( $file )

The reverse bestie β€” loads the YAML-encoded data back from the specified filepath.

[% USE yaml; my_data = yaml.undumpfile(".storage") %]

πŸ‘‘ AUTHORS πŸ‘‘

Richard Clamp <richardc@unixbeard.net>, with undump, undumpfile, and dumpfile implementation by Randal L. Schwartz <merlyn@stonehenge.com>

and it's based on Simon Matthews' Template::Plugin::Dumper 🌟


Copyright 2003, 2008 Richard Clamp All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. 🫢


🌈 SEE ALSO 🌈

  • Template::Plugin::Dumper

and that's the whole page, bestie, you ate it, no crumbs 🍽️✨

this was perl v5.34.0, dated 2022-06-17, from the Templa...::YAML(3pm) page β€” mwah, go forth and template πŸ’‹πŸ’…

πŸ“¦ where this page comes from