Subject: | Bad hash line on reading stream |
Reading file 'file.conf' described in SYNOPSIS in pod of YAML::Tiny
is died with message "Bad hash line."
Attached patch resolves this problem simply.
Subject: | multidocs.t |
#!/usr/bin/perl -w
# Testing of multible documents in a yaml stream
use strict;
use File::Spec::Functions ':ALL';
BEGIN {
$| = 1;
}
use lib catdir('t', 'lib');
#use MyTests;
use Test::More tests => 2*5;
use YAML::Tiny;
sub check
{
my $yaml = shift;
my $str = shift;
my $msg = shift;
is($yaml->write_string, $str, "$msg (serialize)");
is_deeply($yaml->read_string($yaml->write_string), $yaml, "$msg (round trip)");
}
my $yaml = YAML::Tiny->new();
check($yaml, '', "empty object");
$yaml->[0]->{newsection} = { this => 'that' }; # Add a section
check($yaml, <<YAML, "add a section");
---
newsection:
this: that
YAML
# Add a document
$yaml->[1] = [ 'foo', 'bar', 'baz' ];
check($yaml, <<YAML, "add a document");
---
newsection:
this: that
---
- foo
- bar
- baz
YAML
# add 3rd.
$yaml->[2]->{newsection} = { these => 'those' }; # Add a section
check($yaml, <<YAML, "add 3rd document");
---
newsection:
this: that
---
- foo
- bar
- baz
---
newsection:
these: those
YAML
# add 4th.
$yaml->[3] = [ 'one', 'two', 'three' ];
check($yaml, <<YAML, "add 4th document");
---
newsection:
this: that
---
- foo
- bar
- baz
---
newsection:
these: those
---
- one
- two
- three
YAML
Subject: | YAML-Tiny-1.04.multidocs.patch |
diff -urN YAML-Tiny-1.04.orig/lib/YAML/Tiny.pm YAML-Tiny-1.04/lib/YAML/Tiny.pm
--- YAML-Tiny-1.04.orig/lib/YAML/Tiny.pm 2007-02-21 20:42:42.000000000 +0900
+++ YAML-Tiny-1.04/lib/YAML/Tiny.pm 2007-03-13 13:50:06.000000000 +0900
@@ -186,7 +186,10 @@
if ( length($1) < $indent->[-1] ) {
return 1;
} elsif ( length($1) > $indent->[-1] ) {
- die "Hash line over-indented";
+ die "Array line over-indented";
+ }
+ if ( $lines->[0] =~ /^---(?:\s*(.+)\s*)?$/ ) {
+ return 1;
}
if ( $lines->[0] =~ /^(\s*\-\s+)\S+\s*:(?:\s+|$)/ ) {
@@ -241,6 +244,9 @@
} elsif ( length($1) > $indent->[-1] ) {
die "Hash line over-indented";
}
+ if ( $lines->[0] =~ /^---(?:\s*(.+)\s*)?$/ ) {
+ return 1;
+ }
# Get the key
unless ( $lines->[0] =~ s/^\s*(\S+)\s*:(\s+|$)// ) {