line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Goo::Thing::pm::Perl5Editor; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# Nigel Hamilton |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2005 |
7
|
|
|
|
|
|
|
# All Rights Reserved |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
10
|
|
|
|
|
|
|
# Filename: Goo::Thing::pm::Perl5Editor.pm |
11
|
|
|
|
|
|
|
# Description: Edit a program interactively as fast as possible |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Date Change |
14
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
15
|
|
|
|
|
|
|
# 15/02/2005 Auto generated file |
16
|
|
|
|
|
|
|
# 15/02/2005 Wanted to boost my code-cutting productivity and accuracy |
17
|
|
|
|
|
|
|
# Other things to add - renaming methods automatically changes |
18
|
|
|
|
|
|
|
# tests and 'link backs' from other modules |
19
|
|
|
|
|
|
|
# 16/02/2005 Added deleteMethod method - this is a bit of a mind bend! |
20
|
|
|
|
|
|
|
# 05/05/2005 Added a TypeLessTranslator to make typing quicker - think |
21
|
|
|
|
|
|
|
# phone txt 4 code! The idea is write shrt read looonger. |
22
|
|
|
|
|
|
|
# 01/07/2005 Integrated new model of "Things" |
23
|
|
|
|
|
|
|
# 01/08/2005 New command-based system caused massive refactoring of this |
24
|
|
|
|
|
|
|
# module. It used a whopping 16 other modules - crazy! |
25
|
|
|
|
|
|
|
# 07/08/2005 Want to add ThereDocs back into the mix |
26
|
|
|
|
|
|
|
# 17/08/2005 Added method: doTypeLessTranslation |
27
|
|
|
|
|
|
|
# 17/08/2005 Added method: doThereDoc |
28
|
|
|
|
|
|
|
# 02/11/2005 Now returns to the location of the original ThereDoc |
29
|
|
|
|
|
|
|
# Handles all actions a Thing can do: e > > p > > l > > |
30
|
|
|
|
|
|
|
# 03/11/2005 Preparing for CPAN alpha release |
31
|
|
|
|
|
|
|
# |
32
|
|
|
|
|
|
|
############################################################################### |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
1
|
|
6243
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
1
|
|
7
|
use Data::Dumper; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# top level utility functions |
39
|
1
|
|
|
1
|
|
6
|
use Goo::Differ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
40
|
1
|
|
|
1
|
|
5
|
use Goo::Object; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
41
|
1
|
|
|
1
|
|
5
|
use Goo::Prompter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
42
|
1
|
|
|
1
|
|
6
|
use Goo::TextEditor; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
43
|
1
|
|
|
1
|
|
5
|
use Goo::FileUtilities; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# thing specific modules |
46
|
1
|
|
|
1
|
|
6
|
use Goo::Thing::pm::ExecDocManager; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
47
|
1
|
|
|
1
|
|
5
|
use Goo::Thing::pm::PerlTidyManager; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
48
|
1
|
|
|
1
|
|
6
|
use Goo::Thing::pm::TypeLessTranslator; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
49
|
1
|
|
|
1
|
|
4
|
use Goo::Thing::pm::Perl5ThereDocManager; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
1
|
|
5
|
use base qw(Goo::Object); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
242
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
############################################################################### |
55
|
|
|
|
|
|
|
# |
56
|
|
|
|
|
|
|
# run - edit a program |
57
|
|
|
|
|
|
|
# |
58
|
|
|
|
|
|
|
############################################################################### |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub run { |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
0
|
1
|
|
my ($this, $thing, $line_number) = @_; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# continuously edit if they use ThereDocs |
65
|
0
|
|
|
|
|
|
while (1) { |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#my @old_file = FileUtilities::getFileAsLines($thing->get_full_path()); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# clear the page |
70
|
0
|
|
|
|
|
|
Goo::Prompter::clear(); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# can we write to this Thing? |
73
|
0
|
0
|
|
|
|
|
unless (-W $thing->get_full_path()) { |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# just view the file then |
76
|
0
|
|
|
|
|
|
Goo::TextEditor::view($thing->get_full_path(), $line_number); |
77
|
0
|
|
|
|
|
|
last; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# edit the file |
82
|
0
|
|
|
|
|
|
Goo::TextEditor::edit($thing->get_full_path(), $line_number); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# process any ThereDocs |
85
|
0
|
|
|
|
|
|
my ($theredoc_line_number, $target_thing, $target_action, $target_line_number) = |
86
|
|
|
|
|
|
|
Goo::Thing::pm::Perl5ThereDocManager->new()->process($thing); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# jump out - no other action to take |
89
|
0
|
0
|
|
|
|
|
unless ($target_thing) { |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# ok ... let's tidy this up |
92
|
|
|
|
|
|
|
# this does mean some modules may not be tidied |
93
|
|
|
|
|
|
|
# if a user exited at a different location |
94
|
0
|
|
|
|
|
|
Goo::Thing::pm::PerlTidyManager::process($thing->get_full_path()); |
95
|
0
|
|
|
|
|
|
last; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
$target_thing->do_action($target_action, $target_line_number); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# return to the editor from where we came >> |
101
|
0
|
|
|
|
|
|
$line_number = $theredoc_line_number; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# does it contain any "execdocs"? |
107
|
|
|
|
|
|
|
# ExecDocManager::process($thing); |
108
|
|
|
|
|
|
|
#my @new_file = FileUtilities::getFileAsLines($thing->get_full_path()); |
109
|
|
|
|
|
|
|
#my $diff = Differ->new(); |
110
|
|
|
|
|
|
|
# take the diff |
111
|
|
|
|
|
|
|
#$diff->diff(\@old_file, \@new_file); |
112
|
|
|
|
|
|
|
# check for TypeLessTranslation |
113
|
|
|
|
|
|
|
#foreach my $line_number ($diff->get_line_numbers()) { |
114
|
|
|
|
|
|
|
# change array in place |
115
|
|
|
|
|
|
|
# $new_file[ $line_number - 1 ] = |
116
|
|
|
|
|
|
|
# TypeLessTranslator::translateLine($diff->get_line($line_number)); |
117
|
|
|
|
|
|
|
# |
118
|
|
|
|
|
|
|
#} |
119
|
|
|
|
|
|
|
# save the file |
120
|
|
|
|
|
|
|
#FileUtilities::writeLinesAsFile($thing->get_full_path(), @new_file); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 NAME |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Goo::Thing::pm::Perl5Editor - Edit a Perl5 Program using your favourite editor (e.g., vi, vim, |
133
|
|
|
|
|
|
|
nano) |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 SYNOPSIS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
use Goo::Thing::pm::Perl5Editor; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 DESCRIPTION |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 METHODS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=over |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item run |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Edit a Perl5 program by calling an external editor then process any embedded ThereDocs and |
149
|
|
|
|
|
|
|
apply PerlTidy to format the code. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=back |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 AUTHOR |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 SEE ALSO |
158
|
|
|
|
|
|
|
|