line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Goo::Perl5ModuleMaker; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
############################################################################### |
6
|
|
|
|
|
|
|
# Nigel Hamilton |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2003 |
9
|
|
|
|
|
|
|
# All Rights Reserved |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
12
|
|
|
|
|
|
|
# Filename: Goo::Perl5ModuleMaker.pm |
13
|
|
|
|
|
|
|
# Description: Command line utility for making module skeletons faster |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# Date Change |
16
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
# 14/8/2005 Version 1 |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
############################################################################### |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
5
|
use Goo::Prompter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
24
|
1
|
|
|
1
|
|
5
|
use Goo::TeamManager; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
25
|
1
|
|
|
1
|
|
4
|
use Goo::Thing::pm::PerlCoder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
4
|
use base qw(Goo::Object); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
580
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
############################################################################### |
31
|
|
|
|
|
|
|
# |
32
|
|
|
|
|
|
|
# run - interface method |
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
############################################################################### |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub run { |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
0
|
|
|
my ($this, $filename) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# keep making modules --- don't ever stop!!! ;-) |
41
|
0
|
|
|
|
|
|
while (1) { |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# show the header --- use the Goo::Header instead |
44
|
0
|
|
|
|
|
|
Goo::Prompter::show_detailed_header("Perl5ModuleMaker", $filename); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $name = Goo::FileUtilities::get_prefix($filename); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# employ a PerlCoder to help out! |
49
|
0
|
|
|
|
|
|
my $pc = Goo::PerlCoder->new($filename); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# add the module name to start of the file: package MyModule; |
52
|
0
|
|
|
|
|
|
$pc->add_module_name($name); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# add the comments header |
55
|
0
|
|
|
|
|
|
$pc->add_header($filename, |
56
|
|
|
|
|
|
|
Goo::Prompter::pick_one("author?", |
57
|
|
|
|
|
|
|
Goo::TeamManager::get_programmer_names() |
58
|
|
|
|
|
|
|
), |
59
|
|
|
|
|
|
|
Goo::Prompter::pick_one("company?", Goo::TeamManager::get_companies()), |
60
|
|
|
|
|
|
|
ucfirst(Goo::Prompter::ask("Enter a description of $name?")), |
61
|
|
|
|
|
|
|
ucfirst(Goo::Prompter::ask("Enter a reason for creating $name?")) |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# what packages? |
65
|
0
|
|
|
|
|
|
my @packages = Goo::Prompter::keep_asking("Add a package?"); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# add the packages to the file |
68
|
0
|
|
|
|
|
|
$pc->add_packages(@packages); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# do we inherit from anything? |
71
|
0
|
|
|
|
|
|
my $isa_package = |
72
|
|
|
|
|
|
|
Goo::Prompter::pick_one("Which package does $name inherit from?", @packages); |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if ($isa_package) { |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# add the isa_package |
77
|
0
|
|
|
|
|
|
$pc->add_isa($isa_package); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# if so add a constructor |
80
|
0
|
0
|
|
|
|
|
if (Goo::Prompter::confirm("Add a constructor?", "Y")) { |
81
|
0
|
|
|
|
|
|
my @parameters = |
82
|
|
|
|
|
|
|
Goo::Prompter::keep_asking( |
83
|
|
|
|
|
|
|
"enter a constructor parameter (mandatories first)?"); |
84
|
0
|
|
|
|
|
|
$pc->add_constructor(@parameters); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# keep asking for a new method |
89
|
0
|
|
|
|
|
|
while (my $method = Goo::Prompter::ask("Enter a method for $name?")) { |
90
|
0
|
0
|
|
|
|
|
last unless $method; |
91
|
0
|
|
|
|
|
|
my $description = Goo::Prompter::ask("Enter a description for $method?"); |
92
|
0
|
|
|
|
|
|
my @parameters = |
93
|
|
|
|
|
|
|
Goo::Prompter::keep_asking("enter a parameter for $method (mandatories first)?"); |
94
|
0
|
|
|
|
|
|
$pc->add_method($method, $description, @parameters); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# add the returns true 1; at the bottom |
98
|
0
|
|
|
|
|
|
$pc->add_returns_true($name); |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
Goo::Prompter::yell("Module $name created."); |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
if (Goo::Prompter::confirm("Save module $name?", "Y")) { |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# save the code to disk |
105
|
0
|
|
|
|
|
|
$pc->save(); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
Goo::Prompter::yell("Module $name saved."); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# create a unit test? |
111
|
0
|
0
|
|
|
|
|
if (Goo::Prompter::confirm("Create unit test?")) { |
112
|
0
|
|
|
|
|
|
my $tm = Goo::Thing::tpm::TestMaker->new($filename); |
113
|
0
|
|
|
|
|
|
$tm->create_test_for_module(); |
114
|
0
|
|
|
|
|
|
Goo::Prompter::yell("Created unit test."); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# create another module! |
118
|
0
|
0
|
|
|
|
|
if (Goo::Prompter::confirm("Create another module?", "N")) { |
119
|
0
|
|
|
|
|
|
$filename = Goo::Prompter::ask("Enter the name of the new module?"); |
120
|
|
|
|
|
|
|
} else { |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# finished! |
123
|
0
|
|
|
|
|
|
last; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 NAME |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Goo::Perl5ModuleMaker - Command line utility for making Perl5 module skeletons faster |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 SYNOPSIS |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
use Goo::Perl5ModuleMaker; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 DESCRIPTION |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 METHODS |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item run |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
make the module skeleton |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=back |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 AUTHOR |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SEE ALSO |
162
|
|
|
|
|
|
|
|