Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rakudo release version.

  • Loading branch information...
commit 62d1e512efd2f8402a25740bb0917d9b588e68d6 1 parent 127fe48
@ingydotnet authored
Showing with 47 additions and 10 deletions.
  1. +19 −4 README
  2. +10 −2 lib/YAML/Dumper.pm
  3. +18 −4 t/strings.tml
View
23 README
@@ -1,19 +1,34 @@
-= YAML
+== YAML
This is the pure Perl 6 implementation of YAML.
-At this early point in time, only the dump() operation is supported.
-
use YAML;
say dump($any_perl_object);
+== BENEFITS
+
+At this point in Perl 6, using YAML is the only way to dump an object
+graph to text. The `.perl` method will stop at object nodes, rather than
+dumping them further. The `.perl` method also cannot dump cyclic data
+graphs. YAML.pm handles these things fine.
+
+== CAVEATS
+
+At this early point in time, only the dump() operation is supported. You
+cannot use this module to load YAML streams into memory objects.
+
+Also, this early version of YAML.pm should only be used for
+_visualizing_ (dumping) complex data. The output quite possibly might
+not be perfectly valid YAML, so don't use this module for data
+communication just yet.
+
== INSTALLATION
Use `ufo`. http://github.com/masak/ufo
> cd yaml-pm6
> ufo
- > make test
+ > make test # requires testml - http://github.com/ingydotnet/testml-pm6
> make install
== COPYRIGHT
View
12 lib/YAML/Dumper.pm
@@ -125,8 +125,9 @@ method dump_alias($node) {
method dump_string($node) {
return $.dump_single($node) if $node ~~ /^ true | false | null | '~' $/;
- return $.dump_single($node) if $node ~~ /^ ' ' /;
- return $.dump_single($node) if $node ~~ / ' ' $/;
+ return $.dump_double($node) if $node ~~ /^ ' ' /;
+ return $.dump_double($node) if $node ~~ / ' ' $/;
+ return $.dump_double($node) if $node ~~ / \n | '"' /;
return $.dump_unquoted($node);
}
@@ -134,6 +135,13 @@ method dump_single($node) {
push $.out, "'", $node.subst(m/"'"/, "''", :g), "'";
}
+method dump_double($node) {
+ my $text = $node\
+ .subst(m/'"'/, '\\"', :g)\
+ .subst(m/\n/, '\\n', :g);
+ push $.out, '"', $text, '"';
+}
+
method dump_unquoted($node) {
push $.out, $node;
}
View
22 t/strings.tml
@@ -1,6 +1,6 @@
%TestML: 1.0
%Title: Various String Quoting
-%Plan: 1
+%Plan: 3
%PointMarker: +++
@@ -11,8 +11,22 @@
+++ perl: [ ' x', ' y ', 'z ' ]
+++ yaml
---
-- ' x'
-- ' y '
-- 'z '
+- " x"
+- " y "
+- "z "
...
+
+=== Newlines
++++ perl: { "foo\n" => "O\nHAI\n\n" }
++++ yaml
+---
+"foo\n": "O\nHAI\n\n"
+...
+
+
+=== Double Quote
++++ perl: '"O HAI", said I.'
++++ yaml
+--- "\"O HAI\", said I."
+...
Please sign in to comment.
Something went wrong with that request. Please try again.