line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Goo::Thing::pm::ProgramCloner; |
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::ProgramCloner.pm |
11
|
|
|
|
|
|
|
# Description: Clone a program and generate a test stub |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Date Change |
14
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
15
|
|
|
|
|
|
|
# 10/02/2005 Clone a program |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
############################################################################### |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
6747
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
8
|
use Goo::Date; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
22
|
1
|
|
|
1
|
|
5
|
use Goo::Object; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
23
|
1
|
|
|
1
|
|
5
|
use Goo::Prompter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
24
|
1
|
|
|
1
|
|
6
|
use Goo::Template; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
25
|
1
|
|
|
1
|
|
5
|
use Goo::WebDBLite; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
16
|
|
26
|
1
|
|
|
1
|
|
5
|
use Goo::FileUtilities; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
27
|
1
|
|
|
1
|
|
47
|
use Goo::Thing::tpm::TestMaker; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our @ISA = ("Goo::Object"); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# default to Perl templates - but can be overridden later (e.g., Javascript, Ruby etc) |
32
|
|
|
|
|
|
|
# page output regions |
33
|
|
|
|
|
|
|
my $header_template = "perl-header.tpl"; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
############################################################################### |
37
|
|
|
|
|
|
|
# |
38
|
|
|
|
|
|
|
# new - set all the values required |
39
|
|
|
|
|
|
|
# |
40
|
|
|
|
|
|
|
############################################################################### |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new { |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my ($class, $params) = @_; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $this = $class->SUPER::new(); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
if (-e $params->{to}) { |
49
|
|
|
|
|
|
|
exit unless Goo::Prompter::confirm("The file $params->{to} already exists. Continue cloning?"); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$this->{to} = $params->{to}; |
53
|
|
|
|
|
|
|
$this->{from} = $params->{from}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$this->{to_filename} = $params->{to}; |
56
|
|
|
|
|
|
|
$this->{from_filename} = $params->{from}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# set in the header template |
59
|
|
|
|
|
|
|
$this->{filename} = $params->{to}; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# strip suffixes |
62
|
|
|
|
|
|
|
$params->{to} =~ s/\..*$//; |
63
|
|
|
|
|
|
|
$params->{from} =~ s/\..*$//; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# store the name without the suffix |
66
|
|
|
|
|
|
|
$this->{to_name} = $params->{to}; |
67
|
|
|
|
|
|
|
$this->{from_name} = $params->{from}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# start The GOO! |
70
|
|
|
|
|
|
|
Goo::Prompter::say(""); |
71
|
|
|
|
|
|
|
Goo::Prompter::yell("The GOO - Clone from $this->{from} to $this->{to}"); # title bar |
72
|
|
|
|
|
|
|
Goo::Prompter::say(""); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
return $this; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
############################################################################### |
80
|
|
|
|
|
|
|
# |
81
|
|
|
|
|
|
|
# generate_header - set all the values required in the header of the program |
82
|
|
|
|
|
|
|
# |
83
|
|
|
|
|
|
|
############################################################################### |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub generate_header { |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my ($this, $template) = @_; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# grab the description of the module |
90
|
|
|
|
|
|
|
$this->{description} = ucfirst(Goo::Prompter::ask("Enter a description of $this->{to_name}?")); |
91
|
|
|
|
|
|
|
$this->{reason} = ucfirst(Goo::Prompter::ask("Enter a reason for creating $this->{to_name}?")); |
92
|
|
|
|
|
|
|
$this->{date} = Goo::Date::get_current_date_with_slashes(); |
93
|
|
|
|
|
|
|
$this->{year} = Goo::Date::get_current_year(); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# override the default, if need be |
96
|
|
|
|
|
|
|
$template = $template || $header_template; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# pop on the new header - now clone the rest |
99
|
|
|
|
|
|
|
$this->{header} .= Goo::Template::replace_tokens_in_string(Goo::WebDBLite::get_template($template), $this); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
############################################################################### |
105
|
|
|
|
|
|
|
# |
106
|
|
|
|
|
|
|
# clone_body - clone everything except the header |
107
|
|
|
|
|
|
|
# |
108
|
|
|
|
|
|
|
############################################################################### |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub clone_body { |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my ($this) = @_; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $body = Goo::FileUtilities::get_file_as_string($this->{from_filename}); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# stip the header up to use strict; |
117
|
|
|
|
|
|
|
$body =~ s/.*use strict;/use strict;/s; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$this->{body} = $body; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
############################################################################### |
125
|
|
|
|
|
|
|
# |
126
|
|
|
|
|
|
|
# save - create the program output file |
127
|
|
|
|
|
|
|
# |
128
|
|
|
|
|
|
|
############################################################################### |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub save { |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my ($this) = @_; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my $template = Goo::WebDBLite::get_template("clonemodule.tpl"); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Goo::FileUtilities::write_file($this->{to}, |
137
|
|
|
|
|
|
|
Goo::Template::replace_tokens_in_string($template, $this)); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Prompter::yell("Program cloned as: $this->{to}."); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
############################################################################### |
145
|
|
|
|
|
|
|
# |
146
|
|
|
|
|
|
|
# generate - create the output file |
147
|
|
|
|
|
|
|
# |
148
|
|
|
|
|
|
|
############################################################################### |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub generate { |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
my ($this) = @_; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
$this->generate_header(); |
155
|
|
|
|
|
|
|
$this->clone_body(); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Goo::Prompter::yell("Generated a clone $this->{to_name} of $this->{from_name}."); |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
exit unless Goo::Prompter::confirm("Save the $this->{to_name} module?"); |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
$this->save(); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
exit unless Goo::Prompter::confirm("Create unit test?"); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
my $tm = Goo::Thing::tpm::TestMaker->new($this->{to_filename}); |
166
|
|
|
|
|
|
|
$tm->create_test_for_module(); |
167
|
|
|
|
|
|
|
Goo::Prompter::yell("Created unit test: $tm->{testfilename}"); |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
1; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
__END__ |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 NAME |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Goo::Thing::pm::ProgramCloner - Clone a program and generate a test stub |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 SYNOPSIS |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
use Goo::Thing::pm::ProgramCloner; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 DESCRIPTION |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 METHODS |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=over |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item new |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
constructor |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item generate_header |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
set all the values required in the header of the program |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item clone_body |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
clone everything except the header |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item save |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
create the program output file |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item generate |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
create the output file |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=back |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head1 AUTHOR |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 SEE ALSO |
222
|
|
|
|
|
|
|
|