blib/lib/Game/FaceGenerator/Command/random.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 45 CC 3 SCAR 18.4
CC
3
Cov
0%
run
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 6.3
1 # Copyright (C) 2009-2021 Alex Schroeder <alex@gnu.org>
2 #
3 # This program is free software: you can redistribute it and/or modify it under
4 # the terms of the GNU Affero General Public License as published by the Free
5 # Software Foundation, either version 3 of the License, or (at your option) any
6 # later version.
7 #
8 # This program is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
11 # details.
12 #
13 # You should have received a copy of the GNU Affero General Public License along
14 # with this program. If not, see <http://www.gnu.org/licenses/>.
15  
16 =head1 NAME
17  
18 Game::FaceGenerator::Command::random - random subcommand for the command-line
19  
20 =head1 SYNOPSIS
21  
22 face-generator random [artist] [type]
23 face-generator random help
24  
25 =head1 DESCRIPTION
26  
27 This prints a random image to STDOUT.
28  
29 face-generator random alex man > man.png
30  
31 =head1 OPTIONS
32  
33 C<help> prints the man page.
34  
35 =head1 EXAMPLES
36  
37 face-generator random alex man | display
38  
39 =cut
40  
41 package Game::FaceGenerator::Command::random;
42  
43 use Modern::Perl;
44 use Mojo::Base 'Mojolicious::Command';
45 use Pod::Simple::Text;
46 use Game::FaceGenerator::Core qw(random_components render_components);
47  
48 has description => 'Print a random face to STDOUT';
49  
50 has usage => sub { my $self = shift; $self->extract_usage };
51  
52 sub run {
53 my ($self, $artist, $type, @args) = @_;
54 $artist ||= 'alex';
55 $type ||= 'woman';
56 if ($artist eq 'help') {
57 seek(DATA, 0, 0); # read from this file
58 my $parser = Pod::Simple::Text->new();
59 $parser->output_fh(*STDOUT);
60 $parser->parse_lines(<DATA>);
61 return 1;
62 }
63 my @components = random_components($type, $artist);
64 if (-t STDOUT) {
65 say "@components";
66 say "To generate an image, redirect stdout to a file."
67 } else {
68 print render_components($artist, @components);
69 }
70 }
71  
72 1;
73  
74 __DATA__