YAML::Any(3)

πŸ’– YAML::Any β€” the manual, but make it a group chat πŸ’–

User Contributed Perl Documentation Β· YAML::Any(3) Β· bestie edition πŸŽ€


✨ NAME ✨

YAML::Any β€” pick a YAML implementation and just, like, use it. πŸ’…


🚨 STATUS 🚨

WARNING: this module is about to be deprecated. Not me breaking the news 😭 The plan is that YAML.pm itself will act like an Any module. So yeah. Heads up. 🫢

🌈 SYNOPSIS 🌈

use YAML::Any;
$YAML::Indent = 3;
my $yaml = Dump(@objects);

That's the whole vibe. use it, set your indent, dump your stuff. Iconic. ✨


πŸ’œ DESCRIPTION πŸ’œ

So there's a whole little friend group of YAML implementations out there, and they all support the Dump/Load API. This module's whole job is picking the best one available and using that one. Like a friend who picks the restaurant. πŸ“


πŸ‘‘ ORDER πŸ‘‘

Right now, YAML::Any picks the first one of these that's actually installed on your system:

  • YAML::XS
  • YAML::Syck
  • YAML::Old
  • YAML
  • YAML::Tiny

First come, first served. No cap. πŸ”₯


πŸ’… OPTIONS πŸ’…

If you set an option like this:

$YAML::Indent = 4;

and YAML::Any happens to be running on YAML::XS, then it'll use the proper variable instead β€” that being $YAML::XS::Indent. It translates for you. It's giving translator bestie. πŸ¦‹


🧚 SUBROUTINES 🧚

Like every YAML module that YAML::Any uses, these subroutines are exported by default:

  • Dump
  • Load

and these ones are exportable by request (so you gotta ask nicely, i.e. in your use line):

  • DumpFile
  • LoadFile

🌸 METHODS 🌸

YAML::Any provides the following class methods. 🫢

YAML::Any->order

This method returns a list of all the current possible implementations that YAML::Any will search through. It's the shortlist. The roster. The lineup. ⭐

YAML::Any->implementation

This method returns the implementation that YAML::Any will actually use.

How's it figure that out? It finds the first member of YAML::Any->order that is either already loaded in %INC or that can be loaded with require. If it can't find any implementation, it throws an error. 😭 Periodt.


πŸŽ€ EXAMPLES πŸŽ€

DumpFile and LoadFile

Here's an example for DumpFile:

#!/usr/bin/perl

use strict;
use warnings;

use YAML::Any qw(DumpFile);

my $ds =
{
    array => [5,6,100],
    string => "Hello",
};

DumpFile("hello.yml", $ds);

When you run it, it creates a file called hello.yml in the current working directory, with these contents inside:

---
array:
- 5
- 6
- 100
string: Hello

And then, in turn, this LoadFile example loads the contents from there and accesses them:

#!/usr/bin/perl

use strict;
use warnings;

use YAML::Any qw(LoadFile);

my ($ds) = LoadFile("hello.yml");

print "String == '", $ds->{string}, "'\n";

Assuming hello.yml exists, and is exactly what the DumpFile example made, it prints:

$ perl load.pl
String == 'Hello'
$

Look at that. Output. Slay. πŸ’–


πŸ’– AUTHOR πŸ’–

Ingy dΓΆt Net <ingy@cpan.org>


Copyright 2001-2014. Ingy dΓΆt Net

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

See <http://www.perl.com/perl/misc/Artistic.html>


And that's the whole page, bestie 🫢 this one came from perl v5.42.2 and it's dated 2026-07-27 β€” YAML::Any(3), go forth and dump responsibly πŸ’…βœ¨

πŸ“¦ where this page comes from