summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
5b16db3)
Respect given format, but omit image type if unspecified.
die "Unrecognised file type\n";
}
die "Unrecognised file type\n";
}
+my $format = $opt{format}; # override distinct from image fallback
if ($opt{output}) {{
# derive format from file extension
if ($opt{output}) {{
# derive format from file extension
- if ($opt{output} =~ /\.(yaml|json|txt)$/) {
- $opt{format} //= $1
+ $format //= $1 if $opt{output} =~ /\.([^.]+)$/;
+
+ if ($format ~~ [qw{ yaml json txt }]) {
+ # redirect standard output to given file
+ open my $output, '>', $opt{output}
+ or die "Cannot output to '$opt{output}': $!";
+ select $output;
}
else {
# images are written directly to file
}
else {
# images are written directly to file
-
- # redirect standard output to given file
- open my $output, '>', $opt{output}
- or die "Cannot output to '$opt{output}': $!";
- select $output;
+else {
+ $format //= 'txt';
+}
# output with user-preferred formatting
# output with user-preferred formatting
when ('json') {
require JSON;
say JSON->new->encode($data);
when ('json') {
require JSON;
say JSON->new->encode($data);
my $img = Games::Wormy::Render->composite(
map { $data->{levels}->[$_] } @request
) or die "empty result for levels\n";
my $img = Games::Wormy::Render->composite(
map { $data->{levels}->[$_] } @request
) or die "empty result for levels\n";
- if ($opt{format} ~~ 'pbm') {
+ if ($format ~~ 'pbm') {
$img = $img->to_paletted({make_colors => 'mono'});
$opt{format} = 'pnm';
}
$img->write(
$opt{output} ? (file => $opt{output}) : (fh => \*STDOUT),
$img = $img->to_paletted({make_colors => 'mono'});
$opt{format} = 'pnm';
}
$img->write(
$opt{output} ? (file => $opt{output}) : (fh => \*STDOUT),
- type => $opt{format} // 'pnm',
) or die $img->errstr;
}
}
) or die $img->errstr;
}
}