DESCRIPTION

TUTORIAL

A quick example driven introduction to the wonders of Mojolicious::Lite. Most of what you'll learn here also applies to normal Mojolicious applications.

Hello World

A simple Hello World application can look like this, strict, warnings, utf8 and Perl 5.10 features are automatically enabled and a few functions imported when you use Mojolicious::Lite, turning your script into a full featured web application.

Routes

Routes are basically just fancy paths that can contain different kinds of placeholders and usually lead to an action. The first argument passed to all actions (the invocant $self) is a Mojolicious::Controller object containing both the HTTP request and response.

Just make sure not to use ^ and $ or capturing groups (...), because placeholders become part of a larger regular expression internally, (?:...) is fine though.

Under

Authentication and code shared between multiple routes can be realized easily with bridge routes generated by the "under" statement. All following routes are only evaluated if the callback returned a true value.

File uploads

All files uploaded via multipart/form-data request are automatically available as Mojo::Upload objects. And you don't have to worry about memory usage, because all files above 250KB will be automatically streamed into a temporary file.

To protect you from excessively large files there is also a limit of 10MB by default, which you can tweak with the attribute "max_message_size" in Mojo::Message or MOJO_MAX_MESSAGE_SIZE environment variable.

The default operating mode will usually be development and can be changed with command line options or the MOJO_MODE and PLACK_ENV environment variables. A mode other than development will raise the log level from debug to info.

$ ./myapp.pl daemon -m production

All messages will be written to STDERR or a log/$mode.log file if a log directory exists.

$ mkdir log

Mode changes also affect a few other aspects of the framework, such as mode specific exception and not_found templates.

Testing

Testing your application is as easy as creating a t directory and filling it with normal Perl tests, which can be a lot of fun thanks to Test::Mojo.