Subject: | Loader to preserve order of mappings |
Sometimes I want to load/edit/dump a YAML file, which is stored in a
revision control system, such as subversion.
I know that technically the order of mappings doesn't matter. However,
when my YAML files are stored in a revision control system, it's nice
that edits do not disturb the order more than necessary.
To this end, I have applied somewhat of a horrible hack to YAML::Loader.
I subclass it, copy&paste sub _parse_mapping and alter a single line:
- my $mapping = {};
+ my $mapping = YAML::Node->new({});
With that change, the YAML::Node representing the mapping behaves
exactly like any other normal perl hash, except that the dumper dumps
the keys in the right order. This lets me easily load/edit/dump YAML
files without too much disturbance that upsets revision control.
It would be nice if this behavior would be available as an option; perhaps
$YAML::Loader::PreserveOrder = 1;
I admit that in most use cases it might not be important, but here it's
vital.
Thanks,
--
Paul Evans