GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
YAML::PP::Schema::Merge(3) User Contributed Perl Documentation YAML::PP::Schema::Merge(3)

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

    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]

See <https://yaml.org/type/merge.html> for the specification.

Quote:

"Specify one or more mappings to be merged with the current one.

The "<<" merge key is used to indicate 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 this sequence is expected to contain mapping nodes and each of these 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."

The implementation of this in a generic way is not trivial, because we also have to handle duplicate keys, 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.

Note that 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.

Note that the performed merge is not a "deep merge". Only top-level keys are merged.

register
Called by YAML::PP::Schema
2021-12-25 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.