blib/lib/Game/CharacterSheetGenerator/Command/stats.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 64 CC 2 SCAR 10.3
CC
2
Cov
0%
run
6.0
init
2.0
BEGIN
2.0
CRAP 2.8
1 # Copyright (C) 2022 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::CharacterSheetGenerator::Command::stats
19  
20 =head1 SYNOPSIS
21  
22 character-sheet-generator stats [language] [n]
23 character-sheet-generator stats help
24  
25 =head1 DESCRIPTION
26  
27 This counts the classes picked and the equipment bought.
28  
29 character-sheet-generator stats
30  
31 =head1 OPTIONS
32  
33 The supported languages are C<en> and C<de>. English is the default.
34  
35 The number of characters generated is C<n>. The default is 100.
36  
37 You can provide additional key-value pairs. These can be combined. Class names
38 are case sensitive.
39  
40 ```
41 character-sheet-generator stats en 50 class=elf
42 ```
43  
44 C<help> prints the man page.
45  
46 =cut
47  
48 package Game::CharacterSheetGenerator::Command::stats;
49  
50 use Modern::Perl '2018';
51 use Mojo::Base 'Mojolicious::Command';
52 use Game::CharacterSheetGenerator;
53 use Pod::Simple::Text;
54 use Role::Tiny;
55 use Encode::Locale;
56 use Encode;
57  
58 binmode(STDOUT, ':utf8');
59  
60 has description => 'Print stats for random characters to STDOUT';
61  
62 has usage => sub { my $self = shift; $self->extract_usage };
63  
64 sub init {
65 my %char = ();
66 my @provided;
67 for my $arg (@_) {
68 my ($key, $value) = split(/=/, $arg, 2);
69 push(@provided, $key);
70 $char{$key} = decode(locale => $value);
71 }
72 $char{provided} = \@provided;
73 return \%char;
74 }
75  
76 sub run {
77 my ($self, $lang, $n, @args) = @_;
78 $lang ||= 'en';
79 $n ||= 100;
80 if ($lang eq 'help') {
81 seek(DATA, 0, 0); # read from this file
82 my $parser = Pod::Simple::Text->new();
83 $parser->output_fh(*STDOUT);
84 $parser->parse_lines(<DATA>);
85 return 1;
86 }
87 my $char = init(@args);
88 say Game::CharacterSheetGenerator::stats($char, $lang, $n);
89 return 1;
90 }
91  
92 1;
93  
94 __DATA__