line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (C) 2011-2012 Rocky Bernstein <rocky@cpan.org> |
2
|
12
|
|
|
12
|
|
177
|
use warnings; no warnings 'redefine'; |
|
12
|
|
|
12
|
|
31
|
|
|
12
|
|
|
1
|
|
460
|
|
|
12
|
|
|
1
|
|
70
|
|
|
12
|
|
|
|
|
31
|
|
|
12
|
|
|
|
|
483
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
3
|
12
|
|
|
12
|
|
73
|
use rlib '../../../..'; |
|
12
|
|
|
1
|
|
27
|
|
|
12
|
|
|
|
|
74
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4
|
|
4
|
|
|
|
|
|
|
|
5
|
12
|
|
|
12
|
|
4121
|
use Devel::Trepan::DB::LineCache; |
|
12
|
|
|
1
|
|
27
|
|
|
12
|
|
|
|
|
2071
|
|
|
1
|
|
|
|
|
299
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
150
|
|
6
|
12
|
|
|
12
|
|
153
|
use Devel::Trepan::DB::Sub; |
|
12
|
|
|
1
|
|
33
|
|
|
12
|
|
|
|
|
565
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Devel::Trepan::CmdProcessor::Command::Edit; |
9
|
12
|
|
|
12
|
|
69
|
use if !@ISA, Devel::Trepan::CmdProcessor::Command ; |
|
12
|
|
|
1
|
|
33
|
|
|
12
|
|
|
|
|
89
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
10
|
|
|
|
|
|
|
unless (@ISA) { |
11
|
12
|
|
|
12
|
|
85
|
eval <<"EOE"; |
|
12
|
|
|
12
|
|
40
|
|
|
12
|
|
|
12
|
|
642
|
|
|
12
|
|
|
12
|
|
68
|
|
|
12
|
|
|
12
|
|
27
|
|
|
12
|
|
|
12
|
|
522
|
|
|
12
|
|
|
|
|
67
|
|
|
12
|
|
|
|
|
29
|
|
|
12
|
|
|
|
|
481
|
|
|
12
|
|
|
|
|
76
|
|
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
540
|
|
|
12
|
|
|
|
|
63
|
|
|
12
|
|
|
|
|
29
|
|
|
12
|
|
|
|
|
479
|
|
|
12
|
|
|
|
|
71
|
|
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
400
|
|
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
|
|
|
12
|
|
1990
|
use strict; |
|
12
|
|
|
1
|
|
32
|
|
|
12
|
|
|
|
|
520
|
|
|
1
|
|
|
|
|
56
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
22
|
|
|
|
|
|
|
our @ISA = @CMD_ISA; # value inherited from parent |
23
|
12
|
|
|
12
|
|
70
|
use vars @CMD_VARS; # value inherited from parent |
|
12
|
|
|
1
|
|
34
|
|
|
12
|
|
|
|
|
4579
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
312
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $NAME = set_name(); |
26
|
|
|
|
|
|
|
=pod |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 Synopsis: |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
{ |
58
|
0
|
|
|
0
|
0
|
|
my ($self, $prefix) = @_; |
|
0
|
|
|
0
|
0
|
|
|
59
|
0
|
|
|
|
|
|
my @completions = sort ('.', DB::LineCache::file_list()); |
|
0
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
Devel::Trepan::Complete::complete_token(\@completions, $prefix); |
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# This method runs the command |
64
|
|
|
|
|
|
|
sub run($$) |
65
|
|
|
|
|
|
|
{ |
66
|
0
|
|
|
0
|
0
|
|
my ($self, $args) = @_; |
|
0
|
|
|
0
|
0
|
|
|
67
|
0
|
|
|
|
|
|
my $proc = $self->{proc}; |
|
0
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my ($filename, $line_number); |
|
0
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $count = scalar @$args; |
|
0
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if (1 == $count) { |
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
if ($proc->{terminated}) { |
|
0
|
0
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$proc->msg_need_running("implicit edit file and line"); |
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return; |
|
0
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
|
$filename = $self->{proc}->filename; |
|
0
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$line_number = $self->{proc}->line; |
|
0
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} elsif (2 == $count) { |
78
|
0
|
|
|
|
|
|
$line_number = $self->{proc}->get_int_noerr($args->[1]); |
|
0
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
if (defined $line_number) { |
|
0
|
0
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if ($proc->{terminated}) { |
|
0
|
0
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$proc->msg_need_running("implicit edit file"); |
|
0
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return; |
|
0
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
|
$filename = $self->{proc}->filename; |
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} else { |
86
|
0
|
|
|
|
|
|
$filename = $args->[1]; |
|
0
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$line_number = 1; |
|
0
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} elsif (3 == $count) { |
90
|
0
|
|
|
|
|
|
($line_number, $filename) = ($args->[2], $args->[1]); |
|
0
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} else { |
92
|
0
|
|
|
|
|
|
$self->errmsg("edit needs at most 2 args."); |
|
0
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
return; |
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
0
|
|
0
|
|
|
|
my $editor = $ENV{'EDITOR'} || '/bin/ex'; |
|
0
|
|
0
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
if ( -r $filename ) { |
|
0
|
0
|
|
|
|
|
|
97
|
12
|
|
|
12
|
|
88
|
use File::Basename; |
|
12
|
|
|
1
|
|
28
|
|
|
12
|
|
|
|
|
4104
|
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
282
|
|
98
|
0
|
0
|
|
|
|
|
$filename = basename($filename) if $self->{proc}{settings}{basename}; |
|
0
|
0
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my @edit_cmd = ($editor, "+$line_number", $filename); |
|
0
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$self->{proc}->msg(sprintf "Running: %s...", join(' ', @edit_cmd)); |
|
0
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
system(@edit_cmd); |
|
0
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
$self->{proc}->msg("Warning: return code was $?") if $? != 0; |
|
0
|
0
|
|
|
|
|
|
103
|
|
|
|
|
|
|
} else { |
104
|
0
|
|
|
|
|
|
$self->errmsg("File \"${filename}\" is not readable."); |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
unless (caller) { |
109
|
|
|
|
|
|
|
require Devel::Trepan::CmdProcessor::Mock; |
110
|
|
|
|
|
|
|
my $proc = Devel::Trepan::CmdProcessor->new(undef, 'bogus'); |
111
|
|
|
|
|
|
|
my $cmd = __PACKAGE__->new($proc); |
112
|
|
|
|
|
|
|
my $frame_ary = Devel::Trepan::CmdProcessor::Mock::create_frame(); |
113
|
|
|
|
|
|
|
$proc->frame_setup($frame_ary); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$cmd->run([$NAME]); |
116
|
|
|
|
|
|
|
$cmd->run([$NAME, '7']); |
117
|
|
|
|
|
|
|
$cmd->run([$NAME, __FILE__, '10']); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |