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/Canvas.pm ↑ Summary Kit/Screen.pm »
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
BranchTrueFalseTotal
unless defined $self->prompt 6 8 14
36 14 ▶ $self->text('') unless defined $self->text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->text 12 2 14
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 || []
l!l
1738
MC/DC100%1/1
$self->head || []
$self->head
Truth table100%2/2
A
A= $self->head
Aresult
11
00
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
BranchTrueFalseTotal
if not defined $key or $key eq "eof" or $key eq "interrupt" 5 64 69
Condition100%6/6
not defined $key or $key eq "eof" or $key eq "interrupt"
l!l&&r!l&&!r
4164
not defined $key or $key eq "eof"
l!l&&r!l&&!r
1365
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 64 ▶ return ('chosen', $self->text) if $key eq 'enter';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "enter" 7 57 64
49 57 ▶ return ('back') if $key eq 'escape';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "escape" 4 53 57
50 53 my $text = $self->text;
51 53 ▶ if ($key eq 'backspace') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "backspace") 5 48 53
52 5 ▶ return ('none') unless length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless length $text 2 3 5
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
BranchTrueFalseTotal
if length $key != 1 or $key lt " " 13 35 48
Condition100%3/3
length $key != 1 or $key lt " "
l!l&&r!l&&!r
12135
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 35 ▶ return ('none') if $self->limit > 0 && length $text >= $self->limit;
Branch: 1 branch
BranchTrueFalseTotal
if $self->limit > 0 and length $text >= $self->limit 1 34 35
Condition100%3/3
$self->limit > 0 and length $text >= $self->limit
!ll&&!rl&&r
3311
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 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__
« Kit/Canvas.pm ↑ Summary Kit/Screen.pm »