pvim

filter: Statementstmt 75.3% 803 / 1066 Branchbran 60.7% 469 / 772 Conditioncond 48.6% 197 / 405 MC/DCmcdc 26.2% 64 / 244 Subroutinesub 78.0% 64 / 82 Podpod n/a totaltotal 62.1% 1597 / 2569 CC 541 SCAR 54.1
CC
541
Cov
65%
key
711.7
run
442.9
draw
420.0
CRAP 224.7
↑ Summary lib/App/Pvim.pm »
1 #!/usr/bin/env perl
2 45 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # All runtime code lives here. Packages separate storage, commands and terminal IO.
7 package PVim::Store;
8 25 ▶use File::Temp qw(tempfile);
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 Digest::SHA qw(sha256_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 61 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
14 61 my ($class) = @_;
15 61 my ($data) = tempfile(UNLINK => 1);
16 61 my ($index) = tempfile(UNLINK => 1);
17 61 binmode $data; binmode $index;
18 61 return bless { data => $data, index => $index, next => 0, pieces => [], count => 0,
19 undo => [], redo => [], state => 0, serial => 0, saved => 0, eol => "\n", final => 1 }, $class;
20 }
21 30488 ▶sub _seek { seek($_[0], $_[1], 0) or die "Temporary-file seek: $!\n" }
Subroutine _seek: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
seek $_[0], $_[1], 0 or die "Temporary-file seek: $!\n" 30508 0 30508
22 10350 ▶sub _record {
Subroutine _record: called CC=3 SCAR=11.0
23 10350 my ($s, $offset, $length, $term) = @_;
24 10350 my $id = $s->{next}++;
25 10350 ▶ _seek($s->{index}, $id * 24) unless tell($s->{index}) == $id * 24;
Branch: 1 branch
BranchTrueFalseTotal
unless tell $s->{"index"} == $id * 24 5022 5348 10370
26 10350 ▶ print {$s->{index}} pack('d3', $offset, $length, $term) or die "Temporary index: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
print {$s->{"index"};} pack("d3", $offset, $length, $term) or die "Temporary index: $!\n" 10350 0 10350
27 10350 return $id;
28 }
29 20308 ▶sub record {
Subroutine record: called CC=2 SCAR=7.0
30 20308 my ($s, $id) = @_;
31 20308 _seek($s->{index}, $id * 24);
32 20308 ▶ read($s->{index}, my $record, 24) == 24 or die "Temporary index read failed\n";
Branch: 1 branch
BranchTrueFalseTotal
read($s->{"index"}, my $record, 24) == 24 or die "Temporary index read failed\n" 20308 0 20308
33 20308 return unpack('d3', $record);
34 }
35 10493 ▶sub id {
Subroutine id: called CC=6 SCAR=18.2
36 10493 my ($s, $line) = @_;
37 10493 ▶ die "Line out of range\n" if $line < 0 || $line >= $s->{count};
Branch: 1 branch
BranchTrueFalseTotal
if $line < 0 or $line >= $s->{"count"} 0 10493 10493
Condition66%2/3
$line < 0 or $line >= $s->{"count"}
l!l&&r!l&&!r
01510493
MC/DC0%0/2
$line < 0 or $line >= $s->{"count"}
$line < 0 $line >= $s->{"count"}
Truth table33%1/3
A or B
A= $line < 0B= $line >= $s->{"count"}
ABresult
1X1
011
000
38 10493 my ($lo, $hi) = (0, $#{$s->{pieces}});
39 10493 ▶ while ($lo <= $hi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lo <= $hi) 10566 0 10566
40 10566 my $mid = int(($lo + $hi) / 2);
41 10566 my $p = $s->{pieces}[$mid];
42 10566 ▶ if ($line < $p->[2]) { $hi = $mid - 1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($line < $p->[2]) { } 6 10560 10566
elsif ($line >= $p->[2] + $p->[1]) { } 67 10493 10560
43 67 elsif ($line >= $p->[2] + $p->[1]) { $lo = $mid + 1 }
44 10493 else { return $p->[0] + $line - $p->[2] }
45 }
46 0 die "Corrupt piece index\n";
47 }
48 5372 ▶sub line {
Subroutine line: called CC=6 SCAR=17.9
49 5372 my ($s, $line) = @_;
50 5372 my $id = $s->id($line);
51 5372 ▶ return $s->{cache}{$id} if exists $s->{cache}{$id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $s->{"cache"}{$id} 216 5156 5372
52 5156 my ($offset, $length) = $s->record($id);
53 5156 _seek($s->{data}, $offset);
54 5156 my $text = '';
55 5156 ▶ while (length($text) < $length) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $text < $length) 5147 5156 10303
56 5147 my $got = read($s->{data}, my $chunk, $length - length($text));
57 5147 ▶ die "Temporary data read failed\n" unless $got;
Branch: 1 branch
BranchTrueFalseTotal
unless $got 0 5147 5147
58 5147 $text .= $chunk;
59 }
60 5156 ▶ if (length($text) <= 65536) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $text <= 65536) 5156 0 5156
61 5156 $s->{cache}{$id} = $text; push @{$s->{cache_order}}, $id;
62 5156 ▶ delete $s->{cache}{shift @{$s->{cache_order}}} if @{$s->{cache_order}} > 128;
Branch: 1 branch
BranchTrueFalseTotal
if @{$s->{"cache_order"};} > 128 4875 281 5156
63 }
64 5156 return $text;
65 }
66 5105 ▶sub term { my ($s, $line) = @_; my @r = $s->record($s->id($line)); return $r[2] }
Subroutine term: called CC=1 SCAR=0.0
67 10177 ▶sub append {
Subroutine append: called CC=7 SCAR=20.0
68 10177 my ($s, $text, $term) = @_;
69 10177 ▶ die "Internal newline in line\n" if $text =~ /\n/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\n/ 0 10177 10177
70 10177 ▶ seek($s->{data}, 0, 2) or die "Temporary data seek: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
seek $s->{"data"}, 0, 2 or die "Temporary data seek: $!\n" 10177 0 10177
71 10177 my $off = tell($s->{data});
72 10177 ▶ $term = length($s->{eol}) unless defined $term;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $term 5066 5111 10177
73 10177 ▶ print {$s->{data}} $text, ($term == 2 ? "\r\n" : $term == 1 ? "\n" : '') or die "Temporary data write: $!\n";
Branch: 3 branches
BranchTrueFalseTotal
print {$s->{"data"};} $text, $term == 2 ? "\r\n" : ($term == 1 ? "\n" : "") or die "Temporary data write: $!\n" 10177 0 10177
$term == 2 ? : 0 10177 10177
$term == 1 ? : 10137 40 10177
74 10177 return $s->_record($off, length($text), $term);
75 }
76 180 ▶sub reindex {
Subroutine reindex: called CC=6 SCAR=18.0
77 180 my ($s) = @_;
78 180 my (@out, $n);
79 180 $n = 0;
80 180 for my $p (@{$s->{pieces}}) {
81 5267 ▶ next unless $p->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $p->[1] 0 5267 5267
82 5267 ▶ if (@out && $out[-1][0] + $out[-1][1] == $p->[0] && ($s->record($p->[0]-1))[2]) { $out[-1][1] += $p->[1] }
Branch: 1 branch
BranchTrueFalseTotal
if (@out and $out[-1][0] + $out[-1][1] == $p->[0] and ($s->record($p->[0] - 1))[2]) { } 5032 235 5267
Condition83%5/6
@out and $out[-1][0] + $out[-1][1] == $p->[0] and ($s->record($p->[0] - 1))[2]
!ll&&!rl&&r
23505032
@out and $out[-1][0] + $out[-1][1] == $p->[0]
!ll&&!rl&&r
179565032
MC/DC66%2/3
@out and $out[-1][0] + $out[-1][1] == $p->[0] and ($s->record($p->[0] - 1))[2]
@out $out[-1][0] + $out[-1][1] == $p->[0] ($s->record($p->[0] - 1))[2]
Truth table75%3/4
A and B and C
A= @outB= $out[-1][0] + $out[-1][1] == $p->[0]C= ($s->record($p->[0] - 1))[2]
ABCresult
0XX0
10X0
1100
1111
83 235 else { push @out, [$p->[0], $p->[1], $n] }
84 5267 $n += $p->[1];
85 }
86 180 $s->{pieces} = \@out; $s->{count} = $n;
87 }
88 276 ▶sub slice {
Subroutine slice: called CC=5 SCAR=16.1
89 276 my ($s, $start, $length) = @_;
90 276 my @out;
91 276 for my $p (@{$s->{pieces}}) {
92 284 ▶ my $a = $start > $p->[2] ? $start : $p->[2];
Branch: 1 branch
BranchTrueFalseTotal
$start > $p->[2] ? : 121 163 284
93 284 ▶ my $b = $start + $length < $p->[2] + $p->[1] ? $start + $length : $p->[2] + $p->[1];
Branch: 1 branch
BranchTrueFalseTotal
$start + $length < $p->[2] + $p->[1] ? : 127 157 284
94 284 ▶ push @out, [$p->[0] + $a - $p->[2], $b - $a] if $b > $a;
Branch: 1 branch
BranchTrueFalseTotal
if $b > $a 54 230 284
95 }
96 276 return @out;
97 }
98 113 ▶sub splice_lines {
Subroutine splice_lines: called CC=5 SCAR=19.3
99 113 my ($s, $start, $length, @ids) = @_;
100 113 ▶ die "Invalid splice\n" if $start < 0 || $length < 0 || $start + $length > $s->{count};
Branch: 1 branch
BranchTrueFalseTotal
if $start < 0 or $length < 0 or $start + $length > $s->{"count"} 0 113 113
Condition33%2/6
$start < 0 or $length < 0 or $start + $length > $s->{"count"}
l!l&&r!l&&!r
00113
$start < 0 or $length < 0
l!l&&r!l&&!r
00113
MC/DC0%0/3
$start < 0 or $length < 0 or $start + $length > $s->{"count"}
$start < 0 $length < 0 $start + $length > $s->{"count"}
Truth table25%1/4
A or B or C
A= $start < 0B= $length < 0C= $start + $length > $s->{"count"}
ABCresult
1XX1
01X1
0011
0000
101 113 my @new = ($s->slice(0, $start), (map { [$_, 1] } @ids), $s->slice($start + $length, $s->{count} - $start - $length));
102 113 $s->{pieces} = \@new;
103 113 $s->reindex;
104 0 ▶ unless ($s->{count}) { $s->{pieces} = [[$s->append('', 0), 1]]; $s->reindex }
Branch: 1 branch
BranchTrueFalseTotal
unless ($s->{"count"}) 0 113 113
105 }
106 37 ▶sub set_line {
Subroutine set_line: called CC=1 SCAR=0.0
107 37 my ($s, $n, $text) = @_;
108 37 $s->splice_lines($n, 1, $s->append($text, $s->term($n)));
109 }
110 61 ▶sub snapshot { my ($s) = @_; return { pieces => [map { [@$_] } @{$s->{pieces}}], state => $s->{state}, final => $s->{final}, cursor => [@{$s->{cursor} || [0,0]}] } }
Subroutine snapshot: called CC=2 SCAR=7.0
Condition50%1/2
$s->{'cursor'} || [0, 0]
l!l
610
MC/DC0%0/1
$s->{'cursor'} || [0, 0]
$s->{'cursor'}
Truth table50%1/2
A
A= $s->{'cursor'}
Aresult
11
00
111 14 ▶sub restore { my ($s, $v) = @_; $s->{pieces} = [map { [@$_] } @{$v->{pieces}}]; $s->{state} = $v->{state}; $s->{final} = $v->{final}; $s->{cursor} = [@{$v->{cursor}}]; $s->reindex }
Subroutine restore: called CC=1 SCAR=0.0
112 47 ▶sub begin { my ($s) = @_; $s->{before} = $s->snapshot unless $s->{before} }
Subroutine begin: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
unless $s->{"before"} 47 0 47
113 68 ▶sub commit {
Subroutine commit: called CC=4 SCAR=14.0
114 68 my ($s) = @_;
115 68 ▶ my $before = delete $s->{before} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $before = delete $s->{"before"} or return 47 21 68
116 47 my $old = join(';', map { join(',', @$_[0,1]) } @{$before->{pieces}});
117 47 my $now = join(';', map { join(',', @$_[0,1]) } @{$s->{pieces}});
118 47 ▶ return if $old eq $now && $before->{final} == $s->{final};
Branch: 1 branch
BranchTrueFalseTotal
if $old eq $now and $before->{"final"} == $s->{"final"} 0 47 47
Condition33%1/3
$old eq $now and $before->{"final"} == $s->{"final"}
!ll&&!rl&&r
4700
MC/DC0%0/2
$old eq $now and $before->{"final"} == $s->{"final"}
$old eq $now $before->{"final"} == $s->{"final"}
Truth table33%1/3
A and B
A= $old eq $nowB= $before->{"final"} == $s->{"final"}
ABresult
0X0
100
111
119 47 push @{$s->{undo}}, $before;
120 47 $s->{redo} = []; $s->{state} = ++$s->{serial};
121 }
122 0 ▶sub rollback { my ($s) = @_; my $v = delete $s->{before}; $s->restore($v) if $v }
Subroutine rollback: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $v 0 0 0
123 14 ▶sub undo {
Subroutine undo: called CC=3 SCAR=11.0
124 14 my ($s, $redo) = @_;
125 14 $s->commit;
126 14 ▶ my ($from, $to) = $redo ? ('redo','undo') : ('undo','redo');
Branch: 1 branch
BranchTrueFalseTotal
$redo ? : 2 12 14
127 14 ▶ return 0 unless @{$s->{$from}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$s->{$from};} 0 14 14
128 14 push @{$s->{$to}}, $s->snapshot;
129 14 $s->restore(pop @{$s->{$from}}); return 1;
130 }
131 9 ▶sub dirty { my ($s) = @_; return $s->{state} != $s->{saved} || !!$s->{before} }
Subroutine dirty: called CC=2 SCAR=7.1
Condition66%2/3
$s->{'state'} != $s->{'saved'} || !!$s->{'before'}
l!l&&r!l&&!r
702
MC/DC50%1/2
$s->{'state'} != $s->{'saved'} || !!$s->{'before'}
$s->{'state'} != $s->{'saved'} !!$s->{'before'}
Truth table66%2/3
A || B
A= $s->{'state'} != $s->{'saved'}B= !!$s->{'before'}
ABresult
1X1
011
000
132 21 ▶sub fingerprint {
Subroutine fingerprint: called CC=4 SCAR=14.0
133 21 my ($path) = @_;
134 21 ▶ return '' unless -e $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $path 2 19 21
135 19 ▶ open my $fh, '<', $path or die "Read $path: $!\n"; binmode $fh;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $path or die "Read ${path}: $!\n" 19 0 19
136 19 my $digest = Digest::SHA->new(256); $digest->addfile($fh);
137 19 ▶ close $fh or die "Close $path: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Close ${path}: $!\n" 19 0 19
138 19 return $digest->hexdigest;
139 }
140 61 ▶sub load {
Subroutine load: called CC=29 SCAR=34.0
141 61 my ($class, $path, $input) = @_;
142 61 my $s = $class->new;
143 61 ▶ $s->{path} = $path if defined($path) && length($path);
Branch: 1 branch
BranchTrueFalseTotal
if defined $path and length $path 18 43 61
Condition66%2/3
defined $path and length $path
!ll&&!rl&&r
43018
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
144 61 ▶ unless ($input || (defined($path) && length($path) && -e $path)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($input or defined $path and length $path and -e $path) 33 28 61
Condition77%7/9
$input or defined $path and length $path and -e $path
l!l&&r!l&&!r
101833
defined $path and length $path and -e $path
!ll&&!rl&&r
33018
defined $path and length $path
!ll&&!rl&&r
33018
MC/DC50%2/4
$input or defined $path and length $path and -e $path
$input defined $path length $path -e $path
Truth table60%3/5
A or B and C and D
A= $inputB= defined $pathC= length $pathD= -e $path
ABCDresult
1XXX1
01111
00XX0
010X0
01100
145 33 ▶ die "Refusing dangling symlink\n" if defined($path) && -l $path;
Branch: 1 branch
BranchTrueFalseTotal
if defined $path and -l $path 0 33 33
Condition33%1/3
defined $path and -l $path
!ll&&!rl&&r
3300
MC/DC0%0/2
defined $path and -l $path
defined $path -l $path
Truth table33%1/3
A and B
A= defined $pathB= -l $path
ABresult
0X0
100
111
146 33 $s->splice_lines(0, 0, $s->append('', 0)); $s->{fingerprint} = ''; return $s;
147 }
148 28 ▶ die "Not a regular file: $path\n" unless $input || -f $path;
Branch: 1 branch
BranchTrueFalseTotal
unless $input or -f $path 0 28 28
Condition66%2/3
$input or -f $path
l!l&&r!l&&!r
10180
MC/DC0%0/2
$input or -f $path
$input -f $path
Truth table66%2/3
A or B
A= $inputB= -f $path
ABresult
1X1
011
000
149 28 my $fh = $input;
150 28 ▶ unless ($fh) { open $fh, '<', $path or die "Read $path: $!\n" }
Branch: 2 branches
BranchTrueFalseTotal
unless ($fh) 18 10 28
open $fh, "<", $path or die "Read ${path}: $!\n" 18 0 18
151 28 binmode $fh;
152 28 ▶ my $label = $input ? 'standard input' : $path;
Branch: 1 branch
BranchTrueFalseTotal
$input ? : 10 18 28
153 28 my $digest = Digest::SHA->new(256);
154 28 my ($offset, $start, $prev, $first, $last_term) = (0, 0, '', 1, 0);
155 28 while (1) {
156 179 my $got = read($fh, my $chunk, 65536);
157 179 ▶ die "Read $label: $!\n" unless defined $got;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $got 0 179 179
158 179 ▶ last unless $got;
Branch: 1 branch
BranchTrueFalseTotal
unless $got 28 151 179
159 151 $digest->add($chunk);
160 151 ▶ print {$s->{data}} $chunk or die "Temporary data: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
print {$s->{"data"};} $chunk or die "Temporary data: $!\n" 151 0 151
161 151 ▶ while ($chunk =~ /\n/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk =~ /\n/g) 161 151 312
162 161 my $end = $offset + pos($chunk) - 1;
163 161 ▶ my $cr = pos($chunk) > 1 ? substr($chunk, pos($chunk) - 2, 1) eq "\r" : $prev eq "\r";
Branch: 1 branch
BranchTrueFalseTotal
pos $chunk > 1 ? : 160 1 161
164 161 ▶ my $term = $cr ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$cr ? : 129 32 161
165 161 ▶ $s->_record($start, $end - $start - ($cr ? 1 : 0), $term);
Branch: 1 branch
BranchTrueFalseTotal
$cr ? : 129 32 161
166 161 ▶ if ($first) { $s->{eol} = $cr ? "\r\n" : "\n"; $first = 0 }
Branch: 2 branches
BranchTrueFalseTotal
if ($first) 18 143 161
$cr ? : 2 16 18
167 161 $start = $end + 1; $last_term = $term;
168 }
169 151 $offset += $got; $prev = substr($chunk, -1);
170 }
171 28 ▶ unless ($input) { close $fh or die "Close $path: $!\n" }
Branch: 2 branches
BranchTrueFalseTotal
unless ($input) 18 10 28
close $fh or die "Close ${path}: $!\n" 18 0 18
172 28 ▶ if ($start < $offset || !$offset) { $s->_record($start, $offset - $start, 0); $last_term = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($start < $offset or not $offset) 12 16 28
Condition100%3/3
$start < $offset or not $offset
l!l&&r!l&&!r
7516
MC/DC100%2/2
$start < $offset or not $offset
$start < $offset not $offset
Truth table100%3/3
A or not(B)
A= $start < $offsetB= not $offset
ABresult
1X1
011
000
173 28 ▶ $s->{final} = $last_term ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$last_term ? : 16 12 28
174 28 $s->{fingerprint} = $digest->hexdigest;
175 28 $s->{pieces} = [[0, $s->{next}]]; $s->reindex;
176 28 ▶ if ($input) { $s->{state} = ++$s->{serial}; $s->{fingerprint} = '' }
Branch: 1 branch
BranchTrueFalseTotal
if ($input) 10 18 28
177 28 return $s;
178 }
179 7 ▶sub write_to {
Subroutine write_to: called CC=11 SCAR=24.6
180 7 my ($s, $out) = @_;
181 # Every run has physical newlines internally; its boundary may need a newline.
182 7 for my $p (@{$s->{pieces}}) {
183 7 my ($offset) = $s->record($p->[0]);
184 7 my ($end, $body, $term) = $s->record($p->[0]+$p->[1]-1);
185 7 my $len = $end + $body - $offset;
186 7 _seek($s->{data}, $offset);
187 7 ▶ while ($len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len) 6 7 13
188 6 ▶ my $got = read($s->{data}, my $chunk, $len > 65536 ? 65536 : $len);
Branch: 1 branch
BranchTrueFalseTotal
$len > 65536 ? : 0 6 6
189 6 ▶ die "Temporary data read failed\n" unless $got;
Branch: 1 branch
BranchTrueFalseTotal
unless $got 0 6 6
190 6 ▶ print {$out} $chunk or die "Write: $!\n"; $len -= $got;
Branch: 1 branch
BranchTrueFalseTotal
print {$out;} $chunk or die "Write: $!\n" 6 0 6
191 }
192 7 my $last = $p->[2] + $p->[1] == $s->{count};
193 7 ▶ my $eol = $term == 2 ? "\r\n" : $term == 1 ? "\n" : $s->{eol};
Branch: 2 branches
BranchTrueFalseTotal
$term == 2 ? : 0 7 7
$term == 1 ? : 5 2 7
194 7 ▶ print {$out} $eol or die "Write: $!\n" if !$last || $s->{final};
Branch: 1 branch
BranchTrueFalseTotal
if not $last or $s->{"final"} 5 2 7
Condition62%5/8
(!$last || $s->{'final'}) && (print({$out;} $eol) || die("Write: $!\n"))
!ll&&!rl&&r
250
not $last or $s->{"final"}
l!l&&r!l&&!r
052
print {$out;} $eol or die "Write: $!\n"
l!l
50
MC/DC0%0/3
(!$last || $s->{'final'}) && (print({$out;} $eol) || die("Write: $!\n"))
not $last $s->{"final"} print {$out;} $eol
Truth table20%1/5
not(A) or B && C
A= not $lastB= $s->{"final"}C= print {$out;} $eol
ABCresult
00X0
1X00
0100
1X11
0111
195 }
196 }
197 7 ▶sub save {
Subroutine save: called CC=23 SCAR=35.6
198 7 my ($s, $path, $force) = @_;
199 7 $s->commit;
200 7 ▶ $path = $s->{path} unless defined($path) && length($path);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path and length $path 1 6 7
Condition66%2/3
defined $path and length $path
!ll&&!rl&&r
106
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
201 7 ▶ die "No filename; use :w filename\n" unless defined($path) && length($path);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path and length $path 0 7 7
Condition33%1/3
defined $path and length $path
!ll&&!rl&&r
007
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
202 7 ▶ die "Refusing to replace a symlink\n" if -l $path;
Branch: 1 branch
BranchTrueFalseTotal
if -l $path 0 7 7
203 7 ▶ die "Not a regular file: $path\n" if -e $path && !-f $path;
Branch: 1 branch
BranchTrueFalseTotal
if -e $path and not -f $path 0 7 7
Condition66%2/3
-e $path and not -f $path
!ll&&!rl&&r
160
MC/DC0%0/2
-e $path and not -f $path
-e $path not -f $path
Truth table66%2/3
A and not(B)
A= -e $pathB= not -f $path
ABresult
0X0
100
111
204 7 ▶ my $same = defined($s->{path}) && File::Spec->rel2abs($path) eq File::Spec->rel2abs($s->{path});
Condition66%2/3
defined $s->{'path'} && 'File::Spec'->rel2abs($path) eq 'File::Spec'->rel2abs($s->{'path'})
!ll&&!rl&&r
601
MC/DC50%1/2
defined $s->{'path'} && 'File::Spec'->rel2abs($path) eq 'File::Spec'->rel2abs($s->{'path'})
defined $s->{'path'} 'File::Spec'->rel2abs($path) eq 'File::Spec'->rel2abs($s->{'path'})
Truth table66%2/3
A && B
A= defined $s->{'path'}B= 'File::Spec'->rel2abs($path) eq 'File::Spec'->rel2abs($s->{'path'})
ABresult
0X0
100
111
205 7 ▶ my $expected = $same ? $s->{fingerprint} : '';
Branch: 1 branch
BranchTrueFalseTotal
$same ? : 1 6 7
206 7 my $current = fingerprint($path);
207 7 ▶ die "File exists or changed on disk; use :w! to overwrite\n" if !$force && $current ne $expected;
Branch: 1 branch
BranchTrueFalseTotal
if not $force and $current ne $expected 0 7 7
Condition66%2/3
not $force and $current ne $expected
!ll&&!rl&&r
610
MC/DC0%0/2
not $force and $current ne $expected
not $force $current ne $expected
Truth table66%2/3
not(A) and B
A= not $forceB= $current ne $expected
ABresult
0X0
100
111
208 7 my @stat = stat($path);
209 7 ▶ die "File has multiple hard links; refusing atomic replacement\n" if @stat && $stat[3] > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @stat and $stat[3] > 1 0 7 7
Condition66%2/3
@stat and $stat[3] > 1
!ll&&!rl&&r
160
MC/DC0%0/2
@stat and $stat[3] > 1
@stat $stat[3] > 1
Truth table66%2/3
A and B
A= @statB= $stat[3] > 1
ABresult
0X0
100
111
210 7 ▶ die "File is read-only\n" if @stat && !($stat[2] & 0222);
Branch: 1 branch
BranchTrueFalseTotal
if @stat and not $stat[2] & 146 0 7 7
Condition66%2/3
@stat and not $stat[2] & 146
!ll&&!rl&&r
160
MC/DC0%0/2
@stat and not $stat[2] & 146
@stat not $stat[2] & 146
Truth table66%2/3
A and not(B)
A= @statB= not $stat[2] & 146
ABresult
0X0
100
111
211 7 my ($fh, $tmp) = tempfile('.pvim-save-XXXXXX', DIR => dirname(File::Spec->rel2abs($path)), UNLINK => 0);
212 7 binmode $fh;
213 7 my $ok = eval {
214 7 ▶ $s->write_to($fh); close($fh) or die "Close output: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Close output: $!\n" 7 0 7
215 7 ▶ my $mode = @stat ? $stat[2] & 0777 : 0666 & ~umask;
Branch: 1 branch
BranchTrueFalseTotal
@stat ? : 6 1 7
216 7 ▶ chmod($mode, $tmp) or die "chmod: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chmod $mode, $tmp or die "chmod: $!\n" 7 0 7
217 7 ▶ die "Target changed during save\n" if -l $path || fingerprint($path) ne $current;
Branch: 1 branch
BranchTrueFalseTotal
if -l $path or fingerprint($path) ne $current 0 7 7
Condition33%1/3
-l $path or fingerprint($path) ne $current
l!l&&r!l&&!r
007
MC/DC0%0/2
-l $path or fingerprint($path) ne $current
-l $path fingerprint($path) ne $current
Truth table33%1/3
A or B
A= -l $pathB= fingerprint($path) ne $current
ABresult
1X1
011
000
218 7 ▶ rename($tmp, $path) or die "Rename: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
rename $tmp, $path or die "Rename: $!\n" 7 0 7
219 7 1;
220 };
221 7 my $error = $@;
222 0 ▶ unless ($ok) { close $fh; unlink $tmp; die $error }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 7 7
223 7 $s->{path} = $path; $s->{fingerprint} = fingerprint($path); $s->{saved} = $s->{state};
224 7 return $path;
225 }
226  
227 package PVim::Editor;
228 45 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
229 45 my ($class, $store) = @_;
230 45 return bless { b => $store, row => 0, col => 0, mode => 'normal', number => 0,
231 tabstop => 8, message => '', pending => '', count => '', register => [], page => 20 }, $class;
232 }
233 124 ▶sub clamp {
Subroutine clamp: called CC=7 SCAR=19.7
234 124 my ($e) = @_;
235 124 ▶ $e->{row} = 0 if $e->{row} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"row"} < 0 0 124 124
236 124 ▶ $e->{row} = $e->{b}{count} - 1 if $e->{row} >= $e->{b}{count};
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"row"} >= $e->{"b"}{"count"} 1 123 124
237 124 ▶ my $max = length($e->{b}->line($e->{row})) - ($e->{mode} eq 'normal' ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$e->{'mode'} eq 'normal' ? : 111 13 124
238 124 ▶ $max = 0 if $max < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $max < 0 5 119 124
239 124 ▶ $e->{col} = 0 if $e->{col} < 0; $e->{col} = $max if $e->{col} > $max;
Branch: 2 branches
BranchTrueFalseTotal
if $e->{"col"} < 0 0 124 124
if $e->{"col"} > $max 0 124 124
240 }
241 32 ▶sub edit {
Subroutine edit: called CC=2 SCAR=7.2
242 32 my ($e, $cb) = @_;
243 32 my $b = $e->{b}; $b->{cursor} = [@{$e}{qw(row col)}]; $b->begin;
244 32 my $ok = eval { $cb->(); 1 };
245 0 ▶ unless ($ok) { my $err = $@; $b->rollback; die $err }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 32 32
246 32 $b->commit; $e->clamp;
247 }
248 5 ▶sub insert_mode { my ($e, $mode) = @_; $e->{b}{cursor} = [@{$e}{qw(row col)}]; $e->{b}->begin; $e->{mode} = $mode || 'insert' }
Subroutine insert_mode: called CC=2 SCAR=6.9
Condition100%2/2
$mode || 'insert'
l!l
14
MC/DC100%1/1
$mode || 'insert'
$mode
Truth table100%2/2
A
A= $mode
Aresult
11
00
249 14 ▶sub undo {
Subroutine undo: called CC=2 SCAR=6.9
250 14 my ($e,$redo) = @_; my $b = $e->{b}; $b->{cursor} = [@{$e}{qw(row col)}];
251 14 ▶ return 0 unless $b->undo($redo); @{$e}{qw(row col)} = @{$b->{cursor}}; $e->clamp; return 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $b->undo($redo) 0 14 14
252 }
253 3 ▶sub word {
Subroutine word: called CC=22 SCAR=38.5
254 3 my ($e, $key, $count) = @_;
255 3 for (1 .. $count) {
256 3 my $line = $e->{b}->line($e->{row}); my $c = $e->{col};
257 3 ▶ if ($key eq 'b') {
Branch: 2 branches
BranchTrueFalseTotal
if ($key eq 'b') { } 1 2 3
elsif ($key eq 'w') { } 1 1 2
258 0 ▶ if (!$c && $e->{row}) { --$e->{row}; $line = $e->{b}->line($e->{row}); $c = length($line) }
Branch: 1 branch
BranchTrueFalseTotal
if (not $c and $e->{"row"}) 0 1 1
Condition33%1/3
not $c and $e->{"row"}
!ll&&!rl&&r
100
MC/DC0%0/2
not $c and $e->{"row"}
not $c $e->{"row"}
Truth table33%1/3
not(A) and B
A= not $cB= $e->{"row"}
ABresult
0X0
100
111
259 1 ▶ $c-- if $c; $c-- while $c && substr($line,$c,1) =~ /\s/;
Branch: 2 branches
BranchTrueFalseTotal
if $c 1 0 1
$c and substr($line, $c, 1) =~ /\s/ and do { --$c } 1 1 2
Condition66%2/3
$c and substr($line, $c, 1) =~ /\s/
!ll&&!rl&&r
011
MC/DC50%1/2
$c and substr($line, $c, 1) =~ /\s/
$c substr($line, $c, 1) =~ /\s/
Truth table66%2/3
A and B
A= $cB= substr($line, $c, 1) =~ /\s/
ABresult
0X0
100
111
260 1 ▶ my $type = substr($line,$c,1) =~ /\w/ ? qr/\w/ : qr/[^\w\s]/;
Branch: 1 branch
BranchTrueFalseTotal
substr($line, $c, 1) =~ /\w/ ? : 1 0 1
261 1 ▶ $c-- while $c && substr($line,$c-1,1) =~ $type;
Branch: 1 branch
BranchTrueFalseTotal
$c and substr($line, $c - 1, 1) =~ /$type/ and do { --$c } 4 1 5
Condition66%2/3
$c and substr($line, $c - 1, 1) =~ /$type/
!ll&&!rl&&r
104
MC/DC50%1/2
$c and substr($line, $c - 1, 1) =~ /$type/
$c substr($line, $c - 1, 1) =~ /$type/
Truth table66%2/3
A and B
A= $cB= substr($line, $c - 1, 1) =~ /$type/
ABresult
0X0
100
111
262 } elsif ($key eq 'w') {
263 1 my $tail = substr($line,$c); $tail =~ /^(?:\w+|[^\w\s]+)?\s*/; $c += length($&);
264 1 ▶ if ($c >= length($line) && $e->{row} < $e->{b}{count}-1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c >= length $line and $e->{"row"} < $e->{"b"}{"count"} - 1) 0 1 1
Condition33%1/3
$c >= length $line and $e->{"row"} < $e->{"b"}{"count"} - 1
!ll&&!rl&&r
100
MC/DC0%0/2
$c >= length $line and $e->{"row"} < $e->{"b"}{"count"} - 1
$c >= length $line $e->{"row"} < $e->{"b"}{"count"} - 1
Truth table33%1/3
A and B
A= $c >= length $lineB= $e->{"row"} < $e->{"b"}{"count"} - 1
ABresult
0X0
100
111
265 0 ++$e->{row}; $line = $e->{b}->line($e->{row}); $line =~ /^\s*/; $c = length($&);
266 }
267 } else {
268 1 ▶ $c++ if $c < length($line)-1;
Branch: 1 branch
BranchTrueFalseTotal
if $c < length($line) - 1 1 0 1
269 0 ▶ if ($c >= length($line) && $e->{row} < $e->{b}{count}-1) { ++$e->{row}; $line = $e->{b}->line($e->{row}); $c = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($c >= length $line and $e->{"row"} < $e->{"b"}{"count"} - 1) 0 1 1
Condition33%1/3
$c >= length $line and $e->{"row"} < $e->{"b"}{"count"} - 1
!ll&&!rl&&r
100
MC/DC0%0/2
$c >= length $line and $e->{"row"} < $e->{"b"}{"count"} - 1
$c >= length $line $e->{"row"} < $e->{"b"}{"count"} - 1
Truth table33%1/3
A and B
A= $c >= length $lineB= $e->{"row"} < $e->{"b"}{"count"} - 1
ABresult
0X0
100
111
270 1 ▶ $c++ while $c < length($line)-1 && substr($line,$c,1) =~ /\s/;
Branch: 1 branch
BranchTrueFalseTotal
$c < length($line) - 1 and substr($line, $c, 1) =~ /\s/ and do { ++$c } 0 1 1
Condition33%1/3
$c < length($line) - 1 and substr($line, $c, 1) =~ /\s/
!ll&&!rl&&r
010
MC/DC0%0/2
$c < length($line) - 1 and substr($line, $c, 1) =~ /\s/
$c < length($line) - 1 substr($line, $c, 1) =~ /\s/
Truth table33%1/3
A and B
A= $c < length($line) - 1B= substr($line, $c, 1) =~ /\s/
ABresult
0X0
100
111
271 1 ▶ my $type = substr($line,$c,1) =~ /\w/ ? qr/\w/ : qr/[^\w\s]/;
Branch: 1 branch
BranchTrueFalseTotal
substr($line, $c, 1) =~ /\w/ ? : 1 0 1
272 1 ▶ $c++ while $c < length($line)-1 && substr($line,$c+1,1) =~ $type;
Branch: 1 branch
BranchTrueFalseTotal
$c < length($line) - 1 and substr($line, $c + 1, 1) =~ /$type/ and do { ++$c } 3 1 4
Condition66%2/3
$c < length($line) - 1 and substr($line, $c + 1, 1) =~ /$type/
!ll&&!rl&&r
013
MC/DC50%1/2
$c < length($line) - 1 and substr($line, $c + 1, 1) =~ /$type/
$c < length($line) - 1 substr($line, $c + 1, 1) =~ /$type/
Truth table66%2/3
A and B
A= $c < length($line) - 1B= substr($line, $c + 1, 1) =~ /$type/
ABresult
0X0
100
111
273 }
274 3 $e->{col} = $c;
275 }
276 3 $e->clamp;
277 }
278 12 ▶sub search {
Subroutine search: called CC=16 SCAR=28.1
279 12 my ($e, $pattern, $dir) = @_;
280 12 ▶ $pattern = $e->{search} unless length $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless length $pattern 7 5 12
281 12 ▶ die "No previous search\n" unless defined $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pattern 0 12 12
282 12 ▶ my $rx = eval { qr/$pattern/ }; die "Invalid regex: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 11 12
283 11 $e->{search} = $pattern; $e->{direction} = $dir;
284 11 my $n = $e->{b}{count};
285 11 for my $step (0 .. $n) {
286 21 my $r = ($e->{row} + $dir * $step) % $n;
287 21 my $text = $e->{b}->line($r); my @positions;
288 21 ▶ while ($text =~ /$rx/g) { push @positions, $-[0] }
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /$rx/g) 23 21 44
289 21 ▶ @positions = reverse @positions if $dir < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $dir < 0 6 15 21
290 21 for my $c (@positions) {
291 # Zero-width EOF matches occupy the final displayed character cell.
292 21 ▶ $c = length($text)-1 if $c >= length($text);
Branch: 1 branch
BranchTrueFalseTotal
if $c >= length $text 7 14 21
293 21 ▶ $c = 0 if $c < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $c < 0 0 21 21
294 21 ▶ next if !$step && ($dir > 0 ? $c <= $e->{col} : $c >= $e->{col});
Branch: 2 branches
BranchTrueFalseTotal
if not $step and $dir > 0 ? $c <= $e->{"col"} : $c >= $e->{"col"} 11 10 21
$dir > 0 ? : 9 4 13
Condition100%3/3
not $step and $dir > 0 ? $c <= $e->{"col"} : $c >= $e->{"col"}
!ll&&!rl&&r
8211
MC/DC100%2/2
not $step and $dir > 0 ? $c <= $e->{"col"} : $c >= $e->{"col"}
not $step $dir > 0 ? $c <= $e->{"col"} : $c >= $e->{"col"}
Truth table100%3/3
not(A) and B
A= not $stepB= $dir > 0 ? $c <= $e->{"col"} : $c >= $e->{"col"}
ABresult
0X0
100
111
295 10 ▶ next if $step == $n && ($dir > 0 ? $c > $e->{col} : $c < $e->{col});
Branch: 2 branches
BranchTrueFalseTotal
if $step == $n and $dir > 0 ? $c > $e->{"col"} : $c < $e->{"col"} 0 10 10
$dir > 0 ? : 0 0 0
Condition33%1/3
$step == $n and $dir > 0 ? $c > $e->{"col"} : $c < $e->{"col"}
!ll&&!rl&&r
1000
MC/DC0%0/2
$step == $n and $dir > 0 ? $c > $e->{"col"} : $c < $e->{"col"}
$step == $n $dir > 0 ? $c > $e->{"col"} : $c < $e->{"col"}
Truth table33%1/3
A and B
A= $step == $nB= $dir > 0 ? $c > $e->{"col"} : $c < $e->{"col"}
ABresult
0X0
100
111
296 10 ($e->{row}, $e->{col}) = ($r, $c); $e->clamp; return;
297 }
298 }
299 1 die "Pattern not found: $pattern\n";
300 }
301 10015 ▶sub replacement {
Subroutine replacement: called CC=9 SCAR=22.2
302 10015 my ($template, $text, $starts, $ends) = @_;
303 10015 my $out = '';
304 10015 ▶ while (length $template) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $template) 30042 10015 40057
305 30042 my $c = substr($template,0,1,'');
306 30042 ▶ if ($c eq '&') { $out .= substr($text,$starts->[0],$ends->[0]-$starts->[0]) }
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq '&') { } 1 30041 30042
elsif ($c eq '\\' and length $template) { } 5 30036 30041
307 ▶ elsif ($c eq '\\' && length $template) {
Condition66%2/3
$c eq "\\" and length $template
!ll&&!rl&&r
3003605
MC/DC50%1/2
$c eq "\\" and length $template
$c eq "\\" length $template
Truth table66%2/3
A and B
A= $c eq "\\"B= length $template
ABresult
0X0
100
111
308 5 my $n = substr($template,0,1,'');
309 5 ▶ if ($n =~ /[0-9]/) { $out .= substr($text,$starts->[$n],$ends->[$n]-$starts->[$n]) if defined($starts->[$n]) && $starts->[$n] >= 0 }
Branch: 3 branches
BranchTrueFalseTotal
if ($n =~ /[0-9]/) { } 1 4 5
elsif ($n eq 't') { } 1 3 4
if defined $starts->[$n] and $starts->[$n] >= 0 1 0 1
Condition33%1/3
defined $starts->[$n] and $starts->[$n] >= 0
!ll&&!rl&&r
001
MC/DC0%0/2
defined $starts->[$n] and $starts->[$n] >= 0
defined $starts->[$n] $starts->[$n] >= 0
Truth table33%1/3
A and B
A= defined $starts->[$n]B= $starts->[$n] >= 0
ABresult
0X0
100
111
310 1 elsif ($n eq 't') { $out .= "\t" }
311 3 else { $out .= $n }
312 30036 } else { $out .= $c }
313 }
314 10015 return $out;
315 }
316 15 ▶sub substitute {
Subroutine substitute: called CC=16 SCAR=27.8
317 15 my ($e, $lo, $hi, $spec) = @_;
318 15 my $delimiter = substr($spec,0,1,'');
319 15 ▶ die "Use s/pattern/replacement/[gi]\n" unless $delimiter =~ m{[^\w\s\\]};
Branch: 1 branch
BranchTrueFalseTotal
unless $delimiter =~ /[^\w\s\\]/ 0 15 15
320 15 my @parts;
321 15 for my $part_number (1 .. 2) {
322 30 my $part = ''; my $done = 0;
323 30 ▶ while (length $spec) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $spec) 104 1 105
324 104 my $c = substr($spec,0,1,'');
325 104 ▶ if ($c eq $delimiter) { $done = 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq $delimiter) 29 75 104
326 75 ▶ if ($c eq '\\' && length($spec)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq '\\' and length $spec) { } 6 69 75
Condition66%2/3
$c eq "\\" and length $spec
!ll&&!rl&&r
6906
MC/DC50%1/2
$c eq "\\" and length $spec
$c eq "\\" length $spec
Truth table66%2/3
A and B
A= $c eq "\\"B= length $spec
ABresult
0X0
100
111
327 6 my $next = substr($spec,0,1,'');
328 6 ▶ $part .= $next eq $delimiter && $part_number == 1 ? quotemeta($next) : '\\' . $next;
Branch: 1 branch
BranchTrueFalseTotal
$next eq $delimiter && $part_number == 1 ? : 1 5 6
Condition100%3/3
$next eq $delimiter and $part_number == 1
!ll&&!rl&&r
321
MC/DC100%2/2
$next eq $delimiter and $part_number == 1
$next eq $delimiter $part_number == 1
Truth table100%3/3
A and B
A= $next eq $delimiterB= $part_number == 1
ABresult
0X0
100
111
329 69 } else { $part .= $c }
330 }
331 30 ▶ die "Missing substitute delimiter\n" unless $done;
Branch: 1 branch
BranchTrueFalseTotal
unless $done 1 29 30
332 29 push @parts, $part;
333 }
334 14 ▶ die "Supported flags: g i\n" unless $spec =~ /^[gi]*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $spec =~ /^[gi]*$/ 1 13 14
335 13 my ($pattern,$replacement) = @parts;
336 13 ▶ $pattern = $e->{search} unless length $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless length $pattern 0 13 13
337 13 ▶ die "No previous search\n" unless defined $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pattern 0 13 13
338 13 ▶ my $rx = eval { $spec =~ /i/ ? qr/$pattern/i : qr/$pattern/ }; die "Invalid regex: $@" if $@;
Branch: 2 branches
BranchTrueFalseTotal
$spec =~ /i/ ? : 1 12 13
if $@ 1 12 13
339 12 my $changed = 0;
340 12 ▶ $e->edit(sub {
Subroutine __ANON__: called CC=10 SCAR=23.0
341 12 my $b = $e->{b};
342 12 my @pieces = $b->slice(0,$lo);
343 12 for my $r ($lo .. $hi) {
344 5013 my $old = $b->line($r); my ($out,$end,$hits) = ('',0,0);
345 5013 ▶ while ($old =~ /$rx/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old =~ /$rx/g) 10015 5005 15020
346 10015 my @starts = @-; my @ends = @+;
347 10015 $out .= substr($old,$end,$starts[0]-$end) . replacement($replacement,$old,\@starts,\@ends);
348 10015 $end = $ends[0]; ++$hits;
349 10015 ▶ last unless $spec =~ /g/;
Branch: 1 branch
BranchTrueFalseTotal
unless $spec =~ /g/ 8 10007 10015
350 }
351 5013 ▶ $out .= substr($old,$end) if $hits;
Branch: 1 branch
BranchTrueFalseTotal
if $hits 5012 1 5013
352 5013 ▶ my $id = $hits && $out ne $old ? $b->append($out,$b->term($r)) : $b->id($r);
Branch: 1 branch
BranchTrueFalseTotal
$hits && $out ne $old ? : 5012 1 5013
Condition66%2/3
$hits and $out ne $old
!ll&&!rl&&r
105012
MC/DC50%1/2
$hits and $out ne $old
$hits $out ne $old
Truth table66%2/3
A and B
A= $hitsB= $out ne $old
ABresult
0X0
100
111
353 5013 ▶ if (@pieces && $pieces[-1][0]+$pieces[-1][1] == $id && ($b->record($id-1))[2]) { ++$pieces[-1][1] }
Branch: 1 branch
BranchTrueFalseTotal
if (@pieces and $pieces[-1][0] + $pieces[-1][1] == $id and ($b->record($id - 1))[2]) { } 5001 12 5013
Condition83%5/6
@pieces and $pieces[-1][0] + $pieces[-1][1] == $id and ($b->record($id - 1))[2]
!ll&&!rl&&r
1205001
@pieces and $pieces[-1][0] + $pieces[-1][1] == $id
!ll&&!rl&&r
1025001
MC/DC66%2/3
@pieces and $pieces[-1][0] + $pieces[-1][1] == $id and ($b->record($id - 1))[2]
@pieces $pieces[-1][0] + $pieces[-1][1] == $id ($b->record($id - 1))[2]
Truth table75%3/4
A and B and C
A= @piecesB= $pieces[-1][0] + $pieces[-1][1] == $idC= ($b->record($id - 1))[2]
ABCresult
0XX0
10X0
1100
1111
354 12 else { push @pieces, [$id,1] }
355 5013 $changed += $hits;
356 }
357 12 push @pieces, $b->slice($hi+1,$b->{count}-$hi-1);
358 12 $b->{pieces} = \@pieces; $b->reindex;
359 12 });
360 12 $e->{search} = $pattern;
361 12 ▶ die "Pattern not found\n" unless $changed;
Branch: 1 branch
BranchTrueFalseTotal
unless $changed 0 12 12
362 12 $e->{message} = "$changed substitutions";
363 }
364 1 ▶sub tidy {
Subroutine tidy: called CC=9 SCAR=41.7
365 1 my ($e) = @_;
366 0 ▶ eval { require Perl::Tidy; 1 } or die "Perl::Tidy is unavailable; install perltidy to use :pt\n";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Perl::Tidy; 1 } } or die "Perl::Tidy is unavailable; install perltidy to use :pt\n" 0 1 1
367 0 ▶ die "Perltidy limited to 8 MiB; format a smaller file\n" if $e->{b}{count} > 200000;
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"b"}{"count"} > 200000 0 0 0
368 0 my $source = '';
369 0 for my $r (0 .. $e->{b}{count}-1) {
370 0 $source .= $e->{b}->line($r) . "\n";
371 0 ▶ die "Perltidy limited to 8 MiB\n" if length($source) > 8*1024*1024;
Branch: 1 branch
BranchTrueFalseTotal
if length $source > 8388608 0 0 0
372 }
373 0 my ($dest,$err) = ('','');
374 0 my $rc = Perl::Tidy::perltidy(source => \$source, destination => \$dest, stderr => \$err, argv => ['-npro','-l=500']);
375 0 ▶ die "Perltidy failed: $err\n" if $rc;
Branch: 1 branch
BranchTrueFalseTotal
if $rc 0 0 0
376 0 ▶ my @lines = split /\n/, $dest, -1; pop @lines if @lines && $lines[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if @lines and $lines[-1] eq "" 0 0 0
Condition0%0/3
@lines and $lines[-1] eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
@lines and $lines[-1] eq ""
@lines $lines[-1] eq ""
Truth table0%0/3
A and B
A= @linesB= $lines[-1] eq ""
ABresult
0X0
100
111
377 0 ▶ @lines = ('') unless @lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @lines 0 0 0
378 0 ▶ $e->edit(sub { $e->{b}->splice_lines(0,$e->{b}{count}, map { $e->{b}->append($_) } @lines) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
379 0 $e->{message} = 'Formatted with perltidy -l 500';
380 }
381 17 ▶sub shell_status {
Subroutine shell_status: called CC=5 SCAR=18.6
382 17 my ($command) = @_;
383 17 ▶ local $SIG{TSTP} = 'DEFAULT' unless $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $^O eq "MSWin32" 17 0 17
384 my $status = $^O eq 'MSWin32'
385 17 ▶ ? system($ENV{COMSPEC} || 'cmd.exe','/d','/s','/c',$command)
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 17 17
Condition0%0/2
$ENV{'COMSPEC'} || 'cmd.exe'
l!l
00
MC/DC0%0/1
$ENV{'COMSPEC'} || 'cmd.exe'
$ENV{'COMSPEC'}
Truth table0%0/2
A
A= $ENV{'COMSPEC'}
Aresult
11
00
386 : system('/bin/sh','-c',$command);
387 17 ▶ die "Cannot execute command: $!\n" if $status == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $status == -1 0 17 17
388 17 return $status;
389 }
390 2 ▶sub shell {
Subroutine shell: called CC=12 SCAR=28.8
391 2 my ($e,$command) = @_;
392 2 ▶ die "Shell command required\n" unless length $command;
Branch: 1 branch
BranchTrueFalseTotal
unless length $command 1 1 2
393 1 my ($status,$suspended);
394 1 my $ok = eval {
395 0 ▶ if ($e->{before_filter}) { $e->{before_filter}->(); $suspended = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"before_filter"}) 0 1 1
396 1 ▶ local $SIG{TSTP} = 'DEFAULT' unless $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $^O eq "MSWin32" 1 0 1
397 1 $status = shell_status($command);
398 1 ▶ $e->{shell_wait}->() if $suspended && $e->{shell_wait};
Branch: 1 branch
BranchTrueFalseTotal
if $suspended and $e->{"shell_wait"} 0 1 1
Condition33%1/3
$suspended and $e->{"shell_wait"}
!ll&&!rl&&r
100
MC/DC0%0/2
$suspended and $e->{"shell_wait"}
$suspended $e->{"shell_wait"}
Truth table33%1/3
A and B
A= $suspendedB= $e->{"shell_wait"}
ABresult
0X0
100
111
399 1 1;
400 };
401 1 my $failure = $@;
402 1 ▶ $e->{after_filter}->() if $suspended && $e->{after_filter};
Branch: 1 branch
BranchTrueFalseTotal
if $suspended and $e->{"after_filter"} 0 1 1
Condition33%1/3
$suspended and $e->{"after_filter"}
!ll&&!rl&&r
100
MC/DC0%0/2
$suspended and $e->{"after_filter"}
$suspended $e->{"after_filter"}
Truth table33%1/3
A and B
A= $suspendedB= $e->{"after_filter"}
ABresult
0X0
100
111
403 1 ▶ die $failure unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 1 1
404 1 ▶ my $reason = $status & 127 ? 'signal '.($status & 127) : 'exit '.($status >> 8);
Branch: 1 branch
BranchTrueFalseTotal
$status & 127 ? : 0 1 1
405 1 ▶ $e->{message} = $status ? "Shell command failed ($reason); buffer unchanged" : 'Shell command completed';
Branch: 1 branch
BranchTrueFalseTotal
$status ? : 0 1 1
406 1 ▶ die "$e->{message}\n" if $status;
Branch: 1 branch
BranchTrueFalseTotal
if $status 0 1 1
407 }
408 16 ▶sub filter {
Subroutine filter: called CC=32 SCAR=36.1
409 16 my ($e,$lo,$hi,$command,$insert) = @_;
410 16 ▶ die "Filter command required\n" unless length $command;
Branch: 1 branch
BranchTrueFalseTotal
unless length $command 0 16 16
411 16 my $input = File::Temp->new(UNLINK => 1);
412 16 my $output = File::Temp->new(UNLINK => 1);
413 16 my $output_path = $output->filename;
414 16 my $errors = File::Temp->new(UNLINK => 1);
415 16 binmode $input; binmode $output; binmode $errors;
416 16 my $b = $e->{b};
417 16 for my $r ($lo..$hi) {
418 27 my $term = $b->term($r);
419 27 ▶ my $ending = $term == 2 ? "\r\n" : $term == 1 ? "\n" : $b->{eol};
Branch: 2 branches
BranchTrueFalseTotal
$term == 2 ? : 0 27 27
$term == 1 ? : 27 0 27
420 27 ▶ $ending = '' if $r == $b->{count}-1 && !$b->{final};
Branch: 1 branch
BranchTrueFalseTotal
if $r == $b->{"count"} - 1 and not $b->{"final"} 0 27 27
Condition66%2/3
$r == $b->{"count"} - 1 and not $b->{"final"}
!ll&&!rl&&r
2070
MC/DC0%0/2
$r == $b->{"count"} - 1 and not $b->{"final"}
$r == $b->{"count"} - 1 not $b->{"final"}
Truth table66%2/3
A and not(B)
A= $r == $b->{"count"} - 1B= not $b->{"final"}
ABresult
0X0
100
111
421 27 ▶ print {$input} $b->line($r),$ending or die "Filter input: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
print {$input;} $b->line($r), $ending or die "Filter input: $!\n" 27 0 27
422 }
423 16 ▶ seek($input,0,0) or die "Filter input seek: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
seek $input, 0, 0 or die "Filter input seek: $!\n" 16 0 16
424 16 my ($saved_in,$saved_out,$saved_err);
425 16 ▶ open $saved_in,'<&',\*STDIN or die "Save stdin: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $saved_in, "<&", \*STDIN or die "Save stdin: $!\n" 16 0 16
426 16 ▶ open $saved_out,'>&',\*STDOUT or die "Save stdout: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $saved_out, ">&", \*STDOUT or die "Save stdout: $!\n" 16 0 16
427 16 ▶ open $saved_err,'>&',\*STDERR or die "Save stderr: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $saved_err, ">&", \*STDERR or die "Save stderr: $!\n" 16 0 16
428 16 my ($status,$suspended);
429 16 my $ok = eval {
430 16 ▶ if ($e->{before_filter}) { $e->{before_filter}->(); $suspended = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"before_filter"}) 1 15 16
431 16 ▶ open STDIN,'<&',$input or die "Filter stdin: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open STDIN, "<&", $input or die "Filter stdin: $!\n" 16 0 16
432 16 ▶ open STDOUT,'>&',$output or die "Filter stdout: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">&", $output or die "Filter stdout: $!\n" 16 0 16
433 16 ▶ open STDERR,'>&',$errors or die "Filter stderr: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&", $errors or die "Filter stderr: $!\n" 16 0 16
434 # Shell execution is explicit and only reached by a user-issued ! filter.
435 # Temp filenames and buffer contents are never interpolated into commands.
436 16 $status = shell_status($command);
437 16 1;
438 };
439 16 my $failure = $@;
440 16 my $restored = 1;
441 16 ▶ $restored = 0 unless open STDIN,'<&',$saved_in;
Branch: 1 branch
BranchTrueFalseTotal
unless open STDIN, "<&", $saved_in 0 16 16
442 16 ▶ $restored = 0 unless open STDOUT,'>&',$saved_out;
Branch: 1 branch
BranchTrueFalseTotal
unless open STDOUT, ">&", $saved_out 0 16 16
443 16 ▶ $restored = 0 unless open STDERR,'>&',$saved_err;
Branch: 1 branch
BranchTrueFalseTotal
unless open STDERR, ">&", $saved_err 0 16 16
444 16 ▶ if ($suspended) { $e->{after_filter}->() if $e->{after_filter} }
Branch: 2 branches
BranchTrueFalseTotal
if ($suspended) 1 15 16
if $e->{"after_filter"} 1 0 1
445 16 ▶ die "Cannot restore filter IO\n" unless $restored;
Branch: 1 branch
BranchTrueFalseTotal
unless $restored 0 16 16
446 16 ▶ die $failure unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 16 16
447 16 ▶ seek($errors,0,0) or die "Filter error seek: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
seek $errors, 0, 0 or die "Filter error seek: $!\n" 16 0 16
448 16 read($errors,my $diagnostic,4096);
449 16 ▶ if ($status) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status) 2 14 16
450 2 ▶ my $reason = $status & 127 ? 'signal '.($status & 127) : 'exit '.($status >> 8);
Branch: 1 branch
BranchTrueFalseTotal
$status & 127 ? : 0 2 2
451 2 die "Filter failed ($reason); buffer unchanged: $diagnostic\n";
452 }
453 # Close the capture handle before reopening on Windows. The file remains
454 # owned by its File::Temp object until this command returns.
455 14 ▶ close $output or die "Close filter output: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $output or die "Close filter output: $!\n" 14 0 14
456 14 my $result = PVim::Store->load($output_path);
457 14 my $empty = !-s $output_path;
458 14 ▶ if ($insert && $empty) { $e->{message} = 'Read 0 lines'; return }
Branch: 1 branch
BranchTrueFalseTotal
if ($insert and $empty) 1 13 14
Condition100%3/3
$insert and $empty
!ll&&!rl&&r
1031
MC/DC100%2/2
$insert and $empty
$insert $empty
Truth table100%3/3
A and B
A= $insertB= $empty
ABresult
0X0
100
111
459 13 ▶ $e->edit(sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
460 13 my @pieces = $b->slice(0,$lo);
461 13 ▶ unless ($empty) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($empty) 11 2 13
462 11 my $first;
463 11 for my $r (0..$result->{count}-1) {
464 25 my $id = $b->append($result->line($r),$result->term($r));
465 25 ▶ $first = $id unless defined $first;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $first 11 14 25
466 }
467 11 push @pieces, [$first,$result->{count}];
468 }
469 13 push @pieces, $b->slice($hi+1,$b->{count}-$hi-1);
470 13 my $through_end = $hi == $b->{count}-1;
471 13 $b->{pieces} = \@pieces; $b->reindex;
472 13 ▶ if (!$b->{count}) { $b->splice_lines(0,0,$b->append('',0)); $b->{final} = 0 }
Branch: 2 branches
BranchTrueFalseTotal
if (not $b->{'count'}) { } 1 12 13
elsif ($through_end and not $empty) { } 7 10 17
473 7 ▶ elsif ($through_end && !$empty) { $b->{final} = $result->{final} }
Condition66%2/3
$through_end and not $empty
!ll&&!rl&&r
507
MC/DC50%1/2
$through_end and not $empty
$through_end not $empty
Truth table66%2/3
A and not(B)
A= $through_endB= not $empty
ABresult
0X0
100
111
474 13 $e->{row} = $lo; $e->{col} = 0;
475 13 });
476 13 ▶ $e->{message} = ($insert ? 'Read '.($empty ? 0 : $result->{count}) : 'Filtered '.($hi-$lo+1)).' lines'.(length($diagnostic) ? ': '.$diagnostic : '');
Branch: 3 branches
BranchTrueFalseTotal
$insert ? : 3 10 13
$empty ? : 0 3 3
length $diagnostic ? : 1 12 13
477 }
478 67 ▶sub ex {
Subroutine ex: called CC=39 SCAR=39.4
479 67 my ($e, $command) = @_;
480 67 $command =~ s/^://; $command =~ s/^\s+|\s+$//g;
481 67 my ($lo,$hi) = ($e->{row},$e->{row}); my $ranged = 0;
482 67 ▶ if ($command =~ s/^%//) { ($lo,$hi) = (0,$e->{b}{count}-1); $ranged = 1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($command =~ s/^%//) { } 10 57 67
elsif ($command =~ s/^(\d+|\.|\$)(?:,(\d+|\.|\$))?//) { } 18 39 57
483 elsif ($command =~ s/^(\d+|\.|\$)(?:,(\d+|\.|\$))?//) {
484 18 ▶ my ($a,$b) = ($1,$2); $b = $a unless defined $b;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b 14 4 18
485 18 ▶ my $resolve = sub { $_[0] eq '.' ? $e->{row} : $_[0] eq '$' ? $e->{b}{count}-1 : $_[0]-1 };
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
$_[0] eq '.' ? : 5 31 36
$_[0] eq '$' ? : 1 30 31
486 18 ($lo,$hi) = ($resolve->($a),$resolve->($b)); $ranged = 1;
487 }
488 67 $command =~ s/^\s+//;
489 67 ▶ if ($command =~ s/^r(?:ead)?\s*!\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command =~ s/^r(?:ead)?\s*!\s*//) 4 63 67
490 4 ▶ die "Invalid read address\n" if $lo < -1 || $hi < $lo || $hi >= $e->{b}{count};
Branch: 1 branch
BranchTrueFalseTotal
if $lo < -1 or $hi < $lo or $hi >= $e->{"b"}{"count"} 0 4 4
Condition33%2/6
$lo < -1 or $hi < $lo or $hi >= $e->{"b"}{"count"}
l!l&&r!l&&!r
004
$lo < -1 or $hi < $lo
l!l&&r!l&&!r
004
MC/DC0%0/3
$lo < -1 or $hi < $lo or $hi >= $e->{"b"}{"count"}
$lo < -1 $hi < $lo $hi >= $e->{"b"}{"count"}
Truth table25%1/4
A or B or C
A= $lo < -1B= $hi < $loC= $hi >= $e->{"b"}{"count"}
ABCresult
1XX1
01X1
0011
0000
491 4 $e->filter($hi+1,$hi,$command,1); return;
492 }
493 63 ▶ die "Invalid line range\n" if $lo < 0 || $hi < $lo || $hi >= $e->{b}{count};
Branch: 1 branch
BranchTrueFalseTotal
if $lo < 0 or $hi < $lo or $hi >= $e->{"b"}{"count"} 4 59 63
Condition83%5/6
$lo < 0 or $hi < $lo or $hi >= $e->{"b"}{"count"}
l!l&&r!l&&!r
2259
$lo < 0 or $hi < $lo
l!l&&r!l&&!r
0261
MC/DC66%2/3
$lo < 0 or $hi < $lo or $hi >= $e->{"b"}{"count"}
$lo < 0 $hi < $lo $hi >= $e->{"b"}{"count"}
Truth table75%3/4
A or B or C
A= $lo < 0B= $hi < $loC= $hi >= $e->{"b"}{"count"}
ABCresult
1XX1
01X1
0011
0000
494 59 ▶ if ($command eq '' && $ranged) { $e->{row} = $hi; $e->clamp; return }
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "" and $ranged) 2 57 59
Condition66%2/3
$command eq "" and $ranged
!ll&&!rl&&r
5702
MC/DC50%1/2
$command eq "" and $ranged
$command eq "" $ranged
Truth table66%2/3
A and B
A= $command eq ""B= $ranged
ABresult
0X0
100
111
495 57 ▶ if ($command =~ s/^s(?=[^a-zA-Z])//) { $e->substitute($lo,$hi,$command); return }
Branch: 1 branch
BranchTrueFalseTotal
if ($command =~ s/^s(?=[^a-zA-Z])//) 15 42 57
496 42 ▶ if ($command =~ s/^!\s*//) { $ranged ? $e->filter($lo,$hi,$command) : $e->shell($command); return }
Branch: 2 branches
BranchTrueFalseTotal
if ($command =~ s/^!\s*//) 14 28 42
$ranged ? : 12 2 14
497 28 ▶ die "Range only supported for substitutions, filters and line jumps\n" if $ranged;
Branch: 1 branch
BranchTrueFalseTotal
if $ranged 0 28 28
498 28 ▶ if ($command =~ /^(q|quit)(!)?$/) { die "Unsaved changes; use :q!\n" if $e->{b}->dirty && !$2; $e->{quit} = 1 }
Branch: 10 branches
BranchTrueFalseTotal
if ($command =~ /^(q|quit)(!)?$/) { } 6 22 28
elsif ($command =~ /^(wq|x|w|write)(!)?(?:\s+(.+))?$/) { } 7 15 22
elsif ($command =~ /^(e|edit)(!)?(?:\s+(.+))?$/) { } 1 14 15
elsif ($command =~ /^enew(!)?$/) { } 1 13 14
elsif ($command =~ /^set\s+(nu|number|nonu|nonumber)$/) { } 2 11 13
elsif ($command eq 'pt' or $command eq 'perltidy') { } 1 10 11
elsif ($command eq 'u' or $command eq 'undo') { } 8 2 10
elsif ($command eq 'redo') { } 1 1 2
elsif ($command eq 'help' or $command eq 'h') { } 0 1 1
if $e->{"b"}->dirty and not $2 3 3 6
Condition100%3/3
$e->{"b"}->dirty and not $2
!ll&&!rl&&r
123
MC/DC100%2/2
$e->{"b"}->dirty and not $2
$e->{"b"}->dirty not $2
Truth table100%3/3
A and not(B)
A= $e->{"b"}->dirtyB= not $2
ABresult
0X0
100
111
499 elsif ($command =~ /^(wq|x|w|write)(!)?(?:\s+(.+))?$/) {
500 7 my ($cmd,$force,$path) = ($1,$2,$3);
501 7 ▶ $e->{b}->save($path,$force); $e->{message} = 'Written ' . $e->{b}{path}; $e->{quit} = 1 if $cmd eq 'wq' || $cmd eq 'x';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "wq" or $cmd eq "x" 0 7 7
Condition33%1/3
$cmd eq "wq" or $cmd eq "x"
l!l&&r!l&&!r
007
MC/DC0%0/2
$cmd eq "wq" or $cmd eq "x"
$cmd eq "wq" $cmd eq "x"
Truth table33%1/3
A or B
A= $cmd eq "wq"B= $cmd eq "x"
ABresult
1X1
011
000
502 }
503 elsif ($command =~ /^(e|edit)(!)?(?:\s+(.+))?$/) {
504 1 ▶ my ($force,$path) = ($2,$3); die "Unsaved changes; use :e!\n" if $e->{b}->dirty && !$force;
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"b"}->dirty and not $force 1 0 1
Condition33%1/3
$e->{"b"}->dirty and not $force
!ll&&!rl&&r
001
MC/DC0%0/2
$e->{"b"}->dirty and not $force
$e->{"b"}->dirty not $force
Truth table33%1/3
A and not(B)
A= $e->{"b"}->dirtyB= not $force
ABresult
0X0
100
111
505 0 ▶ $path = $e->{b}{path} unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 0 0
506 0 $e->{b} = PVim::Store->load($path); ($e->{row},$e->{col}) = (0,0); $e->{register} = []; delete $e->{regtext};
507 }
508 elsif ($command =~ /^enew(!)?$/) {
509 1 ▶ die "Unsaved changes; use :enew!\n" if $e->{b}->dirty && !$1;
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"b"}->dirty and not $1 0 1 1
Condition33%1/3
$e->{"b"}->dirty and not $1
!ll&&!rl&&r
100
MC/DC0%0/2
$e->{"b"}->dirty and not $1
$e->{"b"}->dirty not $1
Truth table33%1/3
A and not(B)
A= $e->{"b"}->dirtyB= not $1
ABresult
0X0
100
111
510 1 $e->{b} = PVim::Store->load(undef); ($e->{row},$e->{col}) = (0,0); $e->{register} = []; delete $e->{regtext};
511 }
512 elsif ($command =~ /^set\s+(nu|number|nonu|nonumber)$/) {
513 2 ▶ my $opt = $1; $e->{number} = $opt =~ /^no/ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$opt =~ /^no/ ? : 1 1 2
514 }
515 1 ▶ elsif ($command eq 'pt' || $command eq 'perltidy') { $e->tidy }
Condition66%2/3
$command eq "pt" or $command eq "perltidy"
l!l&&r!l&&!r
1010
MC/DC50%1/2
$command eq "pt" or $command eq "perltidy"
$command eq "pt" $command eq "perltidy"
Truth table66%2/3
A or B
A= $command eq "pt"B= $command eq "perltidy"
ABresult
1X1
011
000
516 8 ▶ elsif ($command eq 'u' || $command eq 'undo') { $e->undo(0) }
Condition66%2/3
$command eq "u" or $command eq "undo"
l!l&&r!l&&!r
082
MC/DC50%1/2
$command eq "u" or $command eq "undo"
$command eq "u" $command eq "undo"
Truth table66%2/3
A or B
A= $command eq "u"B= $command eq "undo"
ABresult
1X1
011
000
517 1 elsif ($command eq 'redo') { $e->undo(1) }
518 0 ▶ elsif ($command eq 'help' || $command eq 'h') { $e->{message} = 'i insert | Esc normal | :w save | :q quit | / search | :%s/a/b/g | :pt tidy | pvim --manual' }
Condition33%1/3
$command eq "help" or $command eq "h"
l!l&&r!l&&!r
001
MC/DC0%0/2
$command eq "help" or $command eq "h"
$command eq "help" $command eq "h"
Truth table33%1/3
A or B
A= $command eq "help"B= $command eq "h"
ABresult
1X1
011
000
519 1 else { die "Unknown command: $command\n" }
520 }
521 139 ▶sub key {
Subroutine key: called CC=140 SCAR=65.7
522 139 my ($e, $k) = @_;
523 139 $e->{message} = '';
524 139 my $b = $e->{b};
525 139 ▶ $b->{cursor} = [@{$e}{qw(row col)}] unless $b->{before};
Branch: 1 branch
BranchTrueFalseTotal
unless $b->{"before"} 97 42 139
526 139 ▶ if ($e->{mode} eq 'prompt') {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"mode"} eq "prompt") 12 127 139
527 12 ▶ if ($k eq "\e") { $e->{mode} = 'normal'; $e->{prompt} = '' }
Branch: 4 branches
BranchTrueFalseTotal
if ($k eq "\e") { } 1 11 12
elsif ($k eq "\r" or $k eq "\n") { } 1 10 11
elsif ($k eq "\177" or $k eq "\cH") { } 0 10 10
elsif (length $k == 1 and ord $k >= 32 and ord $k < 127) { } 10 0 10
528 ▶ elsif ($k eq "\r" || $k eq "\n") {
Condition66%2/3
$k eq "\r" or $k eq "\n"
l!l&&r!l&&!r
1010
MC/DC50%1/2
$k eq "\r" or $k eq "\n"
$k eq "\r" $k eq "\n"
Truth table66%2/3
A or B
A= $k eq "\r"B= $k eq "\n"
ABresult
1X1
011
000
529 1 my $p = $e->{prompt}; $e->{mode} = 'normal';
530 1 my $kind = substr($p,0,1,'');
531 1 ▶ $kind eq ':' ? $e->ex($p) : $e->search($p,$kind eq '/' ? 1 : -1);
Branch: 2 branches
BranchTrueFalseTotal
$kind eq ':' ? : 1 0 1
$kind eq '/' ? : 0 0 0
532 0 ▶ } elsif ($k eq "\x7f" || $k eq "\b") { chop $e->{prompt}; $e->{mode} = 'normal' unless length($e->{prompt}) }
Branch: 1 branch
BranchTrueFalseTotal
unless length $e->{"prompt"} 0 0 0
Condition33%1/3
$k eq "\177" or $k eq "\b"
l!l&&r!l&&!r
0010
MC/DC0%0/2
$k eq "\177" or $k eq "\b"
$k eq "\177" $k eq "\b"
Truth table33%1/3
A or B
A= $k eq "\177"B= $k eq "\b"
ABresult
1X1
011
000
533 10 ▶ elsif (length($k) == 1 && ord($k) >= 32 && ord($k) < 127) { $e->{prompt} .= $k }
Condition33%2/6
length $k == 1 and ord $k >= 32 and ord $k < 127
!ll&&!rl&&r
0010
length $k == 1 and ord $k >= 32
!ll&&!rl&&r
0010
MC/DC0%0/3
length $k == 1 and ord $k >= 32 and ord $k < 127
length $k == 1 ord $k >= 32 ord $k < 127
Truth table25%1/4
A and B and C
A= length $k == 1B= ord $k >= 32C= ord $k < 127
ABCresult
0XX0
10X0
1100
1111
534 12 return;
535 }
536 127 ▶ if ($e->{mode} ne 'normal') {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"mode"} ne "normal") 42 85 127
537 42 my $text = $b->line($e->{row});
538 42 ▶ if ($k eq "\e") { $e->{mode} = 'normal'; $b->commit; --$e->{col} if $e->{col}; $e->clamp; return }
Branch: 2 branches
BranchTrueFalseTotal
if ($k eq "\e") 11 31 42
if $e->{"col"} 11 0 11
539 31 ▶ if ($k eq 'LEFT' || $k eq 'RIGHT' || $k eq 'UP' || $k eq 'DOWN') {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "LEFT" or $k eq "RIGHT" or $k eq "UP" or $k eq "DOWN") 0 31 31
Condition33%3/9
$k eq "LEFT" or $k eq "RIGHT" or $k eq "UP" or $k eq "DOWN"
l!l&&r!l&&!r
0031
$k eq "LEFT" or $k eq "RIGHT" or $k eq "UP"
l!l&&r!l&&!r
0031
$k eq "LEFT" or $k eq "RIGHT"
l!l&&r!l&&!r
0031
MC/DC0%0/4
$k eq "LEFT" or $k eq "RIGHT" or $k eq "UP" or $k eq "DOWN"
$k eq "LEFT" $k eq "RIGHT" $k eq "UP" $k eq "DOWN"
Truth table20%1/5
A or B or C or D
A= $k eq "LEFT"B= $k eq "RIGHT"C= $k eq "UP"D= $k eq "DOWN"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
540 0 $b->commit; $e->{col} += ($k eq 'RIGHT') - ($k eq 'LEFT'); $e->{row} += ($k eq 'DOWN') - ($k eq 'UP'); $e->clamp; $b->begin; return;
541 }
542 31 ▶ if ($k eq "\r" || $k eq "\n") {
Branch: 3 branches
BranchTrueFalseTotal
if ($k eq "\r" or $k eq "\n") { } 1 30 31
elsif ($k eq "\177" or $k eq "\cH") { } 2 28 30
elsif (length $k == 1 and $k eq "\t" || ord $k >= 32) { } 28 0 28
Condition66%2/3
$k eq "\r" or $k eq "\n"
l!l&&r!l&&!r
1030
MC/DC50%1/2
$k eq "\r" or $k eq "\n"
$k eq "\r" $k eq "\n"
Truth table66%2/3
A or B
A= $k eq "\r"B= $k eq "\n"
ABresult
1X1
011
000
543 1 $b->splice_lines($e->{row},1,$b->append(substr($text,0,$e->{col})),$b->append(substr($text,$e->{col}),$b->term($e->{row})));
544 1 ++$e->{row}; $e->{col} = 0;
545 ▶ } elsif ($k eq "\x7f" || $k eq "\b") {
Condition66%2/3
$k eq "\177" or $k eq "\b"
l!l&&r!l&&!r
0228
MC/DC50%1/2
$k eq "\177" or $k eq "\b"
$k eq "\177" $k eq "\b"
Truth table66%2/3
A or B
A= $k eq "\177"B= $k eq "\b"
ABresult
1X1
011
000
546 2 ▶ if ($e->{col}) { --$e->{col}; if ($e->{mode} eq 'insert') { substr($text,$e->{col},1,''); $b->set_line($e->{row},$text) } }
Branch: 3 branches
BranchTrueFalseTotal
if ($e->{'col'}) { } 1 1 2
elsif ($e->{'row'} and $e->{'mode'} eq 'insert') { } 1 0 1
if ($e->{"mode"} eq "insert") 1 0 1
547 ▶ elsif ($e->{row} && $e->{mode} eq 'insert') {
Condition33%1/3
$e->{"row"} and $e->{"mode"} eq "insert"
!ll&&!rl&&r
001
MC/DC0%0/2
$e->{"row"} and $e->{"mode"} eq "insert"
$e->{"row"} $e->{"mode"} eq "insert"
Truth table33%1/3
A and B
A= $e->{"row"}B= $e->{"mode"} eq "insert"
ABresult
0X0
100
111
548 1 my $prev = $b->line($e->{row}-1); $e->{col} = length($prev);
549 1 $b->splice_lines($e->{row}-1,2,$b->append($prev.$text,$b->term($e->{row}))); --$e->{row};
550 }
551 ▶ } elsif (length($k) == 1 && ($k eq "\t" || ord($k) >= 32)) {
Condition33%2/6
length $k == 1 and $k eq "\t" || ord $k >= 32
!ll&&!rl&&r
0028
$k eq "\t" or ord $k >= 32
l!l&&r!l&&!r
0280
MC/DC0%0/3
length $k == 1 and $k eq "\t" || ord $k >= 32
length $k == 1 $k eq "\t" ord $k >= 32
Truth table25%1/4
A and B or C
A= length $k == 1B= $k eq "\t"C= ord $k >= 32
ABCresult
0XX0
1000
11X1
1011
552 28 ▶ substr($text,$e->{col},$e->{mode} eq 'replace' && $e->{col} < length($text) ? 1 : 0,$k);
Branch: 1 branch
BranchTrueFalseTotal
$e->{'mode'} eq 'replace' && $e->{'col'} < length $text ? : 2 26 28
Condition66%2/3
$e->{"mode"} eq "replace" and $e->{"col"} < length $text
!ll&&!rl&&r
2602
MC/DC50%1/2
$e->{"mode"} eq "replace" and $e->{"col"} < length $text
$e->{"mode"} eq "replace" $e->{"col"} < length $text
Truth table66%2/3
A and B
A= $e->{"mode"} eq "replace"B= $e->{"col"} < length $text
ABresult
0X0
100
111
553 28 ++$e->{col}; $b->set_line($e->{row},$text);
554 }
555 31 return;
556 }
557 85 ▶ if ($k eq "\e") { $e->{pending} = ''; $e->{count} = ''; return }
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "\e") 1 84 85
558 84 ▶ if ($e->{pending} eq 'r') {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"pending"} eq "r") 1 83 84
559 1 my $count = $e->{opcount}; $e->{pending} = '';
560 1 ▶ return unless length($k) == 1 && ord($k) >= 32;
Branch: 1 branch
BranchTrueFalseTotal
unless length $k == 1 and ord $k >= 32 0 1 1
Condition33%1/3
length $k == 1 and ord $k >= 32
!ll&&!rl&&r
001
MC/DC0%0/2
length $k == 1 and ord $k >= 32
length $k == 1 ord $k >= 32
Truth table33%1/3
A and B
A= length $k == 1B= ord $k >= 32
ABresult
0X0
100
111
561 1 my $text = $b->line($e->{row});
562 1 ▶ die "Not enough characters\n" if $e->{col} + $count > length($text);
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"col"} + $count > length $text 0 1 1
563 1 ▶ $e->edit(sub { substr($text,$e->{col},$count,$k x $count); $b->set_line($e->{row},$text) }); return;
Subroutine __ANON__: called CC=1 SCAR=0.0
564 }
565 83 ▶ if ($k =~ /^[1-9]$/ || ($k eq '0' && length($e->{count}))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^[1-9]$/ or $k eq 0 and length $e->{"count"}) 9 74 83
Condition66%4/6
$k =~ /^[1-9]$/ or $k eq 0 and length $e->{"count"}
l!l&&r!l&&!r
9074
$k eq 0 and length $e->{"count"}
!ll&&!rl&&r
7130
MC/DC33%1/3
$k =~ /^[1-9]$/ or $k eq 0 and length $e->{"count"}
$k =~ /^[1-9]$/ $k eq 0 length $e->{"count"}
Truth table75%3/4
A or B and C
A= $k =~ /^[1-9]$/B= $k eq 0C= length $e->{"count"}
ABCresult
1XX1
0111
00X0
0100
566 9 ▶ $e->{count} .= $k; die "Count too large\n" if length($e->{count}) > 7; return;
Branch: 1 branch
BranchTrueFalseTotal
if length $e->{"count"} > 7 0 9 9
567 }
568 74 ▶ my $explicit = length($e->{count}); my $n = $explicit ? 0 + $e->{count} : 1; $e->{count} = '';
Branch: 1 branch
BranchTrueFalseTotal
$explicit ? : 9 65 74
569 74 ▶ if ($e->{pending}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"pending"}) 16 58 74
570 16 my $op = $e->{pending}; $n *= $e->{opcount}; $e->{pending} = '';
571 16 ▶ if ($op eq '!' && $k eq '!') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "!" and $k eq "!") 2 14 16
Condition66%2/3
$op eq "!" and $k eq "!"
!ll&&!rl&&r
1402
MC/DC50%1/2
$op eq "!" and $k eq "!"
$op eq "!" $k eq "!"
Truth table66%2/3
A and B
A= $op eq "!"B= $k eq "!"
ABresult
0X0
100
111
572 2 ▶ my $last = $e->{row}+$n; $last = $b->{count} if $last > $b->{count};
Branch: 1 branch
BranchTrueFalseTotal
if $last > $b->{"count"} 0 2 2
573 2 $e->{mode} = 'prompt';
574 2 ▶ $e->{prompt} = $n == 1 ? ':.!' : ':'.($e->{row}+1).','.$last.'!'; return;
Branch: 1 branch
BranchTrueFalseTotal
$n == 1 ? : 1 1 2
575 }
576 14 ▶ if ($op eq 'g' && $k eq 'g') { $e->{row} = $n-1; $e->{col} = 0; $e->clamp; return }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "g" and $k eq "g") 4 10 14
Condition66%2/3
$op eq "g" and $k eq "g"
!ll&&!rl&&r
1004
MC/DC50%1/2
$op eq "g" and $k eq "g"
$op eq "g" $k eq "g"
Truth table66%2/3
A and B
A= $op eq "g"B= $k eq "g"
ABresult
0X0
100
111
577 0 ▶ if ($op eq '\\' && $k eq 't') { $e->tidy; return }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "\\" and $k eq "t") 0 10 10
Condition33%1/3
$op eq "\\" and $k eq "t"
!ll&&!rl&&r
1000
MC/DC0%0/2
$op eq "\\" and $k eq "t"
$op eq "\\" $k eq "t"
Truth table33%1/3
A and B
A= $op eq "\\"B= $k eq "t"
ABresult
0X0
100
111
578 0 ▶ if ($op eq 'Z' && $k eq 'Z') { $e->ex('wq'); return }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "Z" and $k eq "Z") 0 10 10
Condition33%1/3
$op eq "Z" and $k eq "Z"
!ll&&!rl&&r
1000
MC/DC0%0/2
$op eq "Z" and $k eq "Z"
$op eq "Z" $k eq "Z"
Truth table33%1/3
A and B
A= $op eq "Z"B= $k eq "Z"
ABresult
0X0
100
111
579 10 ▶ if ($op =~ /^[dyc]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /^[dyc]$/) 10 0 10
580 10 ▶ if ($k eq $op) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq $op) 7 3 10
581 7 ▶ $n = $b->{count} - $e->{row} if $e->{row} + $n > $b->{count};
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"row"} + $n > $b->{"count"} 0 7 7
582 7 $e->{register} = [map { $b->id($_) } $e->{row} .. $e->{row}+$n-1]; $e->{regline} = 1;
583 7 ▶ if ($op ne 'y') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "y") 5 2 7
584 5 $b->begin;
585 5 ▶ if ($op eq 'c') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq 'c') { } 3 2 5
586 3 $b->splice_lines($e->{row},$n,$b->append(''));
587 3 $e->{col} = 0; $e->{mode} = 'insert';
588 2 } else { $b->splice_lines($e->{row},$n); $b->commit }
589 5 $e->clamp;
590 }
591 7 return;
592 }
593 # Characterwise operators intentionally limited to same-line motions.
594 3 my ($r,$c) = @{$e}{qw(row col)}; my $line = $b->line($r); my $end;
595 0 ▶ if ($k eq '$') { $end = length($line) }
Branch: 6 branches
BranchTrueFalseTotal
if ($k eq '$') { } 0 3 3
elsif ($k eq '0') { } 0 3 3
elsif ($k eq 'w') { } 3 0 3
elsif ($k eq 'e' or $k eq 'b') { } 0 0 0
elsif ($k eq 'l') { } 0 0 0
elsif ($k eq 'h') { } 0 0 0
596 0 elsif ($k eq '0') { $end = 0 }
597 elsif ($k eq 'w') {
598 3 $end = $c;
599 3 for (1..$n) {
600 3 my $tail = substr($line,$end);
601 3 ▶ if ($op eq 'c' && $tail =~ /^\S/) { $tail =~ /^(?:\w+|[^\w\s]+)/; $end += length($&) }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq 'c' and $tail =~ /^\S/) { } 1 2 3
Condition66%2/3
$op eq "c" and $tail =~ /^\S/
!ll&&!rl&&r
201
MC/DC50%1/2
$op eq "c" and $tail =~ /^\S/
$op eq "c" $tail =~ /^\S/
Truth table66%2/3
A and B
A= $op eq "c"B= $tail =~ /^\S/
ABresult
0X0
100
111
602 2 else { $tail =~ /^(?:\w+|[^\w\s]+)?\s*/; $end += length($&) }
603 }
604 }
605 ▶ elsif ($k eq 'e' || $k eq 'b') {
Condition0%0/3
$k eq "e" or $k eq "b"
l!l&&r!l&&!r
000
MC/DC0%0/2
$k eq "e" or $k eq "b"
$k eq "e" $k eq "b"
Truth table0%0/3
A or B
A= $k eq "e"B= $k eq "b"
ABresult
1X1
011
000
606 0 ▶ $e->word($k,$n); $end = $e->{row} == $r ? $e->{col} + ($k eq 'e' ? 1 : 0) : length($line);
Branch: 2 branches
BranchTrueFalseTotal
$e->{'row'} == $r ? : 0 0 0
$k eq 'e' ? : 0 0 0
607 0 @{$e}{qw(row col)} = ($r,$c);
608 0 ▶ } elsif ($k eq 'l') { $end = $c+$n; $end = length($line) if $end > length($line) }
Branch: 1 branch
BranchTrueFalseTotal
if $end > length $line 0 0 0
609 0 ▶ elsif ($k eq 'h') { $end = $c-$n; $end = 0 if $end < 0 }
Branch: 1 branch
BranchTrueFalseTotal
if $end < 0 0 0 0
610 0 else { die "Supported operator motions: repeated operator, w e b h l 0 \$\n" }
611 3 ▶ my $start = $c < $end ? $c : $end; my $len = abs($end-$c);
Branch: 1 branch
BranchTrueFalseTotal
$c < $end ? : 3 0 3
612 3 $e->{regtext} = substr($line,$start,$len); $e->{regline} = 0;
613 3 ▶ if ($op ne 'y' && $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "y" and $len) 3 0 3
Condition33%1/3
$op ne "y" and $len
!ll&&!rl&&r
003
MC/DC0%0/2
$op ne "y" and $len
$op ne "y" $len
Truth table33%1/3
A and B
A= $op ne "y"B= $len
ABresult
0X0
100
111
614 3 $b->begin; substr($line,$start,$len,''); $b->set_line($r,$line); $e->{col} = $start;
615 3 ▶ if ($op eq 'c') { $e->{mode} = 'insert' } else { $b->commit }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq 'c') { } 1 2 3
616 3 $e->clamp;
617 }
618 3 return;
619 }
620 0 die "Unknown key sequence\n";
621 }
622 58 ▶ if ($k eq '\\' || $k =~ /^[dycrgZ!]$/) { $e->{pending} = $k; $e->{opcount} = $n; return }
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "\\" or $k =~ /^[dycrgZ!]$/) 18 40 58
Condition66%2/3
$k eq "\\" or $k =~ /^[dycrgZ!]$/
l!l&&r!l&&!r
01840
MC/DC50%1/2
$k eq "\\" or $k =~ /^[dycrgZ!]$/
$k eq "\\" $k =~ /^[dycrgZ!]$/
Truth table66%2/3
A or B
A= $k eq "\\"B= $k =~ /^[dycrgZ!]$/
ABresult
1X1
011
000
623 0 ▶ if ($k eq 'h' || $k eq 'LEFT') { $e->{col} -= $n }
Branch: 28 branches
BranchTrueFalseTotal
if ($k eq 'h' or $k eq 'LEFT') { } 0 40 40
elsif ($k eq 'l' or $k eq 'RIGHT') { } 1 39 40
elsif ($k eq 'j' or $k eq 'DOWN') { } 1 38 39
elsif ($k eq 'k' or $k eq 'UP') { } 0 38 38
elsif ($k eq '0') { } 3 35 38
elsif ($k eq '^') { } 1 34 35
elsif ($k eq '$' or $k eq 'END') { } 1 33 34
elsif ($k eq 'HOME') { } 0 33 33
elsif ($k eq 'G') { } 2 31 33
elsif ($k =~ /^[wbe]$/) { } 3 28 31
elsif ($k eq "\cF" or $k eq 'PAGEDOWN') { } 0 28 28
elsif ($k eq "\cB" or $k eq 'PAGEUP') { } 0 28 28
elsif ($k eq "\cD") { } 0 28 28
elsif ($k eq "\cU") { } 0 28 28
elsif ($k eq 'i') { } 3 25 28
elsif ($k eq 'a') { } 0 25 25
elsif ($k eq 'I') { } 0 25 25
elsif ($k eq 'A') { } 1 24 25
elsif ($k eq 'R') { } 1 23 24
elsif ($k eq 'o' or $k eq 'O') { } 2 21 23
elsif ($k eq 'u' or $k eq "\cR") { } 5 16 21
elsif ($k eq 'x' or $k eq 'DELETE') { } 2 14 16
elsif ($k eq 'D' or $k eq 'C') { } 0 14 14
elsif ($k eq 'p' or $k eq 'P') { } 4 10 14
elsif ($k eq 'J') { } 1 9 10
elsif ($k eq ':' or $k eq '/' or $k eq '?') { } 2 7 9
elsif ($k eq 'n' or $k eq 'N') { } 7 0 7
elsif ($k eq "\f" or $k eq 'L') { } 0 0 0
Condition33%1/3
$k eq "h" or $k eq "LEFT"
l!l&&r!l&&!r
0040
MC/DC0%0/2
$k eq "h" or $k eq "LEFT"
$k eq "h" $k eq "LEFT"
Truth table33%1/3
A or B
A= $k eq "h"B= $k eq "LEFT"
ABresult
1X1
011
000
624 1 ▶ elsif ($k eq 'l' || $k eq 'RIGHT') { $e->{col} += $n }
Condition66%2/3
$k eq "l" or $k eq "RIGHT"
l!l&&r!l&&!r
1039
MC/DC50%1/2
$k eq "l" or $k eq "RIGHT"
$k eq "l" $k eq "RIGHT"
Truth table66%2/3
A or B
A= $k eq "l"B= $k eq "RIGHT"
ABresult
1X1
011
000
625 1 ▶ elsif ($k eq 'j' || $k eq 'DOWN') { $e->{row} += $n }
Condition66%2/3
$k eq "j" or $k eq "DOWN"
l!l&&r!l&&!r
1038
MC/DC50%1/2
$k eq "j" or $k eq "DOWN"
$k eq "j" $k eq "DOWN"
Truth table66%2/3
A or B
A= $k eq "j"B= $k eq "DOWN"
ABresult
1X1
011
000
626 0 ▶ elsif ($k eq 'k' || $k eq 'UP') { $e->{row} -= $n }
Condition33%1/3
$k eq "k" or $k eq "UP"
l!l&&r!l&&!r
0038
MC/DC0%0/2
$k eq "k" or $k eq "UP"
$k eq "k" $k eq "UP"
Truth table33%1/3
A or B
A= $k eq "k"B= $k eq "UP"
ABresult
1X1
011
000
627 3 elsif ($k eq '0') { $e->{col} = 0 }
628 1 elsif ($k eq '^') { $b->line($e->{row}) =~ /^(\s*)/; $e->{col} = length($1) }
629 1 ▶ elsif ($k eq '$' || $k eq 'END') { $e->{col} = length($b->line($e->{row}))-1 }
Condition66%2/3
$k eq "\$" or $k eq "END"
l!l&&r!l&&!r
1033
MC/DC50%1/2
$k eq "\$" or $k eq "END"
$k eq "\$" $k eq "END"
Truth table66%2/3
A or B
A= $k eq "\$"B= $k eq "END"
ABresult
1X1
011
000
630 0 elsif ($k eq 'HOME') { $e->{col} = 0 }
631 2 ▶ elsif ($k eq 'G') { $e->{row} = $explicit ? $n-1 : $b->{count}-1 }
Branch: 1 branch
BranchTrueFalseTotal
$explicit ? : 1 1 2
632 3 elsif ($k =~ /^[wbe]$/) { $e->word($k,$n) }
633 0 ▶ elsif ($k eq "\x06" || $k eq 'PAGEDOWN') { $e->{row} += $n*$e->{page} }
Condition33%1/3
$k eq "\6" or $k eq "PAGEDOWN"
l!l&&r!l&&!r
0028
MC/DC0%0/2
$k eq "\6" or $k eq "PAGEDOWN"
$k eq "\6" $k eq "PAGEDOWN"
Truth table33%1/3
A or B
A= $k eq "\6"B= $k eq "PAGEDOWN"
ABresult
1X1
011
000
634 0 ▶ elsif ($k eq "\x02" || $k eq 'PAGEUP') { $e->{row} -= $n*$e->{page} }
Condition33%1/3
$k eq "\2" or $k eq "PAGEUP"
l!l&&r!l&&!r
0028
MC/DC0%0/2
$k eq "\2" or $k eq "PAGEUP"
$k eq "\2" $k eq "PAGEUP"
Truth table33%1/3
A or B
A= $k eq "\2"B= $k eq "PAGEUP"
ABresult
1X1
011
000
635 0 elsif ($k eq "\x04") { $e->{row} += $n*int($e->{page}/2) }
636 0 elsif ($k eq "\x15") { $e->{row} -= $n*int($e->{page}/2) }
637 3 elsif ($k eq 'i') { $e->insert_mode }
638 0 ▶ elsif ($k eq 'a') { ++$e->{col} if length($b->line($e->{row})); $e->insert_mode }
Branch: 1 branch
BranchTrueFalseTotal
if length $b->line($e->{"row"}) 0 0 0
639 0 elsif ($k eq 'I') { $b->line($e->{row}) =~ /^(\s*)/; $e->{col} = length($1); $e->insert_mode }
640 1 elsif ($k eq 'A') { $e->{col} = length($b->line($e->{row})); $e->insert_mode }
641 1 elsif ($k eq 'R') { $e->insert_mode('replace') }
642 ▶ elsif ($k eq 'o' || $k eq 'O') {
Condition100%3/3
$k eq "o" or $k eq "O"
l!l&&r!l&&!r
1121
MC/DC100%2/2
$k eq "o" or $k eq "O"
$k eq "o" $k eq "O"
Truth table100%3/3
A or B
A= $k eq "o"B= $k eq "O"
ABresult
1X1
011
000
643 2 ▶ $b->begin; my $at = $e->{row} + ($k eq 'o' ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$k eq 'o' ? : 1 1 2
644 2 $b->splice_lines($at,0,$b->append('')); $e->{row} = $at; $e->{col} = 0; $e->{mode} = 'insert';
645 }
646 5 ▶ elsif ($k eq 'u' || $k eq "\x12") { for (1..$n) { last unless $e->undo($k eq "\x12") } }
Branch: 1 branch
BranchTrueFalseTotal
unless $e->undo($k eq "\22") 0 5 5
Condition100%3/3
$k eq "u" or $k eq "\22"
l!l&&r!l&&!r
4116
MC/DC100%2/2
$k eq "u" or $k eq "\22"
$k eq "u" $k eq "\22"
Truth table100%3/3
A or B
A= $k eq "u"B= $k eq "\22"
ABresult
1X1
011
000
647 ▶ elsif ($k eq 'x' || $k eq 'DELETE') {
Condition66%2/3
$k eq "x" or $k eq "DELETE"
l!l&&r!l&&!r
2014
MC/DC50%1/2
$k eq "x" or $k eq "DELETE"
$k eq "x" $k eq "DELETE"
Truth table66%2/3
A or B
A= $k eq "x"B= $k eq "DELETE"
ABresult
1X1
011
000
648 2 my $line = $b->line($e->{row}); $e->{regtext} = substr($line,$e->{col},$n); $e->{regline} = 0;
649 2 ▶ $e->edit(sub { substr($line,$e->{col},$n,''); $b->set_line($e->{row},$line) }) if length $e->{regtext};
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
if length $e->{"regtext"} 2 0 2
650 }
651 0 ▶ elsif ($k eq 'D' || $k eq 'C') { $e->{pending} = $k eq 'D' ? 'd' : 'c'; $e->{opcount} = $n; $e->key('$') }
Branch: 1 branch
BranchTrueFalseTotal
$k eq 'D' ? : 0 0 0
Condition33%1/3
$k eq "D" or $k eq "C"
l!l&&r!l&&!r
0014
MC/DC0%0/2
$k eq "D" or $k eq "C"
$k eq "D" $k eq "C"
Truth table33%1/3
A or B
A= $k eq "D"B= $k eq "C"
ABresult
1X1
011
000
652 ▶ elsif ($k eq 'p' || $k eq 'P') {
Condition100%3/3
$k eq "p" or $k eq "P"
l!l&&r!l&&!r
3110
MC/DC100%2/2
$k eq "p" or $k eq "P"
$k eq "p" $k eq "P"
Truth table100%3/3
A or B
A= $k eq "p"B= $k eq "P"
ABresult
1X1
011
000
653 4 ▶ if ($e->{regline} && @{$e->{register}}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($e->{'regline'} and @{$e->{'register'};}) { } 2 2 4
elsif (defined $e->{'regtext'}) { } 1 1 2
Condition100%3/3
$e->{"regline"} and @{$e->{"register"};}
!ll&&!rl&&r
112
MC/DC100%2/2
$e->{"regline"} and @{$e->{"register"};}
$e->{"regline"} @{$e->{"register"};}
Truth table100%3/3
A and B
A= $e->{"regline"}B= @{$e->{"register"};}
ABresult
0X0
100
111
654 2 ▶ my $at = $e->{row} + ($k eq 'p' ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$k eq 'p' ? : 1 1 2
655 2 ▶ $e->edit(sub { $b->splice_lines($at,0,(@{$e->{register}}) x $n); $e->{row} = $at; $e->{col} = 0 });
Subroutine __ANON__: called CC=1 SCAR=0.0
656 } elsif (defined $e->{regtext}) {
657 1 ▶ my $line = $b->line($e->{row}); my $at = $e->{col} + ($k eq 'p' && length($line) ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$k eq 'p' && length $line ? : 1 0 1
Condition33%1/3
$k eq "p" and length $line
!ll&&!rl&&r
001
MC/DC0%0/2
$k eq "p" and length $line
$k eq "p" length $line
Truth table33%1/3
A and B
A= $k eq "p"B= length $line
ABresult
0X0
100
111
658 1 ▶ $e->edit(sub { substr($line,$at,0,$e->{regtext} x $n); $b->set_line($e->{row},$line); $e->{col} = $at });
Subroutine __ANON__: called CC=1 SCAR=0.0
659 }
660 }
661 elsif ($k eq 'J') {
662 1 ▶ $e->edit(sub {
Subroutine __ANON__: called CC=7 SCAR=22.5
663 1 ▶ for (1 .. ($n > 1 ? $n-1 : 1)) {
Branch: 1 branch
BranchTrueFalseTotal
$n > 1 ? : 0 1 1
664 1 ▶ last if $e->{row} >= $b->{count}-1;
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"row"} >= $b->{"count"} - 1 0 1 1
665 1 my $a = $b->line($e->{row}); my $next = $b->line($e->{row}+1); $next =~ s/^\s+//;
666 1 $e->{col} = length $a;
667 1 ▶ $b->splice_lines($e->{row},2,$b->append($a.($a =~ /\s$/ || $a eq '' || $next eq '' ? '' : ' ').$next,$b->term($e->{row}+1)));
Branch: 1 branch
BranchTrueFalseTotal
$a =~ /\s$/ || $a eq '' || $next eq '' ? : 0 1 1
Condition33%2/6
$a =~ /\s$/ or $a eq "" or $next eq ""
l!l&&r!l&&!r
001
$a =~ /\s$/ or $a eq ""
l!l&&r!l&&!r
001
MC/DC0%0/3
$a =~ /\s$/ or $a eq "" or $next eq ""
$a =~ /\s$/ $a eq "" $next eq ""
Truth table25%1/4
A or B or C
A= $a =~ /\s$/B= $a eq ""C= $next eq ""
ABCresult
1XX1
01X1
0011
0000
668 }
669 1 });
670 }
671 2 ▶ elsif ($k eq ':' || $k eq '/' || $k eq '?') { $e->{mode} = 'prompt'; $e->{prompt} = $k }
Condition66%4/6
$k eq ":" or $k eq "/" or $k eq "?"
l!l&&r!l&&!r
207
$k eq ":" or $k eq "/"
l!l&&r!l&&!r
207
MC/DC33%1/3
$k eq ":" or $k eq "/" or $k eq "?"
$k eq ":" $k eq "/" $k eq "?"
Truth table50%2/4
A or B or C
A= $k eq ":"B= $k eq "/"C= $k eq "?"
ABCresult
1XX1
01X1
0011
0000
672 7 ▶ elsif ($k eq 'n' || $k eq 'N') { my $dir = $e->{direction} || 1; for (1..$n) { $e->search('',$dir*($k eq 'N' ? -1 : 1)) } $e->{direction} = $dir }
Branch: 1 branch
BranchTrueFalseTotal
$k eq 'N' ? : 2 5 7
Condition60%3/5
$k eq "n" or $k eq "N"
l!l&&r!l&&!r
520
$e->{'direction'} || 1
l!l
70
MC/DC0%0/2
$k eq "n" or $k eq "N"
$k eq "n" $k eq "N"
MC/DC0%0/1
$e->{'direction'} || 1
$e->{'direction'}
Truth table66%2/3
A or B
A= $k eq "n"B= $k eq "N"
ABresult
1X1
011
000
Truth table50%1/2
A
A= $e->{'direction'}
Aresult
11
00
673 0 ▶ elsif ($k eq "\x0c" || $k eq 'L') { $e->{redraw} = 1 }
Condition0%0/3
$k eq "\f" or $k eq "L"
l!l&&r!l&&!r
000
MC/DC0%0/2
$k eq "\f" or $k eq "L"
$k eq "\f" $k eq "L"
Truth table0%0/3
A or B
A= $k eq "\f"B= $k eq "L"
ABresult
1X1
011
000
674 0 else { $e->{message} = 'Unmapped key; :help for basics' }
675 40 $e->clamp;
676 }
677  
678 package PVim::Terminal;
679 25 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
680 25 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
681 25 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
682 1 ▶sub new { return bless { top => 0, left => 0, previous => [], rows => 24, cols => 80 }, $_[0] }
Subroutine new: called CC=1 SCAR=0.0
683 1 ▶sub start {
Subroutine start: called CC=6 SCAR=32.6
684 1 my ($t) = @_;
685 1 ▶ die "Interactive mode requires a POSIX tty and ANSI/VT100 terminal; use --batch otherwise\n" if $^O eq 'MSWin32' || !-t STDIN || !-t STDOUT;
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" or not -t STDIN or not -t STDOUT 1 0 1
Condition33%2/6
$^O eq "MSWin32" or not -t STDIN or not -t STDOUT
l!l&&r!l&&!r
100
$^O eq "MSWin32" or not -t STDIN
l!l&&r!l&&!r
010
MC/DC0%0/3
$^O eq "MSWin32" or not -t STDIN or not -t STDOUT
$^O eq "MSWin32" not -t STDIN not -t STDOUT
Truth table25%1/4
A or not(B) or not(C)
A= $^O eq "MSWin32"B= not -t STDINC= not -t STDOUT
ABCresult
1XX1
01X1
0011
0000
686 0 ▶ my $old = POSIX::Termios->new; $old->getattr(fileno(STDIN)) or die "tcgetattr: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
$old->getattr(fileno STDIN) or die "tcgetattr: $!\n" 0 0 0
687 0 my $raw = POSIX::Termios->new; $raw->getattr(fileno(STDIN));
688 0 $raw->setlflag($raw->getlflag & ~(POSIX::ICANON() | POSIX::ECHO() | POSIX::ISIG() | POSIX::IEXTEN()));
689 0 $raw->setiflag($raw->getiflag & ~(POSIX::IXON() | POSIX::ICRNL() | POSIX::INLCR() | POSIX::ISTRIP()));
690 0 $raw->setcc(POSIX::VMIN(),1); $raw->setcc(POSIX::VTIME(),0);
691 0 ▶ $t->{old} = $old; $raw->setattr(fileno(STDIN),POSIX::TCSANOW()) or die "tcsetattr: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
$raw->setattr(fileno STDIN, 0) or die "tcsetattr: $!\n" 0 0 0
692 0 binmode STDIN; binmode STDOUT; $| = 1;
693 0 print "\e[?1049h\e[?2004h\e[2J\e[H";
694 }
695 1 ▶sub stop {
Subroutine stop: called CC=2 SCAR=9.2
696 1 my ($t) = @_;
697 0 ▶ if (my $old = delete $t->{old}) { $old->setattr(fileno(STDIN),POSIX::TCSANOW()); print "\e[0m\e[?2004l\e[?1049l\e[?25h\n" }
Branch: 1 branch
BranchTrueFalseTotal
if (my $old = delete $t->{"old"}) 0 1 1
698 }
699 0 ▶sub suspend {
Subroutine suspend: not called CC=4 SCAR=30.0
700 0 my ($t) = @_;
701 0 ▶ return unless $t->{old};
Branch: 1 branch
BranchTrueFalseTotal
unless $t->{"old"} 0 0 0
702 0 $t->stop;
703 # Stop only this editor. Its shell retains control of the foreground job.
704 # The default disposition is essential when called from our TSTP handler.
705 {
706 0 local $SIG{TSTP} = 'DEFAULT';
707 0 my $mask = POSIX::SigSet->new;
708 0 POSIX::sigprocmask(POSIX::SIG_UNBLOCK(), POSIX::SigSet->new(POSIX::SIGTSTP()), $mask);
709 0 ▶ kill 'TSTP', $$ or die "Cannot suspend: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
kill "TSTP", $$ or die "Cannot suspend: $!\n" 0 0 0
710 0 POSIX::sigprocmask(POSIX::SIG_SETMASK(), $mask);
711 }
712 # Execution continues here after fg / SIGCONT. Take a fresh tty snapshot,
713 # since the shell may have changed terminal settings while we were stopped.
714 0 $t->start;
715 0 $t->{previous} = [];
716 0 ▶ $t->{on_resume}->() if $t->{on_resume};
Branch: 1 branch
BranchTrueFalseTotal
if $t->{"on_resume"} 0 0 0
717 }
718 0 ▶sub DESTROY { $_[0]->stop }
Subroutine DESTROY: not called CC=1 SCAR=6.9
719 0 ▶sub size {
Subroutine size: not called CC=11 SCAR=48.8
720 0 my ($t) = @_;
721 0 my $size = pack('S4',0,0,0,0);
722 # TIOCGWINSZ values differ on Linux and BSD; unknown systems use env/defaults.
723 0 ▶ my $request = $^O eq 'linux' ? 0x5413 : $^O =~ /darwin|bsd/ ? 0x40087468 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$^O eq 'linux' ? : 0 0 0
$^O =~ /darwin|bsd/ ? : 0 0 0
724 0 ▶ my ($rows,$cols) = $request && ioctl(STDOUT,$request,$size) ? unpack('S2',$size) : ($ENV{LINES} || 24,$ENV{COLUMNS} || 80);
Branch: 1 branch
BranchTrueFalseTotal
$request && ioctl(STDOUT, $request, $size) ? : 0 0 0
Condition0%0/7
$request and ioctl STDOUT, $request, $size
!ll&&!rl&&r
000
$ENV{"LINES"} or 24
l!l
00
$ENV{"COLUMNS"} or 80
l!l
00
MC/DC0%0/2
$request and ioctl STDOUT, $request, $size
$request ioctl STDOUT, $request, $size
MC/DC0%0/1
$ENV{"LINES"} or 24
$ENV{"LINES"}
MC/DC0%0/1
$ENV{"COLUMNS"} or 80
$ENV{"COLUMNS"}
Truth table0%0/3
A and B
A= $requestB= ioctl STDOUT, $request, $size
ABresult
0X0
100
111
Truth table0%0/2
A
A= $ENV{"LINES"}
Aresult
11
00
Truth table0%0/2
A
A= $ENV{"COLUMNS"}
Aresult
11
00
725 0 ▶ $rows = 24 unless $rows >= 4; $cols = 80 unless $cols >= 12;
Branch: 2 branches
BranchTrueFalseTotal
unless $rows >= 4 0 0 0
unless $cols >= 12 0 0 0
726 0 ▶ if ($rows != $t->{rows} || $cols != $t->{cols}) { $t->{previous} = [] }
Branch: 1 branch
BranchTrueFalseTotal
if ($rows != $t->{"rows"} or $cols != $t->{"cols"}) 0 0 0
Condition0%0/3
$rows != $t->{"rows"} or $cols != $t->{"cols"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$rows != $t->{"rows"} or $cols != $t->{"cols"}
$rows != $t->{"rows"} $cols != $t->{"cols"}
Truth table0%0/3
A or B
A= $rows != $t->{"rows"}B= $cols != $t->{"cols"}
ABresult
1X1
011
000
727 0 @{$t}{qw(rows cols)} = ($rows,$cols);
728 }
729 0 ▶sub read_key {
Subroutine read_key: not called CC=14 SCAR=53.5
730 0 my ($t) = @_;
731 0 my ($got,$k);
732 0 ▶ do { $got = sysread(STDIN,$k,1) } while (!defined($got) && $! == Errno::EINTR());
Branch: 1 branch
BranchTrueFalseTotal
not defined $got and $! == 4 and do { do { $got = sysread(STDIN, $k, 1) } } 0 0 0
Condition0%0/3
not defined $got and $! == 4
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $got and $! == 4
not defined $got $! == 4
Truth table0%0/3
not(A) and B
A= not defined $gotB= $! == 4
ABresult
0X0
100
111
733 0 ▶ return undef unless $got;
Branch: 1 branch
BranchTrueFalseTotal
unless $got 0 0 0
734 0 ▶ return $k unless $k eq "\e";
Branch: 1 branch
BranchTrueFalseTotal
unless $k eq "\e" 0 0 0
735 0 my $select = IO::Select->new(\*STDIN); my $seq = '';
736 0 ▶ while (length($seq) < 16 && $select->can_read(0.035)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $seq < 16 and $select->can_read("0.035")) 0 0 0
Condition0%0/3
length $seq < 16 and $select->can_read("0.035")
!ll&&!rl&&r
000
MC/DC0%0/2
length $seq < 16 and $select->can_read("0.035")
length $seq < 16 $select->can_read("0.035")
Truth table0%0/3
A and B
A= length $seq < 16B= $select->can_read("0.035")
ABresult
0X0
100
111
737 0 ▶ sysread(STDIN,my $c,1) or last; $seq .= $c;
Branch: 1 branch
BranchTrueFalseTotal
sysread STDIN, my $c, 1 or last 0 0 0
738 0 ▶ last if $seq =~ /^(?:\[[0-9;]*[A-Za-z~]|O[A-Za-z])$/;
Branch: 1 branch
BranchTrueFalseTotal
if $seq =~ /^(?:\[[0-9;]*[A-Za-z~]|O[A-Za-z])$/ 0 0 0
739 0 ▶ last if $seq !~ /^[\[O]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $seq =~ /^[\[O]/ 0 0 0
740 }
741 0 ▶ return "\e" unless length $seq;
Branch: 1 branch
BranchTrueFalseTotal
unless length $seq 0 0 0
742 0 my %keys = ('[A'=>'UP','[B'=>'DOWN','[C'=>'RIGHT','[D'=>'LEFT','OA'=>'UP','OB'=>'DOWN','OC'=>'RIGHT','OD'=>'LEFT',
743 '[H'=>'HOME','[F'=>'END','OH'=>'HOME','OF'=>'END','[1~'=>'HOME','[4~'=>'END','[3~'=>'DELETE','[5~'=>'PAGEUP','[6~'=>'PAGEDOWN',
744 '[200~'=>'PASTE_START','[201~'=>'PASTE_END');
745 0 ▶ if (exists $keys{$seq}) { return $keys{$seq} }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $keys{$seq}) 0 0 0
746 # Escape immediately followed by normal text: preserve subsequent keystrokes.
747 0 ▶ $t->{queued} = [split //,$seq] unless $seq =~ /^\[/ && $seq =~ /[A-Za-z~]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $seq =~ /^\[/ and $seq =~ /[A-Za-z~]$/ 0 0 0
Condition0%0/3
$seq =~ /^\[/ and $seq =~ /[A-Za-z~]$/
!ll&&!rl&&r
000
MC/DC0%0/2
$seq =~ /^\[/ and $seq =~ /[A-Za-z~]$/
$seq =~ /^\[/ $seq =~ /[A-Za-z~]$/
Truth table0%0/3
A and B
A= $seq =~ /^\[/B= $seq =~ /[A-Za-z~]$/
ABresult
0X0
100
111
748 0 return "\e";
749 }
750 214 ▶sub safe { my ($text) = @_; $text =~ s/([^\x20-\x7e])/sprintf('<%02X>',ord($1))/ge; return $text }
Subroutine safe: called CC=1 SCAR=0.0
751 5 ▶sub cells {
Subroutine cells: called CC=3 SCAR=11.0
752 5 my ($text,$tabstop) = @_;
753 5 my ($out,@positions) = ('');
754 5 for my $c (split //,$text) {
755 309 push @positions, length($out);
756 309 ▶ $out .= $c eq "\t" ? ' ' x ($tabstop - length($out)%$tabstop) : safe($c);
Branch: 1 branch
BranchTrueFalseTotal
$c eq "\t" ? : 102 207 309
757 }
758 5 push @positions, length($out); return ($out,\@positions);
759 }
760 8 ▶sub display {
Subroutine display: called CC=8 SCAR=20.8
761 8 my ($text,$tabstop,$limit) = @_;
762 8 my $out = '';
763 8 ▶ while ($text =~ /([\x20-\x7e]+)|(\t)|([^\x20-\x7e])/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /([\x20-\x7e]+)|(\t)|([^\x20-\x7e])/g) 117 6 123
764 117 ▶ if (defined $1) { $out .= defined($limit) ? substr($1,0,$limit-length($out)) : $1 }
Branch: 3 branches
BranchTrueFalseTotal
if (defined $1) { } 6 111 117
elsif (defined $2) { } 105 6 111
defined $limit ? : 3 3 6
765 105 elsif (defined $2) { $out .= ' ' x ($tabstop-length($out)%$tabstop) }
766 6 else { $out .= safe($3) }
767 117 ▶ last if defined($limit) && length($out) >= $limit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $limit and length $out >= $limit 2 115 117
Condition100%3/3
defined $limit and length $out >= $limit
!ll&&!rl&&r
10782
MC/DC100%2/2
defined $limit and length $out >= $limit
defined $limit length $out >= $limit
Truth table100%3/3
A and B
A= defined $limitB= length $out >= $limit
ABresult
0X0
100
111
768 }
769 8 ▶ return defined($limit) ? substr($out,0,$limit) : $out;
Branch: 1 branch
BranchTrueFalseTotal
defined $limit ? : 4 4 8
770 }
771 0 ▶sub draw {
Subroutine draw: not called CC=20 SCAR=60.4
772 0 my ($t,$e) = @_;
773 0 $t->size; my ($rows,$cols) = @{$t}{qw(rows cols)}; my $height = $rows-2; $e->{page} = $height;
774 0 my $b = $e->{b};
775 0 ▶ $t->{top} = $e->{row} if $e->{row} < $t->{top};
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"row"} < $t->{"top"} 0 0 0
776 0 ▶ $t->{top} = $e->{row}-$height+1 if $e->{row} >= $t->{top}+$height;
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"row"} >= $t->{"top"} + $height 0 0 0
777 0 ▶ my $digits = length($b->{count}); $digits = 3 if $digits < 3;
Branch: 1 branch
BranchTrueFalseTotal
if $digits < 3 0 0 0
778 0 ▶ my $gutter = $e->{number} ? $digits+1 : 0; $gutter = 0 if $gutter > $cols-4;
Branch: 2 branches
BranchTrueFalseTotal
$e->{'number'} ? : 0 0 0
if $gutter > $cols - 4 0 0 0
779 0 my $width = $cols-$gutter-1;
780 0 my $cx = length(display(substr($b->line($e->{row}),0,$e->{col}),$e->{tabstop},undef));
781 0 ▶ $t->{left} = $cx if $cx < $t->{left}; $t->{left} = $cx-$width+1 if $cx >= $t->{left}+$width;
Branch: 2 branches
BranchTrueFalseTotal
if $cx < $t->{"left"} 0 0 0
if $cx >= $t->{"left"} + $width 0 0 0
782 0 my @screen;
783 0 for my $screen_row (0..$height-1) {
784 0 my $r = $t->{top}+$screen_row;
785 0 ▶ if ($r >= $b->{count}) { push @screen,'~'; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($r >= $b->{"count"}) 0 0 0
786 0 my $text = display($b->line($r),$e->{tabstop},$t->{left}+$width); $text = substr($text,$t->{left},$width);
787 0 ▶ my $prefix = $gutter ? sprintf("\e[33m%*d\e[0m ", $gutter-1,$r+1) : '';
Branch: 1 branch
BranchTrueFalseTotal
$gutter ? : 0 0 0
788 0 push @screen, $prefix.$text;
789 }
790 0 ▶ my $status = sprintf(' %s%s | %s | %d,%d | %d lines',safe($b->{path} || '[No Name]'),$b->dirty ? ' [+]' : '',uc($e->{mode}),$e->{row}+1,$e->{col}+1,$b->{count});
Branch: 1 branch
BranchTrueFalseTotal
$b->dirty ? : 0 0 0
Condition0%0/2
$b->{'path'} || '[No Name]'
l!l
00
MC/DC0%0/1
$b->{'path'} || '[No Name]'
$b->{'path'}
Truth table0%0/2
A
A= $b->{'path'}
Aresult
11
00
791 0 push @screen,"\e[7m".substr($status,0,$cols-1)."\e[0m";
792 0 ▶ push @screen, substr(safe($e->{mode} eq 'prompt' ? $e->{prompt} : $e->{message}),0,$cols-1);
Branch: 1 branch
BranchTrueFalseTotal
$e->{'mode'} eq 'prompt' ? : 0 0 0
793 0 ▶ $t->{previous} = [] if delete $e->{redraw};
Branch: 1 branch
BranchTrueFalseTotal
if delete $e->{"redraw"} 0 0 0
794 0 my $output = "\e[?25l";
795 0 for my $i (0..$#screen) {
796 0 ▶ next if defined($t->{previous}[$i]) && $t->{previous}[$i] eq $screen[$i];
Branch: 1 branch
BranchTrueFalseTotal
if defined $t->{"previous"}[$i] and $t->{"previous"}[$i] eq $screen[$i] 0 0 0
Condition0%0/3
defined $t->{"previous"}[$i] and $t->{"previous"}[$i] eq $screen[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $t->{"previous"}[$i] and $t->{"previous"}[$i] eq $screen[$i]
defined $t->{"previous"}[$i] $t->{"previous"}[$i] eq $screen[$i]
Truth table0%0/3
A and B
A= defined $t->{"previous"}[$i]B= $t->{"previous"}[$i] eq $screen[$i]
ABresult
0X0
100
111
797 0 $output .= sprintf("\e[%d;1H\e[0m%s\e[K",$i+1,$screen[$i]);
798 }
799 0 $t->{previous} = \@screen;
800 0 ▶ my ($cy,$x) = $e->{mode} eq 'prompt' ? ($rows,length(safe($e->{prompt}))+1) : ($e->{row}-$t->{top}+1,$gutter+$cx-$t->{left}+1);
Branch: 1 branch
BranchTrueFalseTotal
$e->{'mode'} eq 'prompt' ? : 0 0 0
801 0 ▶ $x = $cols-1 if $x >= $cols;
Branch: 1 branch
BranchTrueFalseTotal
if $x >= $cols 0 0 0
802 0 print $output.sprintf("\e[%d;%dH\e[?25h",$cy,$x);
803 }
804 0 ▶sub splash_frame {
Subroutine splash_frame: not called CC=5 SCAR=34.0
805 0 my ($t) = @_;
806 0 $t->size;
807 0 my @text = ('pvim - portable vim clone', '', 'Vim-style editing where Perl is available.', '',
808 'Support Us at PerlCommunity.org', '', 'Press any key to begin.');
809 # Keep a one-cell margin and center each line and the whole text block.
810 # On short terminals remove blank spacers before trimming actual content.
811 0 my $height = $t->{rows}-2;
812 0 ▶ while (@text > $height) {
Branch: 1 branch
BranchTrueFalseTotal
if (@text > $height) 0 0 0
813 0 my ($blank) = grep { $text[$_] eq '' } 0..$#text;
814 0 ▶ last unless defined $blank;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $blank 0 0 0
815 0 splice @text,$blank,1;
816 }
817 0 ▶ @text = (@text[0..$height-2],$text[-1]) if @text > $height;
Branch: 1 branch
BranchTrueFalseTotal
if @text > $height 0 0 0
818 0 my $top = int(($t->{rows}-@text)/2)+1;
819 0 print "\e[2J\e[H";
820 0 for my $i (0..$#text) {
821 0 my $line = substr(safe($text[$i]),0,$t->{cols}-2);
822 0 my $left = int(($t->{cols}-length($line))/2)+1;
823 0 print sprintf("\e[%d;%dH%s",$top+$i,$left,$line);
824 }
825 }
826 0 ▶sub splash {
Subroutine splash: not called CC=3 SCAR=24.8
827 0 my ($t) = @_;
828 0 local $t->{in_splash} = 1;
829 0 $t->splash_frame;
830 0 while (1) {
831 0 my $k = $t->read_key;
832 0 ▶ if (defined($k) && $k eq "\x1a") { $t->suspend; next }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $k and $k eq "\32") 0 0 0
Condition0%0/3
defined $k and $k eq "\32"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $k and $k eq "\32"
defined $k $k eq "\32"
Truth table0%0/3
A and B
A= defined $kB= $k eq "\32"
ABresult
0X0
100
111
833 0 last;
834 }
835 0 print "\e[2J\e[H"; $t->{previous} = [];
836 }
837  
838 package main;
839 25 ▶use Getopt::Long qw(GetOptionsFromArray);
Subroutine BEGIN: called CC=1 SCAR=0.0
840 25 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
841 5 our $VERSION = '0.1.13';
842 22 ▶sub run {
Subroutine run: called CC=42 SCAR=60.9
843 22 my (@args) = @_;
844 22 my ($help,$manual,$version,$batch,$no_splash); my @commands;
845 22 Getopt::Long::Configure('no_auto_abbrev','no_ignore_case');
846 22 ▶ GetOptionsFromArray(\@args,'help|h'=>\$help,'manual'=>\$manual,'version|v'=>\$version,'batch'=>\$batch,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptionsFromArray(\@args, "help|h", \$help, "manual", \$manual, "version|v", \$version, "batch", \$batch, "no-splash", \$no_splash, "command|c=s\@", \@commands) or return 2 22 0 22
847 'no-splash'=>\$no_splash,'command|c=s@'=>\@commands) or return 2;
848 22 ▶ if ($help) { Pod::Usage::pod2usage(-exitval=>'NOEXIT',-verbose=>0); return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($help) 1 21 22
849 21 ▶ if ($manual) { Pod::Usage::pod2usage(-exitval=>'NOEXIT',-verbose=>2,-noperldoc=>1); return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($manual) 1 20 21
850 20 ▶ if ($version) { print "pvim $VERSION (Perl $])\n"; return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($version) 5 15 20
851 15 ▶ die "One file at a time; tabs are planned\n" if @args > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args > 1 0 15 15
852 15 ▶ my $from_stdin = (@args && $args[0] eq '-') || (!$batch && !@args && !-t STDIN);
Condition91%11/12
@args && $args[0] eq '-' || !($batch || @args || -t STDIN)
l!l&&r!l&&!r
915
@args and $args[0] eq "-"
!ll&&!rl&&r
249
$batch || @args || -t STDIN
l!l&&r!l&&!r
501
$batch or @args
l!l&&r!l&&!r
411
MC/DC80%4/5
@args && $args[0] eq '-' || !($batch || @args || -t STDIN)
@args $args[0] eq "-" $batch @args -t STDIN
Truth table55%5/9
A and B || not(C or D || E)
A= @argsB= $args[0] eq "-"C= $batchD= @argsE= -t STDIN
ABCDEresult
11XXX1
0X0001
100001
0X1XX0
0X01X0
0X0010
101XX0
1001X0
100010
853 15 my $keyboard;
854 15 ▶ if ($from_stdin && !$batch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from_stdin and not $batch) 1 14 15
Condition100%3/3
$from_stdin and not $batch
!ll&&!rl&&r
591
MC/DC100%2/2
$from_stdin and not $batch
$from_stdin not $batch
Truth table100%3/3
A and not(B)
A= $from_stdinB= not $batch
ABresult
0X0
100
111
855 1 ▶ die "Interactive stdin import requires a POSIX terminal; use --batch otherwise\n"
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" or not -t STDOUT 1 0 1
Condition33%1/3
$^O eq "MSWin32" or not -t STDOUT
l!l&&r!l&&!r
010
MC/DC0%0/2
$^O eq "MSWin32" or not -t STDOUT
$^O eq "MSWin32" not -t STDOUT
Truth table33%1/3
A or not(B)
A= $^O eq "MSWin32"B= not -t STDOUT
ABresult
1X1
011
000
856 if $^O eq 'MSWin32' || !-t STDOUT;
857 0 ▶ open $keyboard, '<', '/dev/tty'
Branch: 1 branch
BranchTrueFalseTotal
open $keyboard, "<", "/dev/tty" or die "No controlling terminal for stdin import; use --batch with explicit '-' otherwise: $!\n" 0 0 0
858 or die "No controlling terminal for stdin import; use --batch with explicit '-' otherwise: $!\n";
859 }
860 14 ▶ my $e = PVim::Editor->new($from_stdin
Branch: 1 branch
BranchTrueFalseTotal
$from_stdin ? : 9 5 14
861 ? PVim::Store->load(undef, \*STDIN) : PVim::Store->load($args[0]));
862 # Rebind descriptor 0 as well as Perl's handle so external shell commands
863 # inherit the keyboard terminal rather than the exhausted producer pipe.
864 0 ▶ if ($keyboard) { open STDIN, '<&', $keyboard or die "Attach keyboard terminal: $!\n" }
Branch: 2 branches
BranchTrueFalseTotal
if ($keyboard) 0 14 14
open STDIN, "<&", $keyboard or die "Attach keyboard terminal: $!\n" 0 0 0
865 14 ▶ for my $cmd (@commands) { $e->ex($cmd); last if $e->{quit} }
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"quit"} 2 10 12
866 11 ▶ return 0 if $batch || $e->{quit};
Branch: 1 branch
BranchTrueFalseTotal
if $batch or $e->{"quit"} 10 1 11
Condition66%2/3
$batch or $e->{"quit"}
l!l&&r!l&&!r
1001
MC/DC50%1/2
$batch or $e->{"quit"}
$batch $e->{"quit"}
Truth table66%2/3
A or B
A= $batchB= $e->{"quit"}
ABresult
1X1
011
000
867 1 my $t = PVim::Terminal->new;
868 0 ▶ local $SIG{TERM} = sub { die "Terminated; unsaved changes were not written\n" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
869 0 ▶ local $SIG{HUP} = sub { die "Terminal disconnected; unsaved changes were not written\n" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
870 0 ▶ local $SIG{INT} = sub { die "Interrupted; unsaved changes were not written\n" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
871 0 ▶ local $SIG{WINCH} = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
872 0 $e->{redraw} = 1;
873 0 ▶ $t->splash_frame if $t->{in_splash} && $t->{old};
Branch: 1 branch
BranchTrueFalseTotal
if $t->{"in_splash"} and $t->{"old"} 0 0 0
Condition0%0/3
$t->{"in_splash"} and $t->{"old"}
!ll&&!rl&&r
000
MC/DC0%0/2
$t->{"in_splash"} and $t->{"old"}
$t->{"in_splash"} $t->{"old"}
Truth table0%0/3
A and B
A= $t->{"in_splash"}B= $t->{"old"}
ABresult
0X0
100
111
874 1 };
875 0 ▶ $e->{before_filter} = sub { $t->stop };
Subroutine __ANON__: not called CC=1 SCAR=1.2
876 0 ▶ $e->{shell_wait} = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
877 0 print "\nPress ENTER to return to pvim: ";
878 0 ▶ while (sysread(STDIN,my $answer,1)) { last if $answer eq "\n" || $answer eq "\r" }
Branch: 2 branches
BranchTrueFalseTotal
if (sysread STDIN, my $answer, 1) 0 0 0
if $answer eq "\n" or $answer eq "\r" 0 0 0
Condition0%0/3
$answer eq "\n" or $answer eq "\r"
l!l&&r!l&&!r
000
MC/DC0%0/2
$answer eq "\n" or $answer eq "\r"
$answer eq "\n" $answer eq "\r"
Truth table0%0/3
A or B
A= $answer eq "\n"B= $answer eq "\r"
ABresult
1X1
011
000
879 1 };
880 0 ▶ $e->{after_filter} = sub { $t->start; $t->{previous} = []; $e->{redraw} = 1 };
Subroutine __ANON__: not called CC=1 SCAR=3.5
881 0 ▶ $t->{on_resume} = sub { $e->{redraw} = 1; $t->{in_splash} ? $t->splash_frame : $t->draw($e) };
Subroutine __ANON__: not called CC=2 SCAR=14.0
Branch: 1 branch
BranchTrueFalseTotal
$t->{'in_splash'} ? : 0 0 0
882 0 ▶ local $SIG{TSTP} = sub { $t->suspend };
Subroutine __ANON__: not called CC=1 SCAR=1.2
883 1 my $ok = eval {
884 0 ▶ $t->start; $t->splash unless @args || $no_splash || $from_stdin;
Branch: 1 branch
BranchTrueFalseTotal
unless @args or $no_splash or $from_stdin 0 0 0
Condition0%0/6
@args or $no_splash or $from_stdin
l!l&&r!l&&!r
000
@args or $no_splash
l!l&&r!l&&!r
000
MC/DC0%0/3
@args or $no_splash or $from_stdin
@args $no_splash $from_stdin
Truth table0%0/4
A or B or C
A= @argsB= $no_splashC= $from_stdin
ABCresult
1XX1
01X1
0011
0000
885 0 my $pasting = 0;
886 0 ▶ while (!$e->{quit}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($e->{"quit"}) 0 0 0
887 0 ▶ $t->draw($e) unless $pasting;
Branch: 1 branch
BranchTrueFalseTotal
unless $pasting 0 0 0
888 0 ▶ my $k = $t->{queued} && @{$t->{queued}} ? shift @{$t->{queued}} : $t->read_key;
Branch: 1 branch
BranchTrueFalseTotal
$t->{'queued'} && @{$t->{'queued'};} ? : 0 0 0
Condition0%0/3
$t->{"queued"} and @{$t->{"queued"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$t->{"queued"} and @{$t->{"queued"};}
$t->{"queued"} @{$t->{"queued"};}
Truth table0%0/3
A and B
A= $t->{"queued"}B= @{$t->{"queued"};}
ABresult
0X0
100
111
889 0 ▶ last unless defined $k;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k 0 0 0
890 0 ▶ if ($k eq "\x1a" && !$pasting) { $t->suspend; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "\32" and not $pasting) 0 0 0
Condition0%0/3
$k eq "\32" and not $pasting
!ll&&!rl&&r
000
MC/DC0%0/2
$k eq "\32" and not $pasting
$k eq "\32" not $pasting
Truth table0%0/3
A and not(B)
A= $k eq "\32"B= not $pasting
ABresult
0X0
100
111
891 0 ▶ if ($k eq 'PASTE_START') {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "PASTE_START") 0 0 0
892 0 ▶ $pasting = 1; $e->insert_mode if $e->{mode} eq 'normal' || $e->{mode} eq 'prompt'; next;
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"mode"} eq "normal" or $e->{"mode"} eq "prompt" 0 0 0
Condition0%0/3
$e->{"mode"} eq "normal" or $e->{"mode"} eq "prompt"
l!l&&r!l&&!r
000
MC/DC0%0/2
$e->{"mode"} eq "normal" or $e->{"mode"} eq "prompt"
$e->{"mode"} eq "normal" $e->{"mode"} eq "prompt"
Truth table0%0/3
A or B
A= $e->{"mode"} eq "normal"B= $e->{"mode"} eq "prompt"
ABresult
1X1
011
000
893 }
894 0 ▶ if ($k eq 'PASTE_END') { $pasting = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "PASTE_END") 0 0 0
895 # During bracketed paste, ESC/colon/control bytes must never execute commands.
896 0 ▶ next if $pasting && (length($k) != 1 || (ord($k) < 32 && $k !~ /^[\t\r\n]$/));
Branch: 1 branch
BranchTrueFalseTotal
if $pasting and length $k != 1 || ord $k < 32 && !($k =~ /^[\t\r\n]$/) 0 0 0
Condition0%0/9
$pasting and length $k != 1 || ord $k < 32 && !($k =~ /^[\t\r\n]$/)
!ll&&!rl&&r
000
length $k != 1 or ord $k < 32 and not $k =~ /^[\t\r\n]$/
l!l&&r!l&&!r
000
ord $k < 32 and not $k =~ /^[\t\r\n]$/
!ll&&!rl&&r
000
MC/DC0%0/4
$pasting and length $k != 1 || ord $k < 32 && !($k =~ /^[\t\r\n]$/)
$pasting length $k != 1 ord $k < 32 not $k =~ /^[\t\r\n]$/
Truth table0%0/5
A and B or C and not(D)
A= $pastingB= length $k != 1C= ord $k < 32D= not $k =~ /^[\t\r\n]$/
ABCDresult
0XXX0
100X0
10100
11XX1
10111
897 0 my $worked = eval { $e->key($k); 1 };
898 0 ▶ unless ($worked) { $e->{message} = $@; $e->{pending} = ''; $e->{count} = '' }
Branch: 1 branch
BranchTrueFalseTotal
unless ($worked) 0 0 0
899 }
900 0 $e->{b}->commit;
901 0 1;
902 };
903 0 ▶ my $error = $@; $t->stop; die $error unless $ok; return 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 0 1
904 }
905 5 ▶unless (caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 5 5
906 0 my $status = eval { run(@ARGV) };
907 0 ▶ if ($@) { print STDERR "pvim: $@"; exit 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
908 0 ▶ exit($status || 0);
Condition0%0/2
$status || 0
l!l
00
MC/DC0%0/1
$status || 0
$status
Truth table0%0/2
A
A= $status
Aresult
11
00
909 }
910 5 1;
911 __END__
↑ Summary lib/App/Pvim.pm »