-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
true/false data structure prevents changing values #25
Comments
I'm not able to reproduce this problem or the output you're seeing. The syntax around your heredoc doesn't look right to me - I think it should be something like this instead: |
@ratsbane sorry markdown ate my formatting. I have updated the comment with the correct format. |
I can reproduce this under perl 5.18.2 |
Here is a minimalist test case (verified on perl 5.20.1, YAML::XS 0.59):
This should not die. |
Looks like I have to implement the same trick as in JSON::XS, special overloaded symbols representing true and false.
|
The import/flatten mechanism was processing every node in the returned data structure, but: 1. That's not needed (the leaf nodes can never change) 2. YAML documents containing literal true/false values will contain read- only nodes, which means that we blow up trying to load them. The glitch that causes GrantStreetGroup#2 is: ingydotnet/yaml-libyaml-pm#25 But the fix here will still be an improvement, even if that gets corrected.
The import/flatten mechanism was processing every node in the returned data structure, but: 1. That's not needed (the leaf nodes can never change) 2. YAML documents containing literal true/false values will contain read- only nodes, which means that we blow up trying to load them. The glitch that causes GrantStreetGroup#2 is: ingydotnet/yaml-libyaml-pm#25 But the fix here will still be an improvement, even if that gets corrected.
The workaround is to use YAML::XS qw(Load);
my $yaml = <<EOM;
hello: true
EOM
my $data = Load($yaml);
# This fails
# $data->{hello}= 1;
# This works
delete $data->{hello};
$data->{hello} = 1; |
@rurban actually I think a round trip loss is not so much of an issue this case, since perl doesn't natively support true value so I don't think people expect that. plus we can have a flag to turn on/off this round trip value. |
perl supports sv_yes and sv_no via the well-known constructs
Note the overlarge refcount and PROTECT denoting an immortal protected special value, i.e. |
Starting with YAML::XS 0.66_001, you can use this: local $YAML::XS::Boolean = "JSON::PP"; # or "boolean"
my $data = Load("booltrue: true");
$data->{boolfalse} = JSON::PP::false;
my $yaml = Dump($data);
# boolfalse: false
# booltrue: true See more about this in the docs. This also does not have the issue of readonly values. |
I'd like to re-open this because this seems like the Consider the following (using Perl 5.30):
One is |
The current solution was chosen to be able to roundtrip booleans. |
#118 is now released as v0.902.0 |
When loading an yaml with true value, the value can't be modified as perl will complain 'changing a read-only value' . to reproduce
I don't know if there is a reason why converting to a data structure that Perl can't modify.
The text was updated successfully, but these errors were encountered: