if ($opt{output}) {{
# derive format from file extension
- if ($opt{output} =~ /\.(yaml|txt)$/) {
+ if ($opt{output} =~ /\.(yaml|json|txt)$/) {
$opt{format} //= $1
}
else {
# output with user-preferred formatting
given ($opt{format}) {
+when ('json') {
+ require JSON;
+ say JSON->new->encode($data);
+}
when ('yaml') {
# full data in yaml (human-readable) formatting
require YAML;
my $img = Games::Wormy::Render->composite(
map { $data->{levels}->[$_] } @request
) or die "empty result for levels\n";
+ if ($opt{format} ~~ 'pbm') {
+ $img = $img->to_paletted({make_colors => 'mono'});
+ $opt{format} = 'pnm';
+ }
$img->write(
$opt{output} ? (file => $opt{output}) : (fh => \*STDOUT),
type => $opt{format} // 'pnm',
All parsed data in YAML syntax.
+=item json
+
+Parsed data in JSON syntax.
+
=item pnm, png, bmp, ...
Image drawing of rendered levels.