Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the YAML CPAN distribution.

Report information
The Basics
Id: 83788
Status: resolved
Priority: 0/
Queue: YAML

People
Owner: Nobody in particular
Requestors: Marek.Rouchal [...] gmx.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.84
Fixed in: 1.20



Subject: optionally preserve hash order when loading
The current implementation of YAML does not allow to preserve the hash order when loading a YAML document. I know, this is not really in the spec, but: - YAML documents come with an implicit order of the keys (as they appear in the document) - YAML::Node supports to keep the hash order via a tied hash In fact, with the Loader changed on one line (around ~326): -my $mapping = {}; +require YAML::Node; +my $mapping = YAML::Node->new({}); ... this works immediately! I am wondering whether this could not be provided as a global option e.g. when $YAML::SortKeys is set to 0. What do you think? Many thanks, Marek
Subject: Re: [rt.cpan.org #83788] optionally preserve hash order when loading
Date: Thu, 7 Mar 2013 19:17:24 -0800
To: bug-YAML [...] rt.cpan.org
From: Ingy dot Net <ingy [...] ingy.net>
Hi Marek, I think it's useful, but I think it should have its own config option. Maybe $YAML::KeyOrder=1 or $YAML::LoadNode Would you be interested in forking this on github, patching it with tests, and submitting a pull request? Cheers, Ingy On Wed, Mar 6, 2013 at 7:48 AM, Marek Rouchal via RT <bug-YAML@rt.cpan.org>wrote: Show quoted text
> Wed Mar 06 10:48:49 2013: Request 83788 was acted upon. > Transaction: Ticket created by MAREKR > Queue: YAML > Subject: optionally preserve hash order when loading > Broken in: 0.84 > Severity: Normal > Owner: Nobody > Requestors: Marek.Rouchal@gmx.net > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=83788 > > > > The current implementation of YAML does not allow to preserve the hash > order when loading a YAML document. I know, this is not really in the > spec, but: > - YAML documents come with an implicit order of the keys (as they appear > in the document) > - YAML::Node supports to keep the hash order via a tied hash > > In fact, with the Loader changed on one line (around ~326): > > -my $mapping = {}; > +require YAML::Node; > +my $mapping = YAML::Node->new({}); > > ... this works immediately! I am wondering whether this could not be > provided as a global option e.g. when $YAML::SortKeys is set to 0. > > What do you think? > > Many thanks, > > Marek >
This issue has been copied to: https://github.com/ingydotnet/yaml-pm/issues/132 please take all future correspondence there. This ticket will remain open but please do not reply here. This ticket will be closed when the github issue is dealt with.
Released 1.20