lib/App/AnteREPL.pm

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