Closed karenetheridge closed 3 years ago
Yes, that sounds like it makes sense and shouldn't be to difficult to implement.
Meanwhile, you can manually create ordered hashes with YAML:PP->preserved_hash
OTOH what do we do in arrays that are inside a preserved hash?
I implemented this in https://metacpan.org/release/TINITA/YAML-PP-0.027_002 maybe you want to test it?
Awesome! I will try to find some time to test it soon.
I actually had to add the behaviour to PUSH, SPLICE and UNSHIFT, too.
Uploaded https://metacpan.org/release/TINITA/YAML-PP-0.028
Please reopen if there are any problems :)
Thanks!
Unfortunately, I found a bug. Here is a small repro case:
#!/usr/bin/env perl
use strict;
use warnings;
use YAML::PP 0.029;
use YAML::PP::Common qw(PRESERVE_ORDER PRESERVE_FLOW_STYLE);
my $yaml = YAML::PP->new(
preserve => PRESERVE_ORDER | PRESERVE_FLOW_STYLE,
);
my $source = <<'YAML';
---
alpha: {}
YAML
my $data = $yaml->load_string($source);
$data->{alpha} = {};
$data->{alpha}{beta} = {};
$data->{alpha}{beta}{gamma}[0] = { name => 'value' };
print $yaml->dump_string($data);
__END__
got:
---
alpha:
beta:
gamma:
- {}
expecting:
---
alpha:
beta:
gamma:
- name: value
There is no bug if we start out with $data = {}
rather than using $source
from the loaded string.
whoops, that's right.
It's because I don't actually add existing data to a given hash/array when tie
ing it.
I prepared a fix under: https://github.com/perlpunk/YAML-PP-p5/tree/fix-preserve
Nice, that works a lot better! \o/
Great, thanks for testing =) I will release it in the next couple of days
thanks again!
I wrote these test cases:
and sadly, they fail:
I think we just need to create a new tied hash when making an assignment to a new slot.