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

filter: Statementstmt 55.1% 85 / 154 Branchbran 10.0% 4 / 40 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 82.7% 24 / 29 Podpod 0.0% 0 / 5 totaltotal 48.2% 113 / 234 CC 31 SCAR 38.8
CC
31
Cov
45%
run
86.8
run
86.8
run
86.8
CRAP 48.3
« blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Program.pm ↑ Summary blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Frame.pm »
1 # Copyright (C) 2011-2012 Rocky Bernstein <rocky@cpan.org>
2 12 ▶use warnings; no warnings 'redefine';
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
3 12 ▶use rlib '../../../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 12 ▶use Devel::Trepan::DB::LineCache;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Devel::Trepan::DB::Sub;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package Devel::Trepan::CmdProcessor::Command::Edit;
9 12 ▶use if !@ISA, Devel::Trepan::CmdProcessor::Command ;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶unless (@ISA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ISA) 0 1 1
11 0 ▶ 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
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
12 use constant ALIASES => ('e');
13 use constant CATEGORY => 'files';
14 use constant SHORT_HELP => 'Invoke an editor on some source code';
15 use constant NEED_STACK => 0;
16 use constant MIN_ARGS => 0; # Need at least this many
17 use constant MAX_ARGS => 2; # Need at most this many - undef -> unlimited.
18 EOE
19 }
20  
21 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 our @ISA = @CMD_ISA; # value inherited from parent
23 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
24  
25 1 our $NAME = set_name();
26 =pod
27  
28 =head2 Synopsis:
29  
30 =cut
31 1 our $HELP = <<"HELP";
32 =pod
33  
34 B<edit> [[I<file>] [I<line>]]
35  
36 With no argument, edits file containing most recent line listed.
37 The value of the environment variable I<EDITOR> is used for the
38 editor to run. If no I<EDITOR> environment variable is set /bin/ex
39 is used. The editor should support line and file positioning via
40  
41 editor-name +line file-name
42  
43 (Most editors do.)
44  
45 =head2 Examples:
46  
47 edit # Edit current location
48 edit 7 # Edit current file at line 7
49 edit test.rb # Edit test.rb, line 1
50 edit test.rb 10 # Edit test.rb line 10
51 =cut
52 HELP
53  
54 # FIXME: include line numbers. Should we include all files?
55 # Combine with BREAK completion.
56 sub complete($$)
57 0 ▶{
Subroutine complete: not called CC=1 SCAR=6.9
Subroutine complete: not called CC=1 SCAR=6.9
Pod undocumented
Pod undocumented
58 0 ▶ my ($self, $prefix) = @_;
Subroutine complete: not called CC=1 SCAR=6.9
Pod undocumented
59 0 my @completions = sort ('.', DB::LineCache::file_list());
60 0 Devel::Trepan::Complete::complete_token(\@completions, $prefix);
61 }
62  
63 # This method runs the command
64 sub run($$)
65 0 ▶{
Subroutine run: not called CC=11 SCAR=44.6
Subroutine run: not called CC=11 SCAR=44.6
Pod undocumented
Pod undocumented
66 0 my ($self, $args) = @_;
67 0 my $proc = $self->{proc};
68 0 my ($filename, $line_number);
69 0 my $count = scalar @$args;
70 0 ▶ if (1 == $count) {
Branch: 6 branches
BranchTrueFalseTotal
if (1 == $count) { } 0 0 0
elsif (2 == $count) { } 0 0 0
elsif (3 == $count) { } 0 0 0
if (1 == $count) { } 11 0 11
elsif (2 == $count) { } 0 11 11
elsif (3 == $count) { } 0 0 0
71 0 ▶ if ($proc->{terminated}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($proc->{"terminated"}) 0 0 0
if ($proc->{"terminated"}) 0 0 0
72 0 $proc->msg_need_running("implicit edit file and line");
73 0 return;
74 }
75 0 $filename = $self->{proc}->filename;
76 0 $line_number = $self->{proc}->line;
77 } elsif (2 == $count) {
78 0 $line_number = $self->{proc}->get_int_noerr($args->[1]);
79 0 ▶ if (defined $line_number) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $line_number) { } 0 0 0
if (defined $line_number) { } 0 0 0
80 0 ▶ if ($proc->{terminated}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($proc->{"terminated"}) 0 0 0
if ($proc->{"terminated"}) 0 0 0
81 0 $proc->msg_need_running("implicit edit file");
82 0 return;
83 }
84 0 $filename = $self->{proc}->filename;
85 } else {
86 0 $filename = $args->[1];
87 0 $line_number = 1;
88 }
89 } elsif (3 == $count) {
90 0 ($line_number, $filename) = ($args->[2], $args->[1]);
91 } else {
92 0 $self->errmsg("edit needs at most 2 args.");
93 0 return;
94 }
95 0 ▶ my $editor = $ENV{'EDITOR'} || '/bin/ex';
Condition0%0/4
$ENV{'EDITOR'} || '/bin/ex'
l!l
00
$ENV{'EDITOR'} || '/bin/ex'
l!l
00
MC/DC0%0/1
$ENV{'EDITOR'} || '/bin/ex'
$ENV{'EDITOR'}
MC/DC0%0/1
$ENV{'EDITOR'} || '/bin/ex'
$ENV{'EDITOR'}
Truth table0%0/2
A
A= $ENV{'EDITOR'}
Aresult
11
00
Truth table0%0/2
A
A= $ENV{'EDITOR'}
Aresult
11
00
96 0 ▶ if ( -r $filename ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-r $filename) { } 0 0 0
if (-r $filename) { } 0 0 0
97 12 ▶ use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
98 0 ▶ $filename = basename($filename) if $self->{proc}{settings}{basename};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"proc"}{"settings"}{"basename"} 0 0 0
if $self->{"proc"}{"settings"}{"basename"} 0 0 0
99 0 my @edit_cmd = ($editor, "+$line_number", $filename);
100 0 $self->{proc}->msg(sprintf "Running: %s...", join(' ', @edit_cmd));
101 0 system(@edit_cmd);
102 0 ▶ $self->{proc}->msg("Warning: return code was $?") if $? != 0;
Branch: 2 branches
BranchTrueFalseTotal
if $? != 0 0 0 0
if $? != 0 0 0 0
103 } else {
104 0 $self->errmsg("File \"${filename}\" is not readable.");
105 }
106 }
107  
108 1 ▶unless (caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 1 1
109 0 require Devel::Trepan::CmdProcessor::Mock;
110 0 my $proc = Devel::Trepan::CmdProcessor->new(undef, 'bogus');
111 0 my $cmd = __PACKAGE__->new($proc);
112 0 my $frame_ary = Devel::Trepan::CmdProcessor::Mock::create_frame();
113 0 $proc->frame_setup($frame_ary);
114  
115 0 $cmd->run([$NAME]);
116 0 $cmd->run([$NAME, '7']);
117 0 $cmd->run([$NAME, __FILE__, '10']);
118 }
119  
120 1 1;
« blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Program.pm ↑ Summary blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Frame.pm »