Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 879 lines (629 sloc) 21.328 kb
a146626 added Mojolicious::Lite
sri authored
1 package Mojolicious::Lite;
3c2998b @kraih added experimental much prettier attribute generator to Mojo::Base
authored
2 use Mojo::Base 'Mojolicious';
a146626 added Mojolicious::Lite
sri authored
3
388f1aa @kraih made simpsons and futurama quotes easier to distinguish from normal comm...
authored
4 # "Since when is the Internet all about robbing people of their privacy?
5 # August 6, 1991."
8a7633c @kraih fixed a few home detection bugs
authored
6 use File::Basename 'dirname';
a146626 added Mojolicious::Lite
sri authored
7 use File::Spec;
8
388f1aa @kraih made simpsons and futurama quotes easier to distinguish from normal comm...
authored
9 # "It's the future, my parents, my co-workers, my girlfriend,
10 # I'll never see any of them ever again... YAHOOO!"
a146626 added Mojolicious::Lite
sri authored
11 sub import {
12 my $class = shift;
13
56f0c8b lite apps are strict by default
sri authored
14 # Lite apps are strict!
15 strict->import;
16 warnings->import;
17
8a7633c @kraih fixed a few home detection bugs
authored
18 # Executable
19 $ENV{MOJO_EXE} ||= (caller)[1];
20
a146626 added Mojolicious::Lite
sri authored
21 # Home
8a7633c @kraih fixed a few home detection bugs
authored
22 local $ENV{MOJO_HOME} =
23 File::Spec->catdir(split '/', dirname($ENV{MOJO_EXE}))
a38e5ae @kraih fixed a complicated application embedding bug
authored
24 unless $ENV{MOJO_HOME};
a146626 added Mojolicious::Lite
sri authored
25
26 # Initialize app
fcf3ef7 added the ability to have multiple Mojolicious::Lite apps at once (Mojol...
Sebastian Riedel authored
27 my $app = $class->new;
a146626 added Mojolicious::Lite
sri authored
28
d8fb4f3 added ladders to Mojolicious::Lite, they are like bridges but lite
Sebastian Riedel authored
29 # Initialize routes
fcf3ef7 added the ability to have multiple Mojolicious::Lite apps at once (Mojol...
Sebastian Riedel authored
30 my $routes = $app->routes;
464f25d made detour much more flexible
Sebastian Riedel authored
31 $routes->namespace('');
d8fb4f3 added ladders to Mojolicious::Lite, they are like bridges but lite
Sebastian Riedel authored
32
a146626 added Mojolicious::Lite
sri authored
33 # Prepare exports
34 my $caller = caller;
35 no strict 'refs';
c69ff10 MOJO_RELOAD=1 now works with Mojolicious::Lite, have fun!
Sebastian Riedel authored
36 no warnings 'redefine';
a146626 added Mojolicious::Lite
sri authored
37
ca0e2e9 fixed typo
Sebastian Riedel authored
38 # Default static and template class
39 $app->static->default_static_class($caller);
a0bdede fixed typo
Sebastian Riedel authored
40 $app->renderer->default_template_class($caller);
41
37c77c5 @kraih allow Mojolicious::Lite style routes in Mojolicious
authored
42 # Root
43 my $root = $routes;
44
a146626 added Mojolicious::Lite
sri authored
45 # Export
a0a4265 added the ability to use Mojolicious::Lite apps as Mojolicious controlle...
Sebastian Riedel authored
46 *{"${caller}::new"} = *{"${caller}::app"} = sub {$app};
37c77c5 @kraih allow Mojolicious::Lite style routes in Mojolicious
authored
47 *{"${caller}::any"} = sub { $routes->any(@_) };
998570d @kraih added put and del functions to Mojolicious::Lite
authored
48 *{"${caller}::del"} = sub { $routes->del(@_) };
37c77c5 @kraih allow Mojolicious::Lite style routes in Mojolicious
authored
49 *{"${caller}::get"} = sub { $routes->get(@_) };
3f8a86e added basic http proxy support
Sebastian Riedel authored
50 *{"${caller}::under"} = *{"${caller}::ladder"} =
37c77c5 @kraih allow Mojolicious::Lite style routes in Mojolicious
authored
51 sub { $routes = $root->under(@_) };
7ee211b added WebSocket support to Mojolicious and Mojolicious::Lite
Sebastian Riedel authored
52 *{"${caller}::plugin"} = sub { $app->plugin(@_) };
37c77c5 @kraih allow Mojolicious::Lite style routes in Mojolicious
authored
53 *{"${caller}::post"} = sub { $routes->post(@_) };
998570d @kraih added put and del functions to Mojolicious::Lite
authored
54 *{"${caller}::put"} = sub { $routes->put(@_) };
37c77c5 @kraih allow Mojolicious::Lite style routes in Mojolicious
authored
55 *{"${caller}::websocket"} = sub { $routes->websocket(@_) };
a146626 added Mojolicious::Lite
sri authored
56
fcf3ef7 added the ability to have multiple Mojolicious::Lite apps at once (Mojol...
Sebastian Riedel authored
57 # We are most likely the app in a lite environment
a38e5ae @kraih fixed a complicated application embedding bug
authored
58 $ENV{MOJO_APP} ||= $app;
a146626 added Mojolicious::Lite
sri authored
59
fcf3ef7 added the ability to have multiple Mojolicious::Lite apps at once (Mojol...
Sebastian Riedel authored
60 # Shagadelic!
065b279 @kraih fixed shagadelic function of Mojolicious::Lite
authored
61 *{"${caller}::shagadelic"} = sub { $app->start(@_) };
a146626 added Mojolicious::Lite
sri authored
62 }
63
64 1;
65 __END__
66
67 =head1 NAME
68
69 Mojolicious::Lite - Micro Web Framework
70
71 =head1 SYNOPSIS
72
24b3bff added ->render(text => "") support and many lite examples
sri authored
73 # Using Mojolicious::Lite will enable "strict" and "warnings"
a146626 added Mojolicious::Lite
sri authored
74 use Mojolicious::Lite;
75
9b87480 improved tutorial a bit
sri authored
76 # Route with placeholder
124ea7e reformatted lite examples to a tutorial
sri authored
77 get '/:foo' => sub {
a146626 added Mojolicious::Lite
sri authored
78 my $self = shift;
f0d4495 made examples more business friendly
Sebastian Riedel authored
79 my $foo = $self->param('foo');
3f8a86e added basic http proxy support
Sebastian Riedel authored
80 $self->render(text => "Hello from $foo!");
a146626 added Mojolicious::Lite
sri authored
81 };
82
9c69cc4 renamed script system to command system
Sebastian Riedel authored
83 # Start the Mojolicious command system
80f8c48 switched to app->start instead of shagadelic as default way to start Moj...
Sebastian Riedel authored
84 app->start;
a146626 added Mojolicious::Lite
sri authored
85
124ea7e reformatted lite examples to a tutorial
sri authored
86 =head1 DESCRIPTION
87
04d0204 @cowens fixed typo
cowens authored
88 L<Mojolicious::Lite> is a micro web framework built around L<Mojolicious>.
124ea7e reformatted lite examples to a tutorial
sri authored
89
ef8a00e @kraih ho ho ho
authored
90 =head1 TUTORIAL
91
a064263 @kraih ho ho ho
authored
92 A quick example driven introduction to the wonders of L<Mojolicious::Lite>.
93 Most of what you'll learn here also applies to normal L<Mojolicious>
94 applications.
ef8a00e @kraih ho ho ho
authored
95
96 =head2 Hello World!
97
c43396b updated tutorial
Sebastian Riedel authored
98 A minimal Hello World application looks like this, L<strict> and L<warnings>
3f8a86e added basic http proxy support
Sebastian Riedel authored
99 are automatically enabled and a few functions imported when you use
100 L<Mojolicious::Lite>, turning your script into a full featured web
101 application.
9b87480 improved tutorial a bit
sri authored
102
103 #!/usr/bin/env perl
104
105 use Mojolicious::Lite;
106
3f8a86e added basic http proxy support
Sebastian Riedel authored
107 get '/' => sub { shift->render(text => 'Hello World!') };
9b87480 improved tutorial a bit
sri authored
108
80f8c48 switched to app->start instead of shagadelic as default way to start Moj...
Sebastian Riedel authored
109 app->start;
9b87480 improved tutorial a bit
sri authored
110
ef8a00e @kraih ho ho ho
authored
111 =head2 Generator
112
9c69cc4 renamed script system to command system
Sebastian Riedel authored
113 There is also a helper command to generate a small example application.
124ea7e reformatted lite examples to a tutorial
sri authored
114
e51aefb replaced the "mojolicious" command with "mojo", for convenience
Sebastian Riedel authored
115 % mojo generate lite_app
124ea7e reformatted lite examples to a tutorial
sri authored
116
ef8a00e @kraih ho ho ho
authored
117 =head2 Commands
118
9c69cc4 renamed script system to command system
Sebastian Riedel authored
119 All the normal L<Mojolicious> command options are available from the command
758c94a fixed typo
sri authored
120 line.
58efd9e cleanup
Sebastian Riedel authored
121 Note that CGI, FastCGI and PSGI environments can usually be auto detected and
122 will just work without commands.
124ea7e reformatted lite examples to a tutorial
sri authored
123
24b3bff added ->render(text => "") support and many lite examples
sri authored
124 % ./myapp.pl daemon
125 Server available at http://127.0.0.1:3000.
124ea7e reformatted lite examples to a tutorial
sri authored
126
629b68c fixed typo
Sebastian Riedel authored
127 % ./myapp.pl daemon --listen http://*:8080
9ac9059 added more lite examples
sri authored
128 Server available at http://127.0.0.1:8080.
124ea7e reformatted lite examples to a tutorial
sri authored
129
0112933 cleaned up the whole script system
sri authored
130 % ./myapp.pl cgi
24b3bff added ->render(text => "") support and many lite examples
sri authored
131 ...CGI output...
124ea7e reformatted lite examples to a tutorial
sri authored
132
0112933 cleaned up the whole script system
sri authored
133 % ./myapp.pl fastcgi
24b3bff added ->render(text => "") support and many lite examples
sri authored
134 ...Blocking FastCGI main loop...
135
3f8a86e added basic http proxy support
Sebastian Riedel authored
136 % ./myapp.pl
137 ...List of available commands (or automatically detected environment)...
138
ef8a00e @kraih ho ho ho
authored
139 =head2 Start
140
80f8c48 switched to app->start instead of shagadelic as default way to start Moj...
Sebastian Riedel authored
141 The app->start call that starts the L<Mojolicious> command system can be
124ea7e reformatted lite examples to a tutorial
sri authored
142 customized to override normal C<@ARGV> use.
143
80f8c48 switched to app->start instead of shagadelic as default way to start Moj...
Sebastian Riedel authored
144 app->start('cgi');
24b3bff added ->render(text => "") support and many lite examples
sri authored
145
ef8a00e @kraih ho ho ho
authored
146 =head2 Reloading
147
8a62cf3 updated lite tutorial with --reload option
Sebastian Riedel authored
148 Your application will automatically reload itself if you set the C<--reload>
149 option, so you don't have to restart the server after every change.
2e9c57b added MOJO_RELOAD section to Mojolicious::Lite tutorial
Sebastian Riedel authored
150
8a62cf3 updated lite tutorial with --reload option
Sebastian Riedel authored
151 % ./myapp.pl daemon --reload
152 Server available at http://127.0.0.1:3000.
2e9c57b added MOJO_RELOAD section to Mojolicious::Lite tutorial
Sebastian Riedel authored
153
ef8a00e @kraih ho ho ho
authored
154 =head2 Routes
155
c564032 fixed typo
sri authored
156 Routes are basically just fancy paths that can contain different kinds of
124ea7e reformatted lite examples to a tutorial
sri authored
157 placeholders.
fdd42b5 @kraih improved Mojolicious::Lite tutorial
authored
158 C<$self> is an instance of L<Mojolicious::Controller> containing both the
159 HTTP request and response.
124ea7e reformatted lite examples to a tutorial
sri authored
160
161 # /foo
c564032 fixed typo
sri authored
162 get '/foo' => sub {
0b889b9 added more examples
sri authored
163 my $self = shift;
3f8a86e added basic http proxy support
Sebastian Riedel authored
164 $self->render(text => 'Hello World!');
0b889b9 added more examples
sri authored
165 };
166
ef8a00e @kraih ho ho ho
authored
167 =head2 Stash
168
229c79d @kraih cleanup
authored
169 The C<stash> is used to pass data to templates, which can be inlined in the
170 C<DATA> section.
d7f702a @kraih added recipe
authored
171
172 # /bar
173 get '/bar' => sub {
174 my $self = shift;
c443fdd @kraih improved recipe
authored
175 $self->stash(one => 23);
176 $self->render('baz', two => 24);
d7f702a @kraih added recipe
authored
177 };
178
179 __DATA__
180
181 @@ baz.html.ep
c443fdd @kraih improved recipe
authored
182 The magic numbers are <%= $one %> and <%= $two %>.
d7f702a @kraih added recipe
authored
183
ef8a00e @kraih ho ho ho
authored
184 =head2 Route Names
185
124ea7e reformatted lite examples to a tutorial
sri authored
186 All routes can have a name associated with them, this allows automatic
4b293ef updated tutorial with tag helpers
Sebastian Riedel authored
187 template detection and back referencing with C<url_for>, C<link_to> and
188 C<form_for>.
832d45d @kraih deprecated wildcard route names in favor of automatically generated defa...
authored
189 Nameless routes get an automatically generated one assigned that is simply
190 equal to the route itself without non-word characters.
124ea7e reformatted lite examples to a tutorial
sri authored
191
192 # /
193 get '/' => 'index';
194
1af6d84 @kraih pod cleanup
authored
195 # /hello
832d45d @kraih deprecated wildcard route names in favor of automatically generated defa...
authored
196 get '/hello';
2f7367e added conditions to MojoX::Routes
Sebastian Riedel authored
197
24b3bff added ->render(text => "") support and many lite examples
sri authored
198 __DATA__
124ea7e reformatted lite examples to a tutorial
sri authored
199
ee5d381 fixed a few cases where exceptions and not found events would result in ...
Sebastian Riedel authored
200 @@ index.html.ep
1af6d84 @kraih pod cleanup
authored
201 <%= link_to Hello => 'hello' %>.
202 <%= link_to Reload => 'index' %>.
124ea7e reformatted lite examples to a tutorial
sri authored
203
1af6d84 @kraih pod cleanup
authored
204 @@ hello.html.ep
205 Hello World!
9ac9059 added more lite examples
sri authored
206
ef8a00e @kraih ho ho ho
authored
207 =head2 Layouts
208
124ea7e reformatted lite examples to a tutorial
sri authored
209 Templates can have layouts.
210
211 # GET /with_layout
885a5e8 added more lite examples
sri authored
212 get '/with_layout' => sub {
213 my $self = shift;
ed7bc44 @kraih pod cleanup
authored
214 $self->render('with_layout');
885a5e8 added more lite examples
sri authored
215 };
124ea7e reformatted lite examples to a tutorial
sri authored
216
885a5e8 added more lite examples
sri authored
217 __DATA__
124ea7e reformatted lite examples to a tutorial
sri authored
218
ee5d381 fixed a few cases where exceptions and not found events would result in ...
Sebastian Riedel authored
219 @@ with_layout.html.ep
ed7bc44 @kraih pod cleanup
authored
220 % title 'Green!';
b61ef91 @kraih pod cleanup
authored
221 % layout 'green';
885a5e8 added more lite examples
sri authored
222 We've got content!
124ea7e reformatted lite examples to a tutorial
sri authored
223
ee5d381 fixed a few cases where exceptions and not found events would result in ...
Sebastian Riedel authored
224 @@ layouts/green.html.ep
93575c8 fixed all html5 tags
Sebastian Riedel authored
225 <!doctype html><html>
8f21bc2 @kraih pod cleanup
authored
226 <head>
227 <title><%= title %></title>
228 <%= base_tag %>
229 </head>
e8cf1a7 updated tutorial with inheritance example
Sebastian Riedel authored
230 <body><%= content %></body>
231 </html>
232
8f21bc2 @kraih pod cleanup
authored
233 All helper generated URLs are usually relative, in combination with the
234 C<base_tag> helper this will keep your applications portable across many
235 different deployment scenarios.
236
ef8a00e @kraih ho ho ho
authored
237 =head2 Blocks
238
e385caf @kraih pod cleanup
authored
239 Template blocks can be used like normal Perl functions and are always
240 delimited by the C<begin> and C<end> keywords.
ec39ab1 added tutorial example for blocks
Sebastian Riedel authored
241
242 # GET /with_block
243 get '/with_block' => 'block';
244
245 __DATA__
246
247 @@ block.html.ep
a9ee8d6 renamed block to begin
Sebastian Riedel authored
248 <% my $link = begin %>
fa261ba cleanup
Sebastian Riedel authored
249 <% my ($url, $name) = @_; %>
a9ee8d6 renamed block to begin
Sebastian Riedel authored
250 Try <%= link_to $url => begin %><%= $name %><% end %>!
6ac074b deprecated old Mojo::Template block syntax and added a very pretty repla...
Sebastian Riedel authored
251 <% end %>
ec39ab1 added tutorial example for blocks
Sebastian Riedel authored
252 <!doctype html><html>
253 <head><title>Sebastians Frameworks!</title></head>
254 <body>
eb527e6 @kraih christmas preparations
authored
255 <%== $link->('http://mojolicio.us', 'Mojolicious') %>
d40100a fixed typo
Sebastian Riedel authored
256 <%== $link->('http://catalystframework.org', 'Catalyst') %>
ec39ab1 added tutorial example for blocks
Sebastian Riedel authored
257 </body>
258 </html>
259
ef8a00e @kraih ho ho ho
authored
260 =head2 Captured Content
261
e391bef @kraih added experimental content_for helper
authored
262 The C<content_for> helper can be used to pass around blocks of captured
263 content.
e8cf1a7 updated tutorial with inheritance example
Sebastian Riedel authored
264
e391bef @kraih added experimental content_for helper
authored
265 # GET /captured
266 get '/captured' => sub {
267 my $self = shift;
268 $self->render('captured');
269 };
2aa74f8 updated example
Sebastian Riedel authored
270
e8cf1a7 updated tutorial with inheritance example
Sebastian Riedel authored
271 __DATA__
272
e391bef @kraih added experimental content_for helper
authored
273 @@ captured.html.ep
b5dbcc0 @kraih improved title helper example
authored
274 % layout 'blue', title => 'Green!';
e391bef @kraih added experimental content_for helper
authored
275 <% content_for header => begin %>
276 <meta http-equiv="Pragma" content="no-cache">
277 <% end %>
278 We've got content!
279 <% content_for header => begin %>
280 <meta http-equiv="Expires" content="-1">
281 <% end %>
282
283 @@ layouts/blue.html.ep
802f808 simplified inheritance example
Sebastian Riedel authored
284 <!doctype html><html>
6ac074b deprecated old Mojo::Template block syntax and added a very pretty repla...
Sebastian Riedel authored
285 <head>
eb923a9 @kraih added experimental title helper
authored
286 <title><%= title %></title>
8f21bc2 @kraih pod cleanup
authored
287 <%= base_tag %>
e391bef @kraih added experimental content_for helper
authored
288 <%= content_for 'header' %>
6ac074b deprecated old Mojo::Template block syntax and added a very pretty repla...
Sebastian Riedel authored
289 </head>
e391bef @kraih added experimental content_for helper
authored
290 <body><%= content %></body>
802f808 simplified inheritance example
Sebastian Riedel authored
291 </html>
e8cf1a7 updated tutorial with inheritance example
Sebastian Riedel authored
292
ef8a00e @kraih ho ho ho
authored
293 =head2 Helpers
294
07da3ee @kraih ho ho ho
authored
295 You can also extend L<Mojolicious> with your own helpers, a list of all built
296 in ones can be found in L<Mojolicious::Plugin::DefaultHelpers> and
297 L<Mojolicious::Plugin::TagHelpers>.
298
299 # "whois" helper
300 app->helper(whois => sub {
301 my $self = shift;
302 my $agent = $self->req->headers->user_agent || 'Anonymous';
303 my $ip = $self->tx->remote_address;
304 return "$agent ($ip)";
305 });
306
307 # GET /secret
308 get '/secret' => sub {
309 my $self = shift;
310 my $user = $self->whois;
311 $self->app->log->debug("Request from $user.");
832d45d @kraih deprecated wildcard route names in favor of automatically generated defa...
authored
312 };
07da3ee @kraih ho ho ho
authored
313
314 __DATA__
315
316 @@ secret.html.ep
317 We know who you are <%= whois %>.
318
ef8a00e @kraih ho ho ho
authored
319 =head2 Placeholders
320
124ea7e reformatted lite examples to a tutorial
sri authored
321 Route placeholders allow capturing parts of a request path until a C</> or
5de8c36 added routes captures to params in Mojolicious
Sebastian Riedel authored
322 C<.> separator occurs, results will be stored by name in the C<stash> and
323 C<param>.
124ea7e reformatted lite examples to a tutorial
sri authored
324
899c130 pod cleanup
Sebastian Riedel authored
325 # /foo/* (everything except "/" and ".")
326 # /foo/test
327 # /foo/test123
124ea7e reformatted lite examples to a tutorial
sri authored
328 get '/foo/:bar' => sub {
f90f056 fixed typo
sri authored
329 my $self = shift;
330 my $bar = $self->stash('bar');
3f8a86e added basic http proxy support
Sebastian Riedel authored
331 $self->render(text => "Our :bar placeholder matched $bar");
9ac9059 added more lite examples
sri authored
332 };
24b3bff added ->render(text => "") support and many lite examples
sri authored
333
899c130 pod cleanup
Sebastian Riedel authored
334 # /*something/foo (everything except "/" and ".")
335 # /test/foo
336 # /test123/foo
124ea7e reformatted lite examples to a tutorial
sri authored
337 get '/(:bar)something/foo' => sub {
f90f056 fixed typo
sri authored
338 my $self = shift;
5de8c36 added routes captures to params in Mojolicious
Sebastian Riedel authored
339 my $bar = $self->param('bar');
3f8a86e added basic http proxy support
Sebastian Riedel authored
340 $self->render(text => "Our :bar placeholder matched $bar");
24b3bff added ->render(text => "") support and many lite examples
sri authored
341 };
342
ef8a00e @kraih ho ho ho
authored
343 =head2 Relaxed Placeholders
344
124ea7e reformatted lite examples to a tutorial
sri authored
345 Relaxed placeholders allow matching of everything until a C</> occurs.
346
899c130 pod cleanup
Sebastian Riedel authored
347 # /*/hello (everything except "/")
348 # /test/hello
349 # /test123/hello
350 # /test.123/hello
351 get '/(.you)/hello' => sub {
c8d4f8f updated pod
Sebastian Riedel authored
352 shift->render('groovy');
885a5e8 added more lite examples
sri authored
353 };
124ea7e reformatted lite examples to a tutorial
sri authored
354
885a5e8 added more lite examples
sri authored
355 __DATA__
124ea7e reformatted lite examples to a tutorial
sri authored
356
ee5d381 fixed a few cases where exceptions and not found events would result in ...
Sebastian Riedel authored
357 @@ groovy.html.ep
358 Your name is <%= $you %>.
885a5e8 added more lite examples
sri authored
359
ef8a00e @kraih ho ho ho
authored
360 =head2 Wildcard Placeholders
361
124ea7e reformatted lite examples to a tutorial
sri authored
362 Wildcard placeholders allow matching absolutely everything, including
363 C</> and C<.>.
364
899c130 pod cleanup
Sebastian Riedel authored
365 # /hello/* (everything)
366 # /hello/test
367 # /hello/test123
368 # /hello/test.123/test/123
885a5e8 added more lite examples
sri authored
369 get '/hello/(*you)' => sub {
c8d4f8f updated pod
Sebastian Riedel authored
370 shift->render('groovy');
885a5e8 added more lite examples
sri authored
371 };
19499ca fixed typo
sri authored
372
885a5e8 added more lite examples
sri authored
373 __DATA__
19499ca fixed typo
sri authored
374
ee5d381 fixed a few cases where exceptions and not found events would result in ...
Sebastian Riedel authored
375 @@ groovy.html.ep
376 Your name is <%= $you %>.
885a5e8 added more lite examples
sri authored
377
ef8a00e @kraih ho ho ho
authored
378 =head2 HTTP Methods
379
124ea7e reformatted lite examples to a tutorial
sri authored
380 Routes can be restricted to specific request methods.
381
382 # GET /bye
3f8a86e added basic http proxy support
Sebastian Riedel authored
383 get '/bye' => sub { shift->render(text => 'Bye!') };
124ea7e reformatted lite examples to a tutorial
sri authored
384
385 # POST /bye
3f8a86e added basic http proxy support
Sebastian Riedel authored
386 post '/bye' => sub { shift->render(text => 'Bye!') };
124ea7e reformatted lite examples to a tutorial
sri authored
387
388 # GET|POST|DELETE /bye
389 any [qw/get post delete/] => '/bye' => sub {
3f8a86e added basic http proxy support
Sebastian Riedel authored
390 shift->render(text => 'Bye!');
124ea7e reformatted lite examples to a tutorial
sri authored
391 };
392
393 # /baz
394 any '/baz' => sub {
1ff4e12 fixed typo
sri authored
395 my $self = shift;
124ea7e reformatted lite examples to a tutorial
sri authored
396 my $method = $self->req->method;
3f8a86e added basic http proxy support
Sebastian Riedel authored
397 $self->render(text => "You called /baz with $method");
124ea7e reformatted lite examples to a tutorial
sri authored
398 };
399
ef8a00e @kraih ho ho ho
authored
400 =head2 Route Constraints
401
124ea7e reformatted lite examples to a tutorial
sri authored
402 All placeholders get compiled to a regex internally, with regex constraints
403 this process can be easily customized.
404
17220cb @kraih improved example
authored
405 # /* (digits)
406 any '/:foo' => [foo => qr/\d+/] => sub {
407 my $self = shift;
408 my $foo = $self->param('foo');
409 $self->render(text => "Our :foo placeholder matched $foo");
410 };
411
412 # /* (everything else)
413 any '/:bar' => [bar => qr/.*/] => sub {
24b3bff added ->render(text => "") support and many lite examples
sri authored
414 my $self = shift;
5de8c36 added routes captures to params in Mojolicious
Sebastian Riedel authored
415 my $bar = $self->param('bar');
3f8a86e added basic http proxy support
Sebastian Riedel authored
416 $self->render(text => "Our :bar placeholder matched $bar");
24b3bff added ->render(text => "") support and many lite examples
sri authored
417 };
418
ef8a00e @kraih ho ho ho
authored
419 =head2 Optional Placeholders
420
124ea7e reformatted lite examples to a tutorial
sri authored
421 Routes allow default values to make placeholders optional.
422
423 # /hello/*
24b3bff added ->render(text => "") support and many lite examples
sri authored
424 get '/hello/:name' => {name => 'Sebastian'} => sub {
425 my $self = shift;
c8d4f8f updated pod
Sebastian Riedel authored
426 $self->render('groovy', format => 'txt');
24b3bff added ->render(text => "") support and many lite examples
sri authored
427 };
124ea7e reformatted lite examples to a tutorial
sri authored
428
24b3bff added ->render(text => "") support and many lite examples
sri authored
429 __DATA__
124ea7e reformatted lite examples to a tutorial
sri authored
430
ee5d381 fixed a few cases where exceptions and not found events would result in ...
Sebastian Riedel authored
431 @@ groovy.txt.ep
432 My name is <%= $name %>.
24b3bff added ->render(text => "") support and many lite examples
sri authored
433
ef8a00e @kraih ho ho ho
authored
434 =head2 A Little Bit Of Everything
435
124ea7e reformatted lite examples to a tutorial
sri authored
436 All those features can be easily used together.
24b3bff added ->render(text => "") support and many lite examples
sri authored
437
124ea7e reformatted lite examples to a tutorial
sri authored
438 # /everything/*?name=*
24b3bff added ->render(text => "") support and many lite examples
sri authored
439 get '/everything/:stuff' => [stuff => qr/\d+/] => {stuff => 23} => sub {
c8d4f8f updated pod
Sebastian Riedel authored
440 shift->render('welcome');
24b3bff added ->render(text => "") support and many lite examples
sri authored
441 };
124ea7e reformatted lite examples to a tutorial
sri authored
442
24b3bff added ->render(text => "") support and many lite examples
sri authored
443 __DATA__
124ea7e reformatted lite examples to a tutorial
sri authored
444
ee5d381 fixed a few cases where exceptions and not found events would result in ...
Sebastian Riedel authored
445 @@ welcome.html.ep
446 Stuff is <%= $stuff %>.
447 Query param name is <%= param 'name' %>.
24b3bff added ->render(text => "") support and many lite examples
sri authored
448
124ea7e reformatted lite examples to a tutorial
sri authored
449 Here's a fully functional example for a html form handling application using
450 multiple features at once.
451
452 #!/usr/bin/env perl
453
454 use Mojolicious::Lite;
455
456 get '/' => 'index';
457
4b293ef updated tutorial with tag helpers
Sebastian Riedel authored
458 post '/test' => sub {
124ea7e reformatted lite examples to a tutorial
sri authored
459 my $self = shift;
460
b26e6b6 added param to Mojolicious::Controller
Sebastian Riedel authored
461 my $groovy = $self->param('groovy') || 'Austin Powers';
124ea7e reformatted lite examples to a tutorial
sri authored
462 $groovy =~ s/[^\w\s]+//g;
463
464 $self->render(
465 template => 'welcome',
b61ef91 @kraih pod cleanup
authored
466 title => 'Welcome!',
124ea7e reformatted lite examples to a tutorial
sri authored
467 layout => 'funky',
468 groovy => $groovy
469 );
4b293ef updated tutorial with tag helpers
Sebastian Riedel authored
470 } => 'test';
124ea7e reformatted lite examples to a tutorial
sri authored
471
80f8c48 switched to app->start instead of shagadelic as default way to start Moj...
Sebastian Riedel authored
472 app->start;
124ea7e reformatted lite examples to a tutorial
sri authored
473 __DATA__
474
ee5d381 fixed a few cases where exceptions and not found events would result in ...
Sebastian Riedel authored
475 @@ index.html.ep
eb923a9 @kraih added experimental title helper
authored
476 % title 'Groovy!';
b61ef91 @kraih pod cleanup
authored
477 % layout 'funky';
124ea7e reformatted lite examples to a tutorial
sri authored
478 Who is groovy?
a9ee8d6 renamed block to begin
Sebastian Riedel authored
479 <%= form_for test => (method => 'post') => begin %>
a513ea9 added even more tag helpers
Sebastian Riedel authored
480 <%= text_field 'groovy' %>
481 <%= submit_button 'Woosh!' %>
6ac074b deprecated old Mojo::Template block syntax and added a very pretty repla...
Sebastian Riedel authored
482 <% end %>
124ea7e reformatted lite examples to a tutorial
sri authored
483
ee5d381 fixed a few cases where exceptions and not found events would result in ...
Sebastian Riedel authored
484 @@ welcome.html.ep
485 <%= $groovy %> is groovy!
e8cf1a7 updated tutorial with inheritance example
Sebastian Riedel authored
486 <%= include 'menu' %>
124ea7e reformatted lite examples to a tutorial
sri authored
487
ee5d381 fixed a few cases where exceptions and not found events would result in ...
Sebastian Riedel authored
488 @@ menu.html.ep
a9ee8d6 renamed block to begin
Sebastian Riedel authored
489 <%= link_to index => begin %>
1f44d4f cleanup
Sebastian Riedel authored
490 Try again
6ac074b deprecated old Mojo::Template block syntax and added a very pretty repla...
Sebastian Riedel authored
491 <% end %>
124ea7e reformatted lite examples to a tutorial
sri authored
492
ee5d381 fixed a few cases where exceptions and not found events would result in ...
Sebastian Riedel authored
493 @@ layouts/funky.html.ep
93575c8 fixed all html5 tags
Sebastian Riedel authored
494 <!doctype html><html>
8f21bc2 @kraih pod cleanup
authored
495 <head>
496 <title><%= title %></title>
497 <%= base_tag %>
498 </head>
e8cf1a7 updated tutorial with inheritance example
Sebastian Riedel authored
499 <body><%= content %>
97d759b cleanup
Sebastian Riedel authored
500 </body>
124ea7e reformatted lite examples to a tutorial
sri authored
501 </html>
502
ef8a00e @kraih ho ho ho
authored
503 =head2 Under
504
3f8a86e added basic http proxy support
Sebastian Riedel authored
505 Authentication and code shared between multiple routes can be realized easily
506 with the C<under> statement.
507 All following routes are only evaluated if the C<under> callback returned a
ab43fc9 fixed bridges/ladders and added tests
Sebastian Riedel authored
508 true value.
509
510 use Mojolicious::Lite;
511
512 # Authenticate based on name parameter
3f8a86e added basic http proxy support
Sebastian Riedel authored
513 under sub {
ab43fc9 fixed bridges/ladders and added tests
Sebastian Riedel authored
514 my $self = shift;
515
516 # Authenticated
517 my $name = $self->param('name') || '';
518 return 1 if $name eq 'Bender';
519
520 # Not authenticated
521 $self->render('denied');
522 return;
523 };
524
3f8a86e added basic http proxy support
Sebastian Riedel authored
525 # GET / (with authentication)
ab43fc9 fixed bridges/ladders and added tests
Sebastian Riedel authored
526 get '/' => 'index';
527
80f8c48 switched to app->start instead of shagadelic as default way to start Moj...
Sebastian Riedel authored
528 app->start;
ab43fc9 fixed bridges/ladders and added tests
Sebastian Riedel authored
529 __DATA__;
530
531 @@ denied.html.ep
532 You are not Bender, permission denied!
533
534 @@ index.html.ep
535 Hi Bender!
536
5a92724 fixed a small under bug in Mojolicious::Lite
Sebastian Riedel authored
537 Prefixing multiple routes is another good use for C<under>.
538
539 use Mojolicious::Lite;
540
541 # /foo
542 under '/foo';
543
544 # GET /foo/bar
545 get '/bar' => sub { shift->render(text => 'bar!') };
546
547 # GET /foo/baz
548 get '/baz' => sub { shift->render(text => 'baz!') };
549
550 app->start;
551
ef8a00e @kraih ho ho ho
authored
552 =head2 Conditions
553
5d59ed2 fixed typo
Sebastian Riedel authored
554 Conditions such as C<agent> allow even more powerful route constructs.
2f7367e added conditions to MojoX::Routes
Sebastian Riedel authored
555
556 # /foo
557 get '/foo' => (agent => qr/Firefox/) => sub {
3f8a86e added basic http proxy support
Sebastian Riedel authored
558 shift->render(
4b293ef updated tutorial with tag helpers
Sebastian Riedel authored
559 text => 'Congratulations, you are using a cool browser!');
3cbb746 @kraih fixed typos
authored
560 };
2f7367e added conditions to MojoX::Routes
Sebastian Riedel authored
561
562 # /foo
563 get '/foo' => (agent => qr/Internet Explorer/) => sub {
3f8a86e added basic http proxy support
Sebastian Riedel authored
564 shift->render(
4b293ef updated tutorial with tag helpers
Sebastian Riedel authored
565 text => 'Dude, you really need to upgrade to Firefox!');
3cbb746 @kraih fixed typos
authored
566 };
2f7367e added conditions to MojoX::Routes
Sebastian Riedel authored
567
ef8a00e @kraih ho ho ho
authored
568 =head2 Formats
569
124ea7e reformatted lite examples to a tutorial
sri authored
570 Formats can be automatically detected by looking at file extensions.
571
572 # /detection.html
573 # /detection.txt
24b3bff added ->render(text => "") support and many lite examples
sri authored
574 get '/detection' => sub {
575 my $self = shift;
c8d4f8f updated pod
Sebastian Riedel authored
576 $self->render('detected');
24b3bff added ->render(text => "") support and many lite examples
sri authored
577 };
124ea7e reformatted lite examples to a tutorial
sri authored
578
24b3bff added ->render(text => "") support and many lite examples
sri authored
579 __DATA__
124ea7e reformatted lite examples to a tutorial
sri authored
580
ee5d381 fixed a few cases where exceptions and not found events would result in ...
Sebastian Riedel authored
581 @@ detected.html.ep
93575c8 fixed all html5 tags
Sebastian Riedel authored
582 <!doctype html><html>
97d759b cleanup
Sebastian Riedel authored
583 <head><title>Detected!</title></head>
584 <body>HTML was detected.</body>
24b3bff added ->render(text => "") support and many lite examples
sri authored
585 </html>
124ea7e reformatted lite examples to a tutorial
sri authored
586
ee5d381 fixed a few cases where exceptions and not found events would result in ...
Sebastian Riedel authored
587 @@ detected.txt.ep
24b3bff added ->render(text => "") support and many lite examples
sri authored
588 TXT was detected.
589
ef8a00e @kraih ho ho ho
authored
590 =head2 Sessions
591
15a91a4 pod cleanup
Sebastian Riedel authored
592 Signed cookie based sessions just work out of the box as soon as you start
593 using them.
0851ec6 cleanup
Sebastian Riedel authored
594 The C<flash> can be used to store values that will only be available for the
595 next request (unlike C<stash>, which is only available for the current
596 request), this is very useful in combination with C<redirect_to>.
9fcb9d0 added login example to the tutorial demonstrating sessions
Sebastian Riedel authored
597
598 use Mojolicious::Lite;
599
600 get '/login' => sub {
601 my $self = shift;
602 my $name = $self->param('name') || '';
603 my $pass = $self->param('pass') || '';
604 return $self->render unless $name eq 'sebastian' && $pass eq '1234';
605 $self->session(name => $name);
b42a2c8 also use flash in the session example
Sebastian Riedel authored
606 $self->flash(message => 'Thanks for logging in!');
9fcb9d0 added login example to the tutorial demonstrating sessions
Sebastian Riedel authored
607 $self->redirect_to('index');
608 } => 'login';
609
610 get '/' => sub {
611 my $self = shift;
612 return $self->redirect_to('login') unless $self->session('name');
613 $self->render;
614 } => 'index';
615
616 get '/logout' => sub {
617 my $self = shift;
618 $self->session(expires => 1);
619 $self->redirect_to('index');
620 } => 'logout';
621
80f8c48 switched to app->start instead of shagadelic as default way to start Moj...
Sebastian Riedel authored
622 app->start;
9fcb9d0 added login example to the tutorial demonstrating sessions
Sebastian Riedel authored
623 __DATA__
624
625 @@ layouts/default.html.ep
626 <!doctype html><html>
8f21bc2 @kraih pod cleanup
authored
627 <head>
628 <title><%= title %></title>
d929cf8 @kraih pod cleanup
authored
629 <%= base_tag %>
8f21bc2 @kraih pod cleanup
authored
630 </head>
9fcb9d0 added login example to the tutorial demonstrating sessions
Sebastian Riedel authored
631 <body><%= content %></body>
632 </html>
633
634 @@ login.html.ep
635 % layout 'default';
eb923a9 @kraih added experimental title helper
authored
636 % title 'Login';
a9ee8d6 renamed block to begin
Sebastian Riedel authored
637 <%= form_for login => begin %>
9fcb9d0 added login example to the tutorial demonstrating sessions
Sebastian Riedel authored
638 <% if (param 'name') { %>
9e0172c @kraih default to lazy html5 style
authored
639 <b>Wrong name or password, please try again.</b><br>
9fcb9d0 added login example to the tutorial demonstrating sessions
Sebastian Riedel authored
640 <% } %>
9e0172c @kraih default to lazy html5 style
authored
641 Name:<br>
642 <%= text_field 'name' %><br>
643 Password:<br>
644 <%= password_field 'pass' %><br>
a513ea9 added even more tag helpers
Sebastian Riedel authored
645 <%= submit_button 'Login' %>
6ac074b deprecated old Mojo::Template block syntax and added a very pretty repla...
Sebastian Riedel authored
646 <% end %>
9fcb9d0 added login example to the tutorial demonstrating sessions
Sebastian Riedel authored
647
648 @@ index.html.ep
649 % layout 'default';
eb923a9 @kraih added experimental title helper
authored
650 % title 'Welcome';
b42a2c8 also use flash in the session example
Sebastian Riedel authored
651 <% if (my $message = flash 'message' ) { %>
9e0172c @kraih default to lazy html5 style
authored
652 <b><%= $message %></b><br>
b42a2c8 also use flash in the session example
Sebastian Riedel authored
653 <% } %>
9e0172c @kraih default to lazy html5 style
authored
654 Welcome <%= session 'name' %>!<br>
a9ee8d6 renamed block to begin
Sebastian Riedel authored
655 <%= link_to logout => begin %>
1f44d4f cleanup
Sebastian Riedel authored
656 Logout
6ac074b deprecated old Mojo::Template block syntax and added a very pretty repla...
Sebastian Riedel authored
657 <% end %>
9fcb9d0 added login example to the tutorial demonstrating sessions
Sebastian Riedel authored
658
ef8a00e @kraih ho ho ho
authored
659 =head2 Secret
660
305e6bc mention secret passphrase in tutorial
Sebastian Riedel authored
661 Note that you should use a custom C<secret> to make signed cookies really secure.
662
663 app->secret('My secret passphrase here!');
664
ef8a00e @kraih ho ho ho
authored
665 =head2 HTTP Client
666
be2bc55 pod updates
Sebastian Riedel authored
667 A full featured HTTP 1.1 and WebSocket client is built right in.
83d6678 mention Mojo::DOM in tutorial
Sebastian Riedel authored
668 Especially in combination with L<Mojo::JSON> and L<Mojo::DOM> this can be a
669 very powerful tool.
be2bc55 pod updates
Sebastian Riedel authored
670
671 get '/test' => sub {
672 my $self = shift;
3f8a86e added basic http proxy support
Sebastian Riedel authored
673 $self->render(
eb527e6 @kraih christmas preparations
authored
674 data => $self->client->get('http://mojolicio.us')->res->body);
be2bc55 pod updates
Sebastian Riedel authored
675 };
676
ef8a00e @kraih ho ho ho
authored
677 =head2 WebSockets
678
be2bc55 pod updates
Sebastian Riedel authored
679 WebSocket applications have never been this easy before.
680
681 websocket '/echo' => sub {
682 my $self = shift;
74763dd deprecated finished and receive_message in favor of on_finish and on_mes...
Sebastian Riedel authored
683 $self->on_message(sub {
be2bc55 pod updates
Sebastian Riedel authored
684 my ($self, $message) = @_;
685 $self->send_message("echo: $message");
686 });
687 };
688
ef8a00e @kraih ho ho ho
authored
689 =head2 External Templates
690
124ea7e reformatted lite examples to a tutorial
sri authored
691 External templates will be searched by the renderer in a C<templates>
692 directory.
693
694 # /external
23161b3 added more lite examples
sri authored
695 any '/external' => sub {
696 my $self = shift;
ad55fb5 updated pod
Sebastian Riedel authored
697
ee5d381 fixed a few cases where exceptions and not found events would result in ...
Sebastian Riedel authored
698 # templates/foo/bar.html.ep
c8d4f8f updated pod
Sebastian Riedel authored
699 $self->render('foo/bar');
23161b3 added more lite examples
sri authored
700 };
701
ef8a00e @kraih ho ho ho
authored
702 =head2 Static Files
703
19a186e added experimental base64 support for static files in the DATA section
Sebastian Riedel authored
704 Static files will be automatically served from the C<DATA> section
705 (even Base 64 encoded) or a C<public> directory if it exists.
82dfd94 protect inline templates from static dispatcher
Sebastian Riedel authored
706
707 @@ something.js
708 alert('hello!');
124ea7e reformatted lite examples to a tutorial
sri authored
709
0d81f76 made inline base64 files a little prettier
Sebastian Riedel authored
710 @@ test.txt (base64)
19a186e added experimental base64 support for static files in the DATA section
Sebastian Riedel authored
711 dGVzdCAxMjMKbGFsYWxh
712
23161b3 added more lite examples
sri authored
713 % mkdir public
714 % mv something.js public/something.js
715
ef8a00e @kraih ho ho ho
authored
716 =head2 Testing
717
a760263 added lite testing example
Sebastian Riedel authored
718 Testing your application is as easy as creating a C<t> directory and filling
a821f78 added external lite app test
Sebastian Riedel authored
719 it with normal Perl unit tests.
720 Some plugins depend on the actual script name, so a test file for the
721 application C<myapp.pl> should be named C<t/myapp.t>.
a760263 added lite testing example
Sebastian Riedel authored
722
723 use Test::More tests => 3;
724 use Test::Mojo;
725
726 use FindBin;
210bb96 made lite test recipe more portable
Sebastian Riedel authored
727 $ENV{MOJO_HOME} = "$FindBin::Bin/../";
728 require "$ENV{MOJO_HOME}/myapp.pl";
a760263 added lite testing example
Sebastian Riedel authored
729
730 my $t = Test::Mojo->new;
731 $t->get_ok('/')->status_is(200)->content_like(qr/Funky!/);
732
733 Run all unit tests with the C<test> command.
734
735 % ./myapp.pl test
736
9e52f8e default to silent tests in Test::Mojo
Sebastian Riedel authored
737 To make your tests more noisy and show you all log messages you can also
738 change the application log level directly in your test files.
0acf934 pod updates
Sebastian Riedel authored
739
9e52f8e default to silent tests in Test::Mojo
Sebastian Riedel authored
740 $t->app->log->level('debug');
0acf934 pod updates
Sebastian Riedel authored
741
ef8a00e @kraih ho ho ho
authored
742 =head2 Mode
743
124ea7e reformatted lite examples to a tutorial
sri authored
744 To disable debug messages later in a production setup you can change the
745 L<Mojolicious> mode, default will be C<development>.
746
862c71c added experimental support for --mode and --home options to all Mojolici...
Sebastian Riedel authored
747 % ./myapp.pl --mode production
f3acdb1 added more lite examples
sri authored
748
ef8a00e @kraih ho ho ho
authored
749 =head2 Logging
750
124ea7e reformatted lite examples to a tutorial
sri authored
751 Log messages will be automatically written to a C<log/$mode.log> file if a
752 C<log> directory exists.
753
5e23803 fixed typo
sri authored
754 % mkdir log
755
124ea7e reformatted lite examples to a tutorial
sri authored
756 For more control the L<Mojolicious> instance can be accessed directly.
757
885a5e8 added more lite examples
sri authored
758 app->log->level('error');
3f8a86e added basic http proxy support
Sebastian Riedel authored
759 app->routes->route('/foo/:bar')->via('get')->to(cb => sub {
885a5e8 added more lite examples
sri authored
760 my $self = shift;
3f8a86e added basic http proxy support
Sebastian Riedel authored
761 $self->render(text => 'Hello Mojo!');
885a5e8 added more lite examples
sri authored
762 });
763
ef8a00e @kraih ho ho ho
authored
764 =head2 Growing
765
124ea7e reformatted lite examples to a tutorial
sri authored
766 In case a lite app needs to grow, lite and real L<Mojolicous> applications
767 can be easily mixed to make the transition process very smooth.
768
e491cf2 added example for mixed mojolicious and lite app
sri authored
769 package MyApp::Foo;
064d42f @kraih use Mojo::Base consistently
authored
770 use Mojo::Base 'Mojolicious::Controller';
124ea7e reformatted lite examples to a tutorial
sri authored
771
3f8a86e added basic http proxy support
Sebastian Riedel authored
772 sub index { shift->render(text => 'It works!') }
124ea7e reformatted lite examples to a tutorial
sri authored
773
e491cf2 added example for mixed mojolicious and lite app
sri authored
774 package main;
775 use Mojolicious::Lite;
124ea7e reformatted lite examples to a tutorial
sri authored
776
3f8a86e added basic http proxy support
Sebastian Riedel authored
777 get '/bar' => sub { shift->render(text => 'This too!') };
124ea7e reformatted lite examples to a tutorial
sri authored
778
e491cf2 added example for mixed mojolicious and lite app
sri authored
779 app->routes->namespace('MyApp');
f5439a5 cleanup
Sebastian Riedel authored
780 app->routes->route('/foo/:action')->via('get')->to('foo#index');
a146626 added Mojolicious::Lite
sri authored
781
80f8c48 switched to app->start instead of shagadelic as default way to start Moj...
Sebastian Riedel authored
782 app->start;
a146626 added Mojolicious::Lite
sri authored
783
c43396b updated tutorial
Sebastian Riedel authored
784 There is also a helper command to generate a full L<Mojolicious> example that
3e366a9 updated tutorial
Sebastian Riedel authored
785 will let you explore the astonishing similarities between
786 L<Mojolicious::Lite> and L<Mojolicious> applications.
787 Both share about 99% of the same code, so almost everything you learned in
788 this tutorial applies there too. :)
c43396b updated tutorial
Sebastian Riedel authored
789
e51aefb replaced the "mojolicious" command with "mojo", for convenience
Sebastian Riedel authored
790 % mojo generate app
c43396b updated tutorial
Sebastian Riedel authored
791
792 Have fun!
793
79a24c9 list functions in Mojolicious::Lite
Sebastian Riedel authored
794 =head1 FUNCTIONS
795
796 L<Mojolicious::Lite> implements the following functions.
797
798 =head2 C<any>
799
800 my $route = any '/:foo' => sub {...};
801 my $route = any [qw/get post/] => '/:foo' => sub {...};
802
803 Generate route matching any of the listed HTTP request methods or all.
804 See also the tutorial above for more argument variations.
805
806 =head2 C<app>
807
808 my $app = app;
809
810 The L<Mojolicious::Lite> application.
811
998570d @kraih added put and del functions to Mojolicious::Lite
authored
812 =head2 C<del>
813
814 my $route = del '/:foo' => sub {...};
815
816 Generate route matching only C<DELETE> requests.
817 See also the tutorial above for more argument variations.
818
79a24c9 list functions in Mojolicious::Lite
Sebastian Riedel authored
819 =head2 C<get>
820
821 my $route = get '/:foo' => sub {...};
822
823 Generate route matching only C<GET> requests.
824 See also the tutorial above for more argument variations.
825
826 =head2 C<plugin>
827
828 plugin 'something';
829 plugin 'something', foo => 23;
830 plugin 'something', {foo => 23};
831 plugin 'Foo::Bar';
832 plugin 'Foo::Bar', foo => 23;
833 plugin 'Foo::Bar', {foo => 23};
834
835 Load a plugin.
836
837 =head2 C<post>
838
839 my $route = post '/:foo' => sub {...};
840
841 Generate route matching only C<POST> requests.
842 See also the tutorial above for more argument variations.
843
998570d @kraih added put and del functions to Mojolicious::Lite
authored
844 =head2 C<put>
845
846 my $route = put '/:foo' => sub {...};
847
848 Generate route matching only C<PUT> requests.
849 See also the tutorial above for more argument variations.
850
79a24c9 list functions in Mojolicious::Lite
Sebastian Riedel authored
851 =head2 C<under>
852
853 my $route = under sub {...};
854 my $route = under '/:foo';
855
856 Generate bridge to which all following routes are automatically appended.
857 See also the tutorial above for more argument variations.
858
859 =head2 C<websocket>
860
861 my $route = websocket '/:foo' => sub {...};
862
863 Generate route matching only C<WebSocket> handshakes.
864 See also the tutorial above for more argument variations.
865
a146626 added Mojolicious::Lite
sri authored
866 =head1 ATTRIBUTES
867
868 L<Mojolicious::Lite> inherits all attributes from L<Mojolicious>.
869
870 =head1 METHODS
871
fcf3ef7 added the ability to have multiple Mojolicious::Lite apps at once (Mojol...
Sebastian Riedel authored
872 L<Mojolicious::Lite> inherits all methods from L<Mojolicious>.
a146626 added Mojolicious::Lite
sri authored
873
d49a4ee pod cleanup
Sebastian Riedel authored
874 =head1 SEE ALSO
875
eb527e6 @kraih christmas preparations
authored
876 L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
d49a4ee pod cleanup
Sebastian Riedel authored
877
a146626 added Mojolicious::Lite
sri authored
878 =cut
Something went wrong with that request. Please try again.