line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Commands; |
2
|
51
|
|
|
51
|
|
1128
|
use Mojo::Base 'Mojolicious::Command'; |
|
51
|
|
|
|
|
172
|
|
|
51
|
|
|
|
|
400
|
|
3
|
|
|
|
|
|
|
|
4
|
51
|
|
|
51
|
|
456
|
use Mojo::Loader qw(find_modules find_packages load_class); |
|
51
|
|
|
|
|
156
|
|
|
51
|
|
|
|
|
3125
|
|
5
|
51
|
|
|
51
|
|
461
|
use Mojo::Server; |
|
51
|
|
|
|
|
157
|
|
|
51
|
|
|
|
|
360
|
|
6
|
51
|
|
|
51
|
|
350
|
use Mojo::Util qw(getopt tablify); |
|
51
|
|
|
|
|
183
|
|
|
51
|
|
|
|
|
53170
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has hint => <
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
See 'APPLICATION help COMMAND' for more information on a specific command. |
11
|
|
|
|
|
|
|
EOF |
12
|
|
|
|
|
|
|
has message => sub { shift->extract_usage . "\nCommands:\n" }; |
13
|
|
|
|
|
|
|
has namespaces => sub { ['Mojolicious::Command::Author', 'Mojolicious::Command'] }; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub detect { |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# PSGI (Plack only for now) |
18
|
100
|
100
|
|
100
|
1
|
2589
|
return 'psgi' if defined $ENV{PLACK_ENV}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# CGI |
21
|
95
|
100
|
100
|
|
|
774
|
return 'cgi' if defined $ENV{PATH_INFO} || defined $ENV{GATEWAY_INTERFACE}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Nothing |
24
|
93
|
|
|
|
|
1014
|
return undef; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub run { |
28
|
44
|
|
|
44
|
1
|
7689
|
my ($self, $name, @args) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Application loader |
31
|
44
|
100
|
|
|
|
208
|
return $self->app if defined $ENV{MOJO_APP_LOADER}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Try to detect environment |
34
|
27
|
100
|
100
|
|
|
176
|
if (!$ENV{MOJO_NO_DETECT} && (my $env = $self->detect)) { $name = $env } |
|
2
|
|
|
|
|
6
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Run command |
37
|
27
|
100
|
100
|
|
|
379
|
if ($name && $name =~ /^\w[\w-]+$/ && ($name ne 'help' || $args[0])) { |
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Help |
40
|
19
|
100
|
|
|
|
71
|
$name = shift @args if my $help = $name eq 'help'; |
41
|
19
|
|
100
|
|
|
168
|
local $ENV{MOJO_HELP} = $help = $ENV{MOJO_HELP} || $help; |
42
|
19
|
|
|
|
|
75
|
$name =~ s/-/_/g; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Remove options shared by all commands before loading the command |
45
|
19
|
|
|
|
|
84
|
_args(\@args); |
46
|
19
|
|
|
|
|
45
|
my $module; |
47
|
19
|
|
100
|
|
|
51
|
$module = _command("${_}::$name", 1) and last for @{$self->namespaces}; |
|
19
|
|
|
|
|
95
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Unknown command |
50
|
19
|
50
|
|
|
|
80
|
die qq{Unknown command "$name", maybe you need to install it?\n} unless $module; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Run command |
53
|
19
|
|
|
|
|
97
|
my $app = $self->app; |
54
|
19
|
|
|
|
|
94
|
my $command = $module->new(app => $app); |
55
|
19
|
100
|
|
|
|
100
|
return $command->help(@args) if $help; |
56
|
14
|
|
|
|
|
60
|
$app->plugins->emit_hook(before_command => $command, \@args); |
57
|
14
|
|
|
|
|
63
|
return $command->run(@args); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
9
|
elsif ($name && $name ne 'help' && $name ne '--help' && $name ne '-h') { die qq{Invalid command "$name".\n} } |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Hide list for tests |
63
|
7
|
100
|
|
|
|
40
|
return 1 if $ENV{HARNESS_ACTIVE}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Find all available commands |
66
|
6
|
|
|
|
|
13
|
my %all; |
67
|
6
|
|
|
|
|
18
|
for my $ns (@{$self->namespaces}) { |
|
6
|
|
|
|
|
27
|
|
68
|
|
|
|
|
|
|
$all{substr $_, length "${ns}::"} //= $_->new->description |
69
|
12
|
|
66
|
|
|
42
|
for grep { _command($_) } find_modules($ns), find_packages($ns); |
|
169
|
|
|
|
|
354
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
6
|
|
|
|
|
28
|
my @rows; |
73
|
6
|
|
|
|
|
59
|
for my $class (sort keys %all) { |
74
|
67
|
|
|
|
|
99
|
my $command = $class; |
75
|
67
|
|
|
|
|
120
|
$command =~ s/(?
|
76
|
67
|
|
|
|
|
189
|
push @rows, [" $command", $all{$class}]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
6
|
|
|
|
|
33
|
return print $self->message, tablify(\@rows), $self->hint; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
11
|
|
|
11
|
1
|
5110
|
sub start_app { shift; Mojo::Server->new->build_app(shift)->start(@_) } |
|
11
|
|
|
|
|
83
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Command line options for MOJO_HELP, MOJO_HOME and MOJO_MODE |
85
|
|
|
|
|
|
|
sub _args { |
86
|
|
|
|
|
|
|
getopt shift, ['pass_through'], |
87
|
|
|
|
|
|
|
'h|help' => \$ENV{MOJO_HELP}, |
88
|
|
|
|
|
|
|
'home=s' => \$ENV{MOJO_HOME}, |
89
|
|
|
|
|
|
|
'm|mode=s' => \$ENV{MOJO_MODE} |
90
|
70
|
100
|
|
70
|
|
429
|
unless __PACKAGE__->detect; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Do not remove options from @ARGV |
94
|
51
|
|
|
51
|
|
476
|
BEGIN { _args([@ARGV]) } |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _command { |
97
|
205
|
|
|
205
|
|
390
|
my ($module, $fatal) = @_; |
98
|
205
|
100
|
|
|
|
445
|
return $module->isa('Mojolicious::Command') ? $module : undef unless my $e = load_class $module; |
|
|
100
|
|
|
|
|
|
99
|
52
|
50
|
66
|
|
|
408
|
$fatal && ref $e ? die $e : return undef; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=encoding utf8 |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 NAME |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Mojolicious::Commands - Command line interface |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SYNOPSIS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Usage: APPLICATION COMMAND [OPTIONS] |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
mojo version |
115
|
|
|
|
|
|
|
mojo generate lite-app |
116
|
|
|
|
|
|
|
./myapp.pl daemon -m production -l http://*:8080 |
117
|
|
|
|
|
|
|
./myapp.pl get /foo |
118
|
|
|
|
|
|
|
./myapp.pl routes -v |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Tip: CGI and PSGI environments can be automatically detected very often and |
121
|
|
|
|
|
|
|
work without commands. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Options (for all commands): |
124
|
|
|
|
|
|
|
-h, --help Get more information on a specific command |
125
|
|
|
|
|
|
|
--home Path to home directory of your application, defaults to |
126
|
|
|
|
|
|
|
the value of MOJO_HOME or auto-detection |
127
|
|
|
|
|
|
|
-m, --mode Operating mode for your application, defaults to the |
128
|
|
|
|
|
|
|
value of MOJO_MODE/PLACK_ENV or "development" |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 DESCRIPTION |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
L is the interactive command line interface for the L framework. It will |
133
|
|
|
|
|
|
|
automatically detect available commands in the C and C namespaces. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 COMMANDS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
These commands are available by default. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 cgi |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$ ./myapp.pl cgi |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Use L to start application with CGI backend, usually auto detected. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 cpanify |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
$ mojo cpanify -u sri -p secr3t Mojolicious-Plugin-Fun-0.1.tar.gz |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Use L for uploading files to CPAN. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 daemon |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
$ ./myapp.pl daemon |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Use L to start application with standalone HTTP and WebSocket server. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 eval |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
$ ./myapp.pl eval 'say app->home' |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Use L to run code against application. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 generate |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
$ mojo generate |
166
|
|
|
|
|
|
|
$ mojo generate help |
167
|
|
|
|
|
|
|
$ ./myapp.pl generate help |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
List available generator commands with short descriptions. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$ mojo generate help |
172
|
|
|
|
|
|
|
$ ./myapp.pl generate help |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
List available options for generator command with short descriptions. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 generate app |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
$ mojo generate app |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Use L to generate application directory structure for a fully functional |
181
|
|
|
|
|
|
|
L application. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 generate dockerfile |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
$ ./myapp.pl generate dockerfile |
186
|
|
|
|
|
|
|
$ ./script/my_app generate dockerfile |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Use L to generate C for application. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 generate lite-app |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
$ mojo generate lite-app |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Use L to generate a fully functional L |
195
|
|
|
|
|
|
|
application. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 generate makefile |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
$ mojo generate makefile |
200
|
|
|
|
|
|
|
$ ./myapp.pl generate makefile |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Use L to generate C file for application. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 generate plugin |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
$ mojo generate plugin |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Use L to generate directory structure for a fully functional |
209
|
|
|
|
|
|
|
L plugin. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head2 get |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
$ mojo get https://mojolicious.org |
214
|
|
|
|
|
|
|
$ ./myapp.pl get /foo |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Use L to perform requests to remote host or local application. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head2 help |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
$ mojo |
221
|
|
|
|
|
|
|
$ mojo help |
222
|
|
|
|
|
|
|
$ ./myapp.pl help |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
List available commands with short descriptions. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
$ mojo help |
227
|
|
|
|
|
|
|
$ ./myapp.pl help |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
List available options for the command with short descriptions. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head2 inflate |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
$ ./myapp.pl inflate |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Use L to turn templates and static files embedded in the C sections of |
236
|
|
|
|
|
|
|
your application into real files. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head2 prefork |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
$ ./myapp.pl prefork |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Use L to start application with standalone pre-forking HTTP and WebSocket server. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head2 psgi |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
$ ./myapp.pl psgi |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Use L to start application with PSGI backend, usually auto detected. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head2 routes |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
$ ./myapp.pl routes |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Use L to list application routes. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head2 version |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
$ mojo version |
259
|
|
|
|
|
|
|
$ ./myapp.pl version |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Use L to show version information for available core and optional modules, very useful |
262
|
|
|
|
|
|
|
for debugging. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
L inherits all attributes from L and implements the following new ones. |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=head2 hint |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
my $hint = $commands->hint; |
271
|
|
|
|
|
|
|
$commands = $commands->hint('Foo'); |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Short hint shown after listing available commands. |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head2 message |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
my $msg = $commands->message; |
278
|
|
|
|
|
|
|
$commands = $commands->message('Hello World!'); |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
Short usage message shown before listing available commands. |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head2 namespaces |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
my $namespaces = $commands->namespaces; |
285
|
|
|
|
|
|
|
$commands = $commands->namespaces(['MyApp::Command']); |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
Namespaces to load commands from, defaults to C and C. |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
# Add another namespace to load commands from |
290
|
|
|
|
|
|
|
push @{$commands->namespaces}, 'MyApp::Command'; |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=head1 METHODS |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
L inherits all methods from L and implements the following new ones. |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=head2 detect |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
my $env = $commands->detect; |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
Try to detect environment, or return C if none could be detected. |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=head2 run |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
$commands->run; |
305
|
|
|
|
|
|
|
$commands->run(@ARGV); |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
Load and run commands. Automatic deployment environment detection can be disabled with the C |
308
|
|
|
|
|
|
|
environment variable. |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=head2 start_app |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
Mojolicious::Commands->start_app('MyApp'); |
313
|
|
|
|
|
|
|
Mojolicious::Commands->start_app(MyApp => @ARGV); |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
Load application from class and start the command line interface for it. Note that the options C<-h>/C<--help>, |
316
|
|
|
|
|
|
|
C<--home> and C<-m>/C<--mode>, which are shared by all commands, will be parsed from C<@ARGV> during compile time. |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
# Always start daemon for application |
319
|
|
|
|
|
|
|
Mojolicious::Commands->start_app('MyApp', 'daemon', '-l', 'http://*:8080'); |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=head1 SEE ALSO |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
L, L, L. |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=cut |