Subject: | [PATCH] small patch to enable block scalars in a subclass |
I want to use YAML::Tiny for something at work, but I to be able to
write scalars in block form instead of as quoted strings. I was going
to implement this by subclassing YAML::Tiny to override _write_scalar,
but unfortunately I can't do it cleanly because the current indent level
isn't being passed into _write_scalar in it's various calls, and without
it you can't indent the block correctly.
I've attached a patch against your SVN trunk makes this little change.
It builds and tests fine, though a lot of tests are skipped on my system.
Let me know what you think, or if I'm missing something important.
Subject: | YAML-Tiny.diff |
Index: Tiny.pm
===================================================================
--- Tiny.pm (revision 4570)
+++ Tiny.pm (working copy)
@@ -334,7 +334,7 @@
# A scalar document
} elsif ( ! ref $cursor ) {
- $lines[-1] .= ' ' . $self->_write_scalar( $cursor );
+ $lines[-1] .= ' ' . $self->_write_scalar( $cursor, $indent );
# A list at the root
} elsif ( ref $cursor eq 'ARRAY' ) {
@@ -387,7 +387,7 @@
my $line = (' ' x $indent) . '-';
my $type = ref $el;
if ( ! $type ) {
- $line .= ' ' . $self->_write_scalar( $el );
+ $line .= ' ' . $self->_write_scalar( $el, $indent + 1 );
push @lines, $line;
} elsif ( $type eq 'ARRAY' ) {
@@ -427,7 +427,7 @@
my $line = (' ' x $indent) . "$name:";
my $type = ref $el;
if ( ! $type ) {
- $line .= ' ' . $self->_write_scalar( $el );
+ $line .= ' ' . $self->_write_scalar( $el, $indent + 1 );
push @lines, $line;
} elsif ( $type eq 'ARRAY' ) {