YAML::P...a::Merge(3)
π YAML::PP::Schema::Merge π
Straight from the User Contributed Perl Documentation, bestie: this is the page for YAML::PP::Schema::Merge. Itβs giving βschema that makes YAML merge keys work for mappings,β and honestly? Iconic. π
β¨ NAME β¨
YAML::PP::Schema::Merge β Enabling YAML merge keys for mappings.
Thatβs the whole vibe: itβs the schema that turns on YAML merge-key behaviour for mappings. No cap. π«Ά
πΈ SYNOPSIS πΈ
Okay so hereβs the setup in code form β exactly how you turn it on, plus a whole YAML example showing the merge-key glow-up:
use YAML::PP;
my $yp = YAML::PP->new( schema => [qw/ + Merge /] );
my $yaml = <<'EOM';
---
- &CENTER { x: 1, y: 2 }
- &LEFT { x: 0, y: 2 }
- &BIG { r: 10 }
- &SMALL { r: 1 }
# All the following maps are equal:
- # Explicit keys
x: 1
y: 2
r: 10
label: center/big
- # Merge one map
<< : *CENTER
r: 10
label: center/big
- # Merge multiple maps
<< : [ *CENTER, *BIG ]
label: center/big
- # Override
<< : [ *BIG, *LEFT, *SMALL ]
x: 1
label: center/big
EOM
my $data = $yp->load_string($yaml);
# $data->[4] == $data->[5] == $data->[6] == $data->[7]
π¦ DESCRIPTION π¦
The official spec lives at https://yaml.org/type/merge.html, and hereβs the tea itβs serving:
βSpecify one or more mappings to be merged with the current one.β
The << merge key is the signal that all the keys of one or more specified maps should be inserted into the current map. If the value associated with the key is a single mapping node, each of its key/value pairs is inserted into the current mapping β unless the key already exists in it. If the value associated with the merge key is a sequence, then that sequence is expected to contain mapping nodes, and each of those nodes is merged in turn according to its order in the sequence. Keys in mapping nodes earlier in the sequence override keys specified in later mapping nodes.
Lowkey, implementing this in a generic way is not trivial, because duplicate keys also have to be handled, and YAML::PP allows you to write your own handler for processing mappings. So the inner API of that is not stable at this point. π«
Heads up, bestie: if you enable this schema, a plain scalar<<will be seen as special anywhere in your document. So if you want a literal<<, you have to put it in quotes. π
Also important: the merge being performed is not a βdeep merge.β Only top-level keys are merged. Periodt. π
π METHODS π
register
Called by YAML::PP::Schema.
Cute sign-off: this page is from perl v5.42.0, dated 2026-04-24, with the footer name YAML::P...a::Merge(3). Slay. πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-YAML-PP 0.40.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms