lib/App/AnteREPL.pm

filter: Statementstmt 82.3% 1236 / 1501 Branchbran 72.8% 753 / 1034 Conditioncond 70.0% 444 / 634 MC/DCmcdc 51.4% 191 / 371 Subroutinesub 81.4% 105 / 129 Podpod 2.9% 1 / 34 totaltotal 73.7% 2730 / 3703 CC 759 SCAR 37.0
CC
759
Cov
77%
main
193.5
shell
156.0
key
148.1
CRAP 40.6
↑ Summary lib/App/AnteREPL/Shorthand.pm »
1 # Check the minimum without adding a version declaration to string evals.
2 25 ▶BEGIN { require 5.016; }
Subroutine BEGIN: called CC=1 SCAR=0.0
3 25 ▶use feature ':5.16';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 package App::AnteREPL;
8  
9 25 ▶use Data::Dumper ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 25 ▶use Encode qw(decode encode FB_CROAK);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 25 ▶use File::Basename qw(dirname);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 25 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 25 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 25 ▶use Text::Balanced qw(extract_quotelike);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 25 ▶use Text::ParseWords qw(shellwords);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 25 ▶use App::AnteREPL::Shorthand ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 25 our $VERSION = '0.02';
19 25 our $PROGRAM_VERSION = '0.1';
20 25 our $FAREWELL = 'Thank you, i hope something good happens to you today!';
21 25 my $next_workspace = 0;
22 25 my $max_line = 999_999_999;
23  
24 # Exact, uppercase shortcuts only. V groups environment-variable operations.
25 25 my %short_commands = (
26 A => 'AUTO', A0 => 'AUTO OFF', AA => 'AUTO ECHO ON', AAA => 'AUTO ECHO OFF',
27 C => 'CLS', C1 => 'CD', D => 'DUMP', D1 => 'DEL',
28 E => 'EVAL', EE => 'EDIT', E2 => 'EXPORT', F => 'FUNCTIONS', H => 'HELP',
29 I => 'IMPORT', L => 'LIST', L1 => 'LOAD', L2 => 'LIST SLOW', L3 => 'LIST PAUSE',
30 N => 'NEW', P => 'PEEK', Q => 'QUIT',
31 R => 'RUN', R1 => 'RENUM', R2 => 'RESET', R3 => 'RECOVER',
32 S => 'SAVE', S1 => 'STATUS', U => 'UNDO',
33 V => 'ENV', V0 => 'ENV RESET', V1 => 'ENV SET', V2 => 'ENV UNSET',
34 V3 => 'ENV EDIT', V4 => 'ENV SAVE', V5 => 'ENV LOAD', V6 => 'ENV RELOAD',
35 );
36 25 my %guarded_shortcuts = map { $_ => 1 } qw(C D1 EE E2 I L1 N Q R1 R2 R3 S U V V0 V1 V2 V3 V4 V5 V6);
37  
38 894 ▶sub _expand_short_command {
Subroutine _expand_short_command: called CC=6 SCAR=17.9
39 894 my ($source) = @_;
40 894 $source =~ s/\A(\s*)L,(?=\s|\z)/$1LIST/;
41 894 ▶ return $source unless $source =~ /\A(\s*)([A-Z]+[0-9]*)(!?)(?=\s|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $source =~ /\A(\s*)([A-Z]+[0-9]*)(!?)(?=\s|\z)/u 417 477 894
42 477 my ($leading, $short, $force, $end) = ($1, $2, $3, $+[0]);
43 477 ▶ return $source unless exists $short_commands{$short};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $short_commands{$short} 338 139 477
44 139 my ($command, $option) = split / /, $short_commands{$short}, 2;
45 139 my $tail = substr($source, $end);
46 # LIST's mode follows its optional range; other fixed options precede args.
47 139 ▶ return "$leading$command$force$tail $option" if $short eq 'L2' || $short eq 'L3';
Branch: 1 branch
BranchTrueFalseTotal
if $short eq "L2" or $short eq "L3" 2 137 139
Condition100%3/3
$short eq "L2" or $short eq "L3"
l!l&&r!l&&!r
11137
MC/DC100%2/2
$short eq "L2" or $short eq "L3"
$short eq "L2" $short eq "L3"
Truth table100%3/3
A or B
A= $short eq "L2"B= $short eq "L3"
ABresult
1X1
011
000
48 137 ▶ return "$leading$command$force" . (defined $option ? " $option" : '') . $tail;
Branch: 1 branch
BranchTrueFalseTotal
defined $option ? : 26 111 137
49 }
50  
51 184 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
52 184 my ($class) = @_;
53 184 return bless {
54 lines => {},
55 saved => '',
56 filename => undef,
57 undo => [],
58 workspace => 'App::AnteREPL::Workspace::S' . ++$next_workspace,
59 format => 'native',
60 initial_env => { %ENV },
61 }, $class;
62 }
63  
64 8 ▶sub _confirmation_answer {
Subroutine _confirmation_answer: called CC=9 SCAR=38.8
65 8 my ($self, $description, $forced) = @_;
66 die "Confirmation required: $description. Try $forced to proceed without a prompt.\n"
67 8 ▶ unless $self->{interactive};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"interactive"} 7 1 8
68 1 ▶ local $SIG{INT} = sub { die "Interrupted.\n" };
Subroutine __ANON__: called CC=1 SCAR=0.0
69 1 print "$description. Continue? [y/N] ";
70 0 my ($answer, $error);
71 0 { local $@;
72 0 ▶ eval { $answer = $self->{screen} ? $self->{screen}->read_data(1) : scalar <STDIN>; 1 }
Branch: 2 branches
BranchTrueFalseTotal
eval { do { $answer = $self->{"screen"} ? $self->{"screen"}->read_data(1) : scalar readline STDIN; 1 } } or $error = $@ 0 0 0
$self->{'screen'} ? : 0 0 0
73 or $error = $@;
74 }
75 0 ▶ STDIN->clearerr if !$self->{screen} && (!defined $answer || defined $error);
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"screen"} and !defined($answer) || defined $error 0 0 0
Condition0%0/6
not $self->{"screen"} and !defined($answer) || defined $error
!ll&&!rl&&r
000
not defined $answer or defined $error
l!l&&r!l&&!r
000
MC/DC0%0/3
not $self->{"screen"} and !defined($answer) || defined $error
not $self->{"screen"} not defined $answer defined $error
Truth table0%0/4
not(A) and not(B) or C
A= not $self->{"screen"}B= not defined $answerC= defined $error
ABCresult
0XX0
1000
11X1
1011
76 0 ▶ die $error if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
77 0 ▶ print "\n" unless defined $answer;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $answer 0 0 0
78 0 return $answer;
79 }
80  
81 166 ▶sub _confirm_destructive {
Subroutine _confirm_destructive: called CC=6 SCAR=17.9
82 166 my ($self, $description) = @_;
83 166 ▶ my $guard = $self->{shortcut_guard} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $guard = $self->{"shortcut_guard"} or return 89 77 166
84 89 ▶ return if $guard->{force} || $guard->{approved};
Branch: 1 branch
BranchTrueFalseTotal
if $guard->{"force"} or $guard->{"approved"} 45 44 89
Condition100%3/3
$guard->{"force"} or $guard->{"approved"}
l!l&&r!l&&!r
43244
MC/DC100%2/2
$guard->{"force"} or $guard->{"approved"}
$guard->{"force"} $guard->{"approved"}
Truth table100%3/3
A or B
A= $guard->{"force"}B= $guard->{"approved"}
ABresult
1X1
011
000
85 44 my $answer = $self->_confirmation_answer($description, $guard->{label} . '!');
86 37 ▶ die "Cancelled.\n" unless defined $answer && $answer =~ /\A\s*y(?:es)?\s*\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $answer and $answer =~ /\A\s*y(?:es)?\s*\z/iu 33 4 37
Condition100%3/3
defined $answer and $answer =~ /\A\s*y(?:es)?\s*\z/iu
!ll&&!rl&&r
2854
MC/DC100%2/2
defined $answer and $answer =~ /\A\s*y(?:es)?\s*\z/iu
defined $answer $answer =~ /\A\s*y(?:es)?\s*\z/iu
Truth table100%3/3
A and B
A= defined $answerB= $answer =~ /\A\s*y(?:es)?\s*\z/iu
ABresult
0X0
100
111
87 4 $guard->{approved} = 1;
88 }
89  
90 15 ▶sub _confirm_environment {
Subroutine _confirm_environment: called CC=3 SCAR=11.0
91 15 my ($self, $values) = @_;
92 15 ▶ return unless grep { !exists $values->{$_} || $ENV{$_} ne $values->{$_} } keys %ENV;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {not exists $values->{$_} or $ENV{$_} ne $values->{$_};} keys %ENV 1 14 15
Condition100%3/3
!exists $values->{$_} || $ENV{$_} ne $values->{$_}
l!l&&r!l&&!r
61413
MC/DC100%2/2
!exists $values->{$_} || $ENV{$_} ne $values->{$_}
!exists $values->{$_} $ENV{$_} ne $values->{$_}
Truth table100%3/3
not(A) || B
A= !exists $values->{$_}B= $ENV{$_} ne $values->{$_}
ABresult
1X1
011
000
93 14 $self->_confirm_destructive('Replace or remove current environment values');
94 }
95  
96 44 ▶sub _evaluate_definition {
Subroutine _evaluate_definition: called CC=10 SCAR=23.0
97 44 my ($self, $definition) = @_;
98 44 my ($type, $name) = @{$definition}{qw(type name)};
99 44 my $package = $self->{workspace} . '::';
100 44 my $existing;
101 {
102 25 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
103 44 ▶ if (exists ${$package}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists do { $package }->{$name}) 13 31 44
104 3 ▶ $existing = $type eq 's' ? defined &{$package . $name}
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'a' ? : 4 6 10
105 4 ▶ : $type eq 'a' ? defined *{$package . $name}{ARRAY}
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'h' ? : 2 4 6
106 2 ▶ : $type eq 'h' ? defined *{$package . $name}{HASH}
Condition100%3/3
defined tied ${$package . $name;} or defined ${$package . $name;}
l!l&&r!l&&!r
121
MC/DC100%2/2
defined tied ${$package . $name;} or defined ${$package . $name;}
defined tied ${$package . $name;} defined ${$package . $name;}
Truth table100%3/3
A or B
A= defined tied ${$package . $name;}B= defined ${$package . $name;}
ABresult
1X1
011
000
107 13 ▶ : defined tied(${$package . $name}) || defined ${$package . $name};
Branch: 1 branch
BranchTrueFalseTotal
$type eq 's' ? : 3 10 13
108 }
109 }
110 44 local $self->{shortcut_guard} = {label=>$definition->{label}, force=>$definition->{force}};
111 44 ▶ my $target = $type eq 's' ? "function $name" : ($type eq 'a' ? '@' : $type eq 'h' ? '%' : '$') . $name;
Branch: 3 branches
BranchTrueFalseTotal
$type eq 's' ? : 10 34 44
$type eq 'a' ? : 18 16 34
$type eq 'h' ? : 6 10 16
112 44 ▶ $self->_confirm_destructive("Replace existing $target") if $existing;
Branch: 1 branch
BranchTrueFalseTotal
if $existing 11 33 44
113 37 return $self->evaluate($definition->{code}, 0);
114 }
115  
116 589 ▶sub numbers { return sort { $a <=> $b } keys %{ $_[0]->{lines} }; }
Subroutine numbers: called CC=1 SCAR=0.0
Pod undocumented
117  
118 152 ▶sub source {
Subroutine source: called CC=1 SCAR=0.0
Pod undocumented
119 152 my ($self) = @_;
120 152 return join '', map { $self->{lines}{$_} . "\n" } $self->numbers;
121 }
122  
123 343 ▶sub listing {
Subroutine listing: called CC=2 SCAR=6.9
Pod undocumented
124 343 my ($self, $range) = @_;
125 343 my ($first, $last) = _range($range);
126 571 return join '', map { $_ . ' ' . $self->{lines}{$_} . "\n" }
127 342 ▶ grep { $_ >= $first && $_ <= $last } $self->numbers;
Condition100%3/3
$_ >= $first && $_ <= $last
!ll&&!rl&&r
216571
MC/DC100%2/2
$_ >= $first && $_ <= $last
$_ >= $first $_ <= $last
Truth table100%3/3
A && B
A= $_ >= $firstB= $_ <= $last
ABresult
0X0
100
111
128 }
129  
130 38 ▶sub display_listing {
Subroutine display_listing: called CC=3 SCAR=11.0
Pod undocumented
131 38 my ($self, $range) = @_;
132 38 my ($first, $last) = _range($range);
133 31 ▶ my @numbers = grep { $_ >= $first && $_ <= $last } $self->numbers;
Condition100%3/3
$_ >= $first && $_ <= $last
!ll&&!rl&&r
51755
MC/DC100%2/2
$_ >= $first && $_ <= $last
$_ >= $first $_ <= $last
Truth table100%3/3
A && B
A= $_ >= $firstB= $_ <= $last
ABresult
0X0
100
111
134 31 ▶ return ('', 0) unless @numbers;
Branch: 1 branch
BranchTrueFalseTotal
unless @numbers 1 30 31
135 30 my $width = length $numbers[-1];
136 30 return (join('', map { sprintf("%-*d %s\n", $width, $_, $self->{lines}{$_}) } @numbers), $width);
137 }
138  
139 38 ▶sub list_program {
Subroutine list_program: called CC=4 SCAR=13.9
Pod undocumented
140 38 my ($self, $argument) = @_;
141 38 ▶ $argument = '' unless defined $argument;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $argument 0 38 38
142 38 my $mode = 'normal';
143 38 ▶ $mode = lc($1) if $argument =~ s/(?:\A|\s)(SLOW|PAUSE)\s*\z//;
Branch: 1 branch
BranchTrueFalseTotal
if $argument =~ s/(?:\A|\s)(SLOW|PAUSE)\s*\z//u 5 33 38
144 38 $argument =~ s/\A\s+|\s+\z//g;
145 38 $argument =~ s/\s*-\s*/-/g;
146 38 my ($text, $width) = $self->display_listing($argument);
147 31 ▶ if ($self->{screen}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'screen'}) { } 8 23 31
148 8 $self->{screen}->list_rows([split /\n/, $text], $width, $mode);
149 }
150 23 else { print $text; }
151 }
152  
153 57 ▶sub dirty { return $_[0]->listing ne $_[0]->{saved}; }
Subroutine dirty: called CC=1 SCAR=0.0
Pod undocumented
154  
155 7 ▶sub clear_screen {
Subroutine clear_screen: called CC=9 SCAR=28.2
Pod undocumented
156 7 my ($self) = @_;
157 $self->_confirm_destructive('Clear the visible screen and its resize recovery copy')
158 7 ▶ if $self->{screen} || (-t STDOUT && ($ENV{TERM} || '') ne 'dumb');
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"screen"} or -t STDOUT and ($ENV{"TERM"} || "") ne "dumb" 5 2 7
Condition37%3/8
$self->{"screen"} or -t STDOUT and ($ENV{"TERM"} || "") ne "dumb"
l!l&&r!l&&!r
502
-t STDOUT and ($ENV{"TERM"} || "") ne "dumb"
!ll&&!rl&&r
200
$ENV{'TERM'} || ''
l!l
00
MC/DC33%1/3
$self->{"screen"} or -t STDOUT and ($ENV{"TERM"} || "") ne "dumb"
$self->{"screen"} -t STDOUT $ENV{'TERM'}
Truth table50%2/4
A or B and C
A= $self->{"screen"}B= -t STDOUTC= $ENV{'TERM'}
ABCresult
1XX1
0111
00X0
0100
159 6 ▶ if ($self->{screen}) { $self->{screen}->clear_display; }
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'screen'}) { } 4 2 6
elsif (-t STDOUT and ($ENV{'TERM'} || '') ne 'dumb') { } 0 4 4
160 0 ▶ elsif (-t STDOUT && ($ENV{TERM} || '') ne 'dumb') { print "\e[2J\e[H"; }
Condition20%1/5
-t STDOUT and ($ENV{"TERM"} || "") ne "dumb"
!ll&&!rl&&r
200
$ENV{'TERM'} || ''
l!l
00
MC/DC0%0/2
-t STDOUT and ($ENV{"TERM"} || "") ne "dumb"
-t STDOUT $ENV{'TERM'}
Truth table33%1/3
A and B
A= -t STDOUTB= $ENV{'TERM'}
ABresult
0X0
100
111
161 }
162  
163 5 ▶sub recover_screen {
Subroutine recover_screen: called CC=2 SCAR=6.9
Pod undocumented
164 5 my ($self) = @_;
165 5 ▶ die "RECOVER requires screen mode.\n" unless $self->{screen};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"screen"} 1 4 5
166 4 $self->{screen}->recover_display($self);
167 }
168  
169 12 ▶sub change_directory {
Subroutine change_directory: called CC=9 SCAR=22.5
Pod undocumented
170 12 my ($self, $tail) = @_;
171 12 my ($path) = _args($tail, 0, 1, 'CD [directory] or CHDIR [directory]');
172 10 ▶ if (!defined $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path) 3 7 10
173 3 $path = $ENV{HOME};
174 3 ▶ $path = $ENV{USERPROFILE} if (!defined $path || !length $path) && $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $path && length $path and $^O eq "MSWin32" 0 3 3
Condition66%4/6
not defined $path && length $path and $^O eq "MSWin32"
!ll&&!rl&&r
210
defined $path && length $path
!ll&&!rl&&r
102
MC/DC0%0/3
not defined $path && length $path and $^O eq "MSWin32"
defined $path length $path $^O eq "MSWin32"
Truth table40%2/5
not(A && B) and C
A= defined $pathB= length $pathC= $^O eq "MSWin32"
ABCresult
11X0
0X00
1000
0X11
1011
175 3 ▶ die "No home directory is set; use CD directory.\n" unless defined $path && length $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path and length $path 1 2 3
Condition66%2/3
defined $path and length $path
!ll&&!rl&&r
102
MC/DC50%1/2
defined $path and length $path
defined $path length $path
Truth table66%2/3
A and B
A= defined $pathB= length $path
ABresult
0X0
100
111
176 }
177 9 ▶ die "Directory paths cannot contain NUL bytes.\n" if $path =~ /\0/;
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ /\0/u 0 9 9
178 9 ▶ chdir $path or die "Cannot change directory to '$path': $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $path or die "Cannot change directory to '${path}': $!\n" 7 2 9
179 }
180  
181 19 ▶sub _command_case_error {
Subroutine _command_case_error: called CC=9 SCAR=22.0
182 19 my ($self, $line, $error) = @_;
183 19 ▶ return $error if $line =~ /\n/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\n/u 0 19 19
184 19 ▶ return $error unless $line =~ /\A\s*([A-Za-z][A-Za-z0-9_]*)(!?)(?=\s|;|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\A\s*([A-Za-z][A-Za-z0-9_]*)(!?)(?=\s|;|\z)/u 0 19 19
185 19 my ($word, $force) = ($1, $2);
186 # These spellings belong to Perl even when their use raises an error.
187 19 ▶ return $error if App::AnteREPL::Shorthand::perl_keyword($word);
Branch: 1 branch
BranchTrueFalseTotal
if App::AnteREPL::Shorthand::perl_keyword($word) 5 14 19
188 14 my $upper = uc $word;
189 14 ▶ return $error if $word eq $upper;
Branch: 1 branch
BranchTrueFalseTotal
if $word eq $upper 1 13 14
190 13 ▶ return $error unless exists $short_commands{$upper}
Branch: 1 branch
BranchTrueFalseTotal
unless exists $short_commands{$upper} or $upper =~ /\A(?:AUTO|ENV|LIST[0-9]*|RUN|EDIT|DEL|DELETE|RENUM|REORDER|UNDO|SAVE|LOAD|IMPORT|EXPORT|NEW|CLEAR|CLS|RECOVER|RESET|FUNCTIONS|STATUS|HELP|QUIT|EXIT|EVAL|DUMP|PEEK|CD|CHDIR)\z/u 1 12 13
Condition100%3/3
exists $short_commands{$upper} or $upper =~ /\A(?:AUTO|ENV|LIST[0-9]*|RUN|EDIT|DEL|DELETE|RENUM|REORDER|UNDO|SAVE|LOAD|IMPORT|EXPORT|NEW|CLEAR|CLS|RECOVER|RESET|FUNCTIONS|STATUS|HELP|QUIT|EXIT|EVAL|DUMP|PEEK|CD|CHDIR)\z/u
l!l&&r!l&&!r
1111
MC/DC100%2/2
exists $short_commands{$upper} or $upper =~ /\A(?:AUTO|ENV|LIST[0-9]*|RUN|EDIT|DEL|DELETE|RENUM|REORDER|UNDO|SAVE|LOAD|IMPORT|EXPORT|NEW|CLEAR|CLS|RECOVER|RESET|FUNCTIONS|STATUS|HELP|QUIT|EXIT|EVAL|DUMP|PEEK|CD|CHDIR)\z/u
exists $short_commands{$upper} $upper =~ /\A(?:AUTO|ENV|LIST[0-9]*|RUN|EDIT|DEL|DELETE|RENUM|REORDER|UNDO|SAVE|LOAD|IMPORT|EXPORT|NEW|CLEAR|CLS|RECOVER|RESET|FUNCTIONS|STATUS|HELP|QUIT|EXIT|EVAL|DUMP|PEEK|CD|CHDIR)\z/u
Truth table100%3/3
A or B
A= exists $short_commands{$upper}B= $upper =~ /\A(?:AUTO|ENV|LIST[0-9]*|RUN|EDIT|DEL|DELETE|RENUM|REORDER|UNDO|SAVE|LOAD|IMPORT|EXPORT|NEW|CLEAR|CLS|RECOVER|RESET|FUNCTIONS|STATUS|HELP|QUIT|EXIT|EVAL|DUMP|PEEK|CD|CHDIR)\z/u
ABresult
1X1
011
000
191 || $upper =~ /\A(?:AUTO|ENV|LIST[0-9]*|RUN|EDIT|DEL|DELETE|RENUM|REORDER|UNDO|SAVE|LOAD|IMPORT|EXPORT|NEW|CLEAR|CLS|RECOVER|RESET|FUNCTIONS|STATUS|HELP|QUIT|EXIT|EVAL|DUMP|PEEK|CD|CHDIR)\z/;
192 {
193 25 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
194 12 ▶ return $error if defined &{ $self->{workspace} . '::' . $word };
Branch: 1 branch
BranchTrueFalseTotal
if defined &{$self->{"workspace"} . '::' . $word;} 1 11 12
195 }
196 11 ▶ return $error unless $error =~ /\ABareword "\Q$word\E" not allowed while "strict subs" in use at PERL_ANTE_REPL_prompt line [0-9]+\b/;
Branch: 1 branch
BranchTrueFalseTotal
unless $error =~ /\ABareword "\Q$word\E" not allowed while "strict subs" in use at PERL_ANTE_REPL_prompt line [0-9]+\b/u 0 11 11
197 11 return "REPL commands must be uppercase; try, \"$upper$force\".\n";
198 }
199  
200 2 ▶sub _input_error {
Subroutine _input_error: called CC=2 SCAR=8.1
201 2 my ($error) = @_;
202 2 ▶ return $error unless $error eq "Interrupted.\n";
Branch: 1 branch
BranchTrueFalseTotal
unless $error eq "Interrupted.\n" 2 0 2
203 0 return $error . "To leave: QUIT, or QUIT! to discard unsaved source.\n"
204 . "Ctrl-D exits when AUTO is off and the source is saved.\n";
205 }
206  
207 286 ▶sub _number {
Subroutine _number: called CC=5 SCAR=16.1
208 286 my ($number) = @_;
209 286 ▶ die "Line numbers must be integers from 1 to $max_line.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number and $number =~ /\A[0-9]+\z/u and $number >= 1 and $number <= $max_line 12 274 286
Condition88%8/9
defined $number and $number =~ /\A[0-9]+\z/u and $number >= 1 and $number <= $max_line
!ll&&!rl&&r
111274
defined $number and $number =~ /\A[0-9]+\z/u and $number >= 1
!ll&&!rl&&r
74275
defined $number and $number =~ /\A[0-9]+\z/u
!ll&&!rl&&r
07279
MC/DC75%3/4
defined $number and $number =~ /\A[0-9]+\z/u and $number >= 1 and $number <= $max_line
defined $number $number =~ /\A[0-9]+\z/u $number >= 1 $number <= $max_line
Truth table80%4/5
A and B and C and D
A= defined $numberB= $number =~ /\A[0-9]+\z/uC= $number >= 1D= $number <= $max_line
ABCDresult
0XXX0
10XX0
110X0
11100
11111
210 unless defined $number && $number =~ /\A[0-9]+\z/
211 && $number >= 1 && $number <= $max_line;
212 274 return 0 + $number;
213 }
214  
215 392 ▶sub _range {
Subroutine _range: called CC=10 SCAR=23.1
216 392 my ($range) = @_;
217 392 ▶ return (1, $max_line) unless defined $range && length $range;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $range and length $range 337 55 392
Condition100%3/3
defined $range and length $range
!ll&&!rl&&r
3261155
MC/DC100%2/2
defined $range and length $range
defined $range length $range
Truth table100%3/3
A and B
A= defined $rangeB= length $range
ABresult
0X0
100
111
218 55 ▶ return (_number($range), _number($range)) if $range =~ /\A[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $range =~ /\A[0-9]+\z/u 26 29 55
219 29 ▶ die "Use a line number or a range such as 10-50, 10-, or -50.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $range =~ /\A([0-9]*)-([0-9]*)\z/u and length $1 || length $2 7 22 29
Condition66%4/6
$range =~ /\A([0-9]*)-([0-9]*)\z/u and length $1 || length $2
!ll&&!rl&&r
7022
length $1 or length $2
l!l&&r!l&&!r
2020
MC/DC33%1/3
$range =~ /\A([0-9]*)-([0-9]*)\z/u and length $1 || length $2
$range =~ /\A([0-9]*)-([0-9]*)\z/u length $1 length $2
Truth table75%3/4
A and B or C
A= $range =~ /\A([0-9]*)-([0-9]*)\z/uB= length $1C= length $2
ABCresult
0XX0
1000
11X1
1011
220 unless $range =~ /\A([0-9]*)-([0-9]*)\z/ && (length($1) || length($2));
221 22 my ($lo, $hi) = ($1, $2);
222 22 ▶ $lo = length($lo) ? _number($lo) : 1;
Branch: 1 branch
BranchTrueFalseTotal
length $lo ? : 20 2 22
223 22 ▶ $hi = length($hi) ? _number($hi) : $max_line;
Branch: 1 branch
BranchTrueFalseTotal
length $hi ? : 19 3 22
224 22 ▶ die "Range starts after it ends.\n" if $lo > $hi;
Branch: 1 branch
BranchTrueFalseTotal
if $lo > $hi 2 20 22
225 20 return ($lo, $hi);
226 }
227  
228 190 ▶sub _replace {
Subroutine _replace: called CC=5 SCAR=16.1
229 190 my ($self, $lines) = @_;
230 387 my $new = join '', map { $_ . ' ' . $lines->{$_} . "\n" }
231 190 sort { $a <=> $b } keys %$lines;
232 190 ▶ return 0 if $new eq $self->listing;
Branch: 1 branch
BranchTrueFalseTotal
if $new eq $self->listing 7 183 190
233 $self->_confirm_destructive('Replace or remove stored source lines')
234 183 ▶ if grep { !exists $lines->{$_} || $lines->{$_} ne $self->{lines}{$_} } keys %{ $self->{lines} };
Branch: 1 branch
BranchTrueFalseTotal
if grep {not exists $lines->{$_} or $lines->{$_} ne $self->{"lines"}{$_};} keys %{$$self{"lines"};} 43 140 183
Condition100%3/3
!exists $lines->{$_} || $lines->{$_} ne $self->{'lines'}{$_}
l!l&&r!l&&!r
5218172
MC/DC100%2/2
!exists $lines->{$_} || $lines->{$_} ne $self->{'lines'}{$_}
!exists $lines->{$_} $lines->{$_} ne $self->{'lines'}{$_}
Truth table100%3/3
not(A) || B
A= !exists $lines->{$_}B= $lines->{$_} ne $self->{'lines'}{$_}
ABresult
1X1
011
000
235 175 push @{ $self->{undo} }, { %{ $self->{lines} } };
236 0 ▶ shift @{ $self->{undo} } if @{ $self->{undo} } > 50;
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"undo"};} > 50 0 175 175
237 175 $self->{lines} = { %$lines };
238 175 return 1;
239 }
240  
241 122 ▶sub set_line {
Subroutine set_line: called CC=5 SCAR=16.3
Pod undocumented
242 122 my ($self, $number, $code, $literal) = @_;
243 122 $number = _number($number);
244 117 my %lines = %{ $self->{lines} };
245 117 ▶ if (!defined $code || ($code eq '' && !$literal)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $code or $code eq '' and not $literal) { } 2 115 117
Condition66%4/6
not defined $code or $code eq "" and not $literal
l!l&&r!l&&!r
20115
$code eq "" and not $literal
!ll&&!rl&&r
11230
MC/DC33%1/3
not defined $code or $code eq "" and not $literal
not defined $code $code eq "" not $literal
Truth table75%3/4
not(A) or B and not(C)
A= not defined $codeB= $code eq ""C= not $literal
ABCresult
1XX1
0111
00X0
0100
246 2 delete $lines{$number};
247 }
248 else {
249 115 ▶ die "A numbered entry must occupy one physical line.\n" if $code =~ /[\r\n\0]/;
Branch: 1 branch
BranchTrueFalseTotal
if $code =~ /[\r\n\0]/u 0 115 115
250 115 $lines{$number} = $code;
251 }
252 117 return $self->_replace(\%lines);
253 }
254  
255 104 ▶sub _typed_source {
Subroutine _typed_source: called CC=20 SCAR=30.0
256 104 my ($code) = @_;
257 104 ▶ return $code unless defined $code && $code =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code and $code =~ /\S/u 2 102 104
Condition100%3/3
defined $code and $code =~ /\S/u
!ll&&!rl&&r
11102
MC/DC100%2/2
defined $code and $code =~ /\S/u
defined $code $code =~ /\S/u
Truth table100%3/3
A and B
A= defined $codeB= $code =~ /\S/u
ABresult
0X0
100
111
258 # A small input convenience, not a Perl parser. Number-colon entries bypass
259 # this entirely; EDIT, IMPORT, LOAD, and the internal setter remain literal.
260 102 ▶ return $code if $code =~ /\A\s*(?:=\w|__(?:DATA|END)__\b)/;
Branch: 1 branch
BranchTrueFalseTotal
if $code =~ /\A\s*(?:=\w|__(?:DATA|END)__\b)/u 0 102 102
261 102 local $@;
262 102 my ($position, $visible, $body, $comment) = (0, '', $code, '');
263 102 ▶ while ($position < length $code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($position < length $code) 536 95 631
264 536 my $rest = substr($code, $position);
265 # Consume sigils first, so $#array and special variables such as $#
266 # and $" are not mistaken for comments or quoted strings.
267 536 ▶ if ($rest =~ /\A([\$\@\%](?:\#?[\p{L}_][\p{L}\p{N}_]*(?:::[\p{L}_][\p{L}\p{N}_]*)*|[0-9]+|[^\w\s{]))/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\A([\$\@\%](?:\#?[\p{L}_][\p{L}\p{N}_]*(?:::[\p{L}_][\p{L}\p{N}_]*)*|[0-9]+|[^\w\s{]))/u) 32 504 536
268 32 $position += length $1;
269 32 $visible .= 'V';
270 32 next;
271 }
272 504 ▶ if ($rest =~ /\A#/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\A#/u) 6 498 504
273 6 $body = substr($code, 0, $position);
274 6 $comment = $rest;
275 6 last;
276 }
277 # Protect hashes and punctuation inside ordinary strings and Perl's
278 # quote-like operators. Never compile or execute input to classify it.
279 498 ▶ my $quoted = $rest =~ /\A['"`]/
Condition100%3/3
$rest =~ /\A['"`]/u || $rest =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)\b\s*(?!=>)[^\w\s]/u
l!l&&r!l&&!r
436449
MC/DC100%2/2
$rest =~ /\A['"`]/u || $rest =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)\b\s*(?!=>)[^\w\s]/u
$rest =~ /\A['"`]/u $rest =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)\b\s*(?!=>)[^\w\s]/u
Truth table100%3/3
A || B
A= $rest =~ /\A['"`]/uB= $rest =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)\b\s*(?!=>)[^\w\s]/u
ABresult
1X1
011
000
280 || $rest =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)\b\s*(?!=>)[^\w\s]/;
281 498 ▶ if ($quoted || $rest =~ /\A\//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quoted or $rest =~ m[\A/]u) 51 447 498
Condition100%3/3
$quoted or $rest =~ m[\A/]u
l!l&&r!l&&!r
492447
MC/DC100%2/2
$quoted or $rest =~ m[\A/]u
$quoted $rest =~ m[\A/]u
Truth table100%3/3
A or B
A= $quotedB= $rest =~ m[\A/]u
ABresult
1X1
011
000
282 51 my ($literal) = extract_quotelike("$rest", '');
283 51 ▶ if (defined $literal && length $literal) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $literal and length $literal) 49 2 51
Condition66%2/3
defined $literal and length $literal
!ll&&!rl&&r
2049
MC/DC50%1/2
defined $literal and length $literal
defined $literal length $literal
Truth table66%2/3
A and B
A= defined $literalB= length $literal
ABresult
0X0
100
111
284 49 $position += length $literal;
285 49 $visible .= 'Q';
286 49 next;
287 }
288 2 ▶ return $code if $quoted; # An unfinished quote needs literal input.
Branch: 1 branch
BranchTrueFalseTotal
if $quoted 1 1 2
289 }
290 448 ▶ if ($rest =~ /\A([\p{L}_][\p{L}\p{N}_]*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\A([\p{L}_][\p{L}\p{N}_]*)/u) 113 335 448
291 113 $visible .= $1;
292 113 $position += length $1;
293 113 next;
294 }
295 335 $visible .= substr($code, $position++, 1);
296 }
297 101 ▶ return $code if $visible =~ /\A\s*\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $visible =~ /\A\s*\z/u 2 99 101
298 99 ▶ return $code if $visible =~ /[;{(\[,]\s*\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $visible =~ /[;{(\[,]\s*\z/u 20 79 99
299 79 ▶ return $code if $visible !~ /(?:\+\+|--)\s*\z/
Branch: 1 branch
BranchTrueFalseTotal
if not $visible =~ /(?:\+\+|--)\s*\z/u and $visible =~ m[(?:[=+*/%.?:&|!~-]|->|\b(?:and|or|xor|not))\s*\z]u 2 77 79
Condition100%3/3
not $visible =~ /(?:\+\+|--)\s*\z/u and $visible =~ m[(?:[=+*/%.?:&|!~-]|->|\b(?:and|or|xor|not))\s*\z]u
!ll&&!rl&&r
2752
MC/DC100%2/2
not $visible =~ /(?:\+\+|--)\s*\z/u and $visible =~ m[(?:[=+*/%.?:&|!~-]|->|\b(?:and|or|xor|not))\s*\z]u
not $visible =~ /(?:\+\+|--)\s*\z/u $visible =~ m[(?:[=+*/%.?:&|!~-]|->|\b(?:and|or|xor|not))\s*\z]u
Truth table100%3/3
not(A) and B
A= not $visible =~ /(?:\+\+|--)\s*\z/uB= $visible =~ m[(?:[=+*/%.?:&|!~-]|->|\b(?:and|or|xor|not))\s*\z]u
ABresult
0X0
100
111
300 && $visible =~ /(?:[=+*\/%.?:&|!~-]|->|\b(?:and|or|xor|not))\s*\z/;
301 77 ▶ return $code if $visible =~ /}\s*\z/ && $visible =~ /\A\s*(?:}|{|(?:(?:[\w]+:)\s*)?(?:if|unless|while|until|for|foreach|given|when|default|else|elsif|continue|sub|package|BEGIN|UNITCHECK|CHECK|INIT|END)\b)/;
Branch: 1 branch
BranchTrueFalseTotal
if $visible =~ /}\s*\z/u and $visible =~ /\A\s*(?:}|{|(?:(?:[\w]+:)\s*)?(?:if|unless|while|until|for|foreach|given|when|default|else|elsif|continue|sub|package|BEGIN|UNITCHECK|CHECK|INIT|END)\b)/u 9 68 77
Condition100%3/3
$visible =~ /}\s*\z/u and $visible =~ /\A\s*(?:}|{|(?:(?:[\w]+:)\s*)?(?:if|unless|while|until|for|foreach|given|when|default|else|elsif|continue|sub|package|BEGIN|UNITCHECK|CHECK|INIT|END)\b)/u
!ll&&!rl&&r
6359
MC/DC100%2/2
$visible =~ /}\s*\z/u and $visible =~ /\A\s*(?:}|{|(?:(?:[\w]+:)\s*)?(?:if|unless|while|until|for|foreach|given|when|default|else|elsif|continue|sub|package|BEGIN|UNITCHECK|CHECK|INIT|END)\b)/u
$visible =~ /}\s*\z/u $visible =~ /\A\s*(?:}|{|(?:(?:[\w]+:)\s*)?(?:if|unless|while|until|for|foreach|given|when|default|else|elsif|continue|sub|package|BEGIN|UNITCHECK|CHECK|INIT|END)\b)/u
Truth table100%3/3
A and B
A= $visible =~ /}\s*\z/uB= $visible =~ /\A\s*(?:}|{|(?:(?:[\w]+:)\s*)?(?:if|unless|while|until|for|foreach|given|when|default|else|elsif|continue|sub|package|BEGIN|UNITCHECK|CHECK|INIT|END)\b)/u
ABresult
0X0
100
111
302 68 $body =~ s/(\s*)\z/;$1/;
303 68 return $body . $comment;
304 }
305  
306 11 ▶sub delete_range {
Subroutine delete_range: called CC=4 SCAR=14.1
Pod undocumented
307 11 my ($self, $range) = @_;
308 11 ▶ die "DEL needs a line number or range.\n" unless defined $range && length $range;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $range and length $range 0 11 11
Condition33%1/3
defined $range and length $range
!ll&&!rl&&r
0011
MC/DC0%0/2
defined $range and length $range
defined $range length $range
Truth table33%1/3
A and B
A= defined $rangeB= length $range
ABresult
0X0
100
111
309 11 my ($first, $last) = _range($range);
310 10 my %lines = %{ $self->{lines} };
311 10 ▶ delete @lines{ grep { $_ >= $first && $_ <= $last } keys %lines };
Condition100%3/3
$_ >= $first && $_ <= $last
!ll&&!rl&&r
1110
MC/DC100%2/2
$_ >= $first && $_ <= $last
$_ >= $first $_ <= $last
Truth table100%3/3
A && B
A= $_ >= $firstB= $_ <= $last
ABresult
0X0
100
111
312 10 return $self->_replace(\%lines);
313 }
314  
315 5 ▶sub renumber {
Subroutine renumber: called CC=6 SCAR=18.2
Pod undocumented
316 5 my ($self, $start, $step) = @_;
317 5 ▶ $start = _number(defined $start ? $start : 10);
Branch: 1 branch
BranchTrueFalseTotal
defined $start ? : 5 0 5
318 5 ▶ $step = _number(defined $step ? $step : 10);
Branch: 1 branch
BranchTrueFalseTotal
defined $step ? : 5 0 5
319 5 my @old = $self->numbers;
320 5 ▶ die "Renumbering would exceed $max_line.\n" if @old && $start + $#old * $step > $max_line;
Branch: 1 branch
BranchTrueFalseTotal
if @old and $start + $#old * $step > $max_line 1 4 5
Condition66%2/3
@old and $start + $#old * $step > $max_line
!ll&&!rl&&r
041
MC/DC50%1/2
@old and $start + $#old * $step > $max_line
@old $start + $#old * $step > $max_line
Truth table66%2/3
A and B
A= @oldB= $start + $#old * $step > $max_line
ABresult
0X0
100
111
321 4 my %lines;
322 4 $lines{ $start + $_ * $step } = $self->{lines}{ $old[$_] } for 0 .. $#old;
323 4 return $self->_replace(\%lines);
324 }
325  
326 17 ▶sub undo {
Subroutine undo: called CC=2 SCAR=7.0
Pod undocumented
327 17 my ($self) = @_;
328 17 ▶ die "Nothing to undo.\n" unless @{ $self->{undo} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"undo"};} 0 17 17
329 17 $self->_confirm_destructive('Replace the current program with its previous source version');
330 16 $self->{lines} = pop @{ $self->{undo} };
331 16 return 1;
332 }
333  
334 60 ▶sub _guard {
Subroutine _guard: called CC=4 SCAR=13.9
335 60 my ($self, $command, $force) = @_;
336 60 ▶ return if $self->{shortcut_guard}; # Shortcuts confirm immediately before mutation.
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shortcut_guard"} 22 38 60
337 38 ▶ die "Unsaved program. Use SAVE, or $command! to discard it.\n" if $self->dirty && !$force;
Branch: 1 branch
BranchTrueFalseTotal
if $self->dirty and not $force 4 34 38
Condition100%3/3
$self->dirty and not $force
!ll&&!rl&&r
2774
MC/DC100%2/2
$self->dirty and not $force
$self->dirty not $force
Truth table100%3/3
A and not(B)
A= $self->dirtyB= not $force
ABresult
0X0
100
111
338 }
339  
340 10 ▶sub clear {
Subroutine clear: called CC=3 SCAR=11.3
Pod undocumented
341 10 my ($self, $force) = @_;
342 10 $self->_guard('NEW', $force);
343 $self->_confirm_destructive('Clear the stored program and its save filename')
344 9 ▶ if keys %{ $self->{lines} } || defined $self->{filename};
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$self{"lines"};} or defined $self->{"filename"} 9 0 9
Condition33%1/3
keys %{$$self{"lines"};} or defined $self->{"filename"}
l!l&&r!l&&!r
900
MC/DC0%0/2
keys %{$$self{"lines"};} or defined $self->{"filename"}
keys %{$$self{"lines"};} defined $self->{"filename"}
Truth table33%1/3
A or B
A= keys %{$$self{"lines"};}B= defined $self->{"filename"}
ABresult
1X1
011
000
345 6 $self->_replace({});
346 6 $self->{filename} = undef;
347 6 $self->{saved} = '';
348 6 $self->{format} = 'native';
349 }
350  
351 75 ▶sub _read_text {
Subroutine _read_text: called CC=5 SCAR=16.2
352 75 my ($path) = @_;
353 75 ▶ open my $fh, '<:raw', $path or die "Cannot open '$path': $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $path or die "Cannot open '${path}': $!\n" 73 2 75
354 73 local $/;
355 73 my $bytes = <$fh>;
356 73 ▶ die "Cannot read '$path': $!\n" unless defined $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 73 73
357 73 ▶ close $fh or die "Cannot close '$path': $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Cannot close '${path}': $!\n" 73 0 73
358 73 my $text = decode('UTF-8', $bytes, FB_CROAK);
359 72 $text =~ s/\A\x{FEFF}//;
360 72 $text =~ s/\r\n/\n/g;
361 72 ▶ die "'$path' contains NUL bytes or unsupported bare carriage returns.\n" if $text =~ /[\0\r]/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /[\0\r]/u 1 71 72
362 71 return $text;
363 }
364  
365 58 ▶sub _write_text {
Subroutine _write_text: called CC=8 SCAR=21.3
366 58 my ($path, $text) = @_;
367 58 my $fh = File::Temp->new(TEMPLATE => '.anterepl-XXXXXX', DIR => dirname($path), UNLINK => 1);
368 58 ▶ binmode $fh, ':raw' or die "Cannot set file mode: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
binmode $fh, ":raw" or die "Cannot set file mode: $!\n" 58 0 58
369 58 ▶ print {$fh} encode('UTF-8', $text, FB_CROAK) or die "Cannot write '$path': $!\n";
Branch: 1 branch
BranchTrueFalseTotal
print {$fh;} &encode("UTF-8", $text, 1) or die "Cannot write '${path}': $!\n" 58 0 58
370 58 my $temporary = $fh->filename;
371 58 ▶ close $fh or die "Cannot close temporary file for '$path': $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Cannot close temporary file for '${path}': $!\n" 58 0 58
372 58 ▶ if (-e $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $path) 19 39 58
373 19 my @stat = stat $path;
374 19 ▶ die "Cannot stat '$path': $!\n" unless @stat;
Branch: 1 branch
BranchTrueFalseTotal
unless @stat 0 19 19
375 19 ▶ chmod($stat[2] & 0777, $temporary) or die "Cannot preserve permissions for '$path': $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chmod $stat[2] & 511, $temporary or die "Cannot preserve permissions for '${path}': $!\n" 19 0 19
376 }
377 58 ▶ rename $temporary, $path or die "Cannot replace '$path': $!\n";
Branch: 1 branch
BranchTrueFalseTotal
rename $temporary, $path or die "Cannot replace '${path}': $!\n" 57 1 58
378 57 return 1;
379 }
380  
381 18 ▶sub save {
Subroutine save: called CC=9 SCAR=22.2
Pod undocumented
382 18 my ($self, $path) = @_;
383 18 ▶ $path = $self->{filename} unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 3 15 18
384 18 ▶ die "SAVE needs a filename, for example SAVE demo.bperl.\n" unless defined $path && length $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path and length $path 0 18 18
Condition33%1/3
defined $path and length $path
!ll&&!rl&&r
0018
MC/DC0%0/2
defined $path and length $path
defined $path length $path
Truth table33%1/3
A and B
A= defined $pathB= length $path
ABresult
0X0
100
111
385 18 ▶ my $format = $path =~ /\.pl\z/i ? 'perl' : $path =~ /\.bperl\z/i ? 'native' : $self->{format};
Branch: 2 branches
BranchTrueFalseTotal
$path =~ /\.pl\z/iu ? : 6 12 18
$path =~ /\.bperl\z/iu ? : 10 2 12
386 18 ▶ $self->_confirm_destructive("Overwrite file '$path'") if -e $path || -l $path;
Branch: 1 branch
BranchTrueFalseTotal
if -e $path or -l $path 9 9 18
Condition66%2/3
-e $path or -l $path
l!l&&r!l&&!r
909
MC/DC50%1/2
-e $path or -l $path
-e $path -l $path
Truth table66%2/3
A or B
A= -e $pathB= -l $path
ABresult
1X1
011
000
387 17 ▶ _write_text($path, $format eq 'perl' ? $self->source : "# PERL ANTE REPL V$PROGRAM_VERSION\n" . $self->listing);
Branch: 1 branch
BranchTrueFalseTotal
$format eq 'perl' ? : 6 11 17
388 16 $self->{filename} = File::Spec->rel2abs($path);
389 16 $self->{format} = $format;
390 16 $self->{saved} = $self->listing;
391 16 return $path;
392 }
393  
394 28 ▶sub load {
Subroutine load: called CC=15 SCAR=27.2
Pod undocumented
395 28 my ($self, $path, $force) = @_;
396 28 $self->_guard('LOAD', $force);
397 26 my $text = _read_text($path);
398 25 ▶ if ($text !~ /\A# (?:PERL ANTE REPL|BASIC PERL)\b/ && $path !~ /\.bperl\z/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($text =~ /\A# (?:PERL ANTE REPL|BASIC PERL)\b/u or $path =~ /\.bperl\z/iu) 8 17 25
Condition100%3/3
$text =~ /\A# (?:PERL ANTE REPL|BASIC PERL)\b/u or $path =~ /\.bperl\z/iu
l!l&&r!l&&!r
1618
MC/DC100%2/2
$text =~ /\A# (?:PERL ANTE REPL|BASIC PERL)\b/u or $path =~ /\.bperl\z/iu
$text =~ /\A# (?:PERL ANTE REPL|BASIC PERL)\b/u $path =~ /\.bperl\z/iu
Truth table100%3/3
A or B
A= $text =~ /\A# (?:PERL ANTE REPL|BASIC PERL)\b/uB= $path =~ /\.bperl\z/iu
ABresult
1X1
011
000
399 8 my $lines = _source_lines($text);
400 $self->_confirm_destructive('Replace the stored program and its save filename')
401 8 ▶ if keys %{ $self->{lines} } || defined $self->{filename};
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$self{"lines"};} or defined $self->{"filename"} 6 2 8
Condition66%2/3
keys %{$$self{"lines"};} or defined $self->{"filename"}
l!l&&r!l&&!r
602
MC/DC50%1/2
keys %{$$self{"lines"};} or defined $self->{"filename"}
keys %{$$self{"lines"};} defined $self->{"filename"}
Truth table66%2/3
A or B
A= keys %{$$self{"lines"};}B= defined $self->{"filename"}
ABresult
1X1
011
000
402 6 $self->_replace($lines);
403 6 $self->{filename} = File::Spec->rel2abs($path);
404 6 $self->{format} = 'perl';
405 6 $self->{saved} = $self->listing;
406 6 return scalar keys %$lines;
407 }
408 17 my @records = split /\n/, $text, -1;
409 17 ▶ pop @records if @records && $records[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if @records and $records[-1] eq "" 17 0 17
Condition33%1/3
@records and $records[-1] eq ""
!ll&&!rl&&r
0017
MC/DC0%0/2
@records and $records[-1] eq ""
@records $records[-1] eq ""
Truth table33%1/3
A and B
A= @recordsB= $records[-1] eq ""
ABresult
0X0
100
111
410 17 ▶ my $header = @records ? shift @records : '';
Branch: 1 branch
BranchTrueFalseTotal
@records ? : 17 0 17
411 17 ▶ die "Not a PERL ANTE REPL V$PROGRAM_VERSION file. Use a .pl filename or IMPORT for ordinary Perl source.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $header eq "# PERL ANTE REPL V$App::AnteREPL::PROGRAM_VERSION" or $header eq "# BASIC PERL V$App::AnteREPL::PROGRAM_VERSION" 3 14 17
Condition100%3/3
$header eq "# PERL ANTE REPL V$App::AnteREPL::PROGRAM_VERSION" or $header eq "# BASIC PERL V$App::AnteREPL::PROGRAM_VERSION"
l!l&&r!l&&!r
1223
MC/DC100%2/2
$header eq "# PERL ANTE REPL V$App::AnteREPL::PROGRAM_VERSION" or $header eq "# BASIC PERL V$App::AnteREPL::PROGRAM_VERSION"
$header eq "# PERL ANTE REPL V$App::AnteREPL::PROGRAM_VERSION" $header eq "# BASIC PERL V$App::AnteREPL::PROGRAM_VERSION"
Truth table100%3/3
A or B
A= $header eq "# PERL ANTE REPL V$App::AnteREPL::PROGRAM_VERSION"B= $header eq "# BASIC PERL V$App::AnteREPL::PROGRAM_VERSION"
ABresult
1X1
011
000
412 unless $header eq "# PERL ANTE REPL V$PROGRAM_VERSION"
413 || $header eq "# BASIC PERL V$PROGRAM_VERSION";
414 14 my %lines;
415 14 for my $record (@records) {
416 29 ▶ die "Invalid numbered record in '$path'.\n" unless $record =~ /\A([0-9]+)[ \t](.*)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $record =~ /\A([0-9]+)[ \t](.*)\z/u 1 28 29
417 28 my ($number, $code) = (_number($1), $2);
418 27 ▶ die "Duplicate line $number in '$path'.\n" if exists $lines{$number};
Branch: 1 branch
BranchTrueFalseTotal
if exists $lines{$number} 4 23 27
419 23 $lines{$number} = $code;
420 }
421 $self->_confirm_destructive('Replace the stored program and its save filename')
422 8 ▶ if keys %{ $self->{lines} } || defined $self->{filename};
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$self{"lines"};} or defined $self->{"filename"} 3 5 8
Condition66%2/3
keys %{$$self{"lines"};} or defined $self->{"filename"}
l!l&&r!l&&!r
305
MC/DC50%1/2
keys %{$$self{"lines"};} or defined $self->{"filename"}
keys %{$$self{"lines"};} defined $self->{"filename"}
Truth table66%2/3
A or B
A= keys %{$$self{"lines"};}B= defined $self->{"filename"}
ABresult
1X1
011
000
423 8 $self->_replace(\%lines);
424 8 $self->{filename} = File::Spec->rel2abs($path);
425 8 $self->{format} = 'native';
426 8 $self->{saved} = $self->listing;
427 8 return scalar keys %lines;
428 }
429  
430 23 ▶sub _source_lines {
Subroutine _source_lines: called CC=5 SCAR=16.2
431 23 my ($text) = @_;
432 23 my @code = split /\n/, $text, -1;
433 23 ▶ pop @code if @code && $code[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if @code and $code[-1] eq "" 22 1 23
Condition66%2/3
@code and $code[-1] eq ""
!ll&&!rl&&r
1022
MC/DC50%1/2
@code and $code[-1] eq ""
@code $code[-1] eq ""
Truth table66%2/3
A and B
A= @codeB= $code[-1] eq ""
ABresult
0X0
100
111
434 23 ▶ die "Program has too many lines.\n" if @code * 10 > $max_line;
Branch: 1 branch
BranchTrueFalseTotal
if @code * 10 > $max_line 0 23 23
435 23 my %lines;
436 23 $lines{ ($_ + 1) * 10 } = $code[$_] for 0 .. $#code;
437 23 return \%lines;
438 }
439  
440 7 ▶sub import_source {
Subroutine import_source: called CC=3 SCAR=11.2
Pod undocumented
441 7 my ($self, $path, $force) = @_;
442 7 $self->_guard('IMPORT', $force);
443 7 my $lines = _source_lines(_read_text($path));
444 $self->_confirm_destructive('Replace the stored program and forget its save filename')
445 7 ▶ if keys %{ $self->{lines} } || defined $self->{filename};
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$self{"lines"};} or defined $self->{"filename"} 7 0 7
Condition33%1/3
keys %{$$self{"lines"};} or defined $self->{"filename"}
l!l&&r!l&&!r
700
MC/DC0%0/2
keys %{$$self{"lines"};} or defined $self->{"filename"}
keys %{$$self{"lines"};} defined $self->{"filename"}
Truth table33%1/3
A or B
A= keys %{$$self{"lines"};}B= defined $self->{"filename"}
ABresult
1X1
011
000
446 5 $self->_replace($lines);
447 5 $self->{filename} = undef;
448 5 $self->{saved} = '';
449 5 $self->{format} = 'native';
450 5 return scalar keys %$lines;
451 }
452  
453 4 ▶sub export_source {
Subroutine export_source: called CC=3 SCAR=11.0
Pod undocumented
454 4 my ($self, $path) = @_;
455 4 my $prelude = "#!/usr/bin/env perl\nBEGIN { require 5.016; }\nuse feature ':5.16';\nuse strict;\nuse warnings;\nno strict 'vars';\nno warnings 'once';\nuse feature 'say';\n";
456 4 ▶ $self->_confirm_destructive("Overwrite file '$path'") if -e $path || -l $path;
Branch: 1 branch
BranchTrueFalseTotal
if -e $path or -l $path 2 2 4
Condition66%2/3
-e $path or -l $path
l!l&&r!l&&!r
202
MC/DC50%1/2
-e $path or -l $path
-e $path -l $path
Truth table66%2/3
A or B
A= -e $pathB= -l $path
ABresult
1X1
011
000
457 3 _write_text($path, $prelude . $self->source);
458 3 return $path;
459 }
460  
461 16 ▶sub _edit_text {
Subroutine _edit_text: called CC=12 SCAR=27.7
462 16 my ($self, $before, $name) = @_;
463 my $editor = (defined $ENV{EDITOR} && $ENV{EDITOR} =~ /\S/) ? $ENV{EDITOR}
464 : (defined $ENV{VISUAL} && $ENV{VISUAL} =~ /\S/) ? $ENV{VISUAL}
465 16 ▶ : $^O eq 'MSWin32' ? 'notepad' : 'vi';
Branch: 3 branches
BranchTrueFalseTotal
defined $ENV{'EDITOR'} && $ENV{'EDITOR'} =~ /\S/u ? : 15 1 16
defined $ENV{'VISUAL'} && $ENV{'VISUAL'} =~ /\S/u ? : 1 0 1
$^O eq 'MSWin32' ? : 0 0 0
Condition50%3/6
defined $ENV{"EDITOR"} and $ENV{"EDITOR"} =~ /\S/u
!ll&&!rl&&r
0115
defined $ENV{"VISUAL"} and $ENV{"VISUAL"} =~ /\S/u
!ll&&!rl&&r
001
MC/DC50%1/2
defined $ENV{"EDITOR"} and $ENV{"EDITOR"} =~ /\S/u
defined $ENV{"EDITOR"} $ENV{"EDITOR"} =~ /\S/u
MC/DC0%0/2
defined $ENV{"VISUAL"} and $ENV{"VISUAL"} =~ /\S/u
defined $ENV{"VISUAL"} $ENV{"VISUAL"} =~ /\S/u
Truth table66%2/3
A and B
A= defined $ENV{"EDITOR"}B= $ENV{"EDITOR"} =~ /\S/u
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $ENV{"VISUAL"}B= $ENV{"VISUAL"} =~ /\S/u
ABresult
0X0
100
111
466 16 my @command = shellwords($editor);
467 16 ▶ die "EDITOR is empty or has unmatched quotes.\n" unless @command && length $command[0];
Branch: 1 branch
BranchTrueFalseTotal
unless @command and length $command[0] 1 15 16
Condition66%2/3
@command and length $command[0]
!ll&&!rl&&r
1015
MC/DC50%1/2
@command and length $command[0]
@command length $command[0]
Truth table66%2/3
A and B
A= @commandB= length $command[0]
ABresult
0X0
100
111
468 15 my $directory = File::Temp->newdir('anterepl-XXXXXX', TMPDIR => 1, CLEANUP => 1);
469 15 my $path = File::Spec->catfile("$directory", $name);
470 15 _write_text($path, $before);
471 # List-form system: editor arguments are supported; no command shell is involved.
472 my $status = $self->{screen}
473 0 ▶ ? $self->{screen}->external(sub { system { $command[0] } @command, $path }, 0)
Subroutine __ANON__: not called CC=1 SCAR=6.9
474 15 ▶ : system { $command[0] } @command, $path;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'screen'} ? : 0 15 15
475 15 ▶ die "Cannot start editor '$command[0]': $!; memory unchanged.\n" if $status == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $status == -1 0 15 15
476 15 ▶ die "Editor terminated by signal " . ($status & 127) . "; memory unchanged.\n" if $status & 127;
Branch: 1 branch
BranchTrueFalseTotal
if $status & 127 0 15 15
477 15 ▶ die "Editor exited with status " . ($status >> 8) . "; memory unchanged.\n" if $status;
Branch: 1 branch
BranchTrueFalseTotal
if $status 2 13 15
478 13 return _read_text($path);
479 }
480  
481 16 ▶sub edit {
Subroutine edit: called CC=2 SCAR=6.9
Pod undocumented
482 16 my ($self) = @_;
483 16 my $before = $self->source;
484 16 my $after = $self->_edit_text($before, 'program.pl');
485 11 ▶ return 0 if $before eq $after;
Branch: 1 branch
BranchTrueFalseTotal
if $before eq $after 3 8 11
486 8 return $self->_replace(_source_lines($after));
487 }
488  
489 179 ▶sub _env_key {
Subroutine _env_key: called CC=3 SCAR=12.5
490 179 my ($key) = @_;
491 179 ▶ die "Environment names cannot contain whitespace, =, #, quotes, or NUL.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key and $key =~ /\A[^\s=\0#'\"]+\z/u 0 179 179
Condition33%1/3
defined $key and $key =~ /\A[^\s=\0#'\"]+\z/u
!ll&&!rl&&r
00179
MC/DC0%0/2
defined $key and $key =~ /\A[^\s=\0#'\"]+\z/u
defined $key $key =~ /\A[^\s=\0#'\"]+\z/u
Truth table33%1/3
A and B
A= defined $keyB= $key =~ /\A[^\s=\0#'\"]+\z/u
ABresult
0X0
100
111
492 unless defined $key && $key =~ /\A[^\s=\0#'\"]+\z/;
493 179 return $key;
494 }
495  
496 14 ▶sub env_text {
Subroutine env_text: called CC=10 SCAR=23.4
Pod undocumented
497 14 my ($values) = @_;
498 14 ▶ $values = \%ENV unless defined $values;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $values 11 3 14
499 14 my $text = '';
500 14 for my $key (sort keys %$values) {
501 129 _env_key($key);
502 129 my $value = $values->{$key};
503 129 ▶ die "Environment values must be strings without NUL bytes.\n" if !defined $value || ref $value || $value =~ /\0/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value or $value =~ /\0/u 0 129 129
Condition33%2/6
not defined $value or ref $value or $value =~ /\0/u
l!l&&r!l&&!r
00129
not defined $value or ref $value
l!l&&r!l&&!r
00129
MC/DC0%0/3
not defined $value or ref $value or $value =~ /\0/u
not defined $value ref $value $value =~ /\0/u
Truth table25%1/4
not(A) or B or C
A= not defined $valueB= ref $valueC= $value =~ /\0/u
ABCresult
1XX1
01X1
0011
0000
504 129 my $byte_escapes = '';
505 129 ▶ if (!utf8::is_utf8($value)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (utf8::is_utf8($value)) 129 0 129
506 129 local $@;
507 129 my $decoded = eval { decode('UTF-8', "$value", FB_CROAK) };
508 129 ▶ if (defined $decoded) { $value = $decoded; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $decoded) { } 128 1 129
509 1 else { $byte_escapes = 1; }
510 }
511 129 ▶ if ($value !~ /\A[A-Za-z0-9_.\/:\@%+,=-]*\z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ m[\A[A-Za-z0-9_./:\@%+,=-]*\z]u) 29 100 129
512 29 $value =~ s/([\\"])/\\$1/g;
513 29 $value =~ s/\n/\\n/g;
514 29 $value =~ s/\r/\\r/g;
515 29 $value =~ s/\t/\\t/g;
516 0 $value =~ s/([\x01-\x08\x0b\x0c\x0e-\x1f\x7f])/sprintf('\\x%02X', ord $1)/ge;
517 29 ▶ $value =~ s/([\x80-\xff])/sprintf('\\x%02X', ord $1)/ge if $byte_escapes;
Branch: 1 branch
BranchTrueFalseTotal
if $byte_escapes 1 28 29
518 29 $value = '"' . $value . '"';
519 }
520 129 $text .= "$key=$value\n";
521 }
522 14 return $text;
523 }
524  
525 16 ▶sub _parse_env {
Subroutine _parse_env: called CC=14 SCAR=26.4
526 16 my ($text) = @_;
527 16 my (%values, $line);
528 16 for my $record (split /\n/, $text) {
529 35 ++$line;
530 35 ▶ next if $record =~ /\A\s*(?:#.*)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $record =~ /\A\s*(?:#.*)?\z/u 1 34 35
531 34 ▶ die "Invalid environment assignment on line $line; use VAR=value.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $record =~ /\A\s*(?:export\s+)?([^\s=]+)\s*=(.*)\z/u 2 32 34
532 unless $record =~ /\A\s*(?:export\s+)?([^\s=]+)\s*=(.*)\z/;
533 32 my ($key, $value) = (_env_key($1), $2);
534 32 ▶ die "Duplicate environment name '$key' on line $line.\n" if exists $values{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $values{$key} 1 31 32
535 31 $value =~ s/\A\s+|\s+\z//g;
536 31 ▶ if ($value =~ /\A"/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value =~ /\A"/u) { } 12 19 31
elsif ($value =~ /\A'/u) { } 2 17 19
537 12 ▶ die "Invalid quoted value on environment line $line.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /\A"((?:[^"\\]|\\.)*)"\s*(?:#.*)?\z/u 1 11 12
538 unless $value =~ /\A"((?:[^"\\]|\\.)*)"\s*(?:#.*)?\z/;
539 11 $value = $1;
540 11 ▶ $value = encode('UTF-8', $value) if utf8::is_utf8($value);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($value) 11 0 11
541 11 my %escape = ('n'=>"\n", 'r'=>"\r", 't'=>"\t", '\\'=>'\\', '"'=>'"');
542 11 ▶ $value =~ s/\\(x[0-9A-Fa-f]{2}|[nrt\\"])/exists $escape{$1} ? $escape{$1} : chr(hex(substr($1, 1)))/ge;
Branch: 1 branch
BranchTrueFalseTotal
exists $escape{$1} ? : 5 3 8
543 }
544 elsif ($value =~ /\A'/) {
545 2 ▶ die "Invalid quoted value on environment line $line.\n" unless $value =~ /\A'([^']*)'\s*(?:#.*)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /\A'([^']*)'\s*(?:#.*)?\z/u 0 2 2
546 2 $value = $1;
547 2 ▶ $value = encode('UTF-8', $value) if utf8::is_utf8($value);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($value) 2 0 2
548 }
549 else {
550 17 $value =~ s/(?:\A|\s+)#.*\z//;
551 17 $value =~ s/\s+\z//;
552 17 ▶ $value = encode('UTF-8', $value) if utf8::is_utf8($value);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($value) 15 2 17
553 }
554 30 ▶ die "NUL is not allowed in environment values (line $line).\n" if $value =~ /\0/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\0/u 1 29 30
555 29 $values{$key} = $value;
556 }
557 11 return \%values;
558 }
559  
560 62 ▶sub environment {
Subroutine environment: called CC=29 SCAR=34.6
Pod undocumented
561 62 my ($self, $tail) = @_;
562 62 my @args = _args($tail, 0, 3, 'ENV [name | SET name value | UNSET name | EDIT | SAVE file | LOAD file | RELOAD | RESET]');
563 62 ▶ if (!@args) { print env_text(); return; }
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 2 60 62
564 60 my $command = shift @args;
565 60 ▶ if ($command eq 'SET') {
Branch: 6 branches
BranchTrueFalseTotal
if ($command eq 'SET') { } 13 47 60
elsif ($command eq 'UNSET') { } 5 42 47
elsif ($command eq 'SAVE') { } 4 38 42
elsif ($command eq 'LOAD' or $command eq 'RELOAD') { } 11 27 38
elsif ($command eq 'EDIT') { } 6 21 27
elsif ($command eq 'RESET') { } 4 17 21
566 13 ▶ die "Usage: ENV SET name value\n" unless @args == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 2 0 13 13
567 13 my ($key, $value) = @args;
568 13 _env_key($key);
569 13 ▶ die "NUL is not allowed in environment values.\n" if $value =~ /\0/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\0/u 0 13 13
570 13 ▶ $value = encode('UTF-8', $value) if utf8::is_utf8($value);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($value) 1 12 13
571 $self->_confirm_destructive("Replace environment variable '$key'")
572 13 ▶ if exists $ENV{$key} && $ENV{$key} ne $value;
Branch: 1 branch
BranchTrueFalseTotal
if exists $ENV{$key} and $ENV{$key} ne $value 5 8 13
Condition100%3/3
exists $ENV{$key} and $ENV{$key} ne $value
!ll&&!rl&&r
625
MC/DC100%2/2
exists $ENV{$key} and $ENV{$key} ne $value
exists $ENV{$key} $ENV{$key} ne $value
Truth table100%3/3
A and B
A= exists $ENV{$key}B= $ENV{$key} ne $value
ABresult
0X0
100
111
573 11 $ENV{$key} = $value;
574 }
575 elsif ($command eq 'UNSET') {
576 5 ▶ die "Usage: ENV UNSET name\n" unless @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 5 5
577 5 my $key = _env_key($args[0]);
578 5 ▶ $self->_confirm_destructive("Remove environment variable '$key'") if exists $ENV{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $ENV{$key} 5 0 5
579 4 delete $ENV{$key};
580 }
581 elsif ($command eq 'SAVE') {
582 4 ▶ die "Usage: ENV SAVE file\n" unless @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 4 4
583 4 ▶ $self->_confirm_destructive("Overwrite file '$args[0]'") if -e $args[0] || -l $args[0];
Branch: 1 branch
BranchTrueFalseTotal
if -e $args[0] or -l $args[0] 2 2 4
Condition66%2/3
-e $args[0] or -l $args[0]
l!l&&r!l&&!r
202
MC/DC50%1/2
-e $args[0] or -l $args[0]
-e $args[0] -l $args[0]
Truth table66%2/3
A or B
A= -e $args[0]B= -l $args[0]
ABresult
1X1
011
000
584 3 _write_text($args[0], env_text());
585 3 $self->{env_filename} = File::Spec->rel2abs($args[0]);
586 3 print "Environment saved.\n";
587 }
588 ▶ elsif ($command eq 'LOAD' || $command eq 'RELOAD') {
Condition100%3/3
$command eq "LOAD" or $command eq "RELOAD"
l!l&&r!l&&!r
7427
MC/DC100%2/2
$command eq "LOAD" or $command eq "RELOAD"
$command eq "LOAD" $command eq "RELOAD"
Truth table100%3/3
A or B
A= $command eq "LOAD"B= $command eq "RELOAD"
ABresult
1X1
011
000
589 11 ▶ die "Usage: ENV $command" . ($command eq 'LOAD' ? ' file' : ' [file]') . "\n"
Branch: 2 branches
BranchTrueFalseTotal
if @args > 1 or $command eq "LOAD" and not @args 0 11 11
$command eq 'LOAD' ? : 0 0 0
Condition50%3/6
@args > 1 or $command eq "LOAD" and not @args
l!l&&r!l&&!r
0011
$command eq "LOAD" and not @args
!ll&&!rl&&r
470
MC/DC0%0/3
@args > 1 or $command eq "LOAD" and not @args
@args > 1 $command eq "LOAD" not @args
Truth table50%2/4
A or B and not(C)
A= @args > 1B= $command eq "LOAD"C= not @args
ABCresult
1XX1
0111
00X0
0100
590 if @args > 1 || ($command eq 'LOAD' && !@args);
591 11 ▶ my $path = @args ? $args[0] : $self->{env_filename};
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 9 2 11
592 11 ▶ die "No environment file yet. Use ENV LOAD file or ENV SAVE file first.\n" unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 11 11
593 11 my $values = _parse_env(_read_text($path));
594 7 $self->_confirm_environment($values);
595 5 %ENV = %$values;
596 5 $self->{env_filename} = File::Spec->rel2abs($path);
597 5 print "Environment loaded.\n";
598 }
599 elsif ($command eq 'EDIT') {
600 6 ▶ die "Usage: ENV EDIT\n" if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 6 6
601 6 my $before = env_text();
602 6 my $after = $self->_edit_text($before, 'environment.env');
603 5 my $values = _parse_env($after);
604 4 $self->_confirm_environment($values);
605 3 %ENV = %$values;
606 3 ▶ print $before eq $after ? "Environment unchanged.\n" : "Environment updated.\n";
Branch: 1 branch
BranchTrueFalseTotal
$before eq $after ? : 0 3 3
607 }
608 elsif ($command eq 'RESET') {
609 4 ▶ die "Usage: ENV RESET\n" if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 4 4
610 4 $self->_confirm_environment($self->{initial_env});
611 3 %ENV = %{ $self->{initial_env} };
612 3 print "Startup environment restored.\n";
613 }
614 else {
615 17 my ($key) = _args($tail, 1, 1, 'ENV name');
616 7 ▶ die "Environment name '$key' is not set.\n" unless exists $ENV{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ENV{$key} 4 3 7
617 3 print env_text({$key => $ENV{$key}});
618 }
619 }
620  
621 43 ▶sub auto_mode {
Subroutine auto_mode: called CC=15 SCAR=27.1
Pod undocumented
622 43 my ($self, $tail) = @_;
623 43 my @args = _args($tail, 0, 2, 'AUTO [start [step]], AUTO OFF, or AUTO ECHO ON|OFF');
624 43 ▶ if (@args && $args[0] eq 'ECHO') {
Branch: 1 branch
BranchTrueFalseTotal
if (@args and $args[0] eq "ECHO") 8 35 43
Condition100%3/3
@args and $args[0] eq "ECHO"
!ll&&!rl&&r
13228
MC/DC100%2/2
@args and $args[0] eq "ECHO"
@args $args[0] eq "ECHO"
Truth table100%3/3
A and B
A= @argsB= $args[0] eq "ECHO"
ABresult
0X0
100
111
625 8 ▶ die "Usage: AUTO ECHO ON|OFF\n" unless @args == 2 && $args[1] =~ /\A(?:ON|OFF)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 2 and $args[1] =~ /\A(?:ON|OFF)\z/u 3 5 8
Condition66%2/3
@args == 2 and $args[1] =~ /\A(?:ON|OFF)\z/u
!ll&&!rl&&r
035
MC/DC50%1/2
@args == 2 and $args[1] =~ /\A(?:ON|OFF)\z/u
@args == 2 $args[1] =~ /\A(?:ON|OFF)\z/u
Truth table66%2/3
A and B
A= @args == 2B= $args[1] =~ /\A(?:ON|OFF)\z/u
ABresult
0X0
100
111
626 5 ▶ $self->{auto_echo} = $args[1] eq 'ON' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args[1] eq 'ON' ? : 3 2 5
627 5 ▶ print 'AUTO echo ', ($self->{auto_echo} ? 'on' : 'off'), ".\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'auto_echo'} ? : 3 2 5
628 5 return;
629 }
630 35 ▶ if (@args == 1 && $args[0] eq 'OFF') {
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 1 and $args[0] eq "OFF") 10 25 35
Condition100%3/3
@args == 1 and $args[0] eq "OFF"
!ll&&!rl&&r
20510
MC/DC100%2/2
@args == 1 and $args[0] eq "OFF"
@args == 1 $args[0] eq "OFF"
Truth table100%3/3
A and B
A= @args == 1B= $args[0] eq "OFF"
ABresult
0X0
100
111
631 10 delete $self->{auto};
632 10 print "AUTO off.\n";
633 10 return;
634 }
635 25 my @numbers = $self->numbers;
636 25 ▶ my $step = @args > 1 ? _number($args[1]) : 5;
Branch: 1 branch
BranchTrueFalseTotal
@args > 1 ? : 7 18 25
637 22 ▶ my $start = @args ? _number($args[0]) : (@numbers ? $numbers[-1] + $step : $step);
Branch: 2 branches
BranchTrueFalseTotal
@args ? : 9 13 22
@numbers ? : 3 10 13
638 19 _number($start);
639 19 ▶ $start += $step while $start <= $max_line && exists $self->{lines}{$start};
Branch: 1 branch
BranchTrueFalseTotal
$start <= $max_line and exists $self->{"lines"}{$start} and do { $start += $step } 2 19 21
Condition66%2/3
$start <= $max_line and exists $self->{"lines"}{$start}
!ll&&!rl&&r
0192
MC/DC50%1/2
$start <= $max_line and exists $self->{"lines"}{$start}
$start <= $max_line exists $self->{"lines"}{$start}
Truth table66%2/3
A and B
A= $start <= $max_lineB= exists $self->{"lines"}{$start}
ABresult
0X0
100
111
640 19 ▶ die "No room for AUTO lines.\n" if $start > $max_line;
Branch: 1 branch
BranchTrueFalseTotal
if $start > $max_line 0 19 19
641 19 $self->{auto} = { next => $start, step => $step };
642 19 print "AUTO $start, step $step. AUTO OFF, Ctrl-C, or Ctrl-D ends entry.\n";
643 }
644  
645 27 ▶sub auto_store {
Subroutine auto_store: called CC=13 SCAR=25.8
Pod undocumented
646 27 my ($self, $source) = @_;
647 27 ▶ die "AUTO source cannot contain NUL bytes or bare carriage returns.\n" if $source =~ /[\r\0]/;
Branch: 1 branch
BranchTrueFalseTotal
if $source =~ /[\r\0]/u 0 27 27
648 27 my $literal = $source =~ s/\A:(?:[ \t])?//;
649 27 my @source = split /\n/, $source, -1;
650 # A complete pasted/continued block is already Perl source. Preserve its
651 # internal syntax. Single-line input gets the usual semicolon convenience.
652 27 ▶ $source[0] = _typed_source($source[0]) if @source == 1 && !$literal;
Branch: 1 branch
BranchTrueFalseTotal
if @source == 1 and not $literal 22 5 27
Condition100%3/3
@source == 1 and not $literal
!ll&&!rl&&r
4122
MC/DC100%2/2
@source == 1 and not $literal
@source == 1 not $literal
Truth table100%3/3
A and not(B)
A= @source == 1B= not $literal
ABresult
0X0
100
111
653 27 my %lines = %{ $self->{lines} };
654 27 my ($next, $step) = @{ $self->{auto} }{qw(next step)};
655 27 my @stored;
656 27 for my $code (@source) {
657 34 ▶ $next += $step while $next <= $max_line && exists $lines{$next};
Branch: 1 branch
BranchTrueFalseTotal
$next <= $max_line and exists $lines{$next} and do { $next += $step } 0 34 34
Condition66%2/3
$next <= $max_line and exists $lines{$next}
!ll&&!rl&&r
1330
MC/DC0%0/2
$next <= $max_line and exists $lines{$next}
$next <= $max_line exists $lines{$next}
Truth table66%2/3
A and B
A= $next <= $max_lineB= exists $lines{$next}
ABresult
0X0
100
111
658 34 ▶ die "AUTO would exceed $max_line; nothing stored. Use AUTO OFF or choose a new start.\n" if $next > $max_line;
Branch: 1 branch
BranchTrueFalseTotal
if $next > $max_line 1 33 34
659 33 push @stored, "$next $code\n";
660 33 $lines{$next} = $code;
661 33 $next += $step;
662 }
663 26 $self->_replace(\%lines);
664 26 ▶ $next += $step while $next <= $max_line && exists $lines{$next};
Branch: 1 branch
BranchTrueFalseTotal
$next <= $max_line and exists $lines{$next} and do { $next += $step } 0 26 26
Condition66%2/3
$next <= $max_line and exists $lines{$next}
!ll&&!rl&&r
1250
MC/DC0%0/2
$next <= $max_line and exists $lines{$next}
$next <= $max_line exists $lines{$next}
Truth table66%2/3
A and B
A= $next <= $max_lineB= exists $lines{$next}
ABresult
0X0
100
111
665 26 ▶ if ($next > $max_line) { delete $self->{auto}; }
Branch: 1 branch
BranchTrueFalseTotal
if ($next > $max_line) { } 1 25 26
666 25 else { $self->{auto}{next} = $next; }
667 26 ▶ print @stored if $self->{auto_echo};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"auto_echo"} 3 23 26
668 26 ▶ print "AUTO off: reached maximum line number.\n" unless $self->{auto};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"auto"} 1 25 26
669 }
670  
671 194 ▶sub input_needs_more {
Subroutine input_needs_more: called CC=4 SCAR=13.9
Pod undocumented
672 194 my ($self, $source) = @_;
673 194 ▶ return 0 if $self->{auto} && $source =~ /\A:/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"auto"} and $source =~ /\A:/u 1 193 194
Condition100%3/3
$self->{"auto"} and $source =~ /\A:/u
!ll&&!rl&&r
181121
MC/DC100%2/2
$self->{"auto"} and $source =~ /\A:/u
$self->{"auto"} $source =~ /\A:/u
Truth table100%3/3
A and B
A= $self->{"auto"}B= $source =~ /\A:/u
ABresult
0X0
100
111
674 193 ▶ my $more = App::AnteREPL::Shorthand->needs_more($source, sub { $self->_has_function($_[0]) });
Subroutine __ANON__: called CC=1 SCAR=0.0
675 193 ▶ return $more if defined $more;
Branch: 1 branch
BranchTrueFalseTotal
if defined $more 13 180 193
676 180 return needs_more($source);
677 }
678  
679 22 ▶sub _has_function {
Subroutine _has_function: called CC=1 SCAR=0.0
680 22 my ($self, $name) = @_;
681 25 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
682 22 return defined &{ $self->{workspace} . '::' . $name };
683 }
684  
685 7 ▶sub reset_workspace {
Subroutine reset_workspace: called CC=1 SCAR=0.0
Pod undocumented
686 7 $_[0]->_confirm_destructive('Discard live workspace variables and functions');
687 6 $_[0]->{workspace} = 'App::AnteREPL::Workspace::S' . ++$next_workspace;
688 }
689  
690 10 ▶sub function_names {
Subroutine function_names: called CC=1 SCAR=0.0
Pod undocumented
691 10 my ($self) = @_;
692 10 my $package = $self->{workspace} . '::';
693 25 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
694 10 return sort grep { defined &{ $package . $_ } } keys %{$package};
695 }
696  
697 345 ▶sub evaluate {
Subroutine evaluate: called CC=6 SCAR=18.1
Pod undocumented
698 345 my ($self, $code, $stored) = @_;
699 345 ▶ my $label = $stored ? 'PERL_ANTE_REPL_program' : 'PERL_ANTE_REPL_prompt';
Branch: 1 branch
BranchTrueFalseTotal
$stored ? : 29 316 345
700 345 my $source = "package $self->{workspace};\n#line 1 \"$label\"\n" . $code . "\n";
701 345 my ($value, $error);
702 {
703 0 ▶ local $SIG{INT} = sub { die "Interrupted.\n" };
Subroutine __ANON__: not called CC=1 SCAR=0.4
704 345 ($value, $error) = App::AnteREPL::Evaluator::evaluate($source);
705 }
706 345 ▶ if (length $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $error) 28 317 345
707 28 ▶ if ($stored) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stored) 4 24 28
708 4 my @numbers = $self->numbers;
709 4 $error =~ s{at PERL_ANTE_REPL_program line ([0-9]+)}{
710 5 ▶ $1 >= 1 && $1 <= @numbers
Branch: 1 branch
BranchTrueFalseTotal
$1 >= 1 && $1 <= @numbers ? : 5 0 5
Condition33%1/3
$1 >= 1 and $1 <= @numbers
!ll&&!rl&&r
005
MC/DC0%0/2
$1 >= 1 and $1 <= @numbers
$1 >= 1 $1 <= @numbers
Truth table33%1/3
A and B
A= $1 >= 1B= $1 <= @numbers
ABresult
0X0
100
111
711 ? 'at stored line ' . $numbers[$1 - 1] . " (source line $1)"
712 : "at program source line $1"
713 }ge;
714 }
715 28 die $error;
716 }
717 317 return $value;
718 }
719  
720 29 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
721 29 my ($self) = @_;
722 29 return $self->evaluate($self->source, 1);
723 }
724  
725 15 ▶sub inspect_value {
Subroutine inspect_value: called CC=10 SCAR=23.7
Pod undocumented
726 15 my ($self, $command, $expression) = @_;
727 15 ▶ die "$command needs a Perl expression.\n" unless $expression =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $expression =~ /\S/u 0 15 15
728 15 ▶ if ($command eq 'DUMP') {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "DUMP") 12 3 15
729 12 local $Data::Dumper::Sortkeys = 1;
730 12 print $self->evaluate("Data::Dumper::Dumper(do { $expression\n })", 0);
731 12 return;
732 }
733 3 require Devel::Peek;
734 3 require POSIX;
735 # Devel::Peek writes to the native stderr descriptor, bypassing tied Perl
736 # handles. Redirect that descriptor temporarily so its output joins VRAM.
737 3 my $temporary = File::Temp->new(UNLINK => 1);
738 3 my $saved = POSIX::dup(2);
739 3 ▶ die "Cannot preserve stderr: $!\n" unless defined $saved && $saved >= 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $saved and $saved >= 0 0 3 3
Condition33%1/3
defined $saved and $saved >= 0
!ll&&!rl&&r
003
MC/DC0%0/2
defined $saved and $saved >= 0
defined $saved $saved >= 0
Truth table33%1/3
A and B
A= defined $savedB= $saved >= 0
ABresult
0X0
100
111
740 3 ▶ unless (defined POSIX::dup2(fileno($temporary), 2)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined POSIX::dup2(fileno $temporary, 2)) 0 3 3
741 0 POSIX::close($saved);
742 0 die "Cannot capture Devel::Peek output: $!\n";
743 }
744 3 $expression =~ s/;\s*\z//;
745 3 my $ok = eval { $self->evaluate("Devel::Peek::Dump($expression\n)", 0); 1 };
746 3 my $error = $@;
747 3 my $restored = POSIX::dup2($saved, 2);
748 3 POSIX::close($saved);
749 3 ▶ die "Cannot restore stderr: $!\n" unless defined $restored;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $restored 0 3 3
750 3 ▶ seek($temporary, 0, 0) or die "Cannot rewind peek output: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
seek $temporary, 0, 0 or die "Cannot rewind peek output: $!\n" 3 0 3
751 3 local $/;
752 3 my $bytes = <$temporary>;
753 3 ▶ print decode('UTF-8', $bytes || '');
Condition100%2/2
$bytes || ''
l!l
21
MC/DC100%1/1
$bytes || ''
$bytes
Truth table100%2/2
A
A= $bytes
Aresult
11
00
754 3 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 2 3
755 }
756  
757 217 ▶sub needs_more {
Subroutine needs_more: called CC=21 SCAR=30.4
Pod undocumented
758 217 my ($source) = @_;
759 217 $source = _expand_short_command($source);
760 # Numbered lines and REPL/file/shell commands keep their own input grammar.
761 217 ▶ return 0 if $source =~ /\A\s*(?:[0-9]+(?:[\s:]|\z)|!)/;
Branch: 1 branch
BranchTrueFalseTotal
if $source =~ /\A\s*(?:[0-9]+(?:[\s:]|\z)|!)/u 11 206 217
762 206 ▶ return 0 if $source =~ /\A\s*(?:AUTO|ENV|LIST|RUN|EDIT|DEL|DELETE|RENUM|REORDER|UNDO|SAVE|LOAD|IMPORT|EXPORT|NEW|CLEAR|CLS|RECOVER|RESET|FUNCTIONS|STATUS|HELP|QUIT|EXIT|CD|CHDIR)\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $source =~ /\A\s*(?:AUTO|ENV|LIST|RUN|EDIT|DEL|DELETE|RENUM|REORDER|UNDO|SAVE|LOAD|IMPORT|EXPORT|NEW|CLEAR|CLS|RECOVER|RESET|FUNCTIONS|STATUS|HELP|QUIT|EXIT|CD|CHDIR)\b/u 29 177 206
763 177 my @stack;
764 177 my %close = (')' => '(', ']' => '[', '}' => '{');
765 177 my $trivia = qr/(?:\s|\#[^\n]*(?:\n|\z))*/;
766 177 my $name = qr/[\p{L}_][\p{L}\p{N}_]*(?:(?:::|')[\p{L}_][\p{L}\p{N}_]*)*/;
767 177 local $@;
768 177 my $position = 0;
769 177 ▶ while ($position < length $source) {
Branch: 1 branch
BranchTrueFalseTotal
if ($position < length $source) 1533 172 1705
770 1533 my $rest = substr($source, $position);
771 1533 ▶ if ($rest =~ /\A\#[^\n]*(?:\n|\z)/ || $rest =~ /\A\s+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\A\#[^\n]*(?:\n|\z)/u or $rest =~ /\A\s+/u) 582 951 1533
Condition100%3/3
$rest =~ /\A\#[^\n]*(?:\n|\z)/u or $rest =~ /\A\s+/u
l!l&&r!l&&!r
2580951
MC/DC100%2/2
$rest =~ /\A\#[^\n]*(?:\n|\z)/u or $rest =~ /\A\s+/u
$rest =~ /\A\#[^\n]*(?:\n|\z)/u $rest =~ /\A\s+/u
Truth table100%3/3
A or B
A= $rest =~ /\A\#[^\n]*(?:\n|\z)/uB= $rest =~ /\A\s+/u
ABresult
1X1
011
000
772 582 $position += length $&;
773 582 next;
774 }
775 # Prototype sigils are declarations, not variables: ($) ends with a
776 # closing parenthesis, not the special variable $). Skip only the
777 # prototype alphabet here; signatures/default expressions still use
778 # the normal scanner, and actual $) / $( variables remain untouched.
779 951 ▶ if ($rest =~ /\A(?:sub\b$trivia(?:$name$trivia)?|:$trivia prototype\b$trivia)
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\A(?:sub\b$trivia(?:$name$trivia)?|:$trivia prototype\b$trivia) \([\$\@%&*+;_\\\[\]\s]*(\)|\z)/ux) 67 884 951
780 \([\$\@%&*+;_\\\[\]\s]*(\)|\z)/x) {
781 67 ▶ return 1 unless length $1;
Branch: 1 branch
BranchTrueFalseTotal
unless length $1 1 66 67
782 66 $position += length $&;
783 66 next;
784 }
785 884 ▶ if ($rest =~ /\A([\$\@\%](?:\#?[\p{L}_][\p{L}\p{N}_]*(?:::[\p{L}_][\p{L}\p{N}_]*)*|[0-9]+|[^\w\s{]))/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\A([\$\@\%](?:\#?[\p{L}_][\p{L}\p{N}_]*(?:::[\p{L}_][\p{L}\p{N}_]*)*|[0-9]+|[^\w\s{]))/u) 54 830 884
786 54 $position += length $1;
787 54 next;
788 }
789 830 ▶ my $quoted = $rest =~ /\A['"`]/
Condition100%3/3
$rest =~ /\A['"`]/u || $rest =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)\b\s*(?!=>)[^\w\s]/u
l!l&&r!l&&!r
3117782
MC/DC100%2/2
$rest =~ /\A['"`]/u || $rest =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)\b\s*(?!=>)[^\w\s]/u
$rest =~ /\A['"`]/u $rest =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)\b\s*(?!=>)[^\w\s]/u
Truth table100%3/3
A || B
A= $rest =~ /\A['"`]/uB= $rest =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)\b\s*(?!=>)[^\w\s]/u
ABresult
1X1
011
000
790 || $rest =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)\b\s*(?!=>)[^\w\s]/;
791 830 ▶ if ($quoted || $rest =~ /\A\//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quoted or $rest =~ m[\A/]u) 50 780 830
Condition100%3/3
$quoted or $rest =~ m[\A/]u
l!l&&r!l&&!r
482780
MC/DC100%2/2
$quoted or $rest =~ m[\A/]u
$quoted $rest =~ m[\A/]u
Truth table100%3/3
A or B
A= $quotedB= $rest =~ m[\A/]u
ABresult
1X1
011
000
792 50 my ($literal) = extract_quotelike("$rest", '');
793 50 ▶ if (defined $literal && length $literal) { $position += length $literal; next; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $literal and length $literal) 46 4 50
Condition66%2/3
defined $literal and length $literal
!ll&&!rl&&r
4046
MC/DC50%1/2
defined $literal and length $literal
defined $literal length $literal
Truth table66%2/3
A and B
A= defined $literalB= length $literal
ABresult
0X0
100
111
794 4 ▶ return 1 if $quoted;
Branch: 1 branch
BranchTrueFalseTotal
if $quoted 3 1 4
795 }
796 781 ▶ if ($rest =~ /\A[\p{L}_][\p{L}\p{N}_]*/) { $position += length $&; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\A[\p{L}_][\p{L}\p{N}_]*/u) 303 478 781
797 478 my $char = substr($source, $position++, 1);
798 478 ▶ if ($char =~ /[({\[]/) { push @stack, $char; }
Branch: 2 branches
BranchTrueFalseTotal
if ($char =~ /[({\[]/u) { } 136 342 478
elsif (exists $close{$char}) { } 83 259 342
799 elsif (exists $close{$char}) {
800 83 ▶ return 0 unless @stack && pop(@stack) eq $close{$char}; # Let Perl report a mismatch.
Branch: 1 branch
BranchTrueFalseTotal
unless @stack and pop @stack eq $close{$char} 1 82 83
Condition66%2/3
@stack and pop @stack eq $close{$char}
!ll&&!rl&&r
0182
MC/DC50%1/2
@stack and pop @stack eq $close{$char}
@stack pop @stack eq $close{$char}
Truth table66%2/3
A and B
A= @stackB= pop @stack eq $close{$char}
ABresult
0X0
100
111
801 }
802 }
803 172 ▶ return @stack ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@stack ? : 52 120 172
804 }
805  
806 246 ▶sub _args {
Subroutine _args: called CC=5 SCAR=16.1
807 246 my ($tail, $min, $max, $usage) = @_;
808 246 my @args = shellwords($tail);
809 246 ▶ die "Usage: $usage\n" if @args < $min || @args > $max || (length($tail) && !@args);
Branch: 1 branch
BranchTrueFalseTotal
if @args < $min or @args > $max or length $tail and not @args 18 228 246
Condition88%8/9
@args < $min or @args > $max or length $tail and not @args
l!l&&r!l&&!r
171228
@args < $min or @args > $max
l!l&&r!l&&!r
017229
length $tail and not @args
!ll&&!rl&&r
931351
MC/DC75%3/4
@args < $min or @args > $max or length $tail and not @args
@args < $min @args > $max length $tail not @args
Truth table80%4/5
A or B or C and not(D)
A= @args < $minB= @args > $maxC= length $tailD= not @args
ABCDresult
1XXX1
01XX1
00111
000X0
00100
810 228 return @args;
811 }
812  
813 3 ▶sub help {
Subroutine help: called CC=1 SCAR=0.0
Pod undocumented
814 3 return <<'HELP';
815 PERL ANTE REPL V0.1 / App::AnteREPL
816 All REPL commands and subcommands must be uppercase, including DUMP and PEEK.
817 Perl keywords/functions retain their meaning. List shorthand is described below.
818 A bareword error matching a command gives an uppercase spelling hint instead.
819 Valid Perl keywords and user functions keep their normal meaning.
820 Quote filenames and values containing spaces.
821  
822 UPPERCASE COMMAND SHORTCUTS
823 A AUTO A0 AUTO OFF
824 AA AUTO ECHO ON AAA AUTO ECHO OFF
825 C CLS C1 CD / CHDIR
826 D DUMP D1 DEL / DELETE
827 E EVAL EE EDIT E2 EXPORT
828 F FUNCTIONS H HELP I IMPORT
829 L LIST L, LIST L1 LOAD
830 L2 LIST SLOW L3 LIST PAUSE
831 N NEW / CLEAR P PEEK Q QUIT / EXIT
832 R RUN R1 RENUM / REORDER
833 R2 RESET R3 RECOVER
834 S SAVE S1 STATUS U UNDO
835 V ENV V0 ENV RESET V1 ENV SET
836 V2 ENV UNSET V3 ENV EDIT / EDIT ENV
837 V4 ENV SAVE V5 ENV LOAD V6 ENV RELOAD
838  
839 Arguments keep their meaning. Examples: E say "hi", L 5-20,
840 L2 5-20 (LIST 5-20 SLOW), C1 .., V1 NAME "value", S demo.pl, Q!.
841 Space separates arguments: L1 loads a file; L 1 lists line 1.
842 Shortcuts are not expanded inside Perl
843 code or stored source. Full names still work. E also accepts definition tags.
844  
845 CONFIRMATION FOR DESTRUCTIVE SHORTCUTS
846 A shortcut that discards/replaces state asks Continue? [y/N]. Only y or yes
847 approves. Enter, No, Ctrl-D, or Esc (screen mode) cancels; Ctrl-C interrupts.
848 Add ! to skip confirmation: D1! 10-30, R2!, S! demo.pl, Q!.
849 Supported force forms: C! D1! EE! E2! I! L1! N! Q! R1! R2! R3! S! U!
850 V! V0! V1! V2! V3! V4! V5! V6!; E! for shorthand definitions only.
851 New files and new values do not ask; replacements do. Q always asks.
852 Editors prepare changes first, then ask before replacing current state.
853 Piped input cannot confirm: add ! explicitly; no following line is consumed.
854 Full command names retain their existing behavior. Arbitrary Perl in E/EVAL,
855 RUN, and shell commands has normal side effects; these are not classified.
856  
857 IMMEDIATE DEFINITIONS AND LIST SHORTHAND
858 E s name body Define a function: E s triple return 3 * shift.
859 E a name values Assign @name. E ar name values makes an arrayref $name.
860 E h name pairs Assign %name. E hr name pairs makes a hashref $name.
861 a one, two, threee Define @a containing the strings one, two, threee.
862 colors red, blue Define @colors; settings color => blue defines %settings.
863  
864 E accepts lowercase definition tags s/a/ar/h/hr, followed by a name and body.
865 E s triple return 3 * shift defines triple. EVAL always takes literal Perl.
866 For a spaced substitution, type EVAL s /old/new/. E s/old/new/ also stays Perl.
867 Names have letters, digits, underscores; no sigil, namespace, or prototype.
868 Data definitions with no values make empty containers. A function needs a body.
869 Commas separate values; => separates each hash key/value. Trailing comma OK.
870 One optional final semicolon is allowed after a data definition.
871 Plain words are quoted exactly; decimal numbers stay numbers; undef is undef.
872 'quoted text', "interpolated text", $scalar, [nested, lists], and
873 {nested => hashes} work. Quote spaces, punctuation, empty text, and leading
874 zeroes: "two words", "red-blue", "", "042". No spelling correction occurs.
875 Native quotes q{a,b}, qq{hi $name}, qw(one two), qr/pattern/, substitutions,
876 and command quotes also work as values, using Perl's normal semantics.
877 Quote operators win over word quoting: write "q", "s" for those literal words
878 next to delimiters. Other Perl expressions can go in parentheses.
879 Parenthesize Perl expressions: (1 + 2), (1..3), ($ENV{HOME}), (\%ENV).
880 They use list context in arrays, scalar context for each hash key/value.
881 Nothing is executed merely to decide how to interpret input.
882  
883 Bare destination lists need a top-level comma or => and AUTO off. Perl keywords
884 and existing functions take priority; E a colors red explicitly assigns @colors.
885 During AUTO, use explicit E forms; they execute without storing or ending AUTO.
886 Values/functions persist between entries. LIST/SAVE do not include them.
887 Open quotes/containers continue; Ctrl-N also inserts a line before submission.
888 Replacing an existing shorthand destination asks first. Forced examples:
889 E! s triple return 4 * shift; E! a colors green; colors! green, blue.
890 Functions contain ordinary Perl; approved redefinition still warns normally.
891 Outside its five reserved tags, E also evaluates Perl. EVAL always means Perl,
892 including function calls named a/ar/h/hr and declarations with prototypes.
893 Ambiguous shorthand is rejected with an explanation. Perl expressions and
894 function bodies retain Perl errors, warnings, and any side effects performed.
895  
896 ENTERING AND RUNNING PERL
897 Perl code Execute immediately, unless AUTO is active.
898 10 Perl code Insert/replace line 10; supply a missing final ;.
899 10: exact source Store one literal line without adding a semicolon.
900 10 Delete line 10. Numbers range from 1 to 999999999.
901 AUTO [start [step]] Store unnumbered source; default increment is 5.
902 Default start: 5, or highest existing number plus 5.
903 Existing numbers are skipped. Use LIST to see numbers.
904 AUTO ECHO ON|OFF Echo numbered copies of stored entries; default OFF.
905 This preference persists for the session; it does not
906 start/end AUTO. Your typed text remains visible.
907 AUTO OFF End AUTO. Ctrl-C/Ctrl-D during entry also end AUTO,
908 keeping stored lines and cancelling unfinished input.
909 : exact source In AUTO, store a literal line without continuation.
910 RUN Execute the whole stored program in numerical order.
911 Perl version declarations such as use v5.10; work
912 in RUN and EVAL. say $^V shows the running Perl.
913 EVAL code Uppercase only: execute Perl, including during AUTO.
914 EVAL leaves AUTO on. AUTO OFF resumes ordinary input.
915 EVAL do { ... } groups multiline code without storing.
916 Lowercase eval keeps Perl's normal eval semantics.
917 EVAL sub name { ... } Define a session function without storing source.
918 Immediate code and RUN can call it. SAVE excludes it.
919 Redefining warns by default and replaces the function.
920 FUNCTIONS List defined names in this workspace, alphabetically.
921 Includes imports; excludes other packages and stubs.
922 Works during AUTO; does not execute or store source.
923 ? expression Evaluate in scalar context and display the result.
924 DUMP expression Data::Dumper output: DUMP $FOO or DUMP \%ENV.
925 PEEK expression Devel::Peek internals: PEEK $FOO or PEEK $FOO, 10.
926  
927 Use $x = 1 or our $x for persistent values; my is local to one evaluation.
928 say/print display output. RUN shares package variables with immediate input.
929 Stored subroutines become callable after RUN; LOAD/LIST do not define them.
930 Open quotes, braces, brackets, or parentheses continue on the next row.
931 A closed subroutine definition, including ($) or (@), submits with Enter.
932 Ctrl-C cancels unfinished input; commands inside it are still Perl text.
933 A complete multiline AUTO entry preserves literal source: supply its final ;.
934 Numbered and AUTO colon entries stay literal, one physical line at a time.
935 Blank input does nothing. Commands remain available during AUTO.
936 For heredocs/POD/unusual Perl, use EDIT or literal numbered/colon entries.
937 DUMP and PEEK are prompt commands; stored Perl uses the module functions.
938  
939 LISTING, EDITING, AND RECOVERY
940 LIST List all source; numbers left-aligned, padded on right.
941 LIST 10 List only line 10.
942 LIST 10-50 Inclusive range. Also LIST 10-, LIST -50, LIST10-50.
943 LIST [range] SLOW Start slow. PAUSE instead pauses after each screenful.
944 Space: pause/resume; S: speed; Enter: step one row;
945 Q/Esc/Ctrl-C: stop. Other typing/movement ends LIST.
946 Plain/batch mode prints the whole range without pauses.
947 EDIT Open the program in $EDITOR, then $VISUAL, then vi
948 (notepad on Windows). Editor receives no line numbers.
949 Save and close: changed source becomes 10,20,... .
950 An unchanged file keeps its numbering. EDIT never runs
951 the source; use SAVE afterward to write the real file.
952 DEL range Delete a line/range; DELETE is an alias.
953 RENUM [start [step]] Renumber; defaults are 10 and 10. REORDER is an alias.
954 UNDO Undo a source edit (last 50), including EDIT or LOAD.
955 No rollback of executed Perl, %ENV, or file writes.
956 CLS Clear screen and resize bank; keep the
957 stored program, variables, %ENV, and AUTO.
958 No output in a pipe or on a dumb terminal.
959 RECOVER Restore the saved pre-shrink screen, only if it fits.
960 Replaces current screen text; never runs code or
961 changes stored source. Screen mode only. RECOVER has
962 no ! suffix; shortcut R3! bypasses confirmation.
963 NEW / CLEAR Clear source and its filename; retain Perl variables.
964 RESET Fresh Perl workspace; retain source and live %ENV.
965 STATUS Line count, save status, filename, and AUTO next/step.
966  
967 FILES
968 LOAD file Read ordinary Perl or numbered PERL ANTE REPL source.
969 Plain source gets numbers 10,20,... . No execution.
970 .bperl files require a valid native header. Legacy
971 BASIC PERL V0.1 headers remain supported.
972 IMPORT file Read plain Perl as an unsaved copy; no save filename.
973 SAVE [file] Save; reuse last SAVE/LOAD filename and format.
974 .pl writes plain source; .bperl writes numbered source.
975 Other extensions retain the current format.
976 EXPORT file Plain Perl plus default pragmas, for standalone use.
977 Initialize any needed variables in the source itself.
978 LOAD!, IMPORT!, NEW!, CLEAR!, QUIT!, EXIT!
979 Explicitly discard unsaved source. No other command
980 accepts this ! suffix in its full name. For shortcuts,
981 see CONFIRMATION above. SAVE/EXPORT replace their file.
982  
983 ENVIRONMENT
984 ENV [name] Display %ENV or one variable as sorted VAR=value lines.
985 ENV SET name value Set a literal value; quote spaces, e.g. 'hello world'.
986 ENV UNSET name Remove a variable. ENV SET name "" sets an empty value.
987 EDIT ENV / ENV EDIT Edit %ENV with the same editor, using VAR=value lines.
988 Save and close to replace live %ENV; removing a line
989 unsets it. Invalid input leaves the environment intact.
990 ENV SAVE file Save an environment snapshot.
991 ENV LOAD file Replace the whole environment from a snapshot file.
992 ENV RELOAD [file] Re-read the last ENV SAVE/LOAD file, or the named file.
993 ENV RESET Restore the environment inherited at startup.
994  
995 Direct Perl $ENV{NAME} assignments/deletes also work. Changes reach future
996 child commands; they cannot change the parent shell or re-read its changes.
997 Files allow blank lines, # comments, optional export, and quotes. Single
998 quotes are literal; double quotes allow \n, \r, \t, \\, \", and \xHH.
999 No $variable, backtick, or command expansion. Duplicate names/NUL are errors.
1000 Names exclude whitespace, =, #, quotes, and NUL. ENV subcommand names are
1001 reserved; inspect SET with DUMP $ENV{SET}. EDIT ENV changes memory;
1002 ENV SAVE persists it. ENV LOAD/RELOAD replace, rather than merge, %ENV.
1003  
1004 SHELL AND EXIT
1005 ! command Run a shell command; screen mode captures output with
1006 closed stdin. Examples: ! pwd, ! env, ! cat filename.
1007 !! command Give an interactive command the real terminal; press
1008 Enter afterward to return. Plain mode uses normal I/O.
1009 CD [directory] Change this session's directory; CHDIR is an alias.
1010 Quote spaces. No argument uses HOME (USERPROFILE on
1011 Windows if HOME is unset). Paths are literal.
1012 chdir '/path' Ordinary Perl also works, including chdir $ENV{HOME}.
1013 ! cd changes only its child shell's directory.
1014 HELP Display this complete reference; pause by screenful.
1015 Plain mode prints it all without pauses.
1016 QUIT / EXIT Exit on a fresh line; protect unsaved source unless !.
1017 Outside AUTO, Ctrl-D also exits if source is saved.
1018 Interactive exits print:
1019 Thank you, i hope something good happens to you today!
1020  
1021 SCREEN KEYS
1022 Arrows Move through screen text, including LIST output.
1023 Left at row start Move to the previous row's end; stop at the first row.
1024 Enter Submit selected row or its complete multiline entry.
1025 Rerunning replaces its output directly below the entry;
1026 later entries remain while they fit on screen.
1027 Cursor follows the new result.
1028 No blank spacer is added. Esc goes to fresh input.
1029 Shift-Enter / Ctrl-N Insert newline at cursor without submitting the entry.
1030 Shift-Enter needs a distinct terminal key sequence;
1031 use Ctrl-N if it behaves like ordinary Enter.
1032 Insert Toggle insert/overwrite; default is insert.
1033 Blinking bar for insert, blinking block for overwrite.
1034 The input loop blinks it every half second; terminal
1035 cursor-shape support determines bar versus block.
1036 Backspace / Delete Remove characters. Tab inserts to a 4-column tab stop.
1037 Home / End Start/end of row. PageUp/PageDown traverse screen rows.
1038 Esc / Ctrl-End Fresh blank row at bottom. Ctrl-Home: visible top row.
1039 Ctrl-U / Ctrl-L Clear current row / redraw screen.
1040 Ctrl-C Cancel input/end AUTO, or interrupt running Perl.
1041 Show a reminder of QUIT, QUIT!, and Ctrl-D to leave.
1042 Ctrl-D End AUTO/cancel input; otherwise exit if source saved.
1043  
1044 The area inside the white border is VRAM: no off-screen rows or columns.
1045 The single command legend line is outside VRAM. Type a key label and Enter;
1046 they are commands, not Ctrl-key bindings. H shows every command.
1047 An 80x24 terminal has 78x21 editable cells. CLS retains border and legend.
1048 Plain mode uses normal terminal input without this frame or cursor styling.
1049 Output scrolls old rows away. Long lines wrap; they do not scroll sideways.
1050 Shrinking crops rows/columns and warns; one inactive pre-shrink copy is kept.
1051 Growing adds empty cells, without warning or automatic recovery. Enlarge to
1052 the size named in the warning, then RECOVER if you want the saved copy back.
1053 Repeated shrinking keeps that first copy until RECOVER or CLS. It is not
1054 saved on disk. Scroll-off alone makes no backup. A clipped entry cannot run.
1055 Use EDIT for code too large for the screen. Wide/combining glyphs may misalign.
1056 Editing screen text alone changes nothing until Enter. Bracketed paste waits
1057 for Enter. GUI editors need a wait option, e.g. $ENV{EDITOR} = 'code --wait'.
1058  
1059 STARTUP
1060 anterepl [--quiet] [--plain] [program.pl|program.bperl]
1061 --quiet Hide the banner. A startup file is loaded, never run.
1062 --plain Plain input; --no-readline is an alias.
1063 --help / -h This reference. --version prints application version.
1064 -- filename Accept a startup filename beginning with a hyphen.
1065 Native Windows screen mode needs Term::ReadKey and an ANSI-capable terminal.
1066 Piped input uses plain mode; errors/incomplete or unsaved input exit nonzero.
1067  
1068 More examples: https://github.com/oodler577/p5-App-AnteREPL/wiki
1069 Offline manual: perldoc App::AnteREPL
1070 HELP
1071 }
1072  
1073 746 ▶sub dispatch {
Subroutine dispatch: called CC=66 SCAR=43.3
Pod undocumented
1074 746 my ($self, $line) = @_;
1075 746 $line =~ s/\r?\n\z//;
1076 746 ▶ return 1 if $line =~ /\A\s*\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A\s*\z/u 1 745 746
1077 745 my $definition = App::AnteREPL::Shorthand->explicit($line);
1078 723 ▶ if (defined $definition) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $definition) 36 687 723
1079 36 $self->_evaluate_definition($definition);
1080 30 return 1;
1081 }
1082 687 local $self->{shortcut_guard};
1083 687 ▶ if ($line =~ /\A\s*([A-Z]+[0-9]*)(!?)(?=\s|\z)/ && exists $short_commands{$1}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A\s*([A-Z]+[0-9]*)(!?)(?=\s|\z)/u and exists $short_commands{$1}) 132 555 687
Condition100%3/3
$line =~ /\A\s*([A-Z]+[0-9]*)(!?)(?=\s|\z)/u and exists $short_commands{$1}
!ll&&!rl&&r
325230132
MC/DC100%2/2
$line =~ /\A\s*([A-Z]+[0-9]*)(!?)(?=\s|\z)/u and exists $short_commands{$1}
$line =~ /\A\s*([A-Z]+[0-9]*)(!?)(?=\s|\z)/u exists $short_commands{$1}
Truth table100%3/3
A and B
A= $line =~ /\A\s*([A-Z]+[0-9]*)(!?)(?=\s|\z)/uB= exists $short_commands{$1}
ABresult
0X0
100
111
1084 132 my ($short, $force) = ($1, $2);
1085 132 ▶ if ($guarded_shortcuts{$short}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($guarded_shortcuts{$short}) { } 88 44 132
elsif ($force) { } 10 34 44
1086 88 $self->{shortcut_guard} = {label=>$short, force=>$force};
1087 # The shortcut layer owns confirmation and force. Do not give the
1088 # long-command parser a new force spelling of its own.
1089 88 ▶ $line =~ s/\A(\s*\Q$short\E)!/$1/ if $force;
Branch: 1 branch
BranchTrueFalseTotal
if $force 35 53 88
1090 }
1091 elsif ($force) {
1092 10 die "The ! suffix is supported only by destructive shortcuts and E! definitions.\n";
1093 }
1094 }
1095 677 $line = _expand_short_command($line);
1096 677 ▶ if ($line =~ /\A\s*LIST(?=[0-9-])(.*?)\s*\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A\s*LIST(?=[0-9-])(.*?)\s*\z/u) 2 675 677
1097 2 $self->list_program($1);
1098 1 return 1;
1099 }
1100 675 ▶ if ($line =~ /\A\s*([0-9]+):(?:[ \t]?(.*))?\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A\s*([0-9]+):(?:[ \t]?(.*))?\z/u) 8 667 675
1101 8 ▶ $self->set_line($1, defined $2 ? $2 : '', 1);
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 8 0 8
1102 8 return 1;
1103 }
1104 667 ▶ if ($line =~ /\A\s*([0-9]+)(?:[ \t](.*))?\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A\s*([0-9]+)(?:[ \t](.*))?\z/u) 82 585 667
1105 82 my ($number, $code) = ($1, $2);
1106 82 $self->set_line($number, _typed_source($code));
1107 82 return 1;
1108 }
1109 585 ▶ if ($line =~ /\A\s*(DUMP|PEEK)\b\s*(.*)\z/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A\s*(DUMP|PEEK)\b\s*(.*)\z/su) 16 569 585
1110 16 $self->inspect_value($1, $2);
1111 15 return 1;
1112 }
1113 569 ▶ if ($line =~ /\A\s*\?\s*(.*)\z/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A\s*\?\s*(.*)\z/su) 3 566 569
1114 3 my $value = $self->evaluate($1, 0);
1115 3 print Data::Dumper->new([$value])->Terse(1)->Indent(1)->Sortkeys(1)->Dump;
1116 3 return 1;
1117 }
1118 566 ▶ if ($line =~ /\A\s*(!{1,2})\s*(\S.*)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A\s*(!{1,2})\s*(\S.*)\z/u) 0 566 566
1119 0 my ($escape, $command) = ($1, $2);
1120 0 ▶ my @command = $^O eq 'MSWin32' ? ($ENV{COMSPEC} || 'cmd.exe', '/c', $command) : ('/bin/sh', '-c', $command);
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
Condition0%0/2
$ENV{"COMSPEC"} or "cmd.exe"
l!l
00
MC/DC0%0/1
$ENV{"COMSPEC"} or "cmd.exe"
$ENV{"COMSPEC"}
Truth table0%0/2
A
A= $ENV{"COMSPEC"}
Aresult
11
00
1121 my $status = $self->{screen}
1122 0 ▶ ? ($escape eq '!!' ? $self->{screen}->external(sub { system @command }, 1) : $self->{screen}->shell(\@command))
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 2 branches
BranchTrueFalseTotal
$self->{'screen'} ? : 0 0 0
$escape eq '!!' ? : 0 0 0
1123 : system @command;
1124 0 ▶ die "Cannot start shell: $!\n" if $status == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $status == -1 0 0 0
1125 0 ▶ die "Shell command failed (status $status).\n" if $status;
Branch: 1 branch
BranchTrueFalseTotal
if $status 0 0 0
1126 0 return 1;
1127 }
1128 566 ▶ if ($line =~ /\A\s*(AUTO|ENV|LIST|RUN|EDIT|DEL|DELETE|RENUM|REORDER|UNDO|SAVE|LOAD|IMPORT|EXPORT|NEW|CLEAR|CLS|RECOVER|RESET|FUNCTIONS|STATUS|HELP|QUIT|EXIT|EVAL|CD|CHDIR)(!?)(?:\s+(.*?))?\s*\z/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A\s*(AUTO|ENV|LIST|RUN|EDIT|DEL|DELETE|RENUM|REORDER|UNDO|SAVE|LOAD|IMPORT|EXPORT|NEW|CLEAR|CLS|RECOVER|RESET|FUNCTIONS|STATUS|HELP|QUIT|EXIT|EVAL|CD|CHDIR)(!?)(?:\s+(.*?))?\s*\z/su) 335 231 566
1129 335 ▶ my ($command, $force, $tail) = ($1, $2, defined $3 ? $3 : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $3 ? : 226 109 335
1130 335 ▶ die "The ! suffix is only supported by LOAD, IMPORT, NEW, CLEAR, QUIT, and EXIT.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $force and not $command =~ /\A(?:LOAD|IMPORT|NEW|CLEAR|QUIT|EXIT)\z/u 6 329 335
Condition100%3/3
$force and not $command =~ /\A(?:LOAD|IMPORT|NEW|CLEAR|QUIT|EXIT)\z/u
!ll&&!rl&&r
32276
MC/DC100%2/2
$force and not $command =~ /\A(?:LOAD|IMPORT|NEW|CLEAR|QUIT|EXIT)\z/u
$force not $command =~ /\A(?:LOAD|IMPORT|NEW|CLEAR|QUIT|EXIT)\z/u
Truth table100%3/3
A and not(B)
A= $forceB= not $command =~ /\A(?:LOAD|IMPORT|NEW|CLEAR|QUIT|EXIT)\z/u
ABresult
0X0
100
111
1131 if $force && $command !~ /\A(?:LOAD|IMPORT|NEW|CLEAR|QUIT|EXIT)\z/;
1132 329 ▶ if ($command eq 'EVAL') {
Branch: 11 branches
BranchTrueFalseTotal
if ($command eq 'EVAL') { } 64 265 329
elsif ($command eq 'AUTO') { } 43 222 265
elsif ($command eq 'ENV') { } 59 163 222
elsif ($command eq 'CD' or $command eq 'CHDIR') { } 12 151 163
elsif ($command eq 'EDIT' and $tail eq 'ENV') { } 3 148 151
elsif ($command eq 'LIST') { } 36 112 148
elsif ($command eq 'DEL' or $command eq 'DELETE') { } 10 102 112
elsif ($command eq 'RENUM' or $command eq 'REORDER') { } 3 99 102
elsif ($command eq 'SAVE') { } 5 94 99
elsif ($command eq 'LOAD' or $command eq 'IMPORT') { } 11 83 94
elsif ($command eq 'EXPORT') { } 3 80 83
1133 64 ▶ die "EVAL needs Perl code.\n" unless length $tail;
Branch: 1 branch
BranchTrueFalseTotal
unless length $tail 0 64 64
1134 64 $self->evaluate($tail, 0);
1135 }
1136 43 elsif ($command eq 'AUTO') { $self->auto_mode($tail); }
1137 59 elsif ($command eq 'ENV') { $self->environment($tail); }
1138 12 ▶ elsif ($command eq 'CD' || $command eq 'CHDIR') { $self->change_directory($tail); }
Condition100%3/3
$command eq "CD" or $command eq "CHDIR"
l!l&&r!l&&!r
75151
MC/DC100%2/2
$command eq "CD" or $command eq "CHDIR"
$command eq "CD" $command eq "CHDIR"
Truth table100%3/3
A or B
A= $command eq "CD"B= $command eq "CHDIR"
ABresult
1X1
011
000
1139 3 ▶ elsif ($command eq 'EDIT' && $tail eq 'ENV') { $self->environment('EDIT'); }
Condition100%3/3
$command eq "EDIT" and $tail eq "ENV"
!ll&&!rl&&r
14263
MC/DC100%2/2
$command eq "EDIT" and $tail eq "ENV"
$command eq "EDIT" $tail eq "ENV"
Truth table100%3/3
A and B
A= $command eq "EDIT"B= $tail eq "ENV"
ABresult
0X0
100
111
1140 elsif ($command eq 'LIST') {
1141 36 $self->list_program($tail);
1142 }
1143 ▶ elsif ($command eq 'DEL' || $command eq 'DELETE') {
Condition66%2/3
$command eq "DEL" or $command eq "DELETE"
l!l&&r!l&&!r
100102
MC/DC50%1/2
$command eq "DEL" or $command eq "DELETE"
$command eq "DEL" $command eq "DELETE"
Truth table66%2/3
A or B
A= $command eq "DEL"B= $command eq "DELETE"
ABresult
1X1
011
000
1144 10 my ($range) = _args($tail, 1, 1, 'DEL line-or-range');
1145 10 $self->delete_range($range);
1146 }
1147 ▶ elsif ($command eq 'RENUM' || $command eq 'REORDER') {
Condition66%2/3
$command eq "RENUM" or $command eq "REORDER"
l!l&&r!l&&!r
3099
MC/DC50%1/2
$command eq "RENUM" or $command eq "REORDER"
$command eq "RENUM" $command eq "REORDER"
Truth table66%2/3
A or B
A= $command eq "RENUM"B= $command eq "REORDER"
ABresult
1X1
011
000
1148 3 my @args = _args($tail, 0, 2, 'RENUM [start [step]]');
1149 3 $self->renumber(@args);
1150 }
1151 elsif ($command eq 'SAVE') {
1152 5 my ($path) = _args($tail, 0, 1, 'SAVE [file]');
1153 4 print 'Saved ', $self->save($path), ".\n";
1154 }
1155 ▶ elsif ($command eq 'LOAD' || $command eq 'IMPORT') {
Condition100%3/3
$command eq "LOAD" or $command eq "IMPORT"
l!l&&r!l&&!r
7483
MC/DC100%2/2
$command eq "LOAD" or $command eq "IMPORT"
$command eq "LOAD" $command eq "IMPORT"
Truth table100%3/3
A or B
A= $command eq "LOAD"B= $command eq "IMPORT"
ABresult
1X1
011
000
1156 11 my ($path) = _args($tail, 1, 1, "$command file");
1157 11 ▶ my $count = $command eq 'LOAD' ? $self->load($path, $force) : $self->import_source($path, $force);
Branch: 1 branch
BranchTrueFalseTotal
$command eq 'LOAD' ? : 7 4 11
1158 6 print "Loaded $count lines.\n";
1159 }
1160 elsif ($command eq 'EXPORT') {
1161 3 my ($path) = _args($tail, 1, 1, 'EXPORT file');
1162 3 print 'Exported ', $self->export_source($path), ".\n";
1163 }
1164 else {
1165 80 _args($tail, 0, 0, $command);
1166 75 ▶ if ($command eq 'RUN') { $self->run; }
Branch: 11 branches
BranchTrueFalseTotal
if ($command eq 'RUN') { } 12 63 75
elsif ($command eq 'EDIT') { } 4 59 63
elsif ($command eq 'UNDO') { } 3 56 59
elsif ($command eq 'CLS') { } 7 49 56
elsif ($command eq 'RECOVER') { } 5 44 49
elsif ($command eq 'NEW' or $command eq 'CLEAR') { } 10 34 44
elsif ($command eq 'RESET') { } 5 29 34
elsif ($command eq 'FUNCTIONS') { } 7 22 29
elsif ($command eq 'STATUS') { } 1 21 22
elsif ($command eq 'HELP') { } 2 19 21
elsif ($command eq 'QUIT' or $command eq 'EXIT') { } 19 0 19
1167 elsif ($command eq 'EDIT') {
1168 4 ▶ print $self->edit ? "Program updated; lines numbered 10,20,...\n" : "Program unchanged.\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->edit ? : 2 1 3
1169 }
1170 3 elsif ($command eq 'UNDO') { $self->undo; print "Program edit undone.\n"; }
1171 7 elsif ($command eq 'CLS') { $self->clear_screen; }
1172 5 elsif ($command eq 'RECOVER') { $self->recover_screen; }
1173 10 ▶ elsif ($command eq 'NEW' || $command eq 'CLEAR') { $self->clear($force); }
Condition100%3/3
$command eq "NEW" or $command eq "CLEAR"
l!l&&r!l&&!r
9134
MC/DC100%2/2
$command eq "NEW" or $command eq "CLEAR"
$command eq "NEW" $command eq "CLEAR"
Truth table100%3/3
A or B
A= $command eq "NEW"B= $command eq "CLEAR"
ABresult
1X1
011
000
1174 5 elsif ($command eq 'RESET') { $self->reset_workspace; print "Perl workspace reset; program retained.\n"; }
1175 elsif ($command eq 'FUNCTIONS') {
1176 7 my @names = $self->function_names;
1177 7 ▶ print @names ? join('', map { "$_\n" } @names)
Branch: 1 branch
BranchTrueFalseTotal
@names ? : 5 2 7
1178 : "No functions defined in this workspace.\n";
1179 }
1180 elsif ($command eq 'STATUS') {
1181 1 my @numbers = $self->numbers;
1182 print scalar(@numbers), ' lines; ', ($self->dirty ? 'unsaved changes' : 'unchanged'),
1183 1 ▶ '; ', (defined $self->{filename} ? $self->{filename} : 'no save filename'), ".\n";
Branch: 2 branches
BranchTrueFalseTotal
$self->dirty ? : 1 0 1
defined $self->{'filename'} ? : 0 1 1
1184 1 ▶ print "AUTO next $self->{auto}{next}, step $self->{auto}{step}.\n" if $self->{auto};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"auto"} 0 1 1
1185 }
1186 elsif ($command eq 'HELP') {
1187 2 ▶ if ($self->{screen}) { $self->{screen}->list_rows([split /\n/, help()], 0, 'pause', 'HELP'); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'screen'}) { } 2 0 2
1188 0 else { print help(); }
1189 }
1190 ▶ elsif ($command eq 'QUIT' || $command eq 'EXIT') {
Condition66%2/3
$command eq "QUIT" or $command eq "EXIT"
l!l&&r!l&&!r
1720
MC/DC0%0/2
$command eq "QUIT" or $command eq "EXIT"
$command eq "QUIT" $command eq "EXIT"
Truth table66%2/3
A or B
A= $command eq "QUIT"B= $command eq "EXIT"
ABresult
1X1
011
000
1191 19 $self->_confirm_destructive('Exit the REPL and discard its live workspace and any unsaved source');
1192 15 $self->_guard('QUIT', $force);
1193 14 return 0;
1194 }
1195 }
1196 226 return 1;
1197 }
1198 231 ▶ my $implicit = App::AnteREPL::Shorthand->implicit($line, sub { $self->_has_function($_[0]) });
Subroutine __ANON__: called CC=1 SCAR=0.0
1199 229 ▶ if (defined $implicit) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $implicit) { } 9 220 229
elsif ($self->{'auto'}) { } 27 193 220
1200 die "List shorthand is immediate input. Try E a name values or E h name pairs during AUTO, or A0 first.\n"
1201 9 ▶ if $self->{auto};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"auto"} 1 8 9
1202 8 $self->_evaluate_definition($implicit);
1203 }
1204 27 elsif ($self->{auto}) { $self->auto_store($line); }
1205 else {
1206 193 local $@;
1207 193 my $ok = eval { $self->evaluate($line, 0); 1 };
1208 193 ▶ die $self->_command_case_error($line, $@) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 19 174 193
1209 }
1210 207 return 1;
1211 }
1212  
1213 12 ▶sub main {
Subroutine main: called CC=40 SCAR=52.7
Pod undocumented
1214 12 my @args = @_;
1215 12 my ($quiet, $plain, $filename);
1216 12 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 14 12 26
1217 14 my $arg = shift @args;
1218 14 ▶ if ($arg eq '--help' || $arg eq '-h') {
Branch: 6 branches
BranchTrueFalseTotal
if ($arg eq '--help' or $arg eq '-h') { } 0 14 14
elsif ($arg eq '--version') { } 0 14 14
elsif ($arg eq '--quiet') { } 12 2 14
elsif ($arg eq '--plain' or $arg eq '--no-readline') { } 2 0 2
elsif ($arg eq '--') { } 0 0 0
elsif ($arg =~ /^-/u or defined $filename) { } 0 0 0
Condition33%1/3
$arg eq "--help" or $arg eq "-h"
l!l&&r!l&&!r
0014
MC/DC0%0/2
$arg eq "--help" or $arg eq "-h"
$arg eq "--help" $arg eq "-h"
Truth table33%1/3
A or B
A= $arg eq "--help"B= $arg eq "-h"
ABresult
1X1
011
000
1219 0 print "Usage: anterepl [--quiet] [--plain] [program.pl|program.bperl]\n\n", help();
1220 0 return 0;
1221 }
1222 0 elsif ($arg eq '--version') { print "App::AnteREPL $VERSION (PERL ANTE REPL V$PROGRAM_VERSION)\n"; return 0; }
1223 12 elsif ($arg eq '--quiet') { $quiet = 1; }
1224 2 ▶ elsif ($arg eq '--plain' || $arg eq '--no-readline') { $plain = 1; }
Condition33%1/3
$arg eq "--plain" or $arg eq "--no-readline"
l!l&&r!l&&!r
200
MC/DC0%0/2
$arg eq "--plain" or $arg eq "--no-readline"
$arg eq "--plain" $arg eq "--no-readline"
Truth table33%1/3
A or B
A= $arg eq "--plain"B= $arg eq "--no-readline"
ABresult
1X1
011
000
1225 elsif ($arg eq '--') {
1226 0 ▶ die "Only one startup file is supported.\n" if defined $filename || @args != 1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $filename or @args != 1 0 0 0
Condition0%0/3
defined $filename or @args != 1
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $filename or @args != 1
defined $filename @args != 1
Truth table0%0/3
A or B
A= defined $filenameB= @args != 1
ABresult
1X1
011
000
1227 0 $filename = shift @args;
1228 }
1229 0 ▶ elsif ($arg =~ /^-/ || defined $filename) { die "Usage: anterepl [--quiet] [--plain] [program.bperl]\n"; }
Condition0%0/3
$arg =~ /^-/u or defined $filename
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg =~ /^-/u or defined $filename
$arg =~ /^-/u defined $filename
Truth table0%0/3
A or B
A= $arg =~ /^-/uB= defined $filename
ABresult
1X1
011
000
1230 0 else { $filename = $arg; }
1231 }
1232 12 binmode STDIN, ':encoding(UTF-8)';
1233 12 binmode STDOUT, ':encoding(UTF-8)';
1234 12 binmode STDERR, ':encoding(UTF-8)';
1235 12 $| = 1;
1236 12 my $self = __PACKAGE__->new;
1237 12 ▶ $self->load($filename, 1) if defined $filename;
Branch: 1 branch
BranchTrueFalseTotal
if defined $filename 0 12 12
1238 12 ▶ my $interactive = -t STDIN && -t STDOUT;
Condition33%1/3
-t STDIN && -t STDOUT
!ll&&!rl&&r
1200
MC/DC0%0/2
-t STDIN && -t STDOUT
-t STDIN -t STDOUT
Truth table33%1/3
A && B
A= -t STDINB= -t STDOUT
ABresult
0X0
100
111
1239 12 $self->{interactive} = $interactive;
1240 12 ▶ if ($interactive && !$plain && ($ENV{TERM} || '') ne 'dumb') {
Branch: 1 branch
BranchTrueFalseTotal
if ($interactive and not $plain and ($ENV{"TERM"} || "") ne "dumb") 0 12 12
Condition25%2/8
$interactive and not $plain and ($ENV{"TERM"} || "") ne "dumb"
!ll&&!rl&&r
1200
$interactive and not $plain
!ll&&!rl&&r
1200
$ENV{'TERM'} || ''
l!l
00
MC/DC0%0/3
$interactive and not $plain and ($ENV{"TERM"} || "") ne "dumb"
$interactive not $plain $ENV{'TERM'}
Truth table25%1/4
A and not(B) and C
A= $interactiveB= not $plainC= $ENV{'TERM'}
ABCresult
0XX0
10X0
1100
1111
1241 0 my $screen = eval { App::AnteREPL::Screen->terminal };
1242 0 ▶ if ($screen) { return $screen->session($self, $quiet); }
Branch: 1 branch
BranchTrueFalseTotal
if ($screen) 0 0 0
1243 0 print STDERR "Screen editing unavailable: $@";
1244 0 print STDERR "Using plain input without a prompt.\n";
1245 }
1246 12 ▶ print "*** PERL ANTE REPL V$PROGRAM_VERSION ***\nType HELP for commands.\n" unless $quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $quiet 0 12 12
1247 12 my $had_error = 0;
1248 12 while (1) {
1249 36 my ($line, $read_ok);
1250 {
1251 0 ▶ local $SIG{INT} = sub { die "Interrupted.\n" };
Subroutine __ANON__: not called CC=1 SCAR=0.4
1252 36 $read_ok = eval {
1253 36 $line = <STDIN>;
1254 36 ▶ while (defined $line && $self->input_needs_more($line)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line and $self->input_needs_more($line)) 2 36 38
Condition100%3/3
defined $line and $self->input_needs_more($line)
!ll&&!rl&&r
2342
MC/DC100%2/2
defined $line and $self->input_needs_more($line)
defined $line $self->input_needs_more($line)
Truth table100%3/3
A and B
A= defined $lineB= $self->input_needs_more($line)
ABresult
0X0
100
111
1255 2 my $next = <STDIN>;
1256 2 ▶ if (!defined $next && $interactive && $self->{auto}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $next and $interactive and $self->{"auto"}) 0 2 2
Condition33%2/6
not defined $next and $interactive and $self->{"auto"}
!ll&&!rl&&r
200
not defined $next and $interactive
!ll&&!rl&&r
200
MC/DC0%0/3
not defined $next and $interactive and $self->{"auto"}
not defined $next $interactive $self->{"auto"}
Truth table25%1/4
not(A) and B and C
A= not defined $nextB= $interactiveC= $self->{"auto"}
ABCresult
0XX0
10X0
1100
1111
1257 0 $line = undef;
1258 0 last;
1259 }
1260 2 ▶ die "Incomplete Perl entry at end of input.\n" unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 0 2 2
1261 2 $line .= $next;
1262 }
1263 36 1;
1264 };
1265 }
1266 36 ▶ if (!$read_ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($read_ok) 0 36 36
1267 0 my $error = $@;
1268 0 ▶ print STDERR "AUTO off.\n" if delete $self->{auto};
Branch: 1 branch
BranchTrueFalseTotal
if delete $self->{"auto"} 0 0 0
1269 0 print STDERR _input_error($error);
1270 0 $had_error = 1;
1271 0 next;
1272 }
1273 36 ▶ if (!defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line) 2 34 36
1274 2 ▶ STDIN->clearerr if $interactive;
Branch: 1 branch
BranchTrueFalseTotal
if $interactive 0 2 2
1275 2 ▶ if ($interactive && $self->{auto}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interactive and $self->{"auto"}) 0 2 2
Condition33%1/3
$interactive and $self->{"auto"}
!ll&&!rl&&r
200
MC/DC0%0/2
$interactive and $self->{"auto"}
$interactive $self->{"auto"}
Truth table33%1/3
A and B
A= $interactiveB= $self->{"auto"}
ABresult
0X0
100
111
1276 0 $self->auto_mode('OFF');
1277 0 next;
1278 }
1279 2 ▶ if ($self->dirty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dirty) 2 0 2
1280 2 print STDERR "Unsaved program. Use SAVE or QUIT! to discard it.\n";
1281 0 ▶ if ($interactive) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($interactive) 0 2 2
1282 2 return 1;
1283 }
1284 0 last;
1285 }
1286 34 my $continue;
1287 34 my $ok = eval { $continue = $self->dispatch($line); 1 };
1288 34 ▶ if (!$ok) { print STDERR _input_error($@); $had_error = 1; next; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 2 32 34
1289 32 ▶ if (!$continue) { print "\n" unless $interactive; last; }
Branch: 2 branches
BranchTrueFalseTotal
unless ($continue) 10 22 32
unless $interactive 10 0 10
1290 }
1291 10 ▶ print "\n$FAREWELL\n" if $interactive;
Branch: 1 branch
BranchTrueFalseTotal
if $interactive 0 10 10
1292 10 ▶ return $interactive ? 0 : $had_error;
Branch: 1 branch
BranchTrueFalseTotal
$interactive ? : 0 10 10
1293 }
1294  
1295 package App::AnteREPL::Screen;
1296 25 ▶use Encode qw(decode FB_DEFAULT);
Subroutine BEGIN: called CC=1 SCAR=0.0
1297 25 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
1298 25 our $active;
1299  
1300 43 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
1301 43 return bless { rows => [{ text => '' }], row => 0, col => 0, top => 0,
1302 left => 0, width => 80, height => 24, serial => 0, insert => 1 }, $_[0];
1303 }
1304  
1305 0 ▶sub terminal {
Subroutine terminal: not called CC=8 SCAR=42.8
1306 0 my ($class) = @_;
1307 0 my $self = $class->new;
1308 0 ▶ open $self->{in}, '<&', \*STDIN or die "Cannot duplicate terminal input: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"in"}, "<&", \*STDIN or die "Cannot duplicate terminal input: $!\n" 0 0 0
1309 0 ▶ open $self->{out}, '>&', \*STDOUT or die "Cannot duplicate terminal output: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"out"}, ">&", \*STDOUT or die "Cannot duplicate terminal output: $!\n" 0 0 0
1310 0 ▶ open $self->{err}, '>&', \*STDERR or die "Cannot duplicate terminal errors: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"err"}, ">&", \*STDERR or die "Cannot duplicate terminal errors: $!\n" 0 0 0
1311 0 binmode $self->{in}, ':raw';
1312 0 binmode $self->{out}, ':encoding(UTF-8)';
1313 0 $self->{out}->autoflush(1);
1314 0 ▶ if (eval { require Term::ReadKey; 1 }) { $self->{backend} = 'readkey'; }
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Term::ReadKey; 1 } }) { } 0 0 0
1315 else {
1316 0 ▶ die "Install Term::ReadKey for native Windows screen editing (cpanm Term::ReadKey).\n" if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 0 0
1317 0 require POSIX;
1318 0 $self->{backend} = 'posix';
1319 0 my $saved = POSIX::Termios->new;
1320 0 ▶ $saved->getattr(fileno($self->{in})) or die "Cannot read terminal settings: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
$saved->getattr(fileno $self->{"in"}) or die "Cannot read terminal settings: $!\n" 0 0 0
1321 0 $self->{saved_term} = $saved;
1322 0 my $raw = POSIX::Termios->new;
1323 0 $raw->getattr(fileno($self->{in}));
1324 0 $raw->setlflag($raw->getlflag & ~(POSIX::ICANON() | POSIX::ECHO() | POSIX::ECHONL()));
1325 0 $raw->setiflag($raw->getiflag & ~POSIX::IXON());
1326 0 $raw->setcc(POSIX::VMIN(), 1);
1327 0 $raw->setcc(POSIX::VTIME(), 0);
1328 0 $self->{raw_term} = $raw;
1329 0 ▶ eval { require 'sys/ioctl.ph'; $self->{winsize} = &TIOCGWINSZ if defined &TIOCGWINSZ; };
Branch: 1 branch
BranchTrueFalseTotal
if defined &App::AnteREPL::Screen::TIOCGWINSZ 0 0 0
1330 }
1331 0 return $self;
1332 }
1333  
1334 941 ▶sub dimensions {
Subroutine dimensions: called CC=9 SCAR=41.9
1335 941 my ($self) = @_;
1336 941 ▶ return unless $self->{in};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"in"} 941 0 941
1337 0 my ($width, $height);
1338 0 ▶ if ($self->{backend} eq 'readkey') {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'backend'} eq 'readkey') { } 0 0 0
elsif ($self->{'winsize'}) { } 0 0 0
1339 0 ($width, $height) = eval { Term::ReadKey::GetTerminalSize($self->{out}) };
1340 }
1341 elsif ($self->{winsize}) {
1342 0 my $size = pack('S4', 0, 0, 0, 0);
1343 0 ▶ ($height, $width) = unpack('S4', $size) if ioctl($self->{in}, $self->{winsize}, $size);
Branch: 1 branch
BranchTrueFalseTotal
if ioctl $self->{"in"}, $self->{"winsize"}, $size 0 0 0
1344 }
1345 $self->terminal_size($width || $self->{terminal_width} || 80,
1346 0 ▶ $height || $self->{terminal_height} || 24);
Condition0%0/10
$width || $self->{'terminal_width'} || 80
l!l
00
$width or $self->{"terminal_width"}
l!l&&r!l&&!r
000
$height || $self->{'terminal_height'} || 24
l!l
00
$height or $self->{"terminal_height"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$width || $self->{'terminal_width'} || 80
$width $self->{"terminal_width"}
MC/DC0%0/2
$height || $self->{'terminal_height'} || 24
$height $self->{"terminal_height"}
Truth table0%0/3
A or B
A= $widthB= $self->{"terminal_width"}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $heightB= $self->{"terminal_height"}
ABresult
1X1
011
000
1347 }
1348  
1349 9 ▶sub terminal_size {
Subroutine terminal_size: called CC=8 SCAR=20.8
1350 9 my ($self, $width, $height) = @_;
1351 9 my ($old_width, $old_height) = @{$self}{qw(terminal_width terminal_height)};
1352 9 ▶ my $framed = $width >= 3 && $height >= 4;
Condition100%3/3
$width >= 3 && $height >= 4
!ll&&!rl&&r
216
MC/DC100%2/2
$width >= 3 && $height >= 4
$width >= 3 $height >= 4
Truth table100%3/3
A && B
A= $width >= 3B= $height >= 4
ABresult
0X0
100
111
1353 9 @{$self}{qw(terminal_width terminal_height framed)} = ($width, $height, $framed);
1354 9 ▶ delete $self->{last_frame} if !defined $old_width || $old_width != $width || $old_height != $height;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $old_width or $old_width != $width or $old_height != $height 9 0 9
Condition83%5/6
not defined $old_width or $old_width != $width or $old_height != $height
l!l&&r!l&&!r
810
not defined $old_width or $old_width != $width
l!l&&r!l&&!r
351
MC/DC0%0/3
not defined $old_width or $old_width != $width or $old_height != $height
not defined $old_width $old_width != $width $old_height != $height
Truth table75%3/4
not(A) or B or C
A= not defined $old_widthB= $old_width != $widthC= $old_height != $height
ABCresult
1XX1
01X1
0011
0000
1355 # Keep the reservation even when too small to draw it, so enlarging a tiny
1356 # terminal never reduces VRAM when the frame becomes visible again.
1357 9 ▶ my ($inner_width, $inner_height) = ($width > 2 ? $width - 2 : 1, $height > 3 ? $height - 3 : 1);
Branch: 2 branches
BranchTrueFalseTotal
$width > 2 ? : 7 2 9
$height > 3 ? : 7 2 9
1358 9 ▶ if (!$self->{size_seen}++) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'size_seen'}++) { } 3 6 9
1359 3 @{$self}{qw(width height)} = ($inner_width, $inner_height);
1360 3 $self->_fit;
1361 }
1362 6 else { $self->resize($inner_width, $inner_height, $old_width, $old_height); }
1363 }
1364  
1365 # Only these rows are active screen memory. There is no off-screen viewport.
1366 # Soft rows wrap one source line; group joins explicit multiline input.
1367 62 ▶sub _discard_rows {
Subroutine _discard_rows: called CC=21 SCAR=30.6
1368 62 my ($self, $start, $count) = @_;
1369 62 ▶ return unless $count;
Branch: 1 branch
BranchTrueFalseTotal
unless $count 2 60 62
1370 60 my @gone = splice @{ $self->{rows} }, $start, $count;
1371 60 ▶ my %groups = map { $_->{group} ? ($_->{group} => 1) : () } @gone;
Branch: 1 branch
BranchTrueFalseTotal
$_->{'group'} ? : 2 154 156
1372 60 ▶ $_->{clipped} = 1 for grep { $_->{group} && $groups{$_->{group}} } @{ $self->{rows} };
Condition66%2/3
$_->{'group'} && $groups{$_->{'group'}}
!ll&&!rl&&r
73403
MC/DC50%1/2
$_->{'group'} && $groups{$_->{'group'}}
$_->{'group'} $groups{$_->{'group'}}
Truth table66%2/3
A && B
A= $_->{'group'}B= $groups{$_->{'group'}}
ABresult
0X0
100
111
1373 60 ▶ if ($start == 0 && $self->{rows}[0] && delete $self->{rows}[0]{soft}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($start == 0 and $self->{'rows'}[0] and delete $self->{'rows'}[0]{'soft'}) { } 1 59 60
elsif ($start and $gone[0]{'soft'} and $self->{'rows'}[$start - 1]) { } 1 116 117
Condition83%5/6
$start == 0 and $self->{"rows"}[0] and delete $self->{"rows"}[0]{"soft"}
!ll&&!rl&&r
7521
$start == 0 and $self->{"rows"}[0]
!ll&&!rl&&r
7053
MC/DC66%2/3
$start == 0 and $self->{"rows"}[0] and delete $self->{"rows"}[0]{"soft"}
$start == 0 $self->{"rows"}[0] delete $self->{"rows"}[0]{"soft"}
Truth table75%3/4
A and B and C
A= $start == 0B= $self->{"rows"}[0]C= delete $self->{"rows"}[0]{"soft"}
ABCresult
0XX0
10X0
1100
1111
1374 1 $self->{rows}[0]{clipped} = 1;
1375 }
1376 ▶ elsif ($start && $gone[0]{soft} && $self->{rows}[$start - 1]) {
Condition83%5/6
$start and $gone[0]{"soft"} and $self->{"rows"}[$start - 1]
!ll&&!rl&&r
5801
$start and $gone[0]{"soft"}
!ll&&!rl&&r
5261
MC/DC66%2/3
$start and $gone[0]{"soft"} and $self->{"rows"}[$start - 1]
$start $gone[0]{"soft"} $self->{"rows"}[$start - 1]
Truth table75%3/4
A and B and C
A= $startB= $gone[0]{"soft"}C= $self->{"rows"}[$start - 1]
ABCresult
0XX0
10X0
1100
1111
1377 1 $self->{rows}[$start - 1]{clipped} = 1;
1378 }
1379 60 for my $key (qw(row output_row data_row)) {
1380 180 ▶ next unless defined $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 106 74 180
1381 74 my $old = $self->{$key};
1382 74 ▶ $self->{data_lost} = 1 if $key eq 'data_row' && $old >= $start && $old < $start + $count;
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "data_row" and $old >= $start and $old < $start + $count 1 73 74
Condition66%4/6
$key eq "data_row" and $old >= $start and $old < $start + $count
!ll&&!rl&&r
7301
$key eq "data_row" and $old >= $start
!ll&&!rl&&r
7301
MC/DC33%1/3
$key eq "data_row" and $old >= $start and $old < $start + $count
$key eq "data_row" $old >= $start $old < $start + $count
Truth table50%2/4
A and B and C
A= $key eq "data_row"B= $old >= $startC= $old < $start + $count
ABCresult
0XX0
10X0
1100
1111
1383 74 ▶ $self->{$key} -= $count if $old >= $start + $count;
Branch: 1 branch
BranchTrueFalseTotal
if $old >= $start + $count 64 10 74
1384 74 ▶ $self->{$key} = $start if $old >= $start && $old < $start + $count;
Branch: 1 branch
BranchTrueFalseTotal
if $old >= $start and $old < $start + $count 6 68 74
Condition100%3/3
$old >= $start and $old < $start + $count
!ll&&!rl&&r
4646
MC/DC100%2/2
$old >= $start and $old < $start + $count
$old >= $start $old < $start + $count
Truth table100%3/3
A and B
A= $old >= $startB= $old < $start + $count
ABresult
0X0
100
111
1385 74 ▶ $self->{$key} = $#{ $self->{rows} } if $self->{$key} > $#{ $self->{rows} };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$key} > $#{$$self{"rows"};} 5 69 74
1386 74 ▶ $self->{$key} = 0 if $self->{$key} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$key} < 0 0 74 74
1387 }
1388 }
1389  
1390 3014 ▶sub _fit {
Subroutine _fit: called CC=23 SCAR=31.7
1391 3014 my ($self) = @_;
1392 3014 my ($w, $h) = @{$self}{qw(width height)};
1393 3014 ▶ for (my $i = 0; $i < @{ $self->{rows} }; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$self->{"rows"};}) 11538 3014 14552
1394 11538 my $row = $self->{rows}[$i];
1395 next unless length($row->{text}) > $w
1396 11538 ▶ || ($self->{row} == $i && $self->{col} >= $w);
Branch: 1 branch
BranchTrueFalseTotal
unless length $row->{"text"} > $w or $self->{"row"} == $i and $self->{"col"} >= $w 11482 56 11538
Condition100%6/6
length $row->{"text"} > $w or $self->{"row"} == $i and $self->{"col"} >= $w
l!l&&r!l&&!r
451111482
$self->{"row"} == $i and $self->{"col"} >= $w
!ll&&!rl&&r
8469301311
MC/DC100%3/3
length $row->{"text"} > $w or $self->{"row"} == $i and $self->{"col"} >= $w
length $row->{"text"} > $w $self->{"row"} == $i $self->{"col"} >= $w
Truth table100%4/4
A or B and C
A= length $row->{"text"} > $wB= $self->{"row"} == $iC= $self->{"col"} >= $w
ABCresult
1XX1
0111
00X0
0100
1397 56 my $tail = substr($row->{text}, $w, length($row->{text}), '');
1398 56 my $next = $self->{rows}[$i + 1];
1399 56 ▶ if ($next && $next->{soft}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next and $next->{'soft'}) { } 3 53 56
Condition100%3/3
$next and $next->{"soft"}
!ll&&!rl&&r
11423
MC/DC100%2/2
$next and $next->{"soft"}
$next $next->{"soft"}
Truth table100%3/3
A and B
A= $nextB= $next->{"soft"}
ABresult
0X0
100
111
1400 3 $next->{text} = $tail . $next->{text};
1401 3 ▶ $self->{col} += length $tail if $self->{row} == $i + 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"row"} == $i + 1 0 3 3
1402 3 ▶ $self->{data_col} += length $tail if defined $self->{data_row} && $self->{data_row} == $i + 1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"data_row"} and $self->{"data_row"} == $i + 1 0 3 3
Condition66%2/3
defined $self->{"data_row"} and $self->{"data_row"} == $i + 1
!ll&&!rl&&r
210
MC/DC0%0/2
defined $self->{"data_row"} and $self->{"data_row"} == $i + 1
defined $self->{"data_row"} $self->{"data_row"} == $i + 1
Truth table66%2/3
A and B
A= defined $self->{"data_row"}B= $self->{"data_row"} == $i + 1
ABresult
0X0
100
111
1403 }
1404 else {
1405 53 my %copy = %$row;
1406 53 delete $copy{list_width};
1407 53 splice @{ $self->{rows} }, $i + 1, 0, { %copy, text => $tail, soft => 1 };
1408 53 ▶ ++$self->{$_} for grep { defined $self->{$_} && $self->{$_} > $i } qw(row output_row data_row);
Condition100%3/3
defined $self->{$_} && $self->{$_} > $i
!ll&&!rl&&r
1011642
MC/DC100%2/2
defined $self->{$_} && $self->{$_} > $i
defined $self->{$_} $self->{$_} > $i
Truth table100%3/3
A && B
A= defined $self->{$_}B= $self->{$_} > $i
ABresult
0X0
100
111
1409 }
1410 56 ▶ if ($self->{row} == $i && $self->{col} >= $w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"row"} == $i and $self->{"col"} >= $w) 11 45 56
Condition100%3/3
$self->{"row"} == $i and $self->{"col"} >= $w
!ll&&!rl&&r
44111
MC/DC100%2/2
$self->{"row"} == $i and $self->{"col"} >= $w
$self->{"row"} == $i $self->{"col"} >= $w
Truth table100%3/3
A and B
A= $self->{"row"} == $iB= $self->{"col"} >= $w
ABresult
0X0
100
111
1411 11 ++$self->{row}; $self->{col} -= $w;
1412 }
1413 56 ▶ if (defined $self->{data_row} && $self->{data_row} == $i && $self->{data_col} >= $w) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"data_row"} and $self->{"data_row"} == $i and $self->{"data_col"} >= $w) 0 56 56
Condition83%5/6
defined $self->{"data_row"} and $self->{"data_row"} == $i and $self->{"data_col"} >= $w
!ll&&!rl&&r
5240
defined $self->{"data_row"} and $self->{"data_row"} == $i
!ll&&!rl&&r
5024
MC/DC0%0/3
defined $self->{"data_row"} and $self->{"data_row"} == $i and $self->{"data_col"} >= $w
defined $self->{"data_row"} $self->{"data_row"} == $i $self->{"data_col"} >= $w
Truth table75%3/4
A and B and C
A= defined $self->{"data_row"}B= $self->{"data_row"} == $iC= $self->{"data_col"} >= $w
ABCresult
0XX0
10X0
1100
1111
1414 0 ++$self->{data_row}; $self->{data_col} -= $w;
1415 }
1416 56 ▶ $self->{output_row} = $self->{row} if defined $self->{output_row};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"output_row"} 0 56 56
1417 }
1418 3014 my $excess = @{ $self->{rows} } - $h;
1419 3014 ▶ if ($excess > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($excess > 0) 55 2959 3014
1420 55 my $head = $self->{row} - $h + 1;
1421 55 ▶ $head = 0 if $head < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $head < 0 2 53 55
1422 55 ▶ $head = $excess if $head > $excess;
Branch: 1 branch
BranchTrueFalseTotal
if $head > $excess 0 55 55
1423 55 $self->_discard_rows(0, $head);
1424 55 ▶ $self->_discard_rows($h, @{ $self->{rows} } - $h) if @{ $self->{rows} } > $h;
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"rows"};} > $h 2 53 55
1425 }
1426 $self->{col} = length($self->{rows}[$self->{row}]{text})
1427 3014 ▶ if $self->{col} > length($self->{rows}[$self->{row}]{text});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"col"} > length $self->{"rows"}[$self->{"row"}]{"text"} 0 3014 3014
1428 3014 $self->{top} = $self->{left} = 0;
1429 }
1430  
1431 13 ▶sub resize {
Subroutine resize: called CC=19 SCAR=30.1
1432 13 my ($self, $width, $height, $terminal_width, $terminal_height) = @_;
1433 13 ▶ return if $width < 1 || $height < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $width < 1 or $height < 1 0 13 13
Condition33%1/3
$width < 1 or $height < 1
l!l&&r!l&&!r
0013
MC/DC0%0/2
$width < 1 or $height < 1
$width < 1 $height < 1
Truth table33%1/3
A or B
A= $width < 1B= $height < 1
ABresult
1X1
011
000
1434 13 ▶ return if $width == $self->{width} && $height == $self->{height};
Branch: 1 branch
BranchTrueFalseTotal
if $width == $self->{"width"} and $height == $self->{"height"} 2 11 13
Condition66%2/3
$width == $self->{"width"} and $height == $self->{"height"}
!ll&&!rl&&r
1102
MC/DC50%1/2
$width == $self->{"width"} and $height == $self->{"height"}
$width == $self->{"width"} $height == $self->{"height"}
Truth table66%2/3
A and B
A= $width == $self->{"width"}B= $height == $self->{"height"}
ABresult
0X0
100
111
1435 11 ▶ my $shrink = $width < $self->{width} || $height < $self->{height};
Condition66%2/3
$width < $self->{'width'} || $height < $self->{'height'}
l!l&&r!l&&!r
803
MC/DC50%1/2
$width < $self->{'width'} || $height < $self->{'height'}
$width < $self->{'width'} $height < $self->{'height'}
Truth table66%2/3
A || B
A= $width < $self->{'width'}B= $height < $self->{'height'}
ABresult
1X1
011
000
1436 11 ▶ if ($shrink) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shrink) 8 3 11
1437 # Keep the first unclaimed snapshot through repeated resize events.
1438 $self->{resize_bank} ||= { width=>$self->{width}, height=>$self->{height},
1439 terminal_width=>$terminal_width || $self->{width},
1440 terminal_height=>$terminal_height || $self->{height},
1441 8 ▶ row=>$self->{row}, col=>$self->{col}, rows=>[map { +{%$_} } @{ $self->{rows} }] };
Condition75%6/8
$self->{"resize_bank"} ||= {"width", $self->{"width"}, "height", $self->{"height"}, "terminal_width", $terminal_width || $self->{"width"}, "terminal_height", $terminal_height || $self->{"height"}, "row", $self->{"row"}, "col", $self->{"col"}, "rows", [map({+{%$_};} @{$$self{"rows"};})]}
l!l
26
$terminal_width || $self->{'width'}
l!l&&r!l&&!r
240
$terminal_height || $self->{'height'}
l!l&&r!l&&!r
240
MC/DC100%1/1
$self->{"resize_bank"} ||= {"width", $self->{"width"}, "height", $self->{"height"}, "terminal_width", $terminal_width || $self->{"width"}, "terminal_height", $terminal_height || $self->{"height"}, "row", $self->{"row"}, "col", $self->{"col"}, "rows", [map({+{%$_};} @{$$self{"rows"};})]}
$self->{"resize_bank"}
MC/DC0%0/2
$terminal_width || $self->{'width'}
$terminal_width $self->{'width'}
MC/DC0%0/2
$terminal_height || $self->{'height'}
$terminal_height $self->{'height'}
Truth table100%2/2
A
A= $self->{"resize_bank"}
Aresult
11
00
Truth table66%2/3
A || B
A= $terminal_widthB= $self->{'width'}
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $terminal_heightB= $self->{'height'}
ABresult
1X1
011
000
1442 }
1443 11 @{$self}{qw(width height top left)} = ($width, $height, 0, 0);
1444 11 delete $self->{last_frame};
1445 11 ▶ return unless $shrink; # Growing adds empty cells; never restores the bank.
Branch: 1 branch
BranchTrueFalseTotal
unless $shrink 3 8 11
1446 8 my %groups;
1447 8 for my $i (0 .. $#{ $self->{rows} }) {
1448 60 my $row = $self->{rows}[$i];
1449 60 ▶ next unless length($row->{text}) > $width;
Branch: 1 branch
BranchTrueFalseTotal
unless length $row->{"text"} > $width 34 26 60
1450 26 substr($row->{text}, $width) = '';
1451 26 $row->{clipped} = 1;
1452 26 ▶ $groups{$row->{group}} = 1 if $row->{group};
Branch: 1 branch
BranchTrueFalseTotal
if $row->{"group"} 0 26 26
1453 }
1454 8 ▶ $_->{clipped} = 1 for grep { $_->{group} && $groups{$_->{group}} } @{ $self->{rows} };
Condition33%1/3
$_->{'group'} && $groups{$_->{'group'}}
!ll&&!rl&&r
6000
MC/DC0%0/2
$_->{'group'} && $groups{$_->{'group'}}
$_->{'group'} $groups{$_->{'group'}}
Truth table33%1/3
A && B
A= $_->{'group'}B= $groups{$_->{'group'}}
ABresult
0X0
100
111
1455 8 ▶ $self->_discard_rows($height, @{ $self->{rows} } - $height) if @{ $self->{rows} } > $height;
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"rows"};} > $height 5 3 8
1456 8 ▶ $self->{col} = $width - 1 if $self->{col} >= $width;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"col"} >= $width 1 7 8
1457 8 ▶ $self->{data_lost} = 1 if defined $self->{data_row};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"data_row"} 0 8 8
1458 8 delete @{$self}{qw(output_row output_owner)};
1459 8 $self->fresh(1);
1460 8 my $bank = $self->{resize_bank};
1461 8 $self->append("# Screen clipped; RECOVER at $bank->{terminal_width}x$bank->{terminal_height}.\n");
1462 }
1463  
1464 9 ▶sub recover_display {
Subroutine recover_display: called CC=5 SCAR=16.1
1465 9 my ($self, $repl) = @_;
1466 9 ▶ my $bank = $self->{resize_bank} or die "No saved screen. RECOVER follows a terminal shrink.\n";
Branch: 1 branch
BranchTrueFalseTotal
my $bank = $self->{"resize_bank"} or die "No saved screen. RECOVER follows a terminal shrink.\n" 7 2 9
1467 die "Enlarge the terminal to at least $bank->{terminal_width}x$bank->{terminal_height}, then RECOVER.\n"
1468 7 ▶ if $self->{width} < $bank->{width} || $self->{height} < $bank->{height};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"width"} < $bank->{"width"} or $self->{"height"} < $bank->{"height"} 2 5 7
Condition66%2/3
$self->{"width"} < $bank->{"width"} or $self->{"height"} < $bank->{"height"}
l!l&&r!l&&!r
205
MC/DC50%1/2
$self->{"width"} < $bank->{"width"} or $self->{"height"} < $bank->{"height"}
$self->{"width"} < $bank->{"width"} $self->{"height"} < $bank->{"height"}
Truth table66%2/3
A or B
A= $self->{"width"} < $bank->{"width"}B= $self->{"height"} < $bank->{"height"}
ABresult
1X1
011
000
1469 5 ▶ $repl->_confirm_destructive('Replace the visible screen with its saved resize recovery copy') if $repl;
Branch: 1 branch
BranchTrueFalseTotal
if $repl 2 3 5
1470 4 $self->{rows} = [map { +{%$_} } @{ $bank->{rows} }];
1471 4 @{$self}{qw(row col top left)} = ($bank->{row}, $bank->{col}, 0, 0);
1472 4 delete @{$self}{qw(resize_bank output_row output_owner last_frame)};
1473 4 $self->{keep_cursor} = 1;
1474 4 $self->render;
1475 }
1476  
1477 0 ▶sub enter {
Subroutine enter: not called CC=2 SCAR=17.9
1478 0 my ($self) = @_;
1479 0 ▶ if ($self->{backend} eq 'readkey') { Term::ReadKey::ReadMode('cbreak', $self->{in}); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'backend'} eq 'readkey') { } 0 0 0
1480 0 else { $self->{raw_term}->setattr(fileno($self->{in}), POSIX::TCSANOW()); }
1481 0 $self->{entered} = 1;
1482 0 delete $self->{last_frame};
1483 0 $active = $self;
1484 0 print {$self->{out}} "\e[?1049h\e[?2004h\e[2J";
1485 0 $self->render;
1486 }
1487  
1488 0 ▶sub leave {
Subroutine leave: not called CC=3 SCAR=24.8
1489 0 my ($self) = @_;
1490 0 ▶ return unless delete $self->{entered};
Branch: 1 branch
BranchTrueFalseTotal
unless delete $self->{"entered"} 0 0 0
1491 0 print {$self->{out}} "\e[?2004l\e[0 q\e[?25h\e[?1049l";
1492 0 ▶ if ($self->{backend} eq 'readkey') { Term::ReadKey::ReadMode('restore', $self->{in}); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'backend'} eq 'readkey') { } 0 0 0
1493 0 else { $self->{saved_term}->setattr(fileno($self->{in}), POSIX::TCSANOW()); }
1494 }
1495  
1496 25 ▶END { eval { $active->leave if $active; }; }
Subroutine END: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
if $App::AnteREPL::Screen::active 0 25 25
1497  
1498 57 ▶sub fresh {
Subroutine fresh: called CC=14 SCAR=26.4
1499 57 my ($self, $bottom) = @_;
1500 57 ▶ return if delete $self->{keep_cursor};
Branch: 1 branch
BranchTrueFalseTotal
if delete $self->{"keep_cursor"} 2 55 57
1501 55 ▶ my $in_place = !$bottom && defined $self->{output_row};
Condition100%3/3
!$bottom && defined $self->{'output_row'}
!ll&&!rl&&r
13240
MC/DC100%2/2
!$bottom && defined $self->{'output_row'}
!$bottom defined $self->{'output_row'}
Truth table100%3/3
not(A) && B
A= !$bottomB= defined $self->{'output_row'}
ABresult
0X0
100
111
1502 55 ▶ my $row = $in_place ? $self->{output_row} : $#{ $self->{rows} };
Branch: 1 branch
BranchTrueFalseTotal
$in_place ? : 40 15 55
1503 55 ▶ if ($in_place) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_place) { } 40 15 55
1504 40 ▶ if (length $self->{rows}[$row]{text}) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $self->{'rows'}[$row]{'text'}) { } 3 37 40
elsif ($row < $#{$$self{'rows'};} and ($self->{'rows'}[$row]{'output_for'} || 0) == $self->{'output_owner'}) { } 16 42 58
1505 3 ++$row;
1506 3 ▶ push @{ $self->{rows} }, { text => '' } if $row == @{ $self->{rows} };
Branch: 1 branch
BranchTrueFalseTotal
if $row == @{$self->{"rows"};} 1 2 3
1507 }
1508 37 ▶ elsif ($row < $#{ $self->{rows} }
Condition60%3/5
$row < $#{$$self{"rows"};} and ($self->{"rows"}[$row]{"output_for"} || 0) == $self->{"output_owner"}
!ll&&!rl&&r
21016
$self->{'rows'}[$row]{'output_for'} || 0
l!l
160
MC/DC50%1/2
$row < $#{$$self{"rows"};} and ($self->{"rows"}[$row]{"output_for"} || 0) == $self->{"output_owner"}
$row < $#{$$self{"rows"};} $self->{'rows'}[$row]{'output_for'}
Truth table66%2/3
A and B
A= $row < $#{$$self{"rows"};}B= $self->{'rows'}[$row]{'output_for'}
ABresult
0X0
100
111
1509 && ($self->{rows}[$row]{output_for} || 0) == $self->{output_owner}) {
1510 # append's final blank row is a cursor position, not a separator.
1511 # Preserve actual blank output rows and the following entry itself.
1512 16 splice @{ $self->{rows} }, $row, 1;
1513 }
1514 40 ▶ if ($self->{rows}[$row]{text} eq ''
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rows"}[$row]{"text"} eq "" and ($self->{"rows"}[$row]{"output_for"} || 0) == $self->{"output_owner"}) 21 19 40
Condition100%5/5
$self->{"rows"}[$row]{"text"} eq "" and ($self->{"rows"}[$row]{"output_for"} || 0) == $self->{"output_owner"}
!ll&&!rl&&r
18121
$self->{'rows'}[$row]{'output_for'} || 0
l!l
211
MC/DC100%2/2
$self->{"rows"}[$row]{"text"} eq "" and ($self->{"rows"}[$row]{"output_for"} || 0) == $self->{"output_owner"}
$self->{"rows"}[$row]{"text"} eq "" $self->{'rows'}[$row]{'output_for'}
Truth table100%3/3
A and B
A= $self->{"rows"}[$row]{"text"} eq ""B= $self->{'rows'}[$row]{'output_for'}
ABresult
0X0
100
111
1515 && ($self->{rows}[$row]{output_for} || 0) == $self->{output_owner}) {
1516 21 $self->{rows}[$row] = { text => '' };
1517 }
1518 }
1519 else {
1520 15 ▶ push @{ $self->{rows} }, { text => '' } if length $self->{rows}[$row]{text};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"rows"}[$row]{"text"} 6 9 15
1521 15 $row = $#{ $self->{rows} };
1522 15 $self->{rows}[$row] = { text => '' };
1523 }
1524 55 $self->{row} = $row;
1525 55 $self->{col} = 0;
1526 55 $self->{left} = 0;
1527 55 delete @{$self}{qw(output_row output_owner)};
1528 55 $self->_fit;
1529 }
1530  
1531 68 ▶sub start_output {
Subroutine start_output: called CC=14 SCAR=26.9
1532 68 my ($self, $first, $last) = @_;
1533 68 ▶ my $owner = $self->{rows}[$first]{entry_id} || ++$self->{serial};
Condition66%2/3
$self->{'rows'}[$first]{'entry_id'} || ++$self->{'serial'}
l!l&&r!l&&!r
24440
MC/DC0%0/2
$self->{'rows'}[$first]{'entry_id'} || ++$self->{'serial'}
$self->{'rows'}[$first]{'entry_id'} ++$self->{'serial'}
Truth table66%2/3
A || B
A= $self->{'rows'}[$first]{'entry_id'}B= ++$self->{'serial'}
ABresult
1X1
011
000
1534 68 for my $index ($first .. $last) {
1535 98 $self->{rows}[$index]{entry_id} = $owner;
1536 98 delete $self->{rows}[$index]{output_for};
1537 }
1538 68 my $row = $last + 1;
1539 0 splice @{ $self->{rows} }, $row, 1
1540 68 ▶ if $self->{rows}[$row] && $self->{rows}[$row]{soft} && $self->{rows}[$row]{text} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"rows"}[$row] and $self->{"rows"}[$row]{"soft"} and $self->{"rows"}[$row]{"text"} eq "" 0 68 68
Condition50%3/6
$self->{"rows"}[$row] and $self->{"rows"}[$row]{"soft"} and $self->{"rows"}[$row]{"text"} eq ""
!ll&&!rl&&r
6800
$self->{"rows"}[$row] and $self->{"rows"}[$row]{"soft"}
!ll&&!rl&&r
41270
MC/DC0%0/3
$self->{"rows"}[$row] and $self->{"rows"}[$row]{"soft"} and $self->{"rows"}[$row]{"text"} eq ""
$self->{"rows"}[$row] $self->{"rows"}[$row]{"soft"} $self->{"rows"}[$row]{"text"} eq ""
Truth table50%2/4
A and B and C
A= $self->{"rows"}[$row]B= $self->{"rows"}[$row]{"soft"}C= $self->{"rows"}[$row]{"text"} eq ""
ABCresult
0XX0
10X0
1100
1111
1541 68 my $end = $row;
1542 97 ▶ ++$end while $end < @{ $self->{rows} }
Condition100%2/2
$self->{'rows'}[$end]{'output_for'} || 0
l!l
3123
MC/DC100%1/1
$self->{'rows'}[$end]{'output_for'} || 0
$self->{'rows'}[$end]{'output_for'}
Truth table100%2/2
A
A= $self->{'rows'}[$end]{'output_for'}
Aresult
11
00
1543 68 ▶ && ($self->{rows}[$end]{output_for} || 0) == $owner;
Branch: 1 branch
BranchTrueFalseTotal
$end < @{$self->{"rows"};} and ($self->{"rows"}[$end]{"output_for"} || 0) == $owner and do { ++$end } 29 68 97
Condition100%3/3
$end < @{$self->{"rows"};} and ($self->{"rows"}[$end]{"output_for"} || 0) == $owner
!ll&&!rl&&r
432529
MC/DC100%2/2
$end < @{$self->{"rows"};} and ($self->{"rows"}[$end]{"output_for"} || 0) == $owner
$end < @{$self->{"rows"};} ($self->{"rows"}[$end]{"output_for"} || 0) == $owner
Truth table100%3/3
A and B
A= $end < @{$self->{"rows"};}B= ($self->{"rows"}[$end]{"output_for"} || 0) == $owner
ABresult
0X0
100
111
1544 68 splice @{ $self->{rows} }, $row, $end - $row;
1545 68 my $next = $self->{rows}[$row];
1546 # Reuse a blank input row; preserve subsequent commands and their output.
1547 68 ▶ unless ($next && $next->{text} eq '' && !$next->{group}
Branch: 1 branch
BranchTrueFalseTotal
unless ($next and $next->{"text"} eq "" and not $next->{"group"} and not $next->{"entry_id"} and not $next->{"output_for"}) 62 6 68
Condition83%10/12
$next and $next->{"text"} eq "" and not $next->{"group"} and not $next->{"entry_id"} and not $next->{"output_for"}
!ll&&!rl&&r
6116
$next and $next->{"text"} eq "" and not $next->{"group"} and not $next->{"entry_id"}
!ll&&!rl&&r
6107
$next and $next->{"text"} eq "" and not $next->{"group"}
!ll&&!rl&&r
6107
$next and $next->{"text"} eq ""
!ll&&!rl&&r
43187
MC/DC60%3/5
$next and $next->{"text"} eq "" and not $next->{"group"} and not $next->{"entry_id"} and not $next->{"output_for"}
$next $next->{"text"} eq "" not $next->{"group"} not $next->{"entry_id"} not $next->{"output_for"}
Truth table66%4/6
A and B and not(C) and not(D) and not(E)
A= $nextB= $next->{"text"} eq ""C= not $next->{"group"}D= not $next->{"entry_id"}E= not $next->{"output_for"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1548 && !$next->{entry_id} && !$next->{output_for}) {
1549 62 splice @{ $self->{rows} }, $row, 0, { text => '' };
1550 }
1551 68 $self->{rows}[$row]{output_for} = $owner;
1552 68 @{$self}{qw(row col left output_row output_owner)} = ($row, 0, 0, $row, $owner);
1553 68 $self->_fit;
1554 }
1555  
1556 5 ▶sub clear_display {
Subroutine clear_display: called CC=1 SCAR=0.0
1557 5 my ($self) = @_;
1558 5 $self->{rows} = [{ text => '' }];
1559 5 @{$self}{qw(row col top left)} = (0, 0, 0, 0);
1560 5 delete @{$self}{qw(list_status output_row output_owner resize_bank keep_cursor last_frame)};
1561 5 $self->render;
1562 }
1563  
1564 173 ▶sub append {
Subroutine append: called CC=11 SCAR=24.1
1565 173 my ($self, $text) = @_;
1566 173 ▶ my $row = defined $self->{output_row} ? $self->{output_row} : $#{ $self->{rows} };
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'output_row'} ? : 81 92 173
1567 173 $text =~ s/\r\n/\n/g;
1568 173 $text =~ s/\e\][^\a]*(?:\a|\e\\)//g;
1569 173 $text =~ s/\e\[[0-?]*[ -\/]*[\@-~]//g;
1570 173 $text =~ s/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/?/g;
1571 173 for my $part (split /(\n|\r|\t)/, $text) {
1572 497 ▶ if ($part eq "\n") {
Branch: 3 branches
BranchTrueFalseTotal
if ($part eq "\n") { } 242 255 497
elsif ($part eq "\r") { } 0 255 255
elsif ($part eq "\t") { } 0 255 255
1573 242 ▶ if ($self->{rows}[$row]{soft} && $self->{rows}[$row]{text} eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rows"}[$row]{"soft"} and $self->{"rows"}[$row]{"text"} eq "") 1 241 242
Condition100%3/3
$self->{"rows"}[$row]{"soft"} and $self->{"rows"}[$row]{"text"} eq ""
!ll&&!rl&&r
23921
MC/DC100%2/2
$self->{"rows"}[$row]{"soft"} and $self->{"rows"}[$row]{"text"} eq ""
$self->{"rows"}[$row]{"soft"} $self->{"rows"}[$row]{"text"} eq ""
Truth table100%3/3
A and B
A= $self->{"rows"}[$row]{"soft"}B= $self->{"rows"}[$row]{"text"} eq ""
ABresult
0X0
100
111
1574 1 delete $self->{rows}[$row]{soft};
1575 1 next;
1576 }
1577 241 my $next = { text => '' };
1578 241 ▶ $next->{output_for} = $self->{output_owner} if $self->{output_owner};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"output_owner"} 75 166 241
1579 241 splice @{ $self->{rows} }, ++$row, 0, $next;
1580 }
1581 0 elsif ($part eq "\r") { $self->{rows}[$row]{text} = ''; }
1582 0 elsif ($part eq "\t") { $self->{rows}[$row]{text} .= ' ' x (8 - length($self->{rows}[$row]{text}) % 8); }
1583 255 else { $self->{rows}[$row]{text} .= $part; }
1584 }
1585 173 ▶ $self->{output_row} = $row if defined $self->{output_row};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"output_row"} 81 92 173
1586 173 $self->{row} = $row;
1587 173 $self->{col} = length $self->{rows}[$row]{text};
1588 173 $self->{left} = 0;
1589 173 $self->_fit;
1590 173 ▶ $self->render if $self->{entered};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"entered"} 0 173 173
1591 }
1592  
1593 930 ▶sub render {
Subroutine render: called CC=22 SCAR=32.0
1594 930 my ($self) = @_;
1595 930 $self->dimensions;
1596 930 $self->_fit;
1597 930 ▶ return unless $self->{entered};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"entered"} 926 4 930
1598 4 my ($h, $w) = ($self->{height}, $self->{width});
1599 4 my $framed = $self->{framed};
1600 4 my $edge = "\e[97;40m";
1601 4 my $normal = "\e[0m";
1602 4 my $frame = "\e[?25l\e[H$normal";
1603 4 ▶ $frame .= "\e[2J" if !$framed && $self->{terminal_width};
Branch: 1 branch
BranchTrueFalseTotal
if not $framed and $self->{"terminal_width"} 0 4 4
Condition33%1/3
not $framed and $self->{"terminal_width"}
!ll&&!rl&&r
400
MC/DC0%0/2
not $framed and $self->{"terminal_width"}
not $framed $self->{"terminal_width"}
Truth table33%1/3
not(A) and B
A= not $framedB= $self->{"terminal_width"}
ABresult
0X0
100
111
1604 4 ▶ if ($framed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($framed) 4 0 4
1605 4 my $top = "\x{2500}" x $w;
1606 4 ▶ substr($top, 0, 6) = ' VRAM ' if $w >= 6;
Branch: 1 branch
BranchTrueFalseTotal
if $w >= 6 4 0 4
1607 4 $frame .= "\e[2K$edge\x{250c}$top\x{2510}$normal";
1608 }
1609 4 for my $offset (0 .. $h - 1) {
1610 84 my $row = $self->{rows}[$offset];
1611 84 ▶ my $text = $row ? $row->{text} : '';
Branch: 1 branch
BranchTrueFalseTotal
$row ? : 4 80 84
1612 $text = $self->{list_status} if $self->{list_status}
1613 84 ▶ && $offset == $self->{row} && $text eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"list_status"} and $offset == $self->{"row"} and $text eq "" 0 84 84
Condition33%2/6
$self->{"list_status"} and $offset == $self->{"row"} and $text eq ""
!ll&&!rl&&r
8400
$self->{"list_status"} and $offset == $self->{"row"}
!ll&&!rl&&r
8400
MC/DC0%0/3
$self->{"list_status"} and $offset == $self->{"row"} and $text eq ""
$self->{"list_status"} $offset == $self->{"row"} $text eq ""
Truth table25%1/4
A and B and C
A= $self->{"list_status"}B= $offset == $self->{"row"}C= $text eq ""
ABCresult
0XX0
10X0
1100
1111
1614 84 $text = substr($text, 0, $w);
1615 84 $frame .= "\e[" . ($offset + 1 + !!$framed) . ";1H\e[2K";
1616 84 ▶ $frame .= $framed
Branch: 1 branch
BranchTrueFalseTotal
$framed ? : 84 0 84
1617 ? "$edge\x{2502}$normal" . $text . (' ' x ($w - length $text)) . "$edge\x{2502}$normal"
1618 : $text;
1619 }
1620 4 ▶ if ($framed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($framed) 4 0 4
1621 4 $frame .= "\e[" . ($h + 2) . ";1H\e[2K$edge\x{2514}" . ("\x{2500}" x $w) . "\x{2518}$normal";
1622 4 my @legend = $self->legend_lines;
1623 4 for my $i (0 .. $#legend) {
1624 4 my $text = $legend[$i];
1625 4 $text =~ s/(\A| )([A-Z]+[0-9]*)(?= |\z)/$1\e[7m$2\e[27m/g;
1626 4 $frame .= "\e[" . ($h + 3 + $i) . ";1H\e[2K$text$normal";
1627 }
1628 }
1629 4 $frame .= "\e[" . ($self->{row} + 1 + !!$framed) . ';' . ($self->{col} + 1 + !!$framed) . 'H';
1630 4 ▶ $frame .= $self->{insert} ? "\e[6 q" : "\e[2 q";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'insert'} ? : 3 1 4
1631 4 my $now = $self->_cursor_time;
1632 4 ▶ if (!defined $self->{last_frame} || $self->{last_frame} ne $frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"last_frame"} or $self->{"last_frame"} ne $frame) 2 2 4
Condition100%3/3
not defined $self->{"last_frame"} or $self->{"last_frame"} ne $frame
l!l&&r!l&&!r
112
MC/DC100%2/2
not defined $self->{"last_frame"} or $self->{"last_frame"} ne $frame
not defined $self->{"last_frame"} $self->{"last_frame"} ne $frame
Truth table100%3/3
not(A) or B
A= not defined $self->{"last_frame"}B= $self->{"last_frame"} ne $frame
ABresult
1X1
011
000
1633 2 $self->{last_frame} = $frame;
1634 2 $self->{cursor_epoch} = $now;
1635 2 $self->{cursor_visible} = !$self->{list_status};
1636 2 ▶ print {$self->{out}} $frame . ($self->{cursor_visible} ? "\e[?25h" : '');
Branch: 1 branch
BranchTrueFalseTotal
$self->{'cursor_visible'} ? : 2 0 2
1637 2 return;
1638 }
1639 2 ▶ return if $self->{list_status};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"list_status"} 0 2 2
1640 2 ▶ my $visible = int(($now - $self->{cursor_epoch}) / 0.5) % 2 ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
int(($now - $self->{'cursor_epoch'}) / 0.5) % 2 ? : 1 1 2
1641 2 ▶ return if $visible == $self->{cursor_visible};
Branch: 1 branch
BranchTrueFalseTotal
if $visible == $self->{"cursor_visible"} 0 2 2
1642 2 $self->{cursor_visible} = $visible;
1643 2 ▶ print {$self->{out}} $visible ? "\e[?25h" : "\e[?25l";
Branch: 1 branch
BranchTrueFalseTotal
$visible ? : 1 1 2
1644 }
1645  
1646 0 ▶sub _cursor_time { time }
Subroutine _cursor_time: not called CC=1 SCAR=6.9
1647  
1648 5 ▶sub legend_lines {
Subroutine legend_lines: called CC=6 SCAR=17.9
1649 5 my ($self) = @_;
1650 5 my @rows;
1651 5 for my $items (
1652 ['H Help', 'Q Quit', 'L List', 'R Run', 'E Eval', 'A Auto',
1653 'EE Edit', 'S Save', 'L1 Load', 'C Cls', 'F Subs', 'V Env'],
1654 ) {
1655 5 my $text = '';
1656 5 for my $item (@$items) {
1657 47 ▶ my $next = length $text ? "$text $item" : $item;
Branch: 1 branch
BranchTrueFalseTotal
length $text ? : 42 5 47
1658 47 ▶ last if length $next > $self->{terminal_width};
Branch: 1 branch
BranchTrueFalseTotal
if length $next > $self->{"terminal_width"} 5 42 47
1659 42 $text = $next;
1660 }
1661 5 ▶ $text = substr($items->[0], 0, 1) unless length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless length $text 0 5 5
1662 5 push @rows, $text;
1663 }
1664 5 return @rows;
1665 }
1666  
1667 11 ▶sub list_rows {
Subroutine list_rows: called CC=44 SCAR=38.1
1668 11 my ($self, $rows, $width, $mode, $label) = @_;
1669 11 ▶ $label ||= 'LIST';
Condition100%2/2
$label ||= "LIST"
l!l
110
MC/DC100%1/1
$label ||= "LIST"
$label
Truth table100%2/2
A
A= $label
Aresult
11
00
1670 11 ▶ return unless @$rows;
Branch: 1 branch
BranchTrueFalseTotal
unless @$rows 0 11 11
1671 11 $self->dimensions;
1672 11 ▶ my $controlled = @$rows > $self->{height} - 1 || $mode ne 'normal';
Condition100%3/3
@$rows > $self->{'height'} - 1 || $mode ne 'normal'
l!l&&r!l&&!r
416
MC/DC100%2/2
@$rows > $self->{'height'} - 1 || $mode ne 'normal'
@$rows > $self->{'height'} - 1 $mode ne 'normal'
Truth table100%3/3
A || B
A= @$rows > $self->{'height'} - 1B= $mode ne 'normal'
ABresult
1X1
011
000
1673 11 my ($slow, $paused, $stop, $page_count, $cancelled) = ($mode eq 'slow', 0, 0, 0, 0);
1674 0 ▶ local $SIG{INT} = sub { $stop = $cancelled = 1 };
Subroutine __ANON__: not called CC=1 SCAR=1.2
1675 11 my $ok = eval {
1676 11 LINE: for my $index (0 .. $#$rows) {
1677 25 ▶ last if $stop;
Branch: 1 branch
BranchTrueFalseTotal
if $stop 4 21 25
1678 21 ▶ $self->{list_status} = "$label " . ($slow ? 'slow' : 'normal') . ' | Space pause | S speed | Q stop' if $controlled;
Branch: 2 branches
BranchTrueFalseTotal
if $controlled 11 10 21
$slow ? : 2 9 11
1679 21 $self->append($rows->[$index] . "\n");
1680 # Remember which spaces belong to LIST's number column so editing
1681 # and resubmitting a listed row never accumulates source indentation.
1682 21 my $listed = $self->{row} - 1;
1683 21 ▶ --$listed while $listed > 0 && $self->{rows}[$listed]{soft};
Branch: 1 branch
BranchTrueFalseTotal
$listed > 0 and $self->{"rows"}[$listed]{"soft"} and do { --$listed } 2 21 23
Condition100%3/3
$listed > 0 and $self->{"rows"}[$listed]{"soft"}
!ll&&!rl&&r
8132
MC/DC100%2/2
$listed > 0 and $self->{"rows"}[$listed]{"soft"}
$listed > 0 $self->{"rows"}[$listed]{"soft"}
Truth table100%3/3
A and B
A= $listed > 0B= $self->{"rows"}[$listed]{"soft"}
ABresult
0X0
100
111
1684 21 ▶ $self->{rows}[$listed]{list_width} = $width if $listed >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $listed >= 0 21 0 21
1685 21 ++$page_count;
1686 21 ▶ next if !$controlled || $index == $#$rows;
Branch: 1 branch
BranchTrueFalseTotal
if not $controlled or $index == $rows->$#* 10 11 21
Condition66%2/3
not $controlled or $index == $rows->$#*
l!l&&r!l&&!r
10011
MC/DC50%1/2
not $controlled or $index == $rows->$#*
not $controlled $index == $rows->$#*
Truth table66%2/3
not(A) or B
A= not $controlledB= $index == $rows->$#*
ABresult
1X1
011
000
1687 11 ▶ $paused = 1 if $mode eq 'pause' && $page_count >= $self->{height} - 1;
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "pause" and $page_count >= $self->{"height"} - 1 2 9 11
Condition100%3/3
$mode eq "pause" and $page_count >= $self->{"height"} - 1
!ll&&!rl&&r
452
MC/DC100%2/2
$mode eq "pause" and $page_count >= $self->{"height"} - 1
$mode eq "pause" $page_count >= $self->{"height"} - 1
Truth table100%3/3
A and B
A= $mode eq "pause"B= $page_count >= $self->{"height"} - 1
ABresult
0X0
100
111
1688 11 ▶ my $until = time + ($slow ? 0.25 : 0.03);
Branch: 1 branch
BranchTrueFalseTotal
$slow ? : 2 9 11
1689 11 ▶ while (!$stop) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stop) 18 0 18
1690 18 ▶ $self->{list_status} = $paused
Branch: 2 branches
BranchTrueFalseTotal
$paused ? : 6 12 18
$slow ? : 2 10 12
1691 ? "$label paused | Space resume | Enter step | S speed | Q stop"
1692 : "$label " . ($slow ? 'slow' : 'normal') . ' | Space pause | S speed | Q stop';
1693 18 $self->render;
1694 18 my $remaining = $until - time;
1695 18 ▶ last if !$paused && $remaining <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $paused and $remaining <= 0 4 14 18
Condition100%3/3
not $paused and $remaining <= 0
!ll&&!rl&&r
684
MC/DC100%2/2
not $paused and $remaining <= 0
not $paused $remaining <= 0
Truth table100%3/3
not(A) and B
A= not $pausedB= $remaining <= 0
ABresult
0X0
100
111
1696 14 ▶ my $key = $self->key($paused ? 0.1 : $remaining);
Branch: 1 branch
BranchTrueFalseTotal
$paused ? : 6 8 14
1697 14 ▶ next if !ref($key) && $key eq 'NONE';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $key and $key eq "NONE" 4 10 14
Condition100%3/3
not ref $key and $key eq "NONE"
!ll&&!rl&&r
734
MC/DC100%2/2
not ref $key and $key eq "NONE"
not ref $key $key eq "NONE"
Truth table100%3/3
not(A) and B
A= not ref $keyB= $key eq "NONE"
ABresult
0X0
100
111
1698 10 ▶ if ((!ref($key) && $key =~ /\A(?:CANCEL|EOF|ESC)\z/) || (ref($key) && $key->[0] eq 'TEXT' && $key->[1] =~ /\A[qQ]\z/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $key and $key =~ /\A(?:CANCEL|EOF|ESC)\z/u or ref $key and $key->[0] eq "TEXT" and $key->[1] =~ /\A[qQ]\z/u) 4 6 10
Condition91%11/12
not ref $key and $key =~ /\A(?:CANCEL|EOF|ESC)\z/u or ref $key and $key->[0] eq "TEXT" and $key->[1] =~ /\A[qQ]\z/u
l!l&&r!l&&!r
136
not ref $key and $key =~ /\A(?:CANCEL|EOF|ESC)\z/u
!ll&&!rl&&r
721
ref $key and $key->[0] eq "TEXT" and $key->[1] =~ /\A[qQ]\z/u
!ll&&!rl&&r
243
ref $key and $key->[0] eq "TEXT"
!ll&&!rl&&r
207
MC/DC60%3/5
not ref $key and $key =~ /\A(?:CANCEL|EOF|ESC)\z/u or ref $key and $key->[0] eq "TEXT" and $key->[1] =~ /\A[qQ]\z/u
not ref $key $key =~ /\A(?:CANCEL|EOF|ESC)\z/u ref $key $key->[0] eq "TEXT" $key->[1] =~ /\A[qQ]\z/u
Truth table44%4/9
not(A) and B or C and D and E
A= not ref $keyB= $key =~ /\A(?:CANCEL|EOF|ESC)\z/uC= ref $keyD= $key->[0] eq "TEXT"E= $key->[1] =~ /\A[qQ]\z/u
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
1699 4 ▶ $cancelled = 1 if !ref($key) && $key eq 'CANCEL';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $key and $key eq "CANCEL" 1 3 4
Condition66%2/3
not ref $key and $key eq "CANCEL"
!ll&&!rl&&r
301
MC/DC50%1/2
not ref $key and $key eq "CANCEL"
not ref $key $key eq "CANCEL"
Truth table66%2/3
not(A) and B
A= not ref $keyB= $key eq "CANCEL"
ABresult
0X0
100
111
1700 4 $stop = 1;
1701 4 last;
1702 }
1703 6 ▶ if (ref($key) && $key->[0] eq 'TEXT' && $key->[1] eq ' ') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $key and $key->[0] eq 'TEXT' and $key->[1] eq ' ') { } 2 4 6
elsif (ref $key and $key->[0] eq 'TEXT' and $key->[1] =~ /\A[sS]\z/u) { } 1 3 4
elsif (not ref $key and $key eq 'ENTER') { } 2 1 3
Condition83%5/6
ref $key and $key->[0] eq "TEXT" and $key->[1] eq " "
!ll&&!rl&&r
222
ref $key and $key->[0] eq "TEXT"
!ll&&!rl&&r
204
MC/DC66%2/3
ref $key and $key->[0] eq "TEXT" and $key->[1] eq " "
ref $key $key->[0] eq "TEXT" $key->[1] eq " "
Truth table75%3/4
A and B and C
A= ref $keyB= $key->[0] eq "TEXT"C= $key->[1] eq " "
ABCresult
0XX0
10X0
1100
1111
1704 2 $paused = !$paused;
1705 2 ▶ $page_count = 0 unless $paused;
Branch: 1 branch
BranchTrueFalseTotal
unless $paused 1 1 2
1706 }
1707 1 ▶ elsif (ref($key) && $key->[0] eq 'TEXT' && $key->[1] =~ /\A[sS]\z/) { $slow = !$slow; }
Condition83%5/6
ref $key and $key->[0] eq "TEXT" and $key->[1] =~ /\A[sS]\z/u
!ll&&!rl&&r
211
ref $key and $key->[0] eq "TEXT"
!ll&&!rl&&r
202
MC/DC66%2/3
ref $key and $key->[0] eq "TEXT" and $key->[1] =~ /\A[sS]\z/u
ref $key $key->[0] eq "TEXT" $key->[1] =~ /\A[sS]\z/u
Truth table75%3/4
A and B and C
A= ref $keyB= $key->[0] eq "TEXT"C= $key->[1] =~ /\A[sS]\z/u
ABCresult
0XX0
10X0
1100
1111
1708 2 ▶ elsif (!ref($key) && $key eq 'ENTER') { $paused = 1; $page_count = 0; next LINE; }
Condition66%2/3
not ref $key and $key eq "ENTER"
!ll&&!rl&&r
102
MC/DC50%1/2
not ref $key and $key eq "ENTER"
not ref $key $key eq "ENTER"
Truth table66%2/3
not(A) and B
A= not ref $keyB= $key eq "ENTER"
ABresult
0X0
100
111
1709 else {
1710 # A new command or a cursor movement ends LIST and is
1711 # handed back to the editor, rather than eating typed input.
1712 1 push @{ $self->{pending_keys} }, $key;
1713 1 last LINE;
1714 }
1715 3 ▶ $until = time + ($slow ? 0.25 : 0.03);
Branch: 1 branch
BranchTrueFalseTotal
$slow ? : 3 0 3
1716 }
1717 }
1718 11 1;
1719 };
1720 11 my $error = $@;
1721 11 delete $self->{list_status};
1722 11 ▶ $self->{out}->clearerr if $self->{out};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"out"} 0 11 11
1723 11 $self->render;
1724 11 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 11 11
1725 11 ▶ die "Interrupted.\n" if $cancelled;
Branch: 1 branch
BranchTrueFalseTotal
if $cancelled 1 10 11
1726 }
1727  
1728 0 ▶sub byte {
Subroutine byte: not called CC=7 SCAR=40.3
1729 0 my ($self, $timeout) = @_;
1730 # ReadKey's Unix timed read can fall through to blocking getc when a
1731 # signal interrupts select. Use interruptible byte reads on Unix even
1732 # when ReadKey handles terminal modes; Windows needs its keyboard API.
1733 0 ▶ if ($self->{backend} eq 'readkey' && $^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"backend"} eq "readkey" and $^O eq "MSWin32") 0 0 0
Condition0%0/3
$self->{"backend"} eq "readkey" and $^O eq "MSWin32"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"backend"} eq "readkey" and $^O eq "MSWin32"
$self->{"backend"} eq "readkey" $^O eq "MSWin32"
Truth table0%0/3
A and B
A= $self->{"backend"} eq "readkey"B= $^O eq "MSWin32"
ABresult
0X0
100
111
1734 0 ▶ return Term::ReadKey::ReadKey(defined $timeout ? $timeout : 0, $self->{in});
Branch: 1 branch
BranchTrueFalseTotal
defined $timeout ? : 0 0 0
1735 }
1736 0 ▶ if (defined $timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $timeout) 0 0 0
1737 0 my $set = '';
1738 0 vec($set, fileno($self->{in}), 1) = 1;
1739 0 ▶ return undef unless select($set, undef, undef, $timeout) > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless select($set, undef, undef, $timeout) > 0 0 0 0
1740 }
1741 0 my $count = sysread($self->{in}, my $char, 1);
1742 0 ▶ return undef unless $count;
Branch: 1 branch
BranchTrueFalseTotal
unless $count 0 0 0
1743 0 return $char;
1744 }
1745  
1746 9 ▶sub key {
Subroutine key: called CC=26 SCAR=50.0
1747 9 my ($self, $timeout) = @_;
1748 0 ▶ return shift @{ $self->{pending_keys} } if $self->{pending_keys} && @{ $self->{pending_keys} };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pending_keys"} and @{$self->{"pending_keys"};} 0 9 9
Condition33%1/3
$self->{"pending_keys"} and @{$self->{"pending_keys"};}
!ll&&!rl&&r
900
MC/DC0%0/2
$self->{"pending_keys"} and @{$self->{"pending_keys"};}
$self->{"pending_keys"} @{$self->{"pending_keys"};}
Truth table33%1/3
A and B
A= $self->{"pending_keys"}B= @{$self->{"pending_keys"};}
ABresult
0X0
100
111
1749 9 my $char = $self->byte($timeout);
1750 9 ▶ return defined $timeout ? 'NONE' : 'EOF' unless defined $char;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $char 1 8 9
defined $timeout ? : 0 1 1
1751 8 ▶ if ($char eq "\e") {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\e") 5 3 8
1752 5 my $next = $self->byte(0.08);
1753 5 ▶ return 'ESC' unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 0 5 5
1754 5 ▶ return 'ESC' unless $next eq '[' || $next eq 'O';
Branch: 1 branch
BranchTrueFalseTotal
unless $next eq "[" or $next eq "O" 0 5 5
Condition33%1/3
$next eq "[" or $next eq "O"
l!l&&r!l&&!r
500
MC/DC0%0/2
$next eq "[" or $next eq "O"
$next eq "[" $next eq "O"
Truth table33%1/3
A or B
A= $next eq "["B= $next eq "O"
ABresult
1X1
011
000
1755 5 my $sequence = $next;
1756 5 ▶ while (length $sequence < 20) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $sequence < 20) 34 0 34
1757 34 my $part = $self->byte(0.08);
1758 34 ▶ last unless defined $part;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $part 0 34 34
1759 34 $sequence .= $part;
1760 34 ▶ last if $part =~ /[A-Za-z~]/;
Branch: 1 branch
BranchTrueFalseTotal
if $part =~ /[A-Za-z~]/u 5 29 34
1761 }
1762 5 my %keys = ('[A'=>'UP', '[B'=>'DOWN', '[C'=>'RIGHT', '[D'=>'LEFT',
1763 'OA'=>'UP', 'OB'=>'DOWN', 'OC'=>'RIGHT', 'OD'=>'LEFT',
1764 '[H'=>'HOME', '[F'=>'END', 'OH'=>'HOME', 'OF'=>'END',
1765 '[1~'=>'HOME', '[4~'=>'END', '[7~'=>'HOME', '[8~'=>'END',
1766 '[2~'=>'INSERT', '[3~'=>'DELETE', '[5~'=>'PAGEUP', '[6~'=>'PAGEDOWN',
1767 '[1;5H'=>'TOP', '[1;5F'=>'BOTTOM', '[27;2;13~'=>'NEWLINE');
1768 # CSI-u Shift+Enter, including key press/repeat event forms. Ignore
1769 # release events. No terminal-wide keyboard protocol is enabled here.
1770 5 ▶ return 'NEWLINE' if $sequence =~ /\A\[13;2(?::[12])?u\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $sequence =~ /\A\[13;2(?::[12])?u\z/u 3 2 5
1771 2 ▶ if ($sequence eq '[200~') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sequence eq "[200~") 0 2 2
1772 0 my $paste = '';
1773 0 ▶ while ($paste !~ /\e\[201~\z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($paste =~ /\e\[201~\z/u) 0 0 0
1774 0 my $byte = $self->byte;
1775 0 ▶ last unless defined $byte;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $byte 0 0 0
1776 0 $paste .= $byte;
1777 }
1778 0 $paste =~ s/\e\[201~\z//;
1779 0 ▶ $paste = decode('UTF-8', $paste, FB_DEFAULT) unless utf8::is_utf8($paste);
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::is_utf8($paste) 0 0 0
1780 0 $paste =~ s/\r\n?/\n/g;
1781 0 $paste =~ s/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]//g;
1782 0 return ['PASTE', $paste];
1783 }
1784 2 ▶ return $keys{$sequence} || 'IGNORE';
Condition100%2/2
$keys{$sequence} || 'IGNORE'
l!l
11
MC/DC100%1/1
$keys{$sequence} || 'IGNORE'
$keys{$sequence}
Truth table100%2/2
A
A= $keys{$sequence}
Aresult
11
00
1785 }
1786 3 my %control = ("\r"=>'ENTER', "\n"=>'ENTER', "\x7f"=>'BACKSPACE', "\x08"=>'BACKSPACE',
1787 "\x03"=>'CANCEL', "\x04"=>'ENDINPUT', "\x0e"=>'NEWLINE',
1788 "\x15"=>'CLEAR', "\x0c"=>'REDRAW', "\t"=>'TAB');
1789 3 ▶ return $control{$char} if exists $control{$char};
Branch: 1 branch
BranchTrueFalseTotal
if exists $control{$char} 3 0 3
1790 0 ▶ return 'IGNORE' if ord($char) < 32;
Branch: 1 branch
BranchTrueFalseTotal
if ord $char < 32 0 0 0
1791 0 ▶ if (!utf8::is_utf8($char) && ord($char) >= 128) {
Branch: 1 branch
BranchTrueFalseTotal
if (not utf8::is_utf8($char) and ord $char >= 128) 0 0 0
Condition0%0/3
not utf8::is_utf8($char) and ord $char >= 128
!ll&&!rl&&r
000
MC/DC0%0/2
not utf8::is_utf8($char) and ord $char >= 128
not utf8::is_utf8($char) ord $char >= 128
Truth table0%0/3
not(A) and B
A= not utf8::is_utf8($char)B= ord $char >= 128
ABresult
0X0
100
111
1792 0 ▶ my $count = ord($char) < 224 ? 2 : ord($char) < 240 ? 3 : 4;
Branch: 2 branches
BranchTrueFalseTotal
ord $char < 224 ? : 0 0 0
ord $char < 240 ? : 0 0 0
1793 0 ▶ for (2 .. $count) { my $byte = $self->byte(0.2); last unless defined $byte; $char .= $byte; }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $byte 0 0 0
1794 0 $char = decode('UTF-8', $char, FB_DEFAULT);
1795 }
1796 0 return ['TEXT', $char];
1797 }
1798  
1799 888 ▶sub edit_key {
Subroutine edit_key: called CC=50 SCAR=41.4
1800 888 my ($self, $key) = @_;
1801 888 $self->_fit;
1802 888 my $row = $self->{rows}[ $self->{row} ];
1803 888 ▶ if (ref $key) {
Branch: 14 branches
BranchTrueFalseTotal
if (ref $key) { } 780 108 888
elsif ($key eq 'UP' or $key eq 'DOWN' or $key eq 'PAGEUP' or $key eq 'PAGEDOWN') { } 21 87 108
elsif ($key eq 'LEFT') { } 15 72 87
elsif ($key eq 'RIGHT') { } 17 55 72
elsif ($key eq 'HOME') { } 8 47 55
elsif ($key eq 'END') { } 6 41 47
elsif ($key eq 'TOP') { } 22 19 41
elsif ($key eq 'BOTTOM' or $key eq 'ESC') { } 4 15 19
elsif ($key eq 'INSERT') { } 3 12 15
elsif ($key eq 'BACKSPACE') { } 7 5 12
elsif ($key eq 'DELETE') { } 1 4 5
elsif ($key eq 'CLEAR') { } 1 3 4
elsif ($key eq 'NEWLINE') { } 3 0 3
elsif ($key eq 'TAB') { } 0 0 0
1804 780 my $text = $key->[1];
1805 780 ▶ if ($key->[0] eq 'PASTE' && $text =~ /\n/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key->[0] eq 'PASTE' and $text =~ /\n/u) { } 8 772 780
Condition66%2/3
$key->[0] eq "PASTE" and $text =~ /\n/u
!ll&&!rl&&r
77208
MC/DC50%1/2
$key->[0] eq "PASTE" and $text =~ /\n/u
$key->[0] eq "PASTE" $text =~ /\n/u
Truth table66%2/3
A and B
A= $key->[0] eq "PASTE"B= $text =~ /\n/u
ABresult
0X0
100
111
1806 8 ▶ my $group = $row->{group} || ++$self->{serial};
Condition66%2/3
$row->{'group'} || ++$self->{'serial'}
l!l&&r!l&&!r
260
MC/DC0%0/2
$row->{'group'} || ++$self->{'serial'}
$row->{'group'} ++$self->{'serial'}
Truth table66%2/3
A || B
A= $row->{'group'}B= ++$self->{'serial'}
ABresult
1X1
011
000
1807 8 my ($first, $last) = ($self->{row}, $self->{row});
1808 8 ▶ --$first while $first && $self->{rows}[$first]{soft};
Branch: 1 branch
BranchTrueFalseTotal
$first and $self->{"rows"}[$first]{"soft"} and do { --$first } 0 8 8
Condition66%2/3
$first and $self->{"rows"}[$first]{"soft"}
!ll&&!rl&&r
530
MC/DC0%0/2
$first and $self->{"rows"}[$first]{"soft"}
$first $self->{"rows"}[$first]{"soft"}
Truth table66%2/3
A and B
A= $firstB= $self->{"rows"}[$first]{"soft"}
ABresult
0X0
100
111
1809 8 ▶ ++$last while $self->{rows}[$last + 1] && $self->{rows}[$last + 1]{soft};
Branch: 1 branch
BranchTrueFalseTotal
$self->{"rows"}[$last + 1] and $self->{"rows"}[$last + 1]{"soft"} and do { ++$last } 0 8 8
Condition66%2/3
$self->{"rows"}[$last + 1] and $self->{"rows"}[$last + 1]{"soft"}
!ll&&!rl&&r
620
MC/DC0%0/2
$self->{"rows"}[$last + 1] and $self->{"rows"}[$last + 1]{"soft"}
$self->{"rows"}[$last + 1] $self->{"rows"}[$last + 1]{"soft"}
Truth table66%2/3
A and B
A= $self->{"rows"}[$last + 1]B= $self->{"rows"}[$last + 1]{"soft"}
ABresult
0X0
100
111
1810 8 $self->{rows}[$_]{group} = $group for $first .. $last;
1811 8 my $before = substr($row->{text}, 0, $self->{col});
1812 8 my $after = substr($row->{text}, $self->{col});
1813 8 my @parts = split /\n/, $before . $text . $after, -1;
1814 8 ▶ my %owner = map { exists $row->{$_} ? ($_ => $row->{$_}) : () } qw(entry_id output_for clipped);
Branch: 1 branch
BranchTrueFalseTotal
exists $row->{$_} ? : 2 22 24
1815 8 splice @{ $self->{rows} }, $self->{row}, 1, map { {text=>$_, group=>$group, %owner} } @parts;
1816 8 ▶ $self->{rows}[$self->{row}]{soft} = 1 if $row->{soft};
Branch: 1 branch
BranchTrueFalseTotal
if $row->{"soft"} 0 8 8
1817 8 $self->{row} += $#parts;
1818 8 $self->{col} = length($parts[-1]) - length($after);
1819 }
1820 else {
1821 772 ▶ my $replace = $self->{insert} || $key->[0] eq 'PASTE' ? 0 : length $text;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'insert'} || $key->[0] eq 'PASTE' ? : 771 1 772
Condition66%2/3
$self->{"insert"} or $key->[0] eq "PASTE"
l!l&&r!l&&!r
77101
MC/DC50%1/2
$self->{"insert"} or $key->[0] eq "PASTE"
$self->{"insert"} $key->[0] eq "PASTE"
Truth table66%2/3
A or B
A= $self->{"insert"}B= $key->[0] eq "PASTE"
ABresult
1X1
011
000
1822 772 substr($row->{text}, $self->{col}, $replace, $text);
1823 772 $self->{col} += length $text;
1824 }
1825 }
1826 ▶ elsif ($key eq 'UP' || $key eq 'DOWN' || $key eq 'PAGEUP' || $key eq 'PAGEDOWN') {
Condition88%8/9
$key eq "UP" or $key eq "DOWN" or $key eq "PAGEUP" or $key eq "PAGEDOWN"
l!l&&r!l&&!r
21087
$key eq "UP" or $key eq "DOWN" or $key eq "PAGEUP"
l!l&&r!l&&!r
17487
$key eq "UP" or $key eq "DOWN"
l!l&&r!l&&!r
15291
MC/DC75%3/4
$key eq "UP" or $key eq "DOWN" or $key eq "PAGEUP" or $key eq "PAGEDOWN"
$key eq "UP" $key eq "DOWN" $key eq "PAGEUP" $key eq "PAGEDOWN"
Truth table80%4/5
A or B or C or D
A= $key eq "UP"B= $key eq "DOWN"C= $key eq "PAGEUP"D= $key eq "PAGEDOWN"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1827 21 ▶ my $delta = $key =~ /PAGE/ ? $self->{height} - 1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /PAGE/u ? : 4 17 21
1828 21 ▶ $delta = -$delta if $key eq 'UP' || $key eq 'PAGEUP';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "UP" or $key eq "PAGEUP" 19 2 21
Condition100%3/3
$key eq "UP" or $key eq "PAGEUP"
l!l&&r!l&&!r
1542
MC/DC100%2/2
$key eq "UP" or $key eq "PAGEUP"
$key eq "UP" $key eq "PAGEUP"
Truth table100%3/3
A or B
A= $key eq "UP"B= $key eq "PAGEUP"
ABresult
1X1
011
000
1829 21 $self->{row} += $delta;
1830 21 ▶ $self->{row} = 0 if $self->{row} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"row"} < 0 2 19 21
1831 0 ▶ $self->{row} = $#{ $self->{rows} } if $self->{row} > $#{ $self->{rows} };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"row"} > $#{$$self{"rows"};} 0 21 21
1832 21 my $length = length $self->{rows}[ $self->{row} ]{text};
1833 21 ▶ --$length if $length == $self->{width};
Branch: 1 branch
BranchTrueFalseTotal
if $length == $self->{"width"} 0 21 21
1834 21 ▶ $self->{col} = $length if $self->{col} > $length;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"col"} > $length 0 21 21
1835 }
1836 elsif ($key eq 'LEFT') {
1837 15 ▶ if ($self->{col} > 0) { --$self->{col}; }
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'col'} > 0) { } 7 8 15
elsif ($self->{'row'} > 0) { } 4 4 8
1838 elsif ($self->{row} > 0) {
1839 4 --$self->{row};
1840 4 $self->{col} = length $self->{rows}[$self->{row}]{text};
1841 4 ▶ --$self->{col} if $self->{col} == $self->{width};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"col"} == $self->{"width"} 0 4 4
1842 }
1843 }
1844 17 ▶ elsif ($key eq 'RIGHT') { ++$self->{col} if $self->{col} < length $row->{text}; }
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"col"} < length $row->{"text"} 17 0 17
1845 8 elsif ($key eq 'HOME') { $self->{col} = 0; }
1846 elsif ($key eq 'END') {
1847 6 $self->{col} = length $row->{text};
1848 6 ▶ --$self->{col} if $self->{col} == $self->{width};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"col"} == $self->{"width"} 0 6 6
1849 }
1850 22 elsif ($key eq 'TOP') { $self->{row} = $self->{col} = 0; }
1851 4 ▶ elsif ($key eq 'BOTTOM' || $key eq 'ESC') { $self->fresh(1); }
Condition66%2/3
$key eq "BOTTOM" or $key eq "ESC"
l!l&&r!l&&!r
4015
MC/DC50%1/2
$key eq "BOTTOM" or $key eq "ESC"
$key eq "BOTTOM" $key eq "ESC"
Truth table66%2/3
A or B
A= $key eq "BOTTOM"B= $key eq "ESC"
ABresult
1X1
011
000
1852 3 elsif ($key eq 'INSERT') { $self->{insert} = !$self->{insert}; }
1853 elsif ($key eq 'BACKSPACE') {
1854 7 ▶ if (!$self->{col} && $self->{row} && $row->{soft}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"col"} and $self->{"row"} and $row->{"soft"}) 2 5 7
Condition66%4/6
not $self->{"col"} and $self->{"row"} and $row->{"soft"}
!ll&&!rl&&r
502
not $self->{"col"} and $self->{"row"}
!ll&&!rl&&r
502
MC/DC33%1/3
not $self->{"col"} and $self->{"row"} and $row->{"soft"}
not $self->{"col"} $self->{"row"} $row->{"soft"}
Truth table50%2/4
not(A) and B and C
A= not $self->{"col"}B= $self->{"row"}C= $row->{"soft"}
ABCresult
0XX0
10X0
1100
1111
1855 2 --$self->{row};
1856 2 $row = $self->{rows}[$self->{row}];
1857 2 $self->{col} = length $row->{text};
1858 }
1859 7 ▶ substr($row->{text}, --$self->{col}, 1, '') if $self->{col} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"col"} > 0 7 0 7
1860 }
1861 1 ▶ elsif ($key eq 'DELETE') { substr($row->{text}, $self->{col}, 1, '') if $self->{col} < length $row->{text}; }
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"col"} < length $row->{"text"} 1 0 1
1862 elsif ($key eq 'CLEAR') {
1863 1 %$row = (text => ''); $self->{col} = 0;
1864 1 ▶ if ($self->{rows}[$self->{row} + 1] && delete $self->{rows}[$self->{row} + 1]{soft}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rows"}[$self->{"row"} + 1] and delete $self->{"rows"}[$self->{"row"} + 1]{"soft"}) 0 1 1
Condition33%1/3
$self->{"rows"}[$self->{"row"} + 1] and delete $self->{"rows"}[$self->{"row"} + 1]{"soft"}
!ll&&!rl&&r
010
MC/DC0%0/2
$self->{"rows"}[$self->{"row"} + 1] and delete $self->{"rows"}[$self->{"row"} + 1]{"soft"}
$self->{"rows"}[$self->{"row"} + 1] delete $self->{"rows"}[$self->{"row"} + 1]{"soft"}
Truth table33%1/3
A and B
A= $self->{"rows"}[$self->{"row"} + 1]B= delete $self->{"rows"}[$self->{"row"} + 1]{"soft"}
ABresult
0X0
100
111
1865 0 $self->{rows}[$self->{row} + 1]{clipped} = 1;
1866 }
1867 }
1868 3 elsif ($key eq 'NEWLINE') { $self->edit_key(['PASTE', "\n"]); }
1869 0 elsif ($key eq 'TAB') { $self->edit_key(['TEXT', ' ' x (4 - $self->{col} % 4)]); }
1870 888 $self->_fit;
1871 }
1872  
1873 87 ▶sub entry {
Subroutine entry: called CC=22 SCAR=31.0
1874 87 my ($self) = @_;
1875 87 my ($first, $last) = ($self->{row}, $self->{row});
1876 87 my $group = $self->{rows}[$first]{group};
1877 87 ▶ if (defined $group) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $group) 19 68 87
1878 19 ▶ --$first while $first > 0 && ($self->{rows}[$first - 1]{group} || 0) == $group;
Branch: 1 branch
BranchTrueFalseTotal
$first > 0 and ($self->{"rows"}[$first - 1]{"group"} || 0) == $group and do { --$first } 28 19 47
Condition100%5/5
$first > 0 and ($self->{"rows"}[$first - 1]{"group"} || 0) == $group
!ll&&!rl&&r
14528
$self->{'rows'}[$first - 1]{'group'} || 0
l!l
285
MC/DC100%2/2
$first > 0 and ($self->{"rows"}[$first - 1]{"group"} || 0) == $group
$first > 0 $self->{'rows'}[$first - 1]{'group'}
Truth table100%3/3
A and B
A= $first > 0B= $self->{'rows'}[$first - 1]{'group'}
ABresult
0X0
100
111
1879 19 ▶ ++$last while $last < $#{ $self->{rows} } && ($self->{rows}[$last + 1]{group} || 0) == $group;
Branch: 1 branch
BranchTrueFalseTotal
$last < $#{$$self{"rows"};} and ($self->{"rows"}[$last + 1]{"group"} || 0) == $group and do { ++$last } 9 19 28
Condition100%5/5
$last < $#{$$self{"rows"};} and ($self->{"rows"}[$last + 1]{"group"} || 0) == $group
!ll&&!rl&&r
1369
$self->{'rows'}[$last + 1]{'group'} || 0
l!l
96
MC/DC100%2/2
$last < $#{$$self{"rows"};} and ($self->{"rows"}[$last + 1]{"group"} || 0) == $group
$last < $#{$$self{"rows"};} $self->{'rows'}[$last + 1]{'group'}
Truth table100%3/3
A and B
A= $last < $#{$$self{"rows"};}B= $self->{'rows'}[$last + 1]{'group'}
ABresult
0X0
100
111
1880 }
1881 87 ▶ --$first while $first > 0 && $self->{rows}[$first]{soft};
Branch: 1 branch
BranchTrueFalseTotal
$first > 0 and $self->{"rows"}[$first]{"soft"} and do { --$first } 2 87 89
Condition100%3/3
$first > 0 and $self->{"rows"}[$first]{"soft"}
!ll&&!rl&&r
56312
MC/DC100%2/2
$first > 0 and $self->{"rows"}[$first]{"soft"}
$first > 0 $self->{"rows"}[$first]{"soft"}
Truth table100%3/3
A and B
A= $first > 0B= $self->{"rows"}[$first]{"soft"}
ABresult
0X0
100
111
1882 87 ▶ ++$last while $self->{rows}[$last + 1] && $self->{rows}[$last + 1]{soft};
Branch: 1 branch
BranchTrueFalseTotal
$self->{"rows"}[$last + 1] and $self->{"rows"}[$last + 1]{"soft"} and do { ++$last } 8 87 95
Condition100%3/3
$self->{"rows"}[$last + 1] and $self->{"rows"}[$last + 1]{"soft"}
!ll&&!rl&&r
54338
MC/DC100%2/2
$self->{"rows"}[$last + 1] and $self->{"rows"}[$last + 1]{"soft"}
$self->{"rows"}[$last + 1] $self->{"rows"}[$last + 1]{"soft"}
Truth table100%3/3
A and B
A= $self->{"rows"}[$last + 1]B= $self->{"rows"}[$last + 1]{"soft"}
ABresult
0X0
100
111
1883 die "This entry was clipped. Re-enter it, use EDIT, or enlarge and RECOVER a saved screen.\n"
1884 87 ▶ if grep { $_->{clipped} } @{ $self->{rows} }[$first .. $last];
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_->{"clipped"};} @{$$self{"rows"};}[$first .. $last] 2 85 87
1885 85 ▶ --$last if $last > $first && $self->{rows}[$last]{soft} && $self->{rows}[$last]{text} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $last > $first and $self->{"rows"}[$last]{"soft"} and $self->{"rows"}[$last]{"text"} eq "" 1 84 85
Condition100%6/6
$last > $first and $self->{"rows"}[$last]{"soft"} and $self->{"rows"}[$last]{"text"} eq ""
!ll&&!rl&&r
8041
$last > $first and $self->{"rows"}[$last]{"soft"}
!ll&&!rl&&r
62185
MC/DC100%3/3
$last > $first and $self->{"rows"}[$last]{"soft"} and $self->{"rows"}[$last]{"text"} eq ""
$last > $first $self->{"rows"}[$last]{"soft"} $self->{"rows"}[$last]{"text"} eq ""
Truth table100%4/4
A and B and C
A= $last > $firstB= $self->{"rows"}[$last]{"soft"}C= $self->{"rows"}[$last]{"text"} eq ""
ABCresult
0XX0
10X0
1100
1111
1886 85 my $text = join('', map { ($_ == $first || $self->{rows}[$_]{soft} ? '' : "\n")
1887 129 ▶ . $self->{rows}[$_]{text} } $first .. $last);
Branch: 1 branch
BranchTrueFalseTotal
$_ == $first || $self->{'rows'}[$_]{'soft'} ? : 94 35 129
Condition100%3/3
$_ == $first or $self->{"rows"}[$_]{"soft"}
l!l&&r!l&&!r
85935
MC/DC100%2/2
$_ == $first or $self->{"rows"}[$_]{"soft"}
$_ == $first $self->{"rows"}[$_]{"soft"}
Truth table100%3/3
A or B
A= $_ == $firstB= $self->{"rows"}[$_]{"soft"}
ABresult
1X1
011
000
1888 85 ▶ if ($self->{rows}[$first]{list_width}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rows"}[$first]{"list_width"}) 5 80 85
1889 5 my $width = $self->{rows}[$first]{list_width};
1890 5 ▶ if (length($text) > $width && substr($text, $width, 1) eq ' '
Branch: 1 branch
BranchTrueFalseTotal
if (length $text > $width and substr($text, $width, 1) eq " " and substr($text, 0, $width) =~ /\A([0-9]+) *\z/u) 5 0 5
Condition33%2/6
length $text > $width and substr($text, $width, 1) eq " " and substr($text, 0, $width) =~ /\A([0-9]+) *\z/u
!ll&&!rl&&r
005
length $text > $width and substr($text, $width, 1) eq " "
!ll&&!rl&&r
005
MC/DC0%0/3
length $text > $width and substr($text, $width, 1) eq " " and substr($text, 0, $width) =~ /\A([0-9]+) *\z/u
length $text > $width substr($text, $width, 1) eq " " substr($text, 0, $width) =~ /\A([0-9]+) *\z/u
Truth table25%1/4
A and B and C
A= length $text > $widthB= substr($text, $width, 1) eq " "C= substr($text, 0, $width) =~ /\A([0-9]+) *\z/u
ABCresult
0XX0
10X0
1100
1111
1891 && substr($text, 0, $width) =~ /\A([0-9]+) *\z/) {
1892 5 $text = $1 . ' ' . substr($text, $width + 1);
1893 }
1894 }
1895 85 return ($text, $first, $last);
1896 }
1897  
1898 71 ▶sub read_entry {
Subroutine read_entry: called CC=17 SCAR=28.5
1899 71 my ($self) = @_;
1900 71 while (1) {
1901 865 $self->render;
1902 865 my $key = $self->key(0.1);
1903 865 ▶ next if !ref($key) && $key eq 'NONE';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $key and $key eq "NONE" 0 865 865
Condition66%2/3
not ref $key and $key eq "NONE"
!ll&&!rl&&r
7021630
MC/DC0%0/2
not ref $key and $key eq "NONE"
not ref $key $key eq "NONE"
Truth table66%2/3
not(A) and B
A= not ref $keyB= $key eq "NONE"
ABresult
0X0
100
111
1904 865 ▶ if (!ref($key) && $key eq 'ENTER') {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $key and $key eq "ENTER") 77 788 865
Condition100%3/3
not ref $key and $key eq "ENTER"
!ll&&!rl&&r
7028677
MC/DC100%2/2
not ref $key and $key eq "ENTER"
not ref $key $key eq "ENTER"
Truth table100%3/3
not(A) and B
A= not ref $keyB= $key eq "ENTER"
ABresult
0X0
100
111
1905 77 my ($text, $first, $last) = $self->entry;
1906 77 ▶ if ($self->{repl} ? $self->{repl}->input_needs_more($text) : App::AnteREPL::needs_more($text)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{"repl"} ? $self->{"repl"}->input_needs_more($text) : App::AnteREPL::needs_more($text)) 9 68 77
$self->{'repl'} ? : 62 15 77
1907 9 ▶ my $group = $self->{rows}[$first]{group} || ++$self->{serial};
Condition66%2/3
$self->{'rows'}[$first]{'group'} || ++$self->{'serial'}
l!l&&r!l&&!r
450
MC/DC0%0/2
$self->{'rows'}[$first]{'group'} || ++$self->{'serial'}
$self->{'rows'}[$first]{'group'} ++$self->{'serial'}
Truth table66%2/3
A || B
A= $self->{'rows'}[$first]{'group'}B= ++$self->{'serial'}
ABresult
1X1
011
000
1908 9 $self->{rows}[$_]{group} = $group for $first .. $last;
1909 # Editing an earlier row of a complete entry must not insert a
1910 # second copy; incomplete entries continue after their last row.
1911 9 splice @{ $self->{rows} }, $last + 1, 0, {text=>'', group=>$group};
1912 9 $self->{row} = $last + 1;
1913 9 $self->{col} = 0;
1914 9 $self->_fit;
1915 9 next;
1916 }
1917 68 $self->start_output($first, $last);
1918 68 return $text;
1919 }
1920 788 ▶ if (!ref($key) && $key eq 'ENDINPUT') {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $key and $key eq "ENDINPUT") 2 786 788
Condition100%3/3
not ref $key and $key eq "ENDINPUT"
!ll&&!rl&&r
702842
MC/DC100%2/2
not ref $key and $key eq "ENDINPUT"
not ref $key $key eq "ENDINPUT"
Truth table100%3/3
not(A) and B
A= not ref $keyB= $key eq "ENDINPUT"
ABresult
0X0
100
111
1921 2 ▶ if ($self->{repl} && $self->{repl}{auto}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"repl"} and $self->{"repl"}{"auto"}) 1 1 2
Condition66%2/3
$self->{"repl"} and $self->{"repl"}{"auto"}
!ll&&!rl&&r
011
MC/DC50%1/2
$self->{"repl"} and $self->{"repl"}{"auto"}
$self->{"repl"} $self->{"repl"}{"auto"}
Truth table66%2/3
A and B
A= $self->{"repl"}B= $self->{"repl"}{"auto"}
ABresult
0X0
100
111
1922 1 $self->fresh(1);
1923 1 return 'AUTO OFF';
1924 }
1925 1 return undef;
1926 }
1927 786 ▶ if (!ref($key) && $key eq 'EOF') { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $key and $key eq "EOF") 1 785 786
Condition100%3/3
not ref $key and $key eq "EOF"
!ll&&!rl&&r
702831
MC/DC100%2/2
not ref $key and $key eq "EOF"
not ref $key $key eq "EOF"
Truth table100%3/3
not(A) and B
A= not ref $keyB= $key eq "EOF"
ABresult
0X0
100
111
1928 0 ▶ if (!ref($key) && $key eq 'CANCEL') { die "Interrupted.\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $key and $key eq "CANCEL") 0 785 785
Condition66%2/3
not ref $key and $key eq "CANCEL"
!ll&&!rl&&r
702830
MC/DC0%0/2
not ref $key and $key eq "CANCEL"
not ref $key $key eq "CANCEL"
Truth table66%2/3
not(A) and B
A= not ref $keyB= $key eq "CANCEL"
ABresult
0X0
100
111
1929 785 $self->edit_key($key);
1930 }
1931 }
1932  
1933 5 ▶sub read_data {
Subroutine read_data: called CC=27 SCAR=37.3
1934 5 my ($self, $confirmation) = @_;
1935 5 ▶ my $row = defined $self->{output_row} ? $self->{output_row} : $#{ $self->{rows} };
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'output_row'} ? : 2 3 5
1936 5 $self->{row} = $row;
1937 5 my $start = length $self->{rows}[$row]{text};
1938 5 $self->{col} = $start;
1939 5 local @{$self}{qw(data_row data_col data_lost)} = ($row, $start, 0);
1940 5 while (1) {
1941 50 $self->render;
1942 50 ▶ die "Input was clipped by the screen boundary. Please run the command again.\n" if $self->{data_lost};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"data_lost"} 1 49 50
1943 49 my $key = $self->key(0.1);
1944 49 ▶ next if !ref($key) && $key eq 'NONE';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $key and $key eq "NONE" 0 49 49
Condition66%2/3
not ref $key and $key eq "NONE"
!ll&&!rl&&r
4360
MC/DC0%0/2
not ref $key and $key eq "NONE"
not ref $key $key eq "NONE"
Truth table66%2/3
not(A) and B
A= not ref $keyB= $key eq "NONE"
ABresult
0X0
100
111
1945 49 ▶ if (!ref($key) && $key eq 'ENTER') {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $key and $key eq "ENTER") 4 45 49
Condition100%3/3
not ref $key and $key eq "ENTER"
!ll&&!rl&&r
4324
MC/DC100%2/2
not ref $key and $key eq "ENTER"
not ref $key $key eq "ENTER"
Truth table100%3/3
not(A) and B
A= not ref $keyB= $key eq "ENTER"
ABresult
0X0
100
111
1946 4 my $last = $self->{data_row};
1947 4 ▶ ++$last while $self->{rows}[$last + 1] && $self->{rows}[$last + 1]{soft};
Branch: 1 branch
BranchTrueFalseTotal
$self->{"rows"}[$last + 1] and $self->{"rows"}[$last + 1]{"soft"} and do { ++$last } 3 4 7
Condition100%3/3
$self->{"rows"}[$last + 1] and $self->{"rows"}[$last + 1]{"soft"}
!ll&&!rl&&r
313
MC/DC100%2/2
$self->{"rows"}[$last + 1] and $self->{"rows"}[$last + 1]{"soft"}
$self->{"rows"}[$last + 1] $self->{"rows"}[$last + 1]{"soft"}
Truth table100%3/3
A and B
A= $self->{"rows"}[$last + 1]B= $self->{"rows"}[$last + 1]{"soft"}
ABresult
0X0
100
111
1948 4 my $value = substr($self->{rows}[$self->{data_row}]{text}, $self->{data_col});
1949 4 $value .= $self->{rows}[$_]{text} for $self->{data_row} + 1 .. $last;
1950 4 $self->{row} = $last;
1951 4 $self->{col} = length $self->{rows}[$last]{text};
1952 4 ▶ $self->{output_row} = $last if defined $self->{output_row};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"output_row"} 2 2 4
1953 4 $self->append("\n");
1954 4 return "$value\n";
1955 }
1956 45 ▶ return undef if !ref($key) && ($key eq 'EOF' || $key eq 'ENDINPUT');
Branch: 1 branch
BranchTrueFalseTotal
if not ref $key and $key eq "EOF" || $key eq "ENDINPUT" 0 45 45
Condition50%3/6
not ref $key and $key eq "EOF" || $key eq "ENDINPUT"
!ll&&!rl&&r
4320
$key eq "EOF" or $key eq "ENDINPUT"
l!l&&r!l&&!r
002
MC/DC0%0/3
not ref $key and $key eq "EOF" || $key eq "ENDINPUT"
not ref $key $key eq "EOF" $key eq "ENDINPUT"
Truth table50%2/4
not(A) and B or C
A= not ref $keyB= $key eq "EOF"C= $key eq "ENDINPUT"
ABCresult
0XX0
1000
11X1
1011
1957 45 ▶ return undef if $confirmation && !ref($key) && $key eq 'ESC';
Branch: 1 branch
BranchTrueFalseTotal
if $confirmation and not ref $key and $key eq "ESC" 0 45 45
Condition33%2/6
$confirmation and not ref $key and $key eq "ESC"
!ll&&!rl&&r
4500
$confirmation and not ref $key
!ll&&!rl&&r
4500
MC/DC0%0/3
$confirmation and not ref $key and $key eq "ESC"
$confirmation not ref $key $key eq "ESC"
Truth table25%1/4
A and not(B) and C
A= $confirmationB= not ref $keyC= $key eq "ESC"
ABCresult
0XX0
10X0
1100
1111
1958 45 ▶ die "Interrupted.\n" if !ref($key) && $key eq 'CANCEL';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $key and $key eq "CANCEL" 0 45 45
Condition66%2/3
not ref $key and $key eq "CANCEL"
!ll&&!rl&&r
4320
MC/DC0%0/2
not ref $key and $key eq "CANCEL"
not ref $key $key eq "CANCEL"
Truth table66%2/3
not(A) and B
A= not ref $keyB= $key eq "CANCEL"
ABresult
0X0
100
111
1959 45 ▶ if (ref $key) { $key->[1] =~ s/\n/ /g; $self->edit_key($key); }
Branch: 4 branches
BranchTrueFalseTotal
if (ref $key) { } 43 2 45
elsif ($key eq 'LEFT' or $key eq 'BACKSPACE') { } 2 0 2
elsif ($key eq 'HOME') { } 0 0 0
elsif ($key =~ /\A(?:RIGHT|END|DELETE|INSERT|TAB)\z/u) { } 0 0 0
1960 ▶ elsif ($key eq 'LEFT' || $key eq 'BACKSPACE') {
Condition66%2/3
$key eq "LEFT" or $key eq "BACKSPACE"
l!l&&r!l&&!r
110
MC/DC0%0/2
$key eq "LEFT" or $key eq "BACKSPACE"
$key eq "LEFT" $key eq "BACKSPACE"
Truth table66%2/3
A or B
A= $key eq "LEFT"B= $key eq "BACKSPACE"
ABresult
1X1
011
000
1961 2 ▶ if ($self->{row} > $self->{data_row}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"row"} > $self->{"data_row"} or $self->{"row"} == $self->{"data_row"} and $self->{"col"} > $self->{"data_col"}) 1 1 2
Condition50%3/6
$self->{"row"} > $self->{"data_row"} or $self->{"row"} == $self->{"data_row"} and $self->{"col"} > $self->{"data_col"}
l!l&&r!l&&!r
101
$self->{"row"} == $self->{"data_row"} and $self->{"col"} > $self->{"data_col"}
!ll&&!rl&&r
010
MC/DC33%1/3
$self->{"row"} > $self->{"data_row"} or $self->{"row"} == $self->{"data_row"} and $self->{"col"} > $self->{"data_col"}
$self->{"row"} > $self->{"data_row"} $self->{"row"} == $self->{"data_row"} $self->{"col"} > $self->{"data_col"}
Truth table50%2/4
A or B and C
A= $self->{"row"} > $self->{"data_row"}B= $self->{"row"} == $self->{"data_row"}C= $self->{"col"} > $self->{"data_col"}
ABCresult
1XX1
0111
00X0
0100
1962 || ($self->{row} == $self->{data_row} && $self->{col} > $self->{data_col})) {
1963 1 $self->edit_key($key);
1964 }
1965 }
1966 0 elsif ($key eq 'HOME') { @{$self}{qw(row col)} = @{$self}{qw(data_row data_col)}; }
1967 0 elsif ($key =~ /\A(?:RIGHT|END|DELETE|INSERT|TAB)\z/) { $self->edit_key($key); }
1968 }
1969 }
1970  
1971 0 ▶sub external {
Subroutine external: not called CC=6 SCAR=37.4
1972 0 my ($self, $code, $pause) = @_;
1973 0 $self->leave;
1974 0 my $status;
1975 0 my $ok = eval {
1976 0 local *STDIN;
1977 0 local *STDOUT;
1978 0 local *STDERR;
1979 0 ▶ open STDIN, '<&', $self->{in} or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open STDIN, "<&", $self->{"in"} or die $! 0 0 0
1980 0 ▶ open STDOUT, '>&', $self->{out} or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">&", $self->{"out"} or die $! 0 0 0
1981 0 ▶ open STDERR, '>&', $self->{err} or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&", $self->{"err"} or die $! 0 0 0
1982 0 $status = $code->();
1983 0 ▶ if ($pause) { print STDOUT "\nPress Enter to return to PERL ANTE REPL."; scalar <STDIN>; }
Branch: 1 branch
BranchTrueFalseTotal
if ($pause) 0 0 0
1984 0 1;
1985 };
1986 0 my $error = $@;
1987 0 $self->enter;
1988 0 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
1989 0 return $status;
1990 }
1991  
1992 0 ▶sub shell {
Subroutine shell: not called CC=12 SCAR=50.5
1993 0 my ($self, $command) = @_;
1994 0 require POSIX;
1995 0 my $file = File::Temp->new(UNLINK => 1);
1996 0 ▶ open my $null, '<', File::Spec->devnull or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $null, "<", "File::Spec"->devnull or die $! 0 0 0
1997 0 my @saved = map { POSIX::dup($_) } 0 .. 2;
1998 0 ▶ die "Cannot preserve shell file descriptors: $!\n" if grep { !defined $_ || $_ < 0 } @saved;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_ or $_ < 0;} @saved 0 0 0
Condition0%0/3
!defined($_) || $_ < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
!defined($_) || $_ < 0
!defined($_) $_ < 0
Truth table0%0/3
not(A) || B
A= !defined($_)B= $_ < 0
ABresult
1X1
011
000
1999 0 my ($status, $error);
2000 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { foreach my $fd (0 .. 2) { my $target = $fd ? fileno $file : fileno $null; die "Cannot redirect shell descriptor ${fd}: $!\n" unless defined POSIX::dup2($target, $fd); } ; $status = system(@$command); 1 } } or $error = $@ 0 0 0
2001 0 for my $fd (0 .. 2) {
2002 0 ▶ my $target = $fd ? fileno($file) : fileno($null);
Branch: 1 branch
BranchTrueFalseTotal
$fd ? : 0 0 0
2003 0 ▶ die "Cannot redirect shell descriptor $fd: $!\n" unless defined POSIX::dup2($target, $fd);
Branch: 1 branch
BranchTrueFalseTotal
unless defined POSIX::dup2($target, $fd) 0 0 0
2004 }
2005 0 $status = system @$command;
2006 0 1;
2007 } or $error = $@;
2008 0 for my $fd (0 .. 2) { POSIX::dup2($saved[$fd], $fd); POSIX::close($saved[$fd]); }
2009 0 ▶ seek($file, 0, 0) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
seek $file, 0, 0 or die $! 0 0 0
2010 0 local $/;
2011 0 my $bytes = <$file>;
2012 0 ▶ $self->append(decode('UTF-8', $bytes || '', FB_DEFAULT));
Condition0%0/2
$bytes || ''
l!l
00
MC/DC0%0/1
$bytes || ''
$bytes
Truth table0%0/2
A
A= $bytes
Aresult
11
00
2013 0 ▶ die $error if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
2014 0 return $status;
2015 }
2016  
2017 0 ▶sub session {
Subroutine session: not called CC=11 SCAR=48.8
2018 0 my ($self, $repl, $quiet) = @_;
2019 0 local $repl->{interactive} = 1;
2020 0 $repl->{screen} = $self;
2021 0 local $self->{repl} = $repl;
2022 0 $self->enter;
2023 0 my $ok = eval {
2024 0 ▶ local $SIG{TERM} = sub { die "Terminated.\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
2025 0 ▶ local $SIG{HUP} = sub { die "Terminal disconnected.\n" } unless $^O eq 'MSWin32';
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless $^O eq "MSWin32" 0 0 0
2026 0 local *STDOUT;
2027 0 local *STDERR;
2028 0 local *STDIN;
2029 0 tie *STDOUT, 'App::AnteREPL::ScreenOutput', $self;
2030 0 tie *STDERR, 'App::AnteREPL::ScreenOutput', $self;
2031 0 tie *STDIN, 'App::AnteREPL::ScreenInput', $self;
2032 0 ▶ print "*** PERL ANTE REPL V$App::AnteREPL::PROGRAM_VERSION ***\nType HELP for commands.\n" unless $quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $quiet 0 0 0
2033 0 while (1) {
2034 0 my $line;
2035 my $read_ok;
2036 {
2037 0 ▶ local $SIG{INT} = sub { die "Interrupted.\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
2038 0 $read_ok = eval { $line = $self->read_entry; 1 };
2039 }
2040 0 ▶ if (!$read_ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($read_ok) 0 0 0
2041 0 my $error = $@;
2042 0 $self->{out}->clearerr;
2043 0 $self->fresh(1);
2044 0 ▶ print STDERR "AUTO off.\n" if delete $repl->{auto};
Branch: 1 branch
BranchTrueFalseTotal
if delete $repl->{"auto"} 0 0 0
2045 0 print STDERR App::AnteREPL::_input_error($error);
2046 0 next;
2047 }
2048 0 ▶ if (!defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line) 0 0 0
2049 0 ▶ if ($repl->dirty) { $self->fresh(1); print STDERR "Unsaved program. Use SAVE or QUIT!.\n"; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($repl->dirty) 0 0 0
2050 0 last;
2051 }
2052 0 my $continue;
2053 0 my $ran = eval { $continue = $repl->dispatch($line); 1 };
2054 # Perl/native I/O can move the real cursor after a captured write.
2055 # Redraw once after each command even when its model is unchanged.
2056 0 delete $self->{last_frame};
2057 0 ▶ if (!$ran) { print STDERR App::AnteREPL::_input_error($@); }
Branch: 2 branches
BranchTrueFalseTotal
if (not $ran) { } 0 0 0
elsif (not $continue) { } 0 0 0
2058 0 elsif (!$continue) { last; }
2059 0 $self->fresh;
2060 }
2061 0 1;
2062 };
2063 0 my $error = $@;
2064 0 $self->leave;
2065 # Write to the restored terminal, not the screen's captured output. Keep
2066 # this out of leave(), which also suspends the screen for EDIT and shells.
2067 0 print {$self->{out}} "\n";
2068 0 ▶ print {$self->{out}} "$App::AnteREPL::FAREWELL\n" if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
2069 0 delete $repl->{screen};
2070 0 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
2071 0 return 0;
2072 }
2073  
2074 package App::AnteREPL::ScreenOutput;
2075 82 ▶sub TIEHANDLE { bless { screen => $_[1] }, $_[0] }
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
2076 42 ▶sub PRINT { my $self = shift; $self->{screen}->append(join(defined $, ? $, : '', @_) . (defined $\ ? $\ : '')); return 1; }
Subroutine PRINT: called CC=3 SCAR=11.1
Branch: 2 branches
BranchTrueFalseTotal
defined $, ? : 0 42 42
defined $\ ? : 30 12 42
2077 0 ▶sub PRINTF { my ($self, $format, @args) = @_; $self->{screen}->append(sprintf $format, @args); return 1; }
Subroutine PRINTF: not called CC=1 SCAR=6.9
2078 0 ▶sub WRITE { my ($self, $buffer, $length, $offset) = @_; my $part = substr($buffer, $offset || 0, $length); $self->{screen}->append($part); return length $part; }
Subroutine WRITE: not called CC=2 SCAR=17.9
Condition0%0/2
$offset || 0
l!l
00
MC/DC0%0/1
$offset || 0
$offset
Truth table0%0/2
A
A= $offset
Aresult
11
00
2079 0 ▶sub FILENO { fileno $_[0]->{screen}{out} }
Subroutine FILENO: not called CC=1 SCAR=6.9
2080 0 ▶sub BINMODE { 1 }
Subroutine BINMODE: not called CC=1 SCAR=6.9
2081 0 ▶sub CLOSE { 1 }
Subroutine CLOSE: not called CC=1 SCAR=6.9
2082  
2083 package App::AnteREPL::ScreenInput;
2084 41 ▶sub TIEHANDLE { bless { screen => $_[1] }, $_[0] }
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
2085 2 ▶sub READLINE { $_[0]->{screen}->read_data }
Subroutine READLINE: called CC=1 SCAR=0.0
2086 0 ▶sub FILENO { fileno $_[0]->{screen}{in} }
Subroutine FILENO: not called CC=1 SCAR=6.9
2087 0 ▶sub BINMODE { 1 }
Subroutine BINMODE: not called CC=1 SCAR=6.9
2088 0 ▶sub CLOSE { 1 }
Subroutine CLOSE: not called CC=1 SCAR=6.9
2089  
2090 # Keep REPL internals and their lexical variables out of the user's evaluation.
2091 package App::AnteREPL::Evaluator;
2092 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2093 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2094 25 ▶no strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
2095 25 ▶no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
2096 25 ▶use feature 'say';
Subroutine BEGIN: called CC=1 SCAR=0.0
2097  
2098 345 ▶sub evaluate {
Subroutine evaluate: called CC=1 SCAR=0.0
2099 345 local $@;
2100 345 return (scalar(eval $_[0]), $@);
2101 }
2102  
2103 25 1;
2104  
2105 __END__
↑ Summary lib/App/AnteREPL/Shorthand.pm »