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).
# output with user-preferred formatting
if ($opt{raw}) {
# 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};
}
else {
print $data->{name};