| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Goo::PerlCoder; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
|
4
|
|
|
|
|
|
|
# Nigel Hamilton |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2005 |
|
7
|
|
|
|
|
|
|
# All Rights Reserved |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
|
10
|
|
|
|
|
|
|
# Filename: Goo::PerlCoder.pm |
|
11
|
|
|
|
|
|
|
# Description: Manipulate perl programs like a real coder. Pretend to be |
|
12
|
|
|
|
|
|
|
# a perl programmer! |
|
13
|
|
|
|
|
|
|
# |
|
14
|
|
|
|
|
|
|
# Date Change |
|
15
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
16
|
|
|
|
|
|
|
# 20/02/2005 Auto generated file |
|
17
|
|
|
|
|
|
|
# 20/02/2005 Needed to be called by ProgramEditor |
|
18
|
|
|
|
|
|
|
# 09/08/2005 Added the Add Change Log feature - works well! |
|
19
|
|
|
|
|
|
|
# 09/08/2005 This is one more change but will appear over multiple lines. |
|
20
|
|
|
|
|
|
|
# Will the Goo be able to wrap the text correctly? |
|
21
|
|
|
|
|
|
|
# 10/08/2005 Added method: test |
|
22
|
|
|
|
|
|
|
# 10/08/2005 This is a new change |
|
23
|
|
|
|
|
|
|
# 18/09/2005 Added full path instead of relative path |
|
24
|
|
|
|
|
|
|
# 09/11/2005 Added method: addHeader |
|
25
|
|
|
|
|
|
|
# 09/11/2005 Added method: addConstructor |
|
26
|
|
|
|
|
|
|
# 09/11/2005 Added method: addPackages |
|
27
|
|
|
|
|
|
|
# 09/11/2005 Added method: addISA |
|
28
|
|
|
|
|
|
|
# |
|
29
|
|
|
|
|
|
|
############################################################################### |
|
30
|
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
32
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
6
|
use Goo::Date; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
22
|
|
|
34
|
1
|
|
|
1
|
|
5
|
use Goo::Object; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
25
|
|
|
35
|
1
|
|
|
1
|
|
7
|
use Text::FormatTable; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
18
|
|
|
36
|
1
|
|
|
1
|
|
5
|
use Goo::FileUtilities; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
|
5
|
use base qw(Goo::Object); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
1367
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
############################################################################### |
|
42
|
|
|
|
|
|
|
# |
|
43
|
|
|
|
|
|
|
# new - construct a perl_coder object |
|
44
|
|
|
|
|
|
|
# |
|
45
|
|
|
|
|
|
|
############################################################################### |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub new { |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
0
|
|
|
my ($class, $filename) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $this = $class->SUPER::new(); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# remember the filename |
|
54
|
0
|
|
|
|
|
|
$this->{filename} = $filename; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# if the file exists maybe load it in? |
|
57
|
0
|
0
|
|
|
|
|
if (-e $this->{filename}) { |
|
58
|
0
|
|
|
|
|
|
$this->{code} = Goo::FileUtilities::get_file_as_string($this->{filename}); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $this; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
############################################################################### |
|
67
|
|
|
|
|
|
|
# |
|
68
|
|
|
|
|
|
|
# save - save the updates to disk |
|
69
|
|
|
|
|
|
|
# |
|
70
|
|
|
|
|
|
|
############################################################################### |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub save { |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
0
|
|
|
my ($this) = @_; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
Goo::FileUtilities::write_file($this->{filename}, $this->{code}); |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
############################################################################### |
|
82
|
|
|
|
|
|
|
# |
|
83
|
|
|
|
|
|
|
# rename_method - change the name of the method |
|
84
|
|
|
|
|
|
|
# |
|
85
|
|
|
|
|
|
|
############################################################################### |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub rename_method { |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
|
|
my ($this, $from, $to) = @_; |
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$this->{code} =~ s/^sub $from/sub $to/m; |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$this->{code} =~ s!^\#\s+$from!\# $to!m; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
############################################################################### |
|
99
|
|
|
|
|
|
|
# |
|
100
|
|
|
|
|
|
|
# get_code - return a string value |
|
101
|
|
|
|
|
|
|
# |
|
102
|
|
|
|
|
|
|
############################################################################### |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub get_code { |
|
105
|
|
|
|
|
|
|
|
|
106
|
0
|
|
|
0
|
|
|
my ($this) = @_; |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return $this->{code}; |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
############################################################################### |
|
114
|
|
|
|
|
|
|
# |
|
115
|
|
|
|
|
|
|
# sort_package - sort the package to the program - this needs to be fixed |
|
116
|
|
|
|
|
|
|
# |
|
117
|
|
|
|
|
|
|
############################################################################### |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub sort_packages { |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
|
|
0
|
|
|
my ($a, $b) = @_; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# make sure pragmas come first |
|
124
|
0
|
0
|
|
|
|
|
if ($a =~ /^use\s+[a-z]/) { |
|
125
|
0
|
|
|
|
|
|
return 1; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
|
if ($b =~ /^use\s+[a-z]/) { |
|
129
|
0
|
|
|
|
|
|
return 1; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
return length($a) <=> length($b); |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
############################################################################### |
|
138
|
|
|
|
|
|
|
# |
|
139
|
|
|
|
|
|
|
# add_package - add a package to the program |
|
140
|
|
|
|
|
|
|
# |
|
141
|
|
|
|
|
|
|
############################################################################### |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub add_package { |
|
144
|
|
|
|
|
|
|
|
|
145
|
0
|
|
|
0
|
|
|
my ($this, $package) = @_; |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# remove the existing packages, assumes we always |
|
148
|
|
|
|
|
|
|
# have one package at least: use strict |
|
149
|
0
|
|
|
|
|
|
$this->{code} =~ s/use strict;/placeholder/; |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# will capture trailing comments too |
|
152
|
0
|
|
|
|
|
|
my @packages = $this->{code} =~ m/^(use.*?)$/mg; |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# add the package to the list |
|
155
|
0
|
|
|
|
|
|
push(@packages, "use $package;"); |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# resort the packages by length |
|
158
|
0
|
|
|
|
|
|
my @sorted = sort { sort_packages($a, $b) } @packages; |
|
|
0
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# remove all the packages - need to delete line feeds too! |
|
161
|
0
|
|
|
|
|
|
$this->{code} =~ s/^use.*?\n//mg; |
|
162
|
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
my $packages = join("\n", @sorted); |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# insert the packages back in - use strict comes first |
|
166
|
0
|
|
|
|
|
|
$this->{code} =~ s/^placeholder/use strict;\n\n$packages/m; |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
############################################################################### |
|
172
|
|
|
|
|
|
|
# |
|
173
|
|
|
|
|
|
|
# delete_package - delete a package from the program |
|
174
|
|
|
|
|
|
|
# |
|
175
|
|
|
|
|
|
|
############################################################################### |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub delete_package { |
|
178
|
|
|
|
|
|
|
|
|
179
|
0
|
|
|
0
|
|
|
my ($this, $package) = @_; |
|
180
|
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
$this->{code} =~ s/^use $package.*?\n//sm; |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
############################################################################### |
|
187
|
|
|
|
|
|
|
# |
|
188
|
|
|
|
|
|
|
# delete_method - remove a method from a program |
|
189
|
|
|
|
|
|
|
# |
|
190
|
|
|
|
|
|
|
############################################################################### |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub delete_method { |
|
193
|
|
|
|
|
|
|
|
|
194
|
0
|
|
|
0
|
|
|
my ($this, $method) = @_; |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
# delete any comments box too from ### to the start of the sub |
|
197
|
|
|
|
|
|
|
# match the comment block - note the greedy start otherwise the |
|
198
|
|
|
|
|
|
|
# whole thing gets deleted! |
|
199
|
0
|
|
|
|
|
|
$this->{code} =~ m/.*(^##.*?^#\s$method\s+.*?^sub)/ms; |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# matches the comment box and the word "sub" below |
|
202
|
0
|
|
|
|
|
|
$this->{code} =~ s/$1/sub/ms; |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
#print $1; |
|
205
|
|
|
|
|
|
|
# match opening sub to closing } and any whitespace |
|
206
|
0
|
|
|
|
|
|
$this->{code} =~ s/^sub $method.*?^\}\s+//ms; |
|
207
|
|
|
|
|
|
|
|
|
208
|
0
|
|
|
|
|
|
$this->add_change_log("Deleted method: " . $method); |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
############################################################################### |
|
214
|
|
|
|
|
|
|
# |
|
215
|
|
|
|
|
|
|
# clone_method - copy and paste a method |
|
216
|
|
|
|
|
|
|
# |
|
217
|
|
|
|
|
|
|
############################################################################### |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub clone_method { |
|
220
|
|
|
|
|
|
|
|
|
221
|
0
|
|
|
0
|
|
|
my ($this, $from_name, $to_name) = @_; |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
# get me |
|
224
|
|
|
|
|
|
|
# grab the contents of a method and rename it |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
# copy one method another |
|
227
|
|
|
|
|
|
|
# addMethod |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
} |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
############################################################################### |
|
233
|
|
|
|
|
|
|
# |
|
234
|
|
|
|
|
|
|
# add_change_log - add a change log entry |
|
235
|
|
|
|
|
|
|
# |
|
236
|
|
|
|
|
|
|
############################################################################### |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub add_change_log { |
|
239
|
|
|
|
|
|
|
|
|
240
|
0
|
|
|
0
|
|
|
my ($this, $change) = @_; |
|
241
|
|
|
|
|
|
|
|
|
242
|
0
|
|
|
|
|
|
my $table = Text::FormatTable->new('14l 62l'); |
|
243
|
|
|
|
|
|
|
|
|
244
|
0
|
|
|
|
|
|
$table->row("~" . Goo::Date::get_current_date_with_slashes(), $change); |
|
245
|
|
|
|
|
|
|
|
|
246
|
0
|
|
|
|
|
|
my $comment = $table->render(); |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
# prefix the table with the comment symbol # |
|
249
|
0
|
|
|
|
|
|
$comment =~ s/^/\#/mg; |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
# substitute this temporary placeholder ~ with a space |
|
252
|
0
|
|
|
|
|
|
$comment =~ s/~/ /; |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
# match the last line in the header and add a comment |
|
255
|
|
|
|
|
|
|
# between existing comments |
|
256
|
0
|
|
|
|
|
|
$this->{code} =~ s/^\#\s+.*?\#\#/$comment\#\n\#\#/m; |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
} |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
############################################################################### |
|
262
|
|
|
|
|
|
|
# |
|
263
|
|
|
|
|
|
|
# delete_change_log - delete a changelog entry |
|
264
|
|
|
|
|
|
|
# |
|
265
|
|
|
|
|
|
|
############################################################################### |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub delete_change_log { |
|
268
|
|
|
|
|
|
|
|
|
269
|
0
|
|
|
0
|
|
|
my ($this, $date, $change) = @_; |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
} |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
############################################################################### |
|
276
|
|
|
|
|
|
|
# |
|
277
|
|
|
|
|
|
|
# add_module_name - add this at the top of the module |
|
278
|
|
|
|
|
|
|
# |
|
279
|
|
|
|
|
|
|
############################################################################### |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
sub add_module_name { |
|
282
|
|
|
|
|
|
|
|
|
283
|
0
|
|
|
0
|
|
|
my ($this, $name) = @_; |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
# add a name to the start of the module |
|
286
|
0
|
|
|
|
|
|
$this->{code} =~ s/^/package $name;\n/; |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
} |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
############################################################################### |
|
292
|
|
|
|
|
|
|
# |
|
293
|
|
|
|
|
|
|
# add_returns_true - all modules need to return true - so lets do it. |
|
294
|
|
|
|
|
|
|
# |
|
295
|
|
|
|
|
|
|
############################################################################### |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
sub add_returns_true { |
|
298
|
|
|
|
|
|
|
|
|
299
|
0
|
|
|
0
|
|
|
my ($this) = @_; |
|
300
|
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
# add a name to the start of the module |
|
302
|
0
|
|
|
|
|
|
$this->{code} .= "\n\n1;\n"; |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
} |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
############################################################################### |
|
308
|
|
|
|
|
|
|
# |
|
309
|
|
|
|
|
|
|
# add_header - add a header to the program |
|
310
|
|
|
|
|
|
|
# |
|
311
|
|
|
|
|
|
|
############################################################################### |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
sub add_header { |
|
314
|
|
|
|
|
|
|
|
|
315
|
0
|
|
|
0
|
|
|
my ($this, $filename, $author, $company, $description, $reason) = @_; |
|
316
|
|
|
|
|
|
|
|
|
317
|
0
|
|
|
|
|
|
my $tokens; |
|
318
|
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
# add header tokens to the header |
|
320
|
0
|
|
|
|
|
|
$tokens->{filename} = $filename; |
|
321
|
0
|
|
|
|
|
|
$tokens->{company} = $company; |
|
322
|
0
|
|
|
|
|
|
$tokens->{author} = $author; |
|
323
|
0
|
|
|
|
|
|
$tokens->{description} = $description; |
|
324
|
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
# insert the date |
|
326
|
0
|
|
|
|
|
|
$tokens->{date} = Goo::Date::get_current_date_with_slashes(); |
|
327
|
0
|
|
|
|
|
|
$tokens->{year} = Goo::Date::get_current_year(); |
|
328
|
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
# prepend the header template to the code |
|
330
|
0
|
|
|
|
|
|
$this->{code} .= |
|
331
|
|
|
|
|
|
|
Goo::Template::replace_tokens_in_string( |
|
332
|
|
|
|
|
|
|
Goo::WebDBLite::get_template( |
|
333
|
|
|
|
|
|
|
"perl-module-header.tpl"), |
|
334
|
|
|
|
|
|
|
$tokens |
|
335
|
|
|
|
|
|
|
); |
|
336
|
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
# add a change log - this is version 1! |
|
338
|
0
|
|
|
|
|
|
$this->add_change_log("Version 1 generated by PerlCoder.pm."); |
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
} |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
############################################################################### |
|
344
|
|
|
|
|
|
|
# |
|
345
|
|
|
|
|
|
|
# add_method - add a method |
|
346
|
|
|
|
|
|
|
# |
|
347
|
|
|
|
|
|
|
############################################################################### |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
sub add_method { |
|
350
|
|
|
|
|
|
|
|
|
351
|
0
|
|
|
0
|
|
|
my ($this, $name, $description, @parameters) = @_; |
|
352
|
|
|
|
|
|
|
|
|
353
|
0
|
|
|
|
|
|
my $tokens = {}; |
|
354
|
|
|
|
|
|
|
|
|
355
|
0
|
|
|
|
|
|
$tokens->{name} = $name; |
|
356
|
0
|
|
|
|
|
|
$tokens->{description} = $description; |
|
357
|
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
# get the constructor template |
|
359
|
0
|
|
|
|
|
|
$tokens->{parameter_list} = 'my (' . join(', ', @parameters) . ') = @_;'; |
|
360
|
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
# add the constructor to the code |
|
362
|
|
|
|
|
|
|
# $this->{code} .= Template::replaceTokensInString |
|
363
|
0
|
|
|
|
|
|
my $method_body = |
|
364
|
|
|
|
|
|
|
Goo::Template::replace_tokens_in_string(Goo::WebDBLite::get_template("perl-method.tpl"), |
|
365
|
|
|
|
|
|
|
$tokens); |
|
366
|
|
|
|
|
|
|
|
|
367
|
0
|
0
|
|
|
|
|
if ($this->{code} =~ /^1;/m) { |
|
368
|
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
# v1 only add methods to packages - add it to the end of the file |
|
370
|
0
|
|
|
|
|
|
$this->{code} =~ s/^1;/$method_body\n\n1;/m; |
|
371
|
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
} else { |
|
373
|
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
# this must be a script - append to the end! |
|
375
|
0
|
|
|
|
|
|
$this->{code} .= "\n\n" . $method_body; |
|
376
|
|
|
|
|
|
|
} |
|
377
|
|
|
|
|
|
|
|
|
378
|
0
|
|
|
|
|
|
$this->add_change_log("Added method: " . $name); |
|
379
|
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
} |
|
381
|
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
############################################################################### |
|
384
|
|
|
|
|
|
|
# |
|
385
|
|
|
|
|
|
|
# add_constructor - add a constructor to a program |
|
386
|
|
|
|
|
|
|
# |
|
387
|
|
|
|
|
|
|
############################################################################### |
|
388
|
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
sub add_constructor { |
|
390
|
|
|
|
|
|
|
|
|
391
|
0
|
|
|
0
|
|
|
my ($this, @parameters) = @_; |
|
392
|
|
|
|
|
|
|
|
|
393
|
0
|
|
|
|
|
|
my $tokens = {}; |
|
394
|
|
|
|
|
|
|
|
|
395
|
0
|
|
|
|
|
|
$tokens->{name} = "new()"; |
|
396
|
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
# get the constructor template |
|
398
|
0
|
|
|
|
|
|
$tokens->{parameter_list} = join(", ", @parameters); |
|
399
|
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
# add the constructor to the code |
|
401
|
|
|
|
|
|
|
# $this->{code} .= Template::replaceTokensInString |
|
402
|
0
|
|
|
|
|
|
$this->{code} .= |
|
403
|
|
|
|
|
|
|
Goo::Template::replace_tokens_in_string( |
|
404
|
|
|
|
|
|
|
Goo::WebDBLite::get_template( |
|
405
|
|
|
|
|
|
|
"perl-constructor.tpl"), |
|
406
|
|
|
|
|
|
|
$tokens |
|
407
|
|
|
|
|
|
|
); |
|
408
|
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
} |
|
410
|
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
############################################################################### |
|
413
|
|
|
|
|
|
|
# |
|
414
|
|
|
|
|
|
|
# add_packages - add a list of packages |
|
415
|
|
|
|
|
|
|
# |
|
416
|
|
|
|
|
|
|
############################################################################### |
|
417
|
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
sub add_packages { |
|
419
|
|
|
|
|
|
|
|
|
420
|
0
|
|
|
0
|
|
|
my ($this, @packages) = @_; |
|
421
|
|
|
|
|
|
|
|
|
422
|
0
|
|
|
|
|
|
foreach my $package (@packages) { |
|
423
|
0
|
|
|
|
|
|
$this->add_package($package); |
|
424
|
|
|
|
|
|
|
} |
|
425
|
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
} |
|
427
|
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
############################################################################### |
|
430
|
|
|
|
|
|
|
# |
|
431
|
|
|
|
|
|
|
# add_isa - add isa to this module |
|
432
|
|
|
|
|
|
|
# |
|
433
|
|
|
|
|
|
|
############################################################################### |
|
434
|
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
sub add_isa { |
|
436
|
|
|
|
|
|
|
|
|
437
|
0
|
|
|
0
|
|
|
my ($this, $package) = @_; |
|
438
|
|
|
|
|
|
|
|
|
439
|
0
|
|
|
|
|
|
$this->{code} .= "\n"; |
|
440
|
0
|
|
|
|
|
|
$this->{code} .= "use base qw($package);"; |
|
441
|
0
|
|
|
|
|
|
$this->{code} .= "\n"; |
|
442
|
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
} |
|
444
|
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
1; |
|
446
|
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
__END__ |
|
449
|
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
=head1 NAME |
|
451
|
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
Goo::PerlCoder - Manipulate Perl programs just like a real programmer. |
|
453
|
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
455
|
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
use Goo::PerlCoder; |
|
457
|
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
459
|
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
=head1 METHODS |
|
461
|
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
=over |
|
463
|
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
=item new |
|
465
|
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
constructor |
|
467
|
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
=item save |
|
469
|
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
save the updates to disk |
|
471
|
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
=item rename_method |
|
473
|
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
change the name of a method |
|
475
|
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
=item get_code |
|
477
|
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
return the code as a string |
|
479
|
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
=item sort_package |
|
481
|
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
sort the use list at the start of the program |
|
483
|
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
=item add_package |
|
485
|
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
add a package to the use list as the start of the program |
|
487
|
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
=item delete_package |
|
489
|
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
delete a package from the use list |
|
491
|
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
=item delete_method |
|
493
|
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
remove a method from the program |
|
495
|
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
=item clone_method |
|
497
|
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
copy and paste a method |
|
499
|
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
=item add_change_log |
|
501
|
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
add a change log entry |
|
503
|
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
=item delete_change_log |
|
505
|
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
delete a change log entry |
|
507
|
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
=item add_module_name |
|
509
|
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
add this at the top of the module |
|
511
|
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
=item add_returns_true |
|
513
|
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
all modules need to return true add a 1; at the bottom of the module |
|
515
|
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
=item add_header |
|
517
|
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
add a header to the program |
|
519
|
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
=item add_method |
|
521
|
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
add a method |
|
523
|
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
=item add_constructor |
|
525
|
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
add a constructor to a program |
|
527
|
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
=item add_packages |
|
529
|
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
add a list of packages |
|
531
|
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
=item add_isa |
|
533
|
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
add an isa to this module |
|
535
|
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
=back |
|
537
|
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
=head1 AUTHOR |
|
539
|
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
|
541
|
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
543
|
|
|
|
|
|
|
|