| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Module::Starter::Plugin::App::Cmd; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
32811
|
use 5.010; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
76
|
|
|
4
|
1
|
|
|
1
|
|
8
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
49
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
62
|
|
|
6
|
1
|
|
|
1
|
|
1286
|
use parent 'Module::Starter::Simple'; |
|
|
1
|
|
|
|
|
427
|
|
|
|
1
|
|
|
|
|
6
|
|
|
7
|
1
|
|
|
1
|
|
40758
|
use ExtUtils::Command qw( rm_rf mkpath touch ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
79
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use File::Spec (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Patch Module::Starter::Simple to call create_script() after create_modules() |
|
11
|
1
|
|
|
1
|
|
1176
|
use Class::Monkey qw/Module::Starter::Simple/; |
|
|
1
|
|
|
|
|
3902
|
|
|
|
1
|
|
|
|
|
7
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
after 'create_modules' => sub { |
|
14
|
|
|
|
|
|
|
my $self = shift; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$self->create_script; |
|
17
|
|
|
|
|
|
|
}, 'Module::Starter::Simple'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Module::Starter::Plugin::App::Cmd |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Guts for L. |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub postprocess_config { |
|
35
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
die "Script name must be specified\n" unless $self->{script}; |
|
38
|
0
|
0
|
|
|
|
|
die "At least one command must be specified\n" unless $self->{commands}; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub pre_create_distro { |
|
45
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$self->{main_module} = @{$self->{modules}}[0]; |
|
|
0
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
push @{$self->{modules}}, $self->{main_module} . "::Command"; |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
foreach my $command (split /,/,$self->{commands}) { |
|
52
|
0
|
|
|
|
|
|
push @{$self->{modules}}, $self->{main_module} . "::Command::" . ucfirst $command; |
|
|
0
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub module_guts { |
|
60
|
0
|
|
|
0
|
1
|
|
my ($self, $module, $rtname) = @_; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $main_module = $self->{main_module}; |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
given ($module) { |
|
65
|
0
|
|
|
|
|
|
when ($main_module) { |
|
66
|
0
|
|
|
|
|
|
$self->main_module_guts($module, $rtname); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
0
|
|
|
|
|
|
when ("$main_module"."::Command") { |
|
69
|
0
|
|
|
|
|
|
$self->command_pm_guts($module); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
0
|
|
|
|
|
|
when (/($main_module\b::Command)::(\w+)/) { |
|
72
|
0
|
|
|
|
|
|
$self->command_module_guts($module, $1, lc $2); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
0
|
|
|
|
|
|
default { |
|
75
|
0
|
|
|
|
|
|
$self->SUPER::module_guts($module, $rtname); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub main_module_guts { |
|
84
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
85
|
0
|
|
|
|
|
|
my $module = shift; |
|
86
|
0
|
|
|
|
|
|
my $rtname = shift; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Sub-templates |
|
89
|
0
|
|
|
|
|
|
my $header = $self->_module_header($module, $rtname); |
|
90
|
0
|
|
|
|
|
|
my $bugs = $self->_module_bugs($module, $rtname); |
|
91
|
0
|
|
|
|
|
|
my $support = $self->_module_support($module, $rtname); |
|
92
|
0
|
|
|
|
|
|
my $license = $self->_module_license($module, $rtname); |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $script = $self->{script}; |
|
95
|
0
|
|
|
|
|
|
my $env_var = uc($script =~ s/-/_/gr) . '_CONFIG'; |
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $content = <<"HERE"; |
|
98
|
|
|
|
|
|
|
$header |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
use 5.010; |
|
101
|
|
|
|
|
|
|
use App::Cmd::Setup -app; |
|
102
|
|
|
|
|
|
|
use Config::General qw/ParseConfig/; |
|
103
|
|
|
|
|
|
|
use File::HomeDir; |
|
104
|
|
|
|
|
|
|
use File::Spec::Functions qw/catfile/; |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub config { |
|
107
|
|
|
|
|
|
|
state \$config = {ParseConfig(config_file())}; |
|
108
|
|
|
|
|
|
|
return \$config; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub config_file { |
|
112
|
|
|
|
|
|
|
my \@files = ( |
|
113
|
|
|
|
|
|
|
\$ENV{$env_var}, |
|
114
|
|
|
|
|
|
|
catfile(File::HomeDir->my_home, '.$script'), |
|
115
|
|
|
|
|
|
|
'/usr/local/etc/$script', |
|
116
|
|
|
|
|
|
|
'/etc/$script', |
|
117
|
|
|
|
|
|
|
); |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
foreach my \$file (grep {defined \$_} \@files) { |
|
120
|
|
|
|
|
|
|
return \$file if -r \$file; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
\=head1 SYNOPSIS |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Quick summary of what the module does. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Perhaps a little code snippet. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
use $module; |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my \$foo = $module->new(); |
|
133
|
|
|
|
|
|
|
... |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
\=head1 AUTHOR |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$self->{author}, C<< <$self->{email_obfuscated}> >> |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
$bugs |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$support |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
$license |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
\=cut |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; # End of $module |
|
148
|
|
|
|
|
|
|
HERE |
|
149
|
0
|
|
|
|
|
|
return $content; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub command_pm_guts { |
|
156
|
0
|
|
|
0
|
0
|
|
my ($self, $module) = @_; |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
return <
|
|
159
|
|
|
|
|
|
|
package $module; |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
use App::Cmd::Setup -command; |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub opt_spec { |
|
164
|
|
|
|
|
|
|
my ( \$class, \$app ) = \@_; |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# Example options |
|
167
|
|
|
|
|
|
|
# |
|
168
|
|
|
|
|
|
|
# return ( |
|
169
|
|
|
|
|
|
|
# [ 'name=s' => "Name", {default => \$SUPER::config->{name} || undef} ], |
|
170
|
|
|
|
|
|
|
# ); |
|
171
|
|
|
|
|
|
|
return (); |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub validate_args { |
|
175
|
|
|
|
|
|
|
my ( \$self, \$opt, \$args ) = \@_; |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# Example validation |
|
178
|
|
|
|
|
|
|
# |
|
179
|
|
|
|
|
|
|
# \$self->usage_message('Your error here') unless (\$some_condition); |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; |
|
183
|
|
|
|
|
|
|
EOT |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub command_module_guts { |
|
190
|
0
|
|
|
0
|
0
|
|
my ($self, $module, $base, $command) = @_; |
|
191
|
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
return <
|
|
193
|
|
|
|
|
|
|
package $module; |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
use strict; |
|
196
|
|
|
|
|
|
|
use warnings; |
|
197
|
|
|
|
|
|
|
use parent '$base'; |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# Documentation |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub abstract { |
|
202
|
|
|
|
|
|
|
return "Abstract for the $command command"; |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub usage_desc { |
|
206
|
|
|
|
|
|
|
return "%c $command %o"; |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub description { |
|
210
|
|
|
|
|
|
|
return "Description for the $command command\\nOptions:"; |
|
211
|
|
|
|
|
|
|
} |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
# Command specific options |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub opt_spec { |
|
217
|
|
|
|
|
|
|
my (\$class, \$app) = \@_; |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
return ( |
|
220
|
|
|
|
|
|
|
# Example options |
|
221
|
|
|
|
|
|
|
# |
|
222
|
|
|
|
|
|
|
# [ "familiar" => "Use an informal greeting", {default => \$SUPER::config->{familiar} || undef} ], |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
\$class->SUPER::opt_spec, # Include global options |
|
225
|
|
|
|
|
|
|
); |
|
226
|
|
|
|
|
|
|
} |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# The command itself |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub execute { |
|
232
|
|
|
|
|
|
|
my (\$self, \$opt, \$args) = \@_; |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
# require 'My::Dependency'; |
|
235
|
|
|
|
|
|
|
# Tip: Using 'require' instead of 'use' will save memory and make startup faster |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# Command code goes here |
|
238
|
|
|
|
|
|
|
} |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
1; |
|
241
|
|
|
|
|
|
|
EOT |
|
242
|
|
|
|
|
|
|
} |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
sub create_script { |
|
248
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
249
|
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
my $script_dir = File::Spec->catdir($self->{basedir}, 'script'); |
|
251
|
0
|
0
|
|
|
|
|
unless (-d $script_dir) { |
|
252
|
0
|
|
|
|
|
|
local @ARGV = $script_dir; |
|
253
|
0
|
|
|
|
|
|
mkpath @ARGV; |
|
254
|
0
|
|
|
|
|
|
$self->progress("Created $script_dir"); |
|
255
|
|
|
|
|
|
|
} |
|
256
|
|
|
|
|
|
|
|
|
257
|
0
|
|
|
|
|
|
my $script_file = File::Spec->catfile($script_dir, $self->{script}); |
|
258
|
0
|
|
|
|
|
|
$self->create_file($script_file, <
|
|
259
|
|
|
|
|
|
|
#! /usr/bin/env perl |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
use $self->{main_module}; |
|
262
|
|
|
|
|
|
|
$self->{main_module}->run; |
|
263
|
|
|
|
|
|
|
EOT |
|
264
|
0
|
|
|
|
|
|
$self->progress("Created $script_file"); |
|
265
|
|
|
|
|
|
|
} |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
sub post_create_distro { |
|
271
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
272
|
|
|
|
|
|
|
} |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=head1 AUTHOR |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
Jon Allen (JJ), C<< >> |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head1 BUGS |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
284
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
285
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=head1 SUPPORT |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
perldoc Module::Starter::Plugin::App::Cmd |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
You can also look for information at: |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=over 4 |
|
300
|
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
L |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
L |
|
308
|
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
L |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=item * Search CPAN |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
L |
|
316
|
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=back |
|
318
|
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
321
|
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
324
|
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
Copyright 2012 Jon Allen (JJ). |
|
326
|
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
328
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
329
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
330
|
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
332
|
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
=cut |
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
1; # End of Module::Starter::Plugin::App::Cmd |