| 1 | package Game::Terminal::Kit::Form; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Game::Terminal::Kit::Line; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Game::Terminal::Kit::Options; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Game::Terminal::Kit::Widget; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | my $OWN = "the game\x27s own"; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | my %INK = ( | |||||||||||||||||||||||||||||||||||||||||
| 17 | key => '1', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | set => '38;5;114', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | own => '2', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | action => '1;32', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | legend => '2', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | has [qw/title action/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | default => '' | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | has [qw/fields legend/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | isa => ArrayRef | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | has values => ( | ||||||||||||||||||||||||||||||||||||||||||
| 36 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 37 | isa => HashRef | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | has extra => ( | ||||||||||||||||||||||||||||||||||||||||||
| 41 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 42 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | default => 1 | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | has [qw/at log screen/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 47 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 20 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 20 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 20 | ▶ | $self->fields([]) unless $self->fields; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 20 | ▶ | $self->values({}) unless $self->values; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 20 | ▶ | $self->title('') unless defined $self->title; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 20 | ▶ | $self->action('Play') unless defined $self->action && length $self->action; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->action and length $self->action
MC/DC50%1/2
defined $self->action and length $self->action
defined $self->action
length $self->action
Truth table66%2/3
A and B
A= defined $self->actionB= length $self->action
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 20 | ▶ | $self->legend([ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 'left and right change a value, enter edits a text, backspace clears,', | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 'enter on ' . $self->action . ' starts, escape goes back', | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ]) unless $self->legend; | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 20 | ▶ | $self->at(scalar @{ $self->rows }) unless defined $self->at; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 20 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 197 | ▶ | sub rows { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rows: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 197 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 197 | ▶ | @{$self->fields}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | ($self->extra | ||||||||||||||||||||||||||||||||||||||||||
| 69 | ? { name => 'extra', type => 'extra', help => 'anything else, as on the command line' } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 71 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 305 | ▶ | sub show_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_value: called CC=10 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 305 | my ($self, $field, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 305 | my $type = $field->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 305 | ▶ | return $value ? 'on' : 'off' if $type eq 'flag'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 276 | ▶ | return !defined $value ? $OWN : $value ? 'on' : 'off' if $type eq 'bool'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 247 | ▶ | return defined $value && length $value ? $value : '(none)' if $type eq 'extra'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
defined $value and length $value
MC/DC0%0/2
defined $value and length $value
defined $value
length $value
Truth table33%1/3
A and B
A= defined $valueB= length $value
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 175 | ▶ | return defined $value ? $value : $OWN; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 74 | ▶ | sub lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lines: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 74 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 74 | my $rows = $self->rows; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 74 | my $values = $self->values; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 74 | my $at = $self->at; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 74 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 74 | ▶ | push @lines, $self->title, '' if length $self->title; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 74 | for my $index (0 .. $#{$rows}) { | |||||||||||||||||||||||||||||||||||||||||
| 91 | 305 | my $field = $rows->[$index]; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 305 | my $value = $values->{ $field->{name} }; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 305 | my $shown = $self->show_value($field, $value); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 305 | ▶ | if ($index == $at) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 24 | my $line = sprintf '%-11s %-18s %s', $field->{name}, $shown, $field->{help}; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 24 | $line =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 24 | push @lines, ' ' . Game::Terminal::Kit::Widget::paint($self, "> $line", '1;7'); | |||||||||||||||||||||||||||||||||||||||||
| 98 | 24 | next; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 281 | ▶ | my $set = $field->{type} eq 'flag' ? $value : defined $value && length $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $value and length $value
MC/DC50%1/2
defined $value and length $value
defined $value
length $value
Truth table66%2/3
A and B
A= defined $valueB= length $value
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | my $line = ' ' . Game::Terminal::Kit::Widget::paint($self, sprintf('%-11s', $field->{name}), $INK{key}) . ' ' | ||||||||||||||||||||||||||||||||||||||||||
| 102 | . Game::Terminal::Kit::Widget::paint($self, sprintf('%-18s', $shown), $set ? $INK{set} : $INK{own}) . ' ' | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 281 | ▶ | . $field->{help}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 281 | $line =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 281 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 74 | push @lines, '', $at == @{$rows} | |||||||||||||||||||||||||||||||||||||||||
| 108 | ? ' ' . Game::Terminal::Kit::Widget::paint($self, '> ' . $self->action, '1;7') | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 74 | ▶ | : ' ' . Game::Terminal::Kit::Widget::paint($self, $self->action, $INK{action}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 74 | ▶ | my @said = $self->log ? $self->log->lines : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 74 | ▶ | push @lines, '', @said if @said; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 142 | push @lines, '', map { Game::Terminal::Kit::Widget::paint($self, $_, $INK{legend}) } @{$self->legend} | |||||||||||||||||||||||||||||||||||||||||
| 113 | 74 | ▶ | if @{$self->legend}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 74 | return @lines; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 26 | ▶ | sub _say { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_say: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 26 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 26 | ▶ | $self->log->note($text) if $self->log; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 26 | return; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 35 | ▶ | sub _keep { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_keep: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 35 | my ($self, $name, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 35 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 29 | $self->values->{$name} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | delete $self->values->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 35 | return; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 12 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 12 | my ($self, $name, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 12 | my ($field) = grep { $_->{name} eq $name } @{ $self->rows }; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 12 | ▶ | return 0 unless $field; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 11 | ▶ | if ($field->{type} eq 'extra') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | ▶ | $text = '' unless defined $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | $text =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | ▶ | $self->_keep($name, length $text ? $text : undef); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 9 | my ($value, $error) = Game::Terminal::Kit::Options::check_value($field, $text); | |||||||||||||||||||||||||||||||||||||||||
| 144 | 9 | ▶ | if (defined $error) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 3 | $self->_say($error); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 6 | $self->_keep($name, $value); | |||||||||||||||||||||||||||||||||||||||||
| 149 | 6 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 13 | ▶ | sub argv { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
argv: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 13 | return Game::Terminal::Kit::Options::argv_for($self->fields, $self->values); | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 110 | ▶ | sub step { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
step: called CC=28 SCAR=33.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 110 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 110 | ▶ | return ('quit') if !defined $key || $key eq 'eof' || $key eq 'interrupt'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "eof"
MC/DC33%1/3
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key
$key eq "eof"
$key eq "interrupt"
Truth table50%2/4
not(A) or B or C
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 107 | ▶ | return ('back') if $key eq 'escape' || $key eq 'q'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "escape" or $key eq "q"
MC/DC100%2/2
$key eq "escape" or $key eq "q"
$key eq "escape"
$key eq "q"
Truth table100%3/3
A or B
A= $key eq "escape"B= $key eq "q"
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 100 | ▶ | return ('chosen', $self->values) if $key eq 'p'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 97 | my $rows = $self->rows; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 97 | my $count = @{$rows} + 1; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 97 | my $at = $self->at; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 97 | ▶ | if ($key eq 'up' || $key eq 'k' || $key eq 'back_tab') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$key eq "up" or $key eq "k" or $key eq "back_tab"
$key eq "up" or $key eq "k"
MC/DC100%3/3
$key eq "up" or $key eq "k" or $key eq "back_tab"
$key eq "up"
$key eq "k"
$key eq "back_tab"
Truth table100%4/4
A or B or C
A= $key eq "up"B= $key eq "k"C= $key eq "back_tab"
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 13 | $self->at(($at - 1) % $count); | |||||||||||||||||||||||||||||||||||||||||
| 168 | 13 | return ('moved'); | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 84 | ▶ | if ($key eq 'down' || $key eq 'j' || $key eq 'tab') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$key eq "down" or $key eq "j" or $key eq "tab"
$key eq "down" or $key eq "j"
MC/DC100%3/3
$key eq "down" or $key eq "j" or $key eq "tab"
$key eq "down"
$key eq "j"
$key eq "tab"
Truth table100%4/4
A or B or C
A= $key eq "down"B= $key eq "j"C= $key eq "tab"
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 18 | $self->at(($at + 1) % $count); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 18 | return ('moved'); | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 66 | ▶ | if ($at == @{$rows}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 31 | ▶ | return ('chosen', $self->values) if $key eq 'enter' || $key eq ' '; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "enter" or $key eq " "
MC/DC100%2/2
$key eq "enter" or $key eq " "
$key eq "enter"
$key eq " "
Truth table100%3/3
A or B
A= $key eq "enter"B= $key eq " "
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 21 | $self->_say('That key does nothing here'); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 21 | return ('none'); | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 35 | my $field = $rows->[$at]; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 35 | my $name = $field->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 35 | my $type = $field->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 35 | ▶ | my $typed = $type eq 'str' || $type eq 'extra' || $type eq 'int'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$type eq 'str' || $type eq 'extra' || $type eq 'int'
$type eq "str" or $type eq "extra"
MC/DC66%2/3
$type eq 'str' || $type eq 'extra' || $type eq 'int'
$type eq "str"
$type eq "extra"
$type eq 'int'
Truth table75%3/4
A or B || C
A= $type eq "str"B= $type eq "extra"C= $type eq 'int'
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 35 | ▶ | if ($key eq 'backspace' || $key eq 'delete') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "backspace" or $key eq "delete"
MC/DC100%2/2
$key eq "backspace" or $key eq "delete"
$key eq "backspace"
$key eq "delete"
Truth table100%3/3
A or B
A= $key eq "backspace"B= $key eq "delete"
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | $self->_keep($name, undef); | |||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | return ('changed'); | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 33 | ▶ | if ($key eq 'left' || $key eq 'right') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "left" or $key eq "right"
MC/DC100%2/2
$key eq "left" or $key eq "right"
$key eq "left"
$key eq "right"
Truth table100%3/3
A or B
A= $key eq "left"B= $key eq "right"
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 20 | ▶ | if ($type eq 'str' || $type eq 'extra') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq "str" or $type eq "extra"
MC/DC50%1/2
$type eq "str" or $type eq "extra"
$type eq "str"
$type eq "extra"
Truth table66%2/3
A or B
A= $type eq "str"B= $type eq "extra"
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | $self->_say("$name is typed: press enter"); | |||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | return ('none'); | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | $self->_keep($name, Game::Terminal::Kit::Options::step_value( | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 19 | ▶ | $field, $self->values->{$name}, $key eq 'right' ? 1 : -1, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 19 | return ('changed'); | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 13 | ▶ | if ($key eq 'enter' || $key eq ' ') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "enter" or $key eq " "
MC/DC100%2/2
$key eq "enter" or $key eq " "
$key eq "enter"
$key eq " "
Truth table100%3/3
A or B
A= $key eq "enter"B= $key eq " "
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 12 | ▶ | return ('edit', $field) if $typed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 6 | $self->_keep($name, Game::Terminal::Kit::Options::step_value($field, $self->values->{$name}, 1)); | |||||||||||||||||||||||||||||||||||||||||
| 201 | 6 | return ('changed'); | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | $self->_say('That key does nothing here'); | |||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | return ('none'); | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 6 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 6 | my ($self, $keys, $screen) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 6 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 210 | 9 | my ($event, $value) = my @result = Game::Terminal::Kit::Widget::run($self, $keys, $screen); | |||||||||||||||||||||||||||||||||||||||||
| 211 | 9 | ▶ | return @result unless $event eq 'edit'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 4 | my $line = Game::Terminal::Kit::Line->new( | |||||||||||||||||||||||||||||||||||||||||
| 213 | prompt => "$value->{name}: ", | ||||||||||||||||||||||||||||||||||||||||||
| 214 | head => [ $self->lines, '' ], | ||||||||||||||||||||||||||||||||||||||||||
| 215 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 4 | my ($answer, $text) = $line->run($keys, $screen); | |||||||||||||||||||||||||||||||||||||||||
| 217 | 4 | ▶ | return ('quit') if $answer eq 'quit'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 3 | ▶ | $self->set($value->{name}, $text) if $answer eq 'chosen'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | __END__ | ||||||||||||||||||||||||||||||||||||||||||