| 1 | package Game::Terminal::Kit::Picker; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Game::Terminal::Kit::Steer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Game::Terminal::Kit::Widget; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | has [qw/items head legend chosen/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 14 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 15 | isa => ArrayRef | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | has game_keys => ( | ||||||||||||||||||||||||||||||||||||||||||
| 19 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | isa => HashRef | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | has prefer => ( | ||||||||||||||||||||||||||||||||||||||||||
| 24 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 25 | isa => CodeRef | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | has [qw/at log screen/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 29 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | has window => ( | ||||||||||||||||||||||||||||||||||||||||||
| 33 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 34 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | default => 8 | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | has need => ( | ||||||||||||||||||||||||||||||||||||||||||
| 39 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 40 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | has numbered => ( | ||||||||||||||||||||||||||||||||||||||||||
| 45 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 46 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | default => 1 | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | has across => ( | ||||||||||||||||||||||||||||||||||||||||||
| 51 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 56 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 56 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 56 | ▶ | $self->items([]) unless $self->items; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 56 | ▶ | $self->head([]) unless $self->head; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 56 | ▶ | $self->legend([]) unless $self->legend; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 56 | ▶ | $self->game_keys({}) unless $self->game_keys; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 56 | ▶ | $self->chosen([]) unless $self->chosen; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 56 | ▶ | $self->at($self->resting) unless defined $self->at; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 56 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 65 | ▶ | sub resting { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resting: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 65 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 65 | return Game::Terminal::Kit::Steer::rest($self->items, $self->prefer); | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 11 | ▶ | sub reset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 11 | my ($self, $items) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 11 | ▶ | $self->items($items) if $items; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 11 | $self->chosen([]); | |||||||||||||||||||||||||||||||||||||||||
| 76 | 11 | $self->at($self->resting); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 11 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 1071 | ▶ | sub skipped { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
skipped: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 1071 | my ($self, $index) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 1071 | my $item = $self->items->[$index]; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 1071 | ▶ | return ref $item eq 'HASH' && $item->{skip} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $item eq "HASH" and $item->{"skip"}
MC/DC100%2/2
ref $item eq "HASH" and $item->{"skip"}
ref $item eq "HASH"
$item->{"skip"}
Truth table100%3/3
A and B
A= ref $item eq "HASH"B= $item->{"skip"}
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 1367 | ▶ | sub label_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
label_of: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 1367 | my ($self, $index) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 1367 | my $item = $self->items->[$index]; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 1367 | ▶ | return ref $item eq 'HASH' ? (defined $item->{label} ? $item->{label} : '') : "$item"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 91 | ▶ | sub value_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value_of: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 91 | my ($self, $index) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 91 | my $item = $self->items->[$index]; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 91 | ▶ | return ref $item eq 'HASH' && exists $item->{value} ? $item->{value} : $item; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $item eq "HASH" and exists $item->{"value"}
MC/DC50%1/2
ref $item eq "HASH" and exists $item->{"value"}
ref $item eq "HASH"
exists $item->{"value"}
Truth table66%2/3
A and B
A= ref $item eq "HASH"B= exists $item->{"value"}
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 62 | ▶ | sub current { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
current: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 62 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 62 | my $at = $self->at; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 62 | ▶ | return undef unless @{$self->items} && !$self->skipped($at); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@{$self->items;} and not $self->skipped($at)
MC/DC50%1/2
@{$self->items;} and not $self->skipped($at)
@{$self->items;}
not $self->skipped($at)
Truth table66%2/3
A and not(B)
A= @{$self->items;}B= not $self->skipped($at)
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 61 | return $self->value_of($at); | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 142 | ▶ | sub rows { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rows: called CC=19 SCAR=29.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 142 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 142 | my $items = $self->items; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 142 | my $at = $self->at; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 142 | my $window = $self->window; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 142 | my ($first, $last) = (0, $#{$items}); | |||||||||||||||||||||||||||||||||||||||||
| 111 | 142 | ▶ | if ($window > 0 && @{$items} > $window) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$window > 0 and @{$items;} > $window
MC/DC100%2/2
$window > 0 and @{$items;} > $window
$window > 0
@{$items;} > $window
Truth table100%3/3
A and B
A= $window > 0B= @{$items;} > $window
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 24 | $first = $at - int($window / 2); | |||||||||||||||||||||||||||||||||||||||||
| 113 | 24 | ▶ | $first = 0 if $first < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 24 | ▶ | $first = @{$items} - $window if $first > @{$items} - $window; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 24 | $last = $first + $window - 1; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 142 | ▶ | my $any_about = grep { ref $_ eq 'HASH' && defined $_->{about} && length $_->{about} } @{$items}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
ref $_ eq 'HASH' && defined $_->{'about'} && length $_->{'about'}
ref $_ eq "HASH" and defined $_->{"about"}
MC/DC100%3/3
ref $_ eq 'HASH' && defined $_->{'about'} && length $_->{'about'}
ref $_ eq "HASH"
defined $_->{"about"}
length $_->{'about'}
Truth table100%4/4
A and B && C
A= ref $_ eq "HASH"B= defined $_->{"about"}C= length $_->{'about'}
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 142 | my ($wide) = sort { $b <=> $a } map { length $self->label_of($_) } 0 .. $#{$items}; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 142 | my %taken = map { $_ => 1 } @{$self->chosen}; | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 142 | my @rows; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 142 | ▶ | push @rows, sprintf ' %d further up', $first if $first; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 142 | for my $index ($first .. $last) { | |||||||||||||||||||||||||||||||||||||||||
| 124 | 537 | my $item = $items->[$index]; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 537 | my $line = ''; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 537 | ▶ | $line .= sprintf '%2d. ', $index + 1 if $self->numbered; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 537 | ▶ | $line .= ($taken{$index} ? '[x] ' : '[ ] ') if $self->need > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 537 | ▶ | if ($any_about) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 71 | ▶ | my $about = ref $item eq 'HASH' && defined $item->{about} ? $item->{about} : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $item eq "HASH" and defined $item->{"about"}
MC/DC50%1/2
ref $item eq "HASH" and defined $item->{"about"}
ref $item eq "HASH"
defined $item->{"about"}
Truth table66%2/3
A and B
A= ref $item eq "HASH"B= defined $item->{"about"}
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 71 | $line .= sprintf '%-*s %s', $wide, $self->label_of($index), $about; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 466 | $line .= $self->label_of($index); | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 537 | $line =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 537 | ▶ | push @rows, $index == $at && !$self->skipped($index) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$index == $at and not $self->skipped($index)
MC/DC100%2/2
$index == $at and not $self->skipped($index)
$index == $at
not $self->skipped($index)
Truth table100%3/3
A and not(B)
A= $index == $atB= not $self->skipped($index)
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | ? ' ' . Game::Terminal::Kit::Widget::paint($self, "> $line", '1;7') | ||||||||||||||||||||||||||||||||||||||||||
| 137 | : $self->skipped($index) | ||||||||||||||||||||||||||||||||||||||||||
| 138 | ? ' ' . Game::Terminal::Kit::Widget::paint($self, $line, '2') | ||||||||||||||||||||||||||||||||||||||||||
| 139 | : " $line"; | ||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 142 | ▶ | push @rows, sprintf ' %d further down', $#{$items} - $last if $last < $#{$items}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 142 | return @rows; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 112 | ▶ | sub lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lines: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 112 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 112 | ▶ | my @said = $self->log ? $self->log->lines : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 112 | ▶ | return (@{$self->head}, (@said ? (@said, '') : ()), $self->rows, @{$self->legend}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 93 | ▶ | sub move { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
move: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 93 | my ($self, $delta) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 153 | my $next = Game::Terminal::Kit::Steer::ring( | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 93 | ▶ | scalar @{$self->items}, $self->at, $delta, sub { $self->skipped($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 93 | ); | |||||||||||||||||||||||||||||||||||||||||
| 156 | 93 | ▶ | return ('none') if $next == $self->at; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 91 | $self->at($next); | |||||||||||||||||||||||||||||||||||||||||
| 158 | 91 | return ('moved'); | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 20 | ▶ | sub jump { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
jump: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 20 | my ($self, $index) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 20 | ▶ | return ('none') if $index < 0 || $index > $#{$self->items} || $self->skipped($index); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$index < 0 or $index > $#{$self->items;} or $self->skipped($index)
$index < 0 or $index > $#{$self->items;}
MC/DC33%1/3
$index < 0 or $index > $#{$self->items;} or $self->skipped($index)
$index < 0
$index > $#{$self->items;}
$self->skipped($index)
Truth table50%2/4
A or B or C
A= $index < 0B= $index > $#{$self->items;}C= $self->skipped($index)
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 19 | ▶ | return ('none') if $index == $self->at; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 15 | $self->at($index); | |||||||||||||||||||||||||||||||||||||||||
| 166 | 15 | return ('moved'); | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 34 | ▶ | sub take { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
take: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 34 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 34 | my $at = $self->at; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 34 | ▶ | return ('none') unless @{$self->items} && !$self->skipped($at); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$self->items;} and not $self->skipped($at)
MC/DC100%2/2
@{$self->items;} and not $self->skipped($at)
@{$self->items;}
not $self->skipped($at)
Truth table100%3/3
A and not(B)
A= @{$self->items;}B= not $self->skipped($at)
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 32 | ▶ | return ('chosen', $self->value_of($at)) unless $self->need > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 7 | my %taken = map { $_ => 1 } @{$self->chosen}; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 7 | ▶ | if ($taken{$at}) { delete $taken{$at} } else { $taken{$at} = 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 7 | my @chosen = sort { $a <=> $b } keys %taken; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 7 | $self->chosen(\@chosen); | |||||||||||||||||||||||||||||||||||||||||
| 178 | 7 | ▶ | return ('changed') unless @chosen == $self->need; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 3 | return ('chosen', [ map { $self->value_of($_) } @chosen ]); | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 203 | ▶ | sub step { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
step: called CC=28 SCAR=33.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 203 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 203 | ▶ | return ('quit') if !defined $key || $key eq 'eof' || $key eq 'interrupt'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "eof"
MC/DC100%3/3
not defined $key or $key eq "eof" or $key eq "interrupt"
not defined $key
$key eq "eof"
$key eq "interrupt"
Truth table100%4/4
not(A) or B or C
A= not defined $keyB= $key eq "eof"C= $key eq "interrupt"
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 197 | ▶ | return ('key', $self->game_keys->{$key}) if exists $self->game_keys->{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 192 | ▶ | my ($back, $on) = $self->across ? ('down', 'up') : ('up', 'down'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 192 | ▶ | return $self->move(-1) if $key eq 'left' || $key eq $back || $key eq 'back_tab'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$key eq "left" or $key eq $back or $key eq "back_tab"
$key eq "left" or $key eq $back
MC/DC100%3/3
$key eq "left" or $key eq $back or $key eq "back_tab"
$key eq "left"
$key eq $back
$key eq "back_tab"
Truth table100%4/4
A or B or C
A= $key eq "left"B= $key eq $backC= $key eq "back_tab"
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 146 | ▶ | return $self->move(+1) if $key eq 'right' || $key eq $on || $key eq 'tab'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$key eq "right" or $key eq $on or $key eq "tab"
$key eq "right" or $key eq $on
MC/DC100%3/3
$key eq "right" or $key eq $on or $key eq "tab"
$key eq "right"
$key eq $on
$key eq "tab"
Truth table100%4/4
A or B or C
A= $key eq "right"B= $key eq $onC= $key eq "tab"
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 99 | my @open = grep { !$self->skipped($_) } 0 .. $#{$self->items}; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 99 | ▶ | return @open ? $self->jump($open[0]) : ('none') if $key eq 'home' || $key eq 'page_up'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$key eq "home" or $key eq "page_up"
MC/DC100%2/2
$key eq "home" or $key eq "page_up"
$key eq "home"
$key eq "page_up"
Truth table100%3/3
A or B
A= $key eq "home"B= $key eq "page_up"
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 92 | ▶ | return @open ? $self->jump($open[-1]) : ('none') if $key eq 'end' || $key eq 'page_down'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$key eq "end" or $key eq "page_down"
MC/DC100%2/2
$key eq "end" or $key eq "page_down"
$key eq "end"
$key eq "page_down"
Truth table100%3/3
A or B
A= $key eq "end"B= $key eq "page_down"
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 84 | ▶ | return $self->jump($key - 1) if $self->numbered && $key =~ m/^[1-9]$/ && $key <= @{$self->items}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->numbered and $key =~ /^[1-9]$/u and $key <= @{$self->items;}
$self->numbered and $key =~ /^[1-9]$/u
MC/DC100%3/3
$self->numbered and $key =~ /^[1-9]$/u and $key <= @{$self->items;}
$self->numbered
$key =~ /^[1-9]$/u
$key <= @{$self->items;}
Truth table100%4/4
A and B and C
A= $self->numberedB= $key =~ /^[1-9]$/uC= $key <= @{$self->items;}
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 78 | ▶ | return $self->take 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 " "
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 44 | ▶ | return ('back') if $key eq 'escape' || $key eq 'backspace'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "escape" or $key eq "backspace"
MC/DC100%2/2
$key eq "escape" or $key eq "backspace"
$key eq "escape"
$key eq "backspace"
Truth table100%3/3
A or B
A= $key eq "escape"B= $key eq "backspace"
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 34 | ▶ | return ('quit') if $key eq 'q'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | $self->log->note('That key does nothing here.' | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 26 | ▶ | . (exists $self->game_keys->{'?'} ? ' Press ? for the ones that do.' : '')) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | if $self->log; | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 26 | return ('none'); | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 5 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 5 | my ($self, $keys, $screen) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 5 | return Game::Terminal::Kit::Widget::run($self, $keys, $screen); | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | __END__ | ||||||||||||||||||||||||||||||||||||||||||