blib/lib/CPAN/Complete.pm

filter: Statementstmt 8.6% 13 / 151 Branchbran 0.0% 0 / 116 Conditioncond 0.0% 0 / 48 MC/DCmcdc 0.0% 0 / 28 Subroutinesub 20.0% 3 / 15 Podpod 0.0% 0 / 12 totaltotal 4.3% 16 / 370 CC 79 SCAR 54.6
CC
79
Cov
4%
cpl
462.0
cpl
462.0
cpl_option
90.0
CRAP 235.6
« blib/lib/CPAN/HandleConfig.pm ↑ Summary blib/lib/CPAN/Author.pm »
1 # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
2 # vim: ts=4 sts=4 sw=4:
3 package CPAN::Complete;
4 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 26 @CPAN::Complete::ISA = qw(CPAN::Debug);
6 # Q: where is the "How do I add a new command" HOWTO?
7 # A: git log -p -1 355c44e9caaec857e4b12f51afb96498833c3e36 where andk added the report command
8 26 @CPAN::Complete::COMMANDS = sort qw(
9 ? ! a b d h i m o q r u
10 autobundle
11 bye
12 clean
13 cvs_import
14 dump
15 exit
16 failed
17 force
18 fforce
19 hosts
20 install
21 install_tested
22 is_tested
23 look
24 ls
25 make
26 mkmyconfig
27 notest
28 perldoc
29 quit
30 readme
31 recent
32 recompile
33 reload
34 report
35 reports
36 scripts
37 smoke
38 test
39 upgrade
40 );
41  
42 26 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
43 $VERSION
44 26 );
45 26 $VERSION = "5.5001";
46  
47 package CPAN::Complete;
48 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 0 ▶sub gnu_cpl {
Subroutine gnu_cpl: not called CC=5 SCAR=34.0
Pod undocumented
51 0 ▶ my($text, $line, $start, $end) = @_;
Subroutine gnu_cpl: not called CC=5 SCAR=34.0
Pod undocumented
52 0 my(@perlret) = cpl($text, $line, $start);
53 # find longest common match. Can anybody show me how to peruse
54 # T::R::Gnu to have this done automatically? Seems expensive.
55 0 ▶ return () unless @perlret;
Branch: 2 branches
BranchTrueFalseTotal
unless @perlret 0 0 0
unless @perlret 0 0 0
56 0 my($newtext) = $text;
57 0 for (my $i = length($text)+1;;$i++) {
58 0 ▶ last unless length($perlret[0]) && length($perlret[0]) >= $i;
Branch: 2 branches
BranchTrueFalseTotal
unless length $perlret[0] and length $perlret[0] >= $i 0 0 0
unless length $perlret[0] and length $perlret[0] >= $i 0 0 0
Condition0%0/6
length $perlret[0] and length $perlret[0] >= $i
!ll&&!rl&&r
000
length $perlret[0] and length $perlret[0] >= $i
!ll&&!rl&&r
000
MC/DC0%0/2
length $perlret[0] and length $perlret[0] >= $i
length $perlret[0] length $perlret[0] >= $i
MC/DC0%0/2
length $perlret[0] and length $perlret[0] >= $i
length $perlret[0] length $perlret[0] >= $i
Truth table0%0/3
A and B
A= length $perlret[0]B= length $perlret[0] >= $i
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= length $perlret[0]B= length $perlret[0] >= $i
ABresult
0X0
100
111
59 0 my $try = substr($perlret[0],0,$i);
60 0 my @tries = grep {substr($_,0,$i) eq $try} @perlret;
61 # warn "try[$try]tries[@tries]";
62 0 ▶ if (@tries == @perlret) {
Branch: 2 branches
BranchTrueFalseTotal
if (@tries == @perlret) { } 0 0 0
if (@tries == @perlret) { } 0 0 0
63 0 $newtext = $try;
64 } else {
65 0 last;
66 }
67 }
68 0 ($newtext,@perlret);
69 }
70  
71 #-> sub CPAN::Complete::cpl ;
72 0 ▶sub cpl {
Subroutine cpl: not called CC=21 SCAR=61.4
Pod undocumented
73 0 ▶ my($word,$line,$pos) = @_;
Subroutine cpl: not called CC=21 SCAR=61.4
Pod undocumented
74 0 ▶ $word ||= "";
Condition0%0/4
$word ||= ""
l!l
00
$word ||= ""
l!l
00
MC/DC0%0/1
$word ||= ""
$word
MC/DC0%0/1
$word ||= ""
$word
Truth table0%0/2
A
A= $word
Aresult
11
00
Truth table0%0/2
A
A= $word
Aresult
11
00
75 0 ▶ $line ||= "";
Condition0%0/4
$line ||= ""
l!l
00
$line ||= ""
l!l
00
MC/DC0%0/1
$line ||= ""
$line
MC/DC0%0/1
$line ||= ""
$line
Truth table0%0/2
A
A= $line
Aresult
11
00
Truth table0%0/2
A
A= $line
Aresult
11
00
76 0 ▶ $pos ||= 0;
Condition0%0/4
$pos ||= 0
l!l
00
$pos ||= 0
l!l
00
MC/DC0%0/1
$pos ||= 0
$pos
MC/DC0%0/1
$pos ||= 0
$pos
Truth table0%0/2
A
A= $pos
Aresult
11
00
Truth table0%0/2
A
A= $pos
Aresult
11
00
77 0 ▶ CPAN->debug("word [$word] line[$line] pos[$pos]") if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
if $CPAN::DEBUG 0 0 0
78 0 $line =~ s/^\s*//;
79 0 ▶ if ($line =~ s/^((?:notest|f?force)\s*)//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ s/^((?:notest|f?force)\s*)//) 0 0 0
if ($line =~ s/^((?:notest|f?force)\s*)//) 0 0 0
80 0 $pos -= length($1);
81 }
82 0 my @return;
83 0 ▶ if ($pos == 0 || $line =~ /^(?:h(?:elp)?|\?)\s/) {
Branch: 22 branches
BranchTrueFalseTotal
if ($pos == 0 or $line =~ /^(?:h(?:elp)?|\?)\s/) { } 0 0 0
elsif (not $line =~ /^[\!abcdghimorutl]/) { } 0 0 0
elsif ($line =~ /^a\s/) { } 0 0 0
elsif ($line =~ /^ls\s/) { } 0 0 0
elsif ($line =~ /^b\s/) { } 0 0 0
elsif ($line =~ /^d\s/) { } 0 0 0
elsif ($line =~ /^( [mru]|make|clean|dump|get|test|install|readme|look|cvs_import|perldoc|recent )\s/x) { } 0 0 0
elsif ($line =~ /^i\s/) { } 0 0 0
elsif ($line =~ /^reload\s/) { } 0 0 0
elsif ($line =~ /^o\s/) { } 0 0 0
elsif ($line =~ /^\S+\s/) { } 0 0 0
if ($pos == 0 or $line =~ /^(?:h(?:elp)?|\?)\s/) { } 0 0 0
elsif (not $line =~ /^[\!abcdghimorutl]/) { } 0 0 0
elsif ($line =~ /^a\s/) { } 0 0 0
elsif ($line =~ /^ls\s/) { } 0 0 0
elsif ($line =~ /^b\s/) { } 0 0 0
elsif ($line =~ /^d\s/) { } 0 0 0
elsif ($line =~ /^( [mru]|make|clean|dump|get|test|install|readme|look|cvs_import|perldoc|recent )\s/x) { } 0 0 0
elsif ($line =~ /^i\s/) { } 0 0 0
elsif ($line =~ /^reload\s/) { } 0 0 0
elsif ($line =~ /^o\s/) { } 0 0 0
elsif ($line =~ /^\S+\s/) { } 0 0 0
Condition0%0/6
$pos == 0 or $line =~ /^(?:h(?:elp)?|\?)\s/
l!l&&r!l&&!r
000
$pos == 0 or $line =~ /^(?:h(?:elp)?|\?)\s/
l!l&&r!l&&!r
000
MC/DC0%0/2
$pos == 0 or $line =~ /^(?:h(?:elp)?|\?)\s/
$pos == 0 $line =~ /^(?:h(?:elp)?|\?)\s/
MC/DC0%0/2
$pos == 0 or $line =~ /^(?:h(?:elp)?|\?)\s/
$pos == 0 $line =~ /^(?:h(?:elp)?|\?)\s/
Truth table0%0/3
A or B
A= $pos == 0B= $line =~ /^(?:h(?:elp)?|\?)\s/
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $pos == 0B= $line =~ /^(?:h(?:elp)?|\?)\s/
ABresult
1X1
011
000
84 0 @return = grep /^\Q$word\E/, @CPAN::Complete::COMMANDS;
85 } elsif ( $line !~ /^[\!abcdghimorutl]/ ) {
86 0 @return = ();
87 } elsif ($line =~ /^a\s/) {
88 0 @return = cplx('CPAN::Author',uc($word));
89 } elsif ($line =~ /^ls\s/) {
90 0 my($author,$rest) = $word =~ m|([^/]+)/?(.*)|;
91 0 ▶ @return = $rest ? () : map {"$_/"} cplx('CPAN::Author',uc($author||""));
Branch: 2 branches
BranchTrueFalseTotal
$rest ? : 0 0 0
$rest ? : 0 0 0
Condition0%0/4
$author || ''
l!l
00
$author || ''
l!l
00
MC/DC0%0/1
$author || ''
$author
MC/DC0%0/1
$author || ''
$author
Truth table0%0/2
A
A= $author
Aresult
11
00
Truth table0%0/2
A
A= $author
Aresult
11
00
92 0 if (0 && 1==@return) { # XXX too slow and even wrong when there is a * already
93 @return = grep /^\Q$word\E/, map {"$author/$_->[2]"} CPAN::Shell->expand("Author",$author)->ls("$rest*","2");
94 }
95 } elsif ($line =~ /^b\s/) {
96 0 CPAN::Shell->local_bundles;
97 0 @return = cplx('CPAN::Bundle',$word);
98 } elsif ($line =~ /^d\s/) {
99 0 @return = cplx('CPAN::Distribution',$word);
100 } elsif ($line =~ m/^(
101 [mru]|make|clean|dump|get|test|install|readme|look|cvs_import|perldoc|recent
102 )\s/x ) {
103 0 ▶ if ($word =~ /^Bundle::/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($word =~ /^Bundle::/) 0 0 0
if ($word =~ /^Bundle::/) 0 0 0
104 0 CPAN::Shell->local_bundles;
105 }
106 0 @return = (cplx('CPAN::Module',$word),cplx('CPAN::Bundle',$word));
107 } elsif ($line =~ /^i\s/) {
108 0 @return = cpl_any($word);
109 } elsif ($line =~ /^reload\s/) {
110 0 @return = cpl_reload($word,$line,$pos);
111 } elsif ($line =~ /^o\s/) {
112 0 @return = cpl_option($word,$line,$pos);
113 } elsif ($line =~ m/^\S+\s/ ) {
114 # fallback for future commands and what we have forgotten above
115 0 @return = (cplx('CPAN::Module',$word),cplx('CPAN::Bundle',$word));
116 } else {
117 0 @return = ();
118 }
119 0 return @return;
120 }
121  
122 #-> sub CPAN::Complete::cplx ;
123 0 ▶sub cplx {
Subroutine cplx: not called CC=3 SCAR=24.8
Pod undocumented
124 0 ▶ my($class, $word) = @_;
Subroutine cplx: not called CC=3 SCAR=24.8
Pod undocumented
125 0 ▶ if (CPAN::_sqlite_running()) {
Branch: 2 branches
BranchTrueFalseTotal
if (CPAN::_sqlite_running()) 0 0 0
if (CPAN::_sqlite_running()) 0 0 0
126 0 $CPAN::SQLite->search($class, "^\Q$word\E");
127 }
128 0 my $method = "id";
129 0 ▶ $method = "pretty_id" if $class eq "CPAN::Distribution";
Branch: 2 branches
BranchTrueFalseTotal
if $class eq "CPAN::Distribution" 0 0 0
if $class eq "CPAN::Distribution" 0 0 0
130 0 sort grep /^\Q$word\E/, map { $_->$method() } $CPAN::META->all_objects($class);
131 }
132  
133 #-> sub CPAN::Complete::cpl_any ;
134 0 ▶sub cpl_any {
Subroutine cpl_any: not called CC=1 SCAR=6.9
Pod undocumented
135 0 ▶ my($word) = shift;
Subroutine cpl_any: not called CC=1 SCAR=6.9
Pod undocumented
136 return (
137 0 cplx('CPAN::Author',$word),
138 cplx('CPAN::Bundle',$word),
139 cplx('CPAN::Distribution',$word),
140 cplx('CPAN::Module',$word),
141 );
142 }
143  
144 #-> sub CPAN::Complete::cpl_reload ;
145 0 ▶sub cpl_reload {
Subroutine cpl_reload: not called CC=6 SCAR=37.4
Pod undocumented
146 0 ▶ my($word,$line,$pos) = @_;
Subroutine cpl_reload: not called CC=6 SCAR=37.4
Pod undocumented
147 0 ▶ $word ||= "";
Condition0%0/4
$word ||= ""
l!l
00
$word ||= ""
l!l
00
MC/DC0%0/1
$word ||= ""
$word
MC/DC0%0/1
$word ||= ""
$word
Truth table0%0/2
A
A= $word
Aresult
11
00
Truth table0%0/2
A
A= $word
Aresult
11
00
148 0 my(@words) = split " ", $line;
149 0 ▶ CPAN->debug("word[$word] line[$line] pos[$pos]") if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
if $CPAN::DEBUG 0 0 0
150 0 my(@ok) = qw(cpan index);
151 0 ▶ return @ok if @words == 1;
Branch: 2 branches
BranchTrueFalseTotal
if @words == 1 0 0 0
if @words == 1 0 0 0
152 0 ▶ return grep /^\Q$word\E/, @ok if @words == 2 && $word;
Branch: 2 branches
BranchTrueFalseTotal
if @words == 2 and $word 0 0 0
if @words == 2 and $word 0 0 0
Condition0%0/6
@words == 2 and $word
!ll&&!rl&&r
000
@words == 2 and $word
!ll&&!rl&&r
000
MC/DC0%0/2
@words == 2 and $word
@words == 2 $word
MC/DC0%0/2
@words == 2 and $word
@words == 2 $word
Truth table0%0/3
A and B
A= @words == 2B= $word
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= @words == 2B= $word
ABresult
0X0
100
111
153 }
154  
155 #-> sub CPAN::Complete::cpl_option ;
156 0 ▶sub cpl_option {
Subroutine cpl_option: not called CC=9 SCAR=45.0
Pod undocumented
157 0 ▶ my($word,$line,$pos) = @_;
Subroutine cpl_option: not called CC=9 SCAR=45.0
Pod undocumented
158 0 ▶ $word ||= "";
Condition0%0/4
$word ||= ""
l!l
00
$word ||= ""
l!l
00
MC/DC0%0/1
$word ||= ""
$word
MC/DC0%0/1
$word ||= ""
$word
Truth table0%0/2
A
A= $word
Aresult
11
00
Truth table0%0/2
A
A= $word
Aresult
11
00
159 0 my(@words) = split " ", $line;
160 0 ▶ CPAN->debug("word[$word] line[$line] pos[$pos]") if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
if $CPAN::DEBUG 0 0 0
161 0 my(@ok) = qw(conf debug);
162 0 ▶ return @ok if @words == 1;
Branch: 2 branches
BranchTrueFalseTotal
if @words == 1 0 0 0
if @words == 1 0 0 0
163 0 ▶ return grep /^\Q$word\E/, @ok if @words == 2 && length($word);
Branch: 2 branches
BranchTrueFalseTotal
if @words == 2 and length $word 0 0 0
if @words == 2 and length $word 0 0 0
Condition0%0/6
@words == 2 and length $word
!ll&&!rl&&r
000
@words == 2 and length $word
!ll&&!rl&&r
000
MC/DC0%0/2
@words == 2 and length $word
@words == 2 length $word
MC/DC0%0/2
@words == 2 and length $word
@words == 2 length $word
Truth table0%0/3
A and B
A= @words == 2B= length $word
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= @words == 2B= length $word
ABresult
0X0
100
111
164 0 ▶ if (0) {
Branch: 6 branches
BranchTrueFalseTotal
if (do { $words[1] eq 'index' }) { } 0 0 0
elsif ($words[1] eq 'conf') { } 0 0 0
elsif ($words[1] eq 'debug') { } 0 0 0
if (do { $words[1] eq 'index' }) { } 0 0 0
elsif ($words[1] eq 'conf') { } 0 0 0
elsif ($words[1] eq 'debug') { } 0 0 0
165 } elsif ($words[1] eq 'index') {
166 0 return ();
167 } elsif ($words[1] eq 'conf') {
168 0 return CPAN::HandleConfig::cpl(@_);
169 } elsif ($words[1] eq 'debug') {
170 0 return sort grep /^\Q$word\E/i,
171 sort keys %CPAN::DEBUG, 'all';
172 }
173 }
174  
175 26 1;
« blib/lib/CPAN/HandleConfig.pm ↑ Summary blib/lib/CPAN/Author.pm »