From: Mischa Poslawsky Date: Sun, 1 Mar 2009 15:11:09 +0000 (+0100) Subject: parse-wormedit: raw output in yaml X-Git-Url: http://git.shiar.nl/wormy.git/commitdiff_plain/e58e4983aac0a969a6476a7ae0ee6aab25771148 parse-wormedit: raw output in yaml Format --raw data using YAML, which should be even more human-readable than JSON, especially using inline hashes (requires some custom replacements because no formatting module seems to support this yet). --- diff --git a/parse-wormedit b/parse-wormedit index bc0d926..8c2f2c9 100755 --- a/parse-wormedit +++ b/parse-wormedit @@ -413,9 +413,26 @@ else { # output with user-preferred formatting if ($opt{raw}) { - require JSON::XS; - my $output = JSON::XS->new->ascii->canonical->pretty->allow_nonref; - print $output->encode($data), "\n"; + # full data in yaml (human-readable) formatting + require YAML; + local $YAML::CompressSeries; + $YAML::CompressSeries = 0; + my $yml = "# Wormy levelset\n" . YAML::Dump($data); + + # inline format of short hashes + $yml =~ s{ + ^(\ *) - \n # array indicator + ((?:\1\ \ [a-z0-9]{1,5}:\ *\d+\n)+) # simple hash declaration + (?!\1\ ) # no further children + }[ + my ($indent, $value) = ($1, $2); + chop $value; + $value =~ s/^ +//gm; + $value =~ s/\n/, /g; + "$indent- {$value}\n"; + ]egmx; + + print $yml; } else { print $data->{name};