lib/Game/HexDescribe/Command/rule.pm

filter: Statementstmt 73.3% 33 / 45 Branchbran 50.0% 3 / 6 Conditioncond 62.5% 5 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 67.1% 49 / 73 SCAR 24.2
CC
9
Cov
69%
run
16.7
__ANON__
1.3
BEGIN
1.0
CRAP 11.3
« blib/lib/Game/HexDescribe/Command/rule.pm ↑ Summary blib/lib/Game/HexDescribe/Log.pm »
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::HexDescribe::Command::rule
19  
20 =head1 SYNOPSIS
21  
22 hex-describe rule [--table=B<table>] [--rule=B<rule>] [--limit=B<number>]
23  
24 hex-describe rule --help
25  
26 =head1 DESCRIPTION
27  
28 Prints the random results of rules.
29  
30 =head1 OPTIONS
31  
32 C<--help> prints the man page.
33  
34 C<--table> specifies the table to load.
35  
36 Without C<--table>, print all the tables there are.
37  
38 C<--rule> specifies the rule to use.
39  
40 C<--text> specifies the text to use (with rules in square brackets).
41  
42 Without C<--rule> or C<--text>, print all the rules there are.
43  
44 C<--limit> limits the output to a certain number of entries. The default is 10.
45  
46 C<--separator> changes the separator between entries. The default is two
47 newlines, three dashes, and two newlines ("\n\n---\n\n").
48  
49 =head1 EXAMPLES
50  
51 Find all orc related rules:
52  
53 C<hex-describe rule --table=schroeder | grep orc>
54  
55 Print an orc tribe:
56  
57 C<hex-describe rule --table=schroeder --rule="orcs" --limit=1>
58  
59 Print ten orc names:
60  
61 C<hex-describe rule --table=schroeder --rule="orc name" --separator=\n
62  
63 =cut
64  
65 package Game::HexDescribe::Command::rule;
66  
67 4 ▶use Modern::Perl '2018';
Subroutine BEGIN: called CC=1 SCAR=0.0
68 4 ▶use Mojo::Base 'Mojolicious::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
69 4 ▶use Pod::Simple::Text;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 4 ▶use Getopt::Long qw(GetOptionsFromArray);
Subroutine BEGIN: called CC=1 SCAR=0.0
71 4 ▶use Game::HexDescribe::Utils qw(markdown describe_text parse_table load_table list_tables);
Subroutine BEGIN: called CC=1 SCAR=0.0
72 4 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 4 binmode(STDOUT, ':utf8');
74  
75 4 has description => 'Print the output of a rule to STDOUT';
76  
77 0 ▶has usage => sub { my $self = shift; $self->extract_usage };
Subroutine __ANON__: not called CC=1 SCAR=2.6
78  
79 sub run {
80 4 ▶ my ($self, @args) = @_;
Subroutine run: called CC=9 SCAR=28.2
Pod documented
81 4 my ($help, $table, $rule, $text, $limit, $separator);
82 4 GetOptionsFromArray (
83 \@args,
84 "help" => \$help,
85 "table=s" => \$table,
86 "rule=s" => \$rule,
87 "text=s" => \$text,
88 "limit=i" => \$limit,
89 "separator=s" => \$separator);
90 4 ▶ if ($help) {
Branch: 1 branch
BranchTrueFalseTotal
if ($help) 0 4 4
91 0 seek(DATA, 0, 0); # read from this file
92 0 my $parser = Pod::Simple::Text->new();
93 0 $parser->output_fh(*STDOUT);
94 0 $parser->parse_lines(<DATA>);
95 0 return 1;
96 }
97 4 my $dir = $self->app->config('contrib');
98 4 ▶ if (not $table) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($table) 0 4 4
99 0 say for list_tables($dir);
100 0 return 1;
101 }
102 4 ▶ if (not $rule and not $text) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rule or $text) 0 4 4
Condition66%2/3
$rule or $text
l!l&&r!l&&!r
310
MC/DC0%0/2
$rule or $text
$rule $text
Truth table66%2/3
A or B
A= $ruleB= $text
ABresult
1X1
011
000
103 0 say for keys %{parse_table(load_table($table, $dir))};
104 0 return 1;
105 }
106 4 my $data = parse_table(load_table($table, $dir));
107 4 ▶ $text //= "[$rule]\n" x ($limit || 10);
Condition60%3/5
$text //= ("[$rule]\n") x ($limit || 10)
l!l&&r!l&&!r
130
$limit || 10
l!l
30
MC/DC0%0/2
$text //= ("[$rule]\n") x ($limit || 10)
$text ("[$rule]\n") x ($limit || 10)
MC/DC0%0/1
$limit || 10
$limit
Truth table66%2/3
A //= B
A= $textB= ("[$rule]\n") x ($limit || 10)
ABresult
1X1
011
000
Truth table50%1/2
A
A= $limit
Aresult
11
00
108 4 say join("\n", markdown(describe_text($text, $data), $separator));
109 4 1;
110 }
111  
112 4 1;
113  
114 __DATA__
« blib/lib/Game/HexDescribe/Command/rule.pm ↑ Summary blib/lib/Game/HexDescribe/Log.pm »