lib/Devel/Trepan/CmdProcessor/Complete.pm

filter: Statementstmt 36.5% 80 / 219 Branchbran 33.3% 38 / 114 Conditioncond 25.0% 15 / 60 MC/DCmcdc 10.0% 4 / 40 Subroutinesub 46.6% 7 / 15 Podpod 0.0% 0 / 10 totaltotal 31.4% 144 / 458 CC 81 SCAR 46.3
CC
81
Cov
34%
complete
137.3
complete
137.3
next_complete
104.5
CRAP 102.1
« lib/Devel/Trepan/CmdProcessor/Command/Help.pm ↑ Summary lib/Devel/Trepan/Client.pm »
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014 Rocky Bernstein <rocky@cpan.org>
3  
4 # Part of Devel::Trepan::CmdProcessor that loads up debugger commands from
5 # builtin and user directories.
6 # Top-level command completion routines.
7 12 ▶use rlib '../../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 package Devel::Trepan::CmdProcessor;
10 12 ▶use warnings; use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use Devel::Trepan::Complete;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 12 my $_list_complete_i = -1;
15 sub list_complete($$$)
16 0 ▶{
Subroutine list_complete: not called CC=4 SCAR=30.0
Pod undocumented
17 0 ▶ my($self, $text, $state) = @_;
Subroutine list_complete: not called CC=4 SCAR=30.0
Pod undocumented
18 # clear counter at the first call
19 0 eval { state $_list_complete_i = -1;
20 0 $_list_complete_i++;;
21 };
22 0 my $cw = $self->{completions};
23 0 ▶ for (; $_list_complete_i <= $#{$cw}; $_list_complete_i++) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_list_complete_i <= $#{$cw;}) 0 0 0
if ($_list_complete_i <= $#{$cw;}) 0 0 0
24 0 ▶ return $cw->[$_list_complete_i]
Branch: 2 branches
BranchTrueFalseTotal
if defined $cw->[$_list_complete_i] and $cw->[$_list_complete_i] =~ /^\Q$text\E/ 0 0 0
if defined $cw->[$_list_complete_i] and $cw->[$_list_complete_i] =~ /^\Q$text\E/ 0 0 0
Condition0%0/6
defined $cw->[$_list_complete_i] and $cw->[$_list_complete_i] =~ /^\Q$text\E/
!ll&&!rl&&r
000
defined $cw->[$_list_complete_i] and $cw->[$_list_complete_i] =~ /^\Q$text\E/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cw->[$_list_complete_i] and $cw->[$_list_complete_i] =~ /^\Q$text\E/
defined $cw->[$_list_complete_i] $cw->[$_list_complete_i] =~ /^\Q$text\E/
MC/DC0%0/2
defined $cw->[$_list_complete_i] and $cw->[$_list_complete_i] =~ /^\Q$text\E/
defined $cw->[$_list_complete_i] $cw->[$_list_complete_i] =~ /^\Q$text\E/
Truth table0%0/3
A and B
A= defined $cw->[$_list_complete_i]B= $cw->[$_list_complete_i] =~ /^\Q$text\E/
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $cw->[$_list_complete_i]B= $cw->[$_list_complete_i] =~ /^\Q$text\E/
ABresult
0X0
100
111
25 if defined $cw->[$_list_complete_i] and ($cw->[$_list_complete_i] =~ /^\Q$text/);
26 }
27 0 return undef;
28 };
29  
30  
31 12 my ($_last_line, $_last_start, $_last_end, @_last_return, $_last_token);
32  
33 # Handle initial completion. We draw from the commands, aliases,
34 # and macros for completion. However we won't include aliases which
35 # are prefixes of other commands.
36 sub complete($$$$$)
37 18 ▶{
Subroutine complete: called CC=21 SCAR=49.2
Pod undocumented
38 0 ▶ my ($self, $text, $line, $start, $end) = @_;
Subroutine complete: not called CC=21 SCAR=49.2
Pod undocumented
39 0 $self->{leading_str} = $line;
40  
41 0 ▶ $_last_line = '' unless defined $_last_line;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $_last_line 3 15 18
unless defined $_last_line 0 0 0
42 0 ▶ $_last_start = -1 unless defined $_last_start;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $_last_start 3 15 18
unless defined $_last_start 0 0 0
43 0 ▶ $_last_end = -1 unless defined $_last_end;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $_last_end 3 15 18
unless defined $_last_end 0 0 0
44 0 ▶ $_last_token = '' unless defined $_last_token;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $_last_token 3 15 18
unless defined $_last_token 0 0 0
45 0 ▶ $_last_token = '' unless
Branch: 2 branches
BranchTrueFalseTotal
unless $_last_start < length $line and 0 == index(substr($line, $_last_start), $_last_token) 4 14 18
unless $_last_start < length $line and 0 == index(substr($line, $_last_start), $_last_token) 0 0 0
Condition33%2/6
$_last_start < length $line and 0 == index(substr($line, $_last_start), $_last_token)
!ll&&!rl&&r
0414
$_last_start < length $line and 0 == index(substr($line, $_last_start), $_last_token)
!ll&&!rl&&r
000
MC/DC50%1/2
$_last_start < length $line and 0 == index(substr($line, $_last_start), $_last_token)
$_last_start < length $line 0 == index(substr($line, $_last_start), $_last_token)
MC/DC0%0/2
$_last_start < length $line and 0 == index(substr($line, $_last_start), $_last_token)
$_last_start < length $line 0 == index(substr($line, $_last_start), $_last_token)
Truth table66%2/3
A and B
A= $_last_start < length $lineB= 0 == index(substr($line, $_last_start), $_last_token)
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $_last_start < length $lineB= 0 == index(substr($line, $_last_start), $_last_token)
ABresult
0X0
100
111
46 $_last_start < length($line) &&
47 0 == index(substr($line, $_last_start), $_last_token);
48 # print "\ntext: $text, line: $line, start: $start, end: $end\n";
49 # print "\nlast_line: $_last_line, last_start: $_last_start, last_end: $last_end\n";
50 0 my $stripped_line;
51 0 ($stripped_line = $line) =~ s/\s*$//;
52 0 ▶ if ($_last_line eq $stripped_line && $stripped_line) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_last_line eq $stripped_line and $stripped_line) 0 18 18
if ($_last_line eq $stripped_line and $stripped_line) 0 0 0
Condition16%1/6
$_last_line eq $stripped_line and $stripped_line
!ll&&!rl&&r
1800
$_last_line eq $stripped_line and $stripped_line
!ll&&!rl&&r
000
MC/DC0%0/2
$_last_line eq $stripped_line and $stripped_line
$_last_line eq $stripped_line $stripped_line
MC/DC0%0/2
$_last_line eq $stripped_line and $stripped_line
$_last_line eq $stripped_line $stripped_line
Truth table33%1/3
A and B
A= $_last_line eq $stripped_lineB= $stripped_line
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $_last_line eq $stripped_lineB= $stripped_line
ABresult
0X0
100
111
53 0 $self->{completions} = \@_last_return;
54 0 return @_last_return;
55 }
56 0 ($_last_line, $_last_start, $_last_end) = ($line, $start, $end);
57  
58 0 my @commands = sort keys %{$self->{commands}};
59 0 my ($next_blank_pos, $token) =
60 Devel::Trepan::Complete::next_token($line, 0);
61 0 ▶ if (!$token && !$_last_token) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($token or $_last_token) 0 18 18
unless ($token or $_last_token) 0 0 0
Condition16%1/6
$token or $_last_token
l!l&&r!l&&!r
1800
$token or $_last_token
l!l&&r!l&&!r
000
MC/DC0%0/2
$token or $_last_token
$token $_last_token
MC/DC0%0/2
$token or $_last_token
$token $_last_token
Truth table33%1/3
A or B
A= $tokenB= $_last_token
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $tokenB= $_last_token
ABresult
1X1
011
000
62 0 @_last_return = @commands;
63 0 $_last_token = $_last_return[0];
64 0 $_last_line = $line . $_last_token;
65 0 $_last_end += length($_last_token);
66 0 $self->{completions} = \@_last_return;
67 0 return (@commands);
68 }
69  
70 0 ▶ $token ||= $_last_token;
Condition16%1/6
$token ||= $_last_token
l!l&&r!l&&!r
1800
$token ||= $_last_token
l!l&&r!l&&!r
000
MC/DC0%0/2
$token ||= $_last_token
$token $_last_token
MC/DC0%0/2
$token ||= $_last_token
$token $_last_token
Truth table33%1/3
A ||= B
A= $tokenB= $_last_token
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $tokenB= $_last_token
ABresult
1X1
011
000
71 0 my @match_pairs = complete_token_with_next($self->{commands}, $token);
72  
73 0 my $match_hash = {};
74 0 for my $pair (@match_pairs) {
75 0 $match_hash->{$pair->[0]} = $pair->[1];
76 }
77  
78 my @alias_pairs = complete_token_filtered_with_next($self->{aliases},
79 $token, $match_hash,
80 0 $self->{commands});
81 0 push @match_pairs, @alias_pairs;
82 0 ▶ if ($next_blank_pos >= length($line)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($next_blank_pos >= length $line) { } 4 14 18
if ($next_blank_pos >= length $line) { } 0 0 0
83 0 @_last_return = sort map {$_->[0]} @match_pairs;
84 0 $_last_token = $_last_return[0];
85 0 ▶ if (defined($_last_token)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_last_token) 4 0 4
if (defined $_last_token) 0 0 0
86 0 $_last_line = $line . $_last_token;
87 0 $_last_end += length($_last_token);
88 }
89 0 ▶ if (scalar @_last_return == 0 && $self->{settings}{autoeval}) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_last_return == 0 and $self->{"settings"}{"autoeval"}) 0 4 4
if (scalar @_last_return == 0 and $self->{"settings"}{"autoeval"}) 0 0 0
Condition16%1/6
scalar @_last_return == 0 and $self->{"settings"}{"autoeval"}
!ll&&!rl&&r
400
scalar @_last_return == 0 and $self->{"settings"}{"autoeval"}
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_last_return == 0 and $self->{"settings"}{"autoeval"}
scalar @_last_return == 0 $self->{"settings"}{"autoeval"}
MC/DC0%0/2
scalar @_last_return == 0 and $self->{"settings"}{"autoeval"}
scalar @_last_return == 0 $self->{"settings"}{"autoeval"}
Truth table33%1/3
A and B
A= scalar @_last_return == 0B= $self->{"settings"}{"autoeval"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= scalar @_last_return == 0B= $self->{"settings"}{"autoeval"}
ABresult
0X0
100
111
90 0 return Devel::Trepan::Complete::complete_subs($stripped_line);
91 }
92 0 $self->{completions} = \@_last_return;
93 0 return @_last_return;
94 } else {
95 0 for my $pair (@alias_pairs) {
96 0 $match_hash->{$pair->[0]} = $pair->[1];
97 }
98 }
99 0 ▶ if (scalar(@match_pairs) > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @match_pairs > 1) 0 14 14
if (scalar @match_pairs > 1) 0 0 0
100 # FIXME: figure out what to do here.
101 # Matched multiple items in the middle of the string
102 # We can't handle this so do nothing.
103 0 return ();
104 # return match_pairs.map do |name, cmd|
105 # ["#{name} #{args[1..-1].join(' ')}"]
106 # }
107 }
108 # scalar @match_pairs == 1
109 0 @_last_return = $self->next_complete($line, $next_blank_pos,
110 $match_pairs[0]->[1],
111 $token);
112  
113 0 $self->{completions} = \@_last_return;
114 0 ▶ if (scalar @_last_return == 0 && $self->{settings}{autoeval}) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_last_return == 0 and $self->{"settings"}{"autoeval"}) 2 12 14
if (scalar @_last_return == 0 and $self->{"settings"}{"autoeval"}) 0 0 0
Condition33%2/6
scalar @_last_return == 0 and $self->{"settings"}{"autoeval"}
!ll&&!rl&&r
1202
scalar @_last_return == 0 and $self->{"settings"}{"autoeval"}
!ll&&!rl&&r
000
MC/DC50%1/2
scalar @_last_return == 0 and $self->{"settings"}{"autoeval"}
scalar @_last_return == 0 $self->{"settings"}{"autoeval"}
MC/DC0%0/2
scalar @_last_return == 0 and $self->{"settings"}{"autoeval"}
scalar @_last_return == 0 $self->{"settings"}{"autoeval"}
Truth table66%2/3
A and B
A= scalar @_last_return == 0B= $self->{"settings"}{"autoeval"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= scalar @_last_return == 0B= $self->{"settings"}{"autoeval"}
ABresult
0X0
100
111
115 0 return Devel::Trepan::Complete::complete_subs($stripped_line);
116 }
117  
118 0 return @_last_return;
119 }
120  
121 sub next_complete($$$$$)
122 20 ▶{
Subroutine next_complete: called CC=18 SCAR=46.5
Pod undocumented
123 0 ▶ my($self, $str, $next_blank_pos, $cmd, $last_token) = @_;
Subroutine next_complete: not called CC=18 SCAR=46.5
Pod undocumented
124  
125 0 my $token;
126 0 ($next_blank_pos, $token) =
127 Devel::Trepan::Complete::next_token($str, $next_blank_pos);
128 0 ▶ return () if !$token && !$last_token;
Branch: 2 branches
BranchTrueFalseTotal
unless $token or $last_token 0 20 20
unless $token or $last_token 0 0 0
Condition33%2/6
$token or $last_token
l!l&&r!l&&!r
1730
$token or $last_token
l!l&&r!l&&!r
000
MC/DC0%0/2
$token or $last_token
$token $last_token
MC/DC0%0/2
$token or $last_token
$token $last_token
Truth table66%2/3
A or B
A= $tokenB= $last_token
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $tokenB= $last_token
ABresult
1X1
011
000
129 0 ▶ return () unless defined($cmd);
Branch: 2 branches
BranchTrueFalseTotal
unless defined $cmd 0 20 20
unless defined $cmd 0 0 0
130 0 ▶ return @{$cmd} if ref($cmd) eq 'ARRAY';
Branch: 2 branches
BranchTrueFalseTotal
if ref $cmd eq "ARRAY" 0 20 20
if ref $cmd eq "ARRAY" 0 0 0
131 0 ▶ return $cmd->($token) if (ref($cmd) eq 'CODE');
Branch: 2 branches
BranchTrueFalseTotal
if ref $cmd eq "CODE" 1 19 20
if ref $cmd eq "CODE" 0 0 0
132  
133 0 ▶ if ($cmd->can("complete_token_with_next")) {
Branch: 4 branches
BranchTrueFalseTotal
if ($cmd->can('complete_token_with_next')) { } 15 4 19
elsif ($cmd->can('complete')) { } 4 0 4
if ($cmd->can('complete_token_with_next')) { } 0 0 0
elsif ($cmd->can('complete')) { } 0 0 0
134 0 my @match_pairs = $cmd->complete_token_with_next($token);
135 0 ▶ return () unless scalar @match_pairs;
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @match_pairs 0 15 15
unless scalar @match_pairs 0 0 0
136 0 ▶ if ($next_blank_pos >= length($str)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($next_blank_pos >= length $str) { } 9 6 15
if ($next_blank_pos >= length $str) { } 0 0 0
137 0 return map {$_->[0]} @match_pairs;
138 } else {
139 0 ▶ if (scalar @match_pairs == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @match_pairs == 1) { } 6 0 6
if (scalar @match_pairs == 1) { } 0 0 0
140 0 ▶ if ($next_blank_pos == length($str)-1
Branch: 4 branches
BranchTrueFalseTotal
if ($next_blank_pos == length($str) - 1 and ' ' ne substr($str, length($str) - 1)) { } 0 6 6
elsif ($match_pairs[0][0] eq $token) { } 6 0 6
if ($next_blank_pos == length($str) - 1 and ' ' ne substr($str, length($str) - 1)) { } 0 0 0
elsif ($match_pairs[0][0] eq $token) { } 0 0 0
Condition33%2/6
$next_blank_pos == length($str) - 1 and " " ne substr($str, length($str) - 1)
!ll&&!rl&&r
510
$next_blank_pos == length($str) - 1 and " " ne substr($str, length($str) - 1)
!ll&&!rl&&r
000
MC/DC0%0/2
$next_blank_pos == length($str) - 1 and " " ne substr($str, length($str) - 1)
$next_blank_pos == length($str) - 1 " " ne substr($str, length($str) - 1)
MC/DC0%0/2
$next_blank_pos == length($str) - 1 and " " ne substr($str, length($str) - 1)
$next_blank_pos == length($str) - 1 " " ne substr($str, length($str) - 1)
Truth table66%2/3
A and B
A= $next_blank_pos == length($str) - 1B= " " ne substr($str, length($str) - 1)
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $next_blank_pos == length($str) - 1B= " " ne substr($str, length($str) - 1)
ABresult
0X0
100
111
141 && ' ' ne substr($str, length($str)-1)) {
142 0 return map {$_->[0]} @match_pairs;
143 } elsif ($match_pairs[0]->[0] eq $token) {
144 0 return $self->next_complete($str, $next_blank_pos,
145 $match_pairs[0]->[1],
146 $token);
147 } else {
148 0 return ();
149 }
150 } else {
151 # FIXME: figure out what to do here.
152 # Matched multiple items in the middle of the string
153 # We can't handle this so do nothing.
154 0 return ();
155 }
156 }
157 } elsif ($cmd->can('complete')) {
158 0 my @matches = $cmd->complete($token);
159 0 ▶ return () unless scalar @matches;
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @matches 0 4 4
unless scalar @matches 0 0 0
160 0 ▶ if (substr($str, $next_blank_pos) =~ /\s*$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($str, $next_blank_pos) =~ /\s*$/) { } 4 0 4
if (substr($str, $next_blank_pos) =~ /\s*$/) { } 0 0 0
161 0 ▶ if (1 == scalar(@matches) && $matches[0] eq $token) {
Branch: 2 branches
BranchTrueFalseTotal
if (1 == scalar @matches and $matches[0] eq $token) { } 2 2 4
if (1 == scalar @matches and $matches[0] eq $token) { } 0 0 0
Condition50%3/6
1 == scalar @matches and $matches[0] eq $token
!ll&&!rl&&r
112
1 == scalar @matches and $matches[0] eq $token
!ll&&!rl&&r
000
MC/DC100%2/2
1 == scalar @matches and $matches[0] eq $token
1 == scalar @matches $matches[0] eq $token
MC/DC0%0/2
1 == scalar @matches and $matches[0] eq $token
1 == scalar @matches $matches[0] eq $token
Truth table100%3/3
A and B
A= 1 == scalar @matchesB= $matches[0] eq $token
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= 1 == scalar @matchesB= $matches[0] eq $token
ABresult
0X0
100
111
162 # Nothing more to complete.
163 0 return ();
164 } else {
165 0 return @matches;
166 }
167 } else {
168 # FIXME: figure out what to do here.
169 # Matched multiple items in the middle of the string
170 # We can't handle this so do nothing.
171 0 return ();
172 }
173 } else {
174 0 return ();
175 }
176 }
177  
178 0 ▶sub filename_complete($$) {
Subroutine filename_complete: not called CC=1 SCAR=6.9
Pod undocumented
179 0 ▶ my ($self, $prefix) = @_;
Subroutine filename_complete: not called CC=1 SCAR=6.9
Pod undocumented
180 0 $self->{interfaces}[-1]->rl_filename_list($prefix);
181 }
182  
183 12 ▶unless (caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 12 12
184 0 require Devel::Trepan::CmdProcessor;
185 0 my $cmdproc = Devel::Trepan::CmdProcessor->new;
186 # $cmdproc->run_cmd(['list', 5]); # Invalid - nonstring arg
187 0 printf "complete('s') => %s\n", join(', ', $cmdproc->complete("s", 's', 0, 1));
188 0 printf "complete('') => %s\n", join(', ', $cmdproc->complete("", '', 0, 1));
189 0 printf "complete('help se') => %s\n", join(', ', $cmdproc->complete("help se", 'help se', 0, 1));
190  
191 eval {
192 0 ▶ sub complete_it($$) {
Subroutine complete_it: not called CC=1 SCAR=6.9
Pod undocumented
193 0 ▶ my ($cmdproc, $str) = @_;
Subroutine complete_it: not called CC=1 SCAR=6.9
Pod undocumented
194 0 my @c = $cmdproc->complete($str, $str, 0, length($str));
195 0 printf "complete('$str') => %s\n", join(', ', @c);
196 0 return @c;
197 }
198 0 };
199  
200 0 my @c = complete_it($cmdproc, "set ");
201 0 @c = complete_it($cmdproc, "help set base");
202 0 @c = complete_it($cmdproc, "set basename on ");
203 0 my $str = './';
204 0 @c = $cmdproc->filename_complete($str);
205 0 printf "complete('$str') => %s\n", join(', ', @c);
206 }
207  
208 12 1;
« lib/Devel/Trepan/CmdProcessor/Command/Help.pm ↑ Summary lib/Devel/Trepan/Client.pm »