lib/Devel/Trepan/CmdProcessor/Command/Complete.pm

filter: Statementstmt 53.6% 103 / 192 Branchbran 25.0% 11 / 44 Conditioncond 16.6% 2 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 89.6% 26 / 29 Podpod 0.0% 0 / 5 totaltotal 49.3% 142 / 288 CC 43 SCAR 44.1
CC
43
Cov
47%
run
130.9
run
130.9
run
130.9
CRAP 82.2
« lib/Devel/Trepan/Client.pm ↑ Summary lib/Devel/Trepan/DB/LineCache.pm »
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2014 Rocky Bernstein <rocky@cpan.org>
3 12 ▶use warnings; no warnings 'redefine'; use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 12 ▶use rlib '../../../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 package Devel::Trepan::CmdProcessor::Command::Complete;
8  
9 12 ▶use Getopt::Long qw(GetOptionsFromArray);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
10 use Devel::Trepan::Complete
11 12 ▶ qw(complete_packages complete_subs complete_builtins);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 12 ▶use if !@ISA, Devel::Trepan::CmdProcessor::Command ;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶unless (@ISA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ISA) 1 1 2
16 12 ▶ eval <<'EOE';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
17 use constant CATEGORY => 'support';
18 use constant SHORT_HELP => 'List the completions for the rest of the line as a command';
19 use constant MAX_ARGS => undef; # Need at most this many -
20 # undef -> unlimited
21 use constant NEED_STACK => 0;
22 EOE
23 }
24  
25 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
26 12 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 @ISA = @CMD_ISA;
28 12 ▶use vars @CMD_VARS; # Value inherited from parent
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 2 our $NAME = set_name();
31 2 our $HELP = <<"HELP";
32 =pod
33  
34 B<complete> [I<options>] I<prefix>
35  
36 options:
37  
38 -b | --builtins
39 -f | --files
40 -p | --packages
41 -s | --subs
42  
43  
44 List the command completions of I<prefix>.
45  
46 =head2 Examples:
47  
48 complete se # => set server
49 complete -p Tie::H # => Tie::Hash (probably)
50 complete -s Tie::Hash::n
51 # => Tie::Hash::new
52  
53 =cut
54 HELP
55  
56 2 my $DEFAULT_OPTIONS = {
57 lexicals => 0,
58 files => 0,
59 'my' => 0,
60 'our' => 0,
61 packages => 0,
62 subs => 0,
63 };
64  
65 sub parse_options($$)
66 0 ▶{
Subroutine parse_options: not called CC=1 SCAR=0.7
Subroutine parse_options: called CC=1 SCAR=0.7
Pod undocumented
Pod undocumented
67 0 ▶ my ($self, $args) = @_;
Subroutine parse_options: not called CC=1 SCAR=0.7
Pod undocumented
68 0 my %opts = %$DEFAULT_OPTIONS;
69 my $result = &GetOptionsFromArray
70 ($args,
71 '-b' => \$opts{builtins},
72 '--builtins' => \$opts{builtins},
73 '-f' => \$opts{files},
74 '--files' => \$opts{files},
75 '-p' => \$opts{packages},
76 '--packages' => \$opts{packages},
77 '-s' => \$opts{subs},
78 '--subs' => \$opts{subs}
79 0 );
80  
81 0 \%opts;
82  
83 }
84  
85 # This method runs the command
86 0 ▶sub run($$) {
Subroutine run: not called CC=15 SCAR=48.7
Subroutine run: called CC=15 SCAR=48.7
Pod undocumented
Pod undocumented
87 0 my ($self, $args) = @_;
88 0 my @args = @{$args}; shift @args; # remove "complete".
89 0 my $opts = parse_options($self, \@args);
90  
91 0 my $proc = $self->{proc};
92  
93 0 ▶ if ($opts->{files}) {
Branch: 6 branches
BranchTrueFalseTotal
if ($opts->{'files'}) { } 0 0 0
elsif ($opts->{'builtins'} or $opts->{'packages'} or $opts->{'subs'}) { } 0 0 0
if ($opts->{'files'}) { } 10 7 17
elsif ($opts->{'builtins'} or $opts->{'packages'} or $opts->{'subs'}) { } 0 17 17
if ($opts->{'files'}) { } 0 1 1
elsif ($opts->{'builtins'} or $opts->{'packages'} or $opts->{'subs'}) { } 0 1 1
94 0 ▶ if (scalar @args != 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @args != 1) 0 0 0
if (scalar @args != 1) 0 0 0
95 0 $proc->errmsg('Expecting only a single argument after options');
96 0 return;
97 }
98 0 foreach my $file ($proc->filename_complete($args[0])) {
99 0 $proc->msg($file);
100 }
101 ▶ } elsif ($opts->{builtins}||$opts->{packages}||$opts->{subs}) {
Condition16%2/12
$opts->{"builtins"} or $opts->{"packages"} or $opts->{"subs"}
l!l&&r!l&&!r
000
$opts->{"builtins"} or $opts->{"packages"}
l!l&&r!l&&!r
000
$opts->{"builtins"} or $opts->{"packages"} or $opts->{"subs"}
l!l&&r!l&&!r
007
$opts->{"builtins"} or $opts->{"packages"}
l!l&&r!l&&!r
007
MC/DC0%0/3
$opts->{"builtins"} or $opts->{"packages"} or $opts->{"subs"}
$opts->{"builtins"} $opts->{"packages"} $opts->{"subs"}
MC/DC0%0/3
$opts->{"builtins"} or $opts->{"packages"} or $opts->{"subs"}
$opts->{"builtins"} $opts->{"packages"} $opts->{"subs"}
Truth table0%0/4
A or B or C
A= $opts->{"builtins"}B= $opts->{"packages"}C= $opts->{"subs"}
ABCresult
1XX1
01X1
0011
0000
Truth table25%1/4
A or B or C
A= $opts->{"builtins"}B= $opts->{"packages"}C= $opts->{"subs"}
ABCresult
1XX1
01X1
0011
0000
102 0 ▶ if (scalar @args != 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @args != 1) 0 0 0
if (scalar @args != 1) 0 0 0
103 0 $proc->errmsg('Expecting only a single argument after options');
104 0 return;
105 }
106 0 my $prefix = $args[0];
107 0 my @matches = ();
108 0 ▶ push @matches, complete_builtins($prefix) if ($opts->{builtins});
Branch: 2 branches
BranchTrueFalseTotal
if $opts->{"builtins"} 0 0 0
if $opts->{"builtins"} 0 0 0
109 0 ▶ push @matches, complete_packages($prefix) if ($opts->{packages});
Branch: 2 branches
BranchTrueFalseTotal
if $opts->{"packages"} 0 0 0
if $opts->{"packages"} 0 0 0
110 0 ▶ push @matches, complete_subs($prefix) if ($opts->{subs});
Branch: 2 branches
BranchTrueFalseTotal
if $opts->{"subs"} 0 0 0
if $opts->{"subs"} 0 0 0
111 0 for my $match (@matches) {
112 0 $proc->msg($match);
113 }
114 } else {
115 0 my $cmd_argstr = $proc->{cmd_argstr};
116 0 ▶ my $last_arg = (' ' eq substr($cmd_argstr, -1)) ? '' : $args[-1];
Branch: 2 branches
BranchTrueFalseTotal
' ' eq substr($cmd_argstr, -1) ? : 0 0 0
' ' eq substr($cmd_argstr, -1) ? : 1 6 7
117 0 ▶ $last_arg = '' unless defined $last_arg;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $last_arg 0 0 0
unless defined $last_arg 0 7 7
118 0 for my $match ($proc->complete($cmd_argstr, $cmd_argstr,
119 0, length($cmd_argstr))) {
120 0 $proc->msg($match);
121 }
122 }
123 }
124  
125 2 ▶unless (caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 2 2
126 0 require Devel::Trepan::CmdProcessor;
127 0 my $proc = Devel::Trepan::CmdProcessor->new;
128 0 my $cmd = __PACKAGE__->new($proc);
129 0 for my $prefix (qw(d b bt)) {
130 0 $cmd->{proc}{cmd_argstr} = $prefix;
131 0 $cmd->run([$cmd->name, $prefix]);
132 0 print '=' x 40, "\n";
133 }
134 0 for my $prefix ('set a') {
135 0 $cmd->{proc}{cmd_argstr} = $prefix;
136 0 $cmd->run([$cmd->name, $prefix]);
137 0 print '=' x 40, "\n";
138 }
139 0 for my $prefix ('help syntax c') {
140 0 $cmd->{proc}{cmd_argstr} = $prefix;
141 0 $cmd->run([$cmd->name, $prefix]);
142 0 print '=' x 40, "\n";
143 }
144  
145 0 %DB::sub = (__PACKAGE__ . '::run', 1);
146 0 for my $tuple (['-b', 'call'], ['-p', __PACKAGE__],
147 ['-s', __PACKAGE__ . '::r']) {
148 0 my ($opt, $prefix) = @$tuple;
149 0 $cmd->{proc}{cmd_argstr} = $prefix;
150 0 $cmd->run([$cmd->name, $opt, $prefix]);
151 0 print '=' x 40, "\n";
152 }
153 # $cmd->run([$cmd->name, 'fdafsasfda']);
154 }
155  
156 2 1;
« lib/Devel/Trepan/Client.pm ↑ Summary lib/Devel/Trepan/DB/LineCache.pm »