Open Altreus opened 5 years ago
Yes, this <<
key is called a merge key: https://yaml.org/type/merge.html
It wasn't really made official, but I know that it is implemented in many other YAML processors.
It would be possible to implement it in YAML::XS, but I would first like to get @ingydotnet's ok before I start doing any work.
It won't be trivial to implement it, because a merge key has impact on the surrounding mapping, so it would be quite some work.
Meanwhile, if it's possible for you to use a module with a not yet stable API, you could try out YAML::PP::LibYAML which is a subclass of YAML::PP, and use the merge key feature like that: YAML::PP::Schema::Merge
Thanks, I didn't know about this alternative module :) I'm sure it will be fine to use for those cases when I particularly need that behaviour :+1:
I see that this has been sitting around for a few years; is there any chance that an effort to do this will get revived?
I wouldn't expect anyone to work on this in the near future. I have many other tasks, and there is the mentioned YAML::PP::LibYAML alternative.
The
<<
key in a YAML hash means merge.http://yaml.org/refcard.html
This does not happen.
Reproducible example
Expected output
Observe that the only way to faithfully reproduce this is to copy the keys from the first mapping (but referencing the original values would be fine). I have only referenced the one that was already a ref since this seems like the most likely behaviour.
(I believe the
fix
syntax is justData::Dump
's way of preparing a structure to be self-referent. I borrowed it from the actual output below.)Actual output
Observe that what actually happens is
<<
is just a ref to the original thing. This strategy works for all keys except<<
, which needs to be handled specially.