1YAML::PP::Schema::MergeU(s3e)r Contributed Perl DocumentaYtAiMoLn::PP::Schema::Merge(3)
2
3
4

NAME

6       YAML::PP::Schema::Merge - Enabling YAML merge keys for mappings
7

SYNOPSIS

9           use YAML::PP;
10           my $yp = YAML::PP->new( schema => [qw/ + Merge /] );
11
12           my $yaml = <<'EOM';
13           ---
14           - &CENTER { x: 1, y: 2 }
15           - &LEFT { x: 0, y: 2 }
16           - &BIG { r: 10 }
17           - &SMALL { r: 1 }
18
19           # All the following maps are equal:
20
21           - # Explicit keys
22             x: 1
23             y: 2
24             r: 10
25             label: center/big
26
27           - # Merge one map
28             << : *CENTER
29             r: 10
30             label: center/big
31
32           - # Merge multiple maps
33             << : [ *CENTER, *BIG ]
34             label: center/big
35
36           - # Override
37             << : [ *BIG, *LEFT, *SMALL ]
38             x: 1
39             label: center/big
40           EOM
41           my $data = $yp->load_string($yaml);
42           # $data->[4] == $data->[5] == $data->[6] == $data->[7]
43

DESCRIPTION

45       See <https://yaml.org/type/merge.html> for the specification.
46
47       Quote:
48
49       "Specify one or more mappings to be merged with the current one.
50
51       The "<<" merge key is used to indicate that all the keys of one or more
52       specified maps should be inserted into the current map. If the value
53       associated with the key is a single mapping node, each of its key/value
54       pairs is inserted into the current mapping, unless the key already
55       exists in it. If the value associated with the merge key is a sequence,
56       then this sequence is expected to contain mapping nodes and each of
57       these nodes is merged in turn according to its order in the sequence.
58       Keys in mapping nodes earlier in the sequence override keys specified
59       in later mapping nodes."
60
61       The implementation of this in a generic way is not trivial, because we
62       also have to handle duplicate keys, and YAML::PP allows you to write
63       your own handler for processing mappings.
64
65       So the inner API of that is not stable at this point.
66
67       Note that if you enable this schema, a plain scalar `<<` will be seen
68       as special anywhere in your document, so if you want a literal `<<`,
69       you have to put it in quotes.
70
71       Note that the performed merge is not a "deep merge". Only top-level
72       keys are merged.
73

METHODS

75       register
76           Called by YAML::PP::Schema
77
78
79
80perl v5.32.0                      2020-09-11        YAML::PP::Schema::Merge(3)
Impressum