#!/usr/bin/perl
use strict;
use warnings;
use version;
our $VERSION = qv('0.1');
use YAML::Tiny;
use Carp qw( cluck );
use Data::Dumper;
my $o = YAML::Tiny->new();
my @stack = ();
for ( qw( a b c d e f )){
push @stack, $_;
$o->[0]->{$_ . '_whitespace'} = ' ' . join q{ ' }, @stack;
}
@stack = ();
for ( qw( a b c d e f )){
push @stack, $_;
$o->[0]->{$_.'_nowhitespace'} = '' . join q{'}, @stack;
}
print "Generated YAML<<'EOF';\n";
print $o->write_string;
print "\nEOF\n";
use YAML::XS;
eval {
YAML::XS::Load( $o->write_string );
1;
} or cluck "YXS: Failed to reload>> $@ $!";
eval {
my $p;
$p = YAML::Tiny->read_string( $o->write_string );
print Dumper( $p );
if( $p->errstr ){
cluck "YTiny: Error ". $p->errstr;
}
1;
} or cluck "YTiny: Failed to reload>> $@ $!";
__END__
Generated YAML<<'EOF';
---
a_nowhitespace: a
a_whitespace: ' a'
b_nowhitespace: a'b
b_whitespace: ' a '' b'
c_nowhitespace: a'b'c
c_whitespace: ' a '' b ' c'
d_nowhitespace: a'b'c'd
d_whitespace: ' a '' b ' c ' d'
e_nowhitespace: a'b'c'd'e
e_whitespace: ' a '' b ' c ' d ' e'
f_nowhitespace: a'b'c'd'e'f
f_whitespace: ' a '' b ' c ' d ' e ' f'
EOF
YXS: Failed to reload>> YAML::XS::Load Error: The problem:
did not find expected key
was found at document: 1, line: 7, column: 26
while parsing a block mapping at line: 2, column: 1
at tiny.pl line 30
$VAR1 = bless( [
{
'b_nowhitespace' => 'a\'b',
'a_nowhitespace' => 'a',
'e_nowhitespace' => 'a\'b\'c\'d\'e',
'a_whitespace' => ' a',
'd_whitespace' => ' a \' b \' c \' d',
'f_whitespace' => ' a \' b \' c \' d \' e \' f',
'e_whitespace' => ' a \' b \' c \' d \' e',
'b_whitespace' => ' a \' b',
'c_nowhitespace' => 'a\'b\'c',
'd_nowhitespace' => 'a\'b\'c\'d',
'c_whitespace' => ' a \' b \' c',
'f_nowhitespace' => 'a\'b\'c\'d\'e\'f'
}
], 'YAML::Tiny' );