| 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
| |||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||
| 99 | 0 | say for list_tables($dir); | |||||||||||||||||||||||||||||
| 100 | 0 | return 1; | |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||
| 102 | 4 | ▶ | if (not $rule and not $text) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$rule or $text
MC/DC0%0/2
$rule or $text
$rule
$text
Truth table66%2/3
A or B
A= $ruleB= $text
| |||||||||||||||||||||||||||||||
| 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)
$limit || 10
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)
Truth table50%1/2
A
A= $limit
| |||||||||||||||||||||||||||||||
| 108 | 4 | say join("\n", markdown(describe_text($text, $data), $separator)); | |||||||||||||||||||||||||||||
| 109 | 4 | 1; | |||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||
| 112 | 4 | 1; | |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||
| 114 | __DATA__ | ||||||||||||||||||||||||||||||