| 1 | package Game::Terminal::Kit::Line; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Game::Terminal::Kit::Widget; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | has [qw/prompt text/] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 13 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||
| 15 | default => '' | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | has limit => ( | ||||||||||||||||||||||||||||||||||||||||||
| 19 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | has head => ( | ||||||||||||||||||||||||||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | isa => ArrayRef | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | has screen => ( | ||||||||||||||||||||||||||||||||||||||||||
| 30 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 14 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 14 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 14 | ▶ | $self->prompt('') unless defined $self->prompt; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 14 | ▶ | $self->text('') unless defined $self->text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 14 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 55 | ▶ | sub lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lines: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 55 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 55 | ▶ | return (@{ $self->head || [] }, $self->prompt . $self->text); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->head || []
MC/DC100%1/1
$self->head || []
$self->head
Truth table100%2/2
A
A= $self->head
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 69 | ▶ | sub step { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
step: called CC=12 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 69 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 69 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 64 | ▶ | return ('chosen', $self->text) if $key eq 'enter'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 57 | ▶ | return ('back') if $key eq 'escape'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 53 | my $text = $self->text; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 53 | ▶ | if ($key eq 'backspace') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | ▶ | return ('none') unless length $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | chop $text; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | $self->text($text); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | return ('changed'); | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 48 | ▶ | return ('none') if length $key != 1 || $key lt ' '; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $key != 1 or $key lt " "
MC/DC100%2/2
length $key != 1 or $key lt " "
length $key != 1
$key lt " "
Truth table100%3/3
A or B
A= length $key != 1B= $key lt " "
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 35 | ▶ | return ('none') if $self->limit > 0 && length $text >= $self->limit; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->limit > 0 and length $text >= $self->limit
MC/DC100%2/2
$self->limit > 0 and length $text >= $self->limit
$self->limit > 0
length $text >= $self->limit
Truth table100%3/3
A and B
A= $self->limit > 0B= length $text >= $self->limit
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 34 | $self->text($text . $key); | |||||||||||||||||||||||||||||||||||||||||
| 60 | 34 | return ('changed'); | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 8 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 8 | my ($self, $keys, $screen) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 8 | return Game::Terminal::Kit::Widget::run($self, $keys, $screen); | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||||||||||||||||||||||||