ingydotnet / yaml-pm

YAML Perl Module
http://search.cpan.org/dist/YAML/
20 stars 27 forks source link

$YAML::Preserve breaks `!!perl/...` objects #185

Open perlpunk opened 6 years ago

perlpunk commented 6 years ago

The first script loads and dumps YAML with a !!perl/hash:Foo tag:

use YAML;
use Data::Dumper;
my $yaml = <<"EOM";
--- !!perl/hash:Foo
b: B
a: A
EOM
my $data = Load $yaml;
say Dumper $data;
say Dump $data;
__END__
$VAR1 = bless( {
                 'b' => 'B',
                 'a' => 'A'
               }, 'Foo' );
--- !!perl/hash:Foo
a: A
b: B

When using $YAML::Preserve, the dumped YAML is broken, the values of the hash are lost:

use YAML;
use Data::Dumper;
$YAML::Preserve = 1;
my $yaml = <<"EOM";
--- !!perl/hash:Foo
b: B
a: A
EOM
my $data = Load $yaml;
say Dumper $data;
say Dump $data;
__END__
$VAR1 = bless( {
                 'b' => 'B',
                 'a' => 'A'
               }, 'Foo' );
--- !!perl/hash:Foo
a: ~
b: ~

While it may not be possible to preserve the key order of such objects, its contents shouldn't be lost, though.