Kit/Line.pm

filter: Statementstmt 100% 43 / 43 Branchbran 100% 18 / 18 Conditioncond 100% 14 / 14 MC/DCmcdc 100% 8 / 8 Subroutinesub 100% 9 / 9 Podpod 75.0% 3 / 4 totaltotal 98.9% 95 / 96 CC 15 SCAR 19.6
CC
15
Cov
100%
step
12.0
BUILD
3.0
lines
2.0
CRAP 7.1
« Kit/Keys.pm ↑ Summary Kit/Screen.pm »
1 package Game::Terminal::Kit::Line;
2  
3 8 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Game::Terminal::Kit::Widget;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 8 our $VERSION = '0.06';
11  
12 has [qw/prompt text/] => (
13 is => 'rw',
14 isa => Str,
15 default => ''
16 8 );
17  
18 has limit => (
19 is => 'rw',
20 isa => Int,
21 default => 0
22 8 );
23  
24 has head => (
25 is => 'rw',
26 isa => ArrayRef
27 8 );
28  
29 has screen => (
30 is => 'rw'
31 8 );
32  
33 17 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.0
Pod undocumented
34 17 my ($self) = @_;
35 17 ▶ $self->prompt('') unless defined $self->prompt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->prompt 6 11 17
36 17 ▶ $self->text('') unless defined $self->text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->text 12 5 17
37 17 return $self;
38 }
39  
40 79 ▶sub lines {
Subroutine lines: called CC=2 SCAR=6.9
Pod documented
41 79 my ($self) = @_;
42 79 ▶ return (@{ $self->head || [] }, $self->prompt . $self->text);
Condition100%2/2
$self->head || []
l!l
4138
MC/DC100%1/1
$self->head || []
$self->head
Truth table100%2/2
A
A= $self->head
Aresult
11
00
43 }
44  
45 93 ▶sub step {
Subroutine step: called CC=12 SCAR=24.8
Pod documented
46 93 my ($self, $key) = @_;
47 93 ▶ return ('quit') if !defined $key || $key eq 'eof' || $key eq 'interrupt';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $key or $key eq "eof" or $key eq "interrupt" 5 88 93
Condition100%6/6
not defined $key or $key eq "eof" or $key eq "interrupt"
l!l&&r!l&&!r
4188
not defined $key or $key eq "eof"
l!l&&r!l&&!r
1389
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"
ABCresult
1XX1
01X1
0011
0000
48 88 ▶ return ('chosen', $self->text) if $key eq 'enter';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "enter" 9 79 88
49 79 ▶ return ('back') if $key eq 'escape';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "escape" 5 74 79
50 74 my $text = $self->text;
51 74 ▶ if ($key eq 'backspace') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "backspace") 17 57 74
52 17 ▶ return ('none') unless length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless length $text 2 15 17
53 15 chop $text;
54 15 $self->text($text);
55 15 return ('changed');
56 }
57 57 ▶ return ('none') if length $key != 1 || $key lt ' ';
Branch: 1 branch
BranchTrueFalseTotal
if length $key != 1 or $key lt " " 13 44 57
Condition100%3/3
length $key != 1 or $key lt " "
l!l&&r!l&&!r
12144
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 " "
ABresult
1X1
011
000
58 44 ▶ return ('none') if $self->limit > 0 && length $text >= $self->limit;
Branch: 1 branch
BranchTrueFalseTotal
if $self->limit > 0 and length $text >= $self->limit 1 43 44
Condition100%3/3
$self->limit > 0 and length $text >= $self->limit
!ll&&!rl&&r
4211
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
ABresult
0X0
100
111
59 43 $self->text($text . $key);
60 43 return ('changed');
61 }
62  
63 11 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod documented
64 11 my ($self, $keys, $screen) = @_;
65 11 return Game::Terminal::Kit::Widget::run($self, $keys, $screen);
66 }
67  
68 8 1;
69  
70 __END__
« Kit/Keys.pm ↑ Summary Kit/Screen.pm »