ingydotnet / yaml-libyaml-pm

Perl Binding to libyaml
http://search.cpan.org/dist/YAML-LibYAML/
33 stars 37 forks source link

add LiteralMultilineStrings config variable #19

Closed mbethke closed 9 years ago

mbethke commented 9 years ago

I switched from pure Perl YAML to YAML::XS a while ago for various reasons, but one thing that has bothered me is the lack of scalar-style heuristics that can choose between block and flow style strings (the way you have it in pure Perl YAML.pm). Our YAML configs have relatively many multi-line documents and YAML::XS' default single-quoted flow style looks just nasty with its empty lines in-between all the text lines. Therefore I added $YAML::XS::LiteralMultilineStrings that switches to YAML_LITERAL_SCALAR_STYLE when there's a newline in the string. I was thinking of adding a variable for the default style as well so as to be able to switch to PP YAML's double-quote style for short multiline strings but wanted to see first whether there's any chance of getting that stuff onto CPAN.

ingydotnet commented 9 years ago

The heuristic code in YAML.pm wants a newline and a str length of at least 30:

See: https://github.com/ingydotnet/yaml-pm/tree/master/lib/YAML/Dumper.pm#L449

I know it might be a pain, but if you could make the YAML.pm and YAML::XS heuristics match, I would gladly release it.

I'd like to stay away from more config vars. Eventually all this will have a nice API with full control per node.

Let me know what you think. Thanks for your contribution.

mbethke commented 9 years ago

Cool. No pain at all, actually I was about to implement an equivalent heuristic on top of the config variable first. I'll just scrap this pull request and send a new one!