controller_class

mode

my $mode = $app->mode;
$app = $app->mode('production');

The operating mode for your application, defaults to the value of the MOJO_MODE environment variable or development. You can also add per mode logic to your application by defining methods named ${mode}_mode in the application class, which will be called right before startup.

Right before calling startup and mode specific methods, Mojolicious will pick up the current mode, name the log file after it and raise the log level from debug to info if it has a value other than development.

secret

my $secret = $app->secret;
$app = $app->secret('passw0rd');

A secret passphrase used for signed cookies and the like, defaults to the application name which is not very secure, so you should change it!!! As long as you are using the insecure default there will be debug messages in the log file reminding you to change your passphrase.

types

Responsible for connecting file extensions with MIME types, defaults to a Mojolicious::Types object.

$app->types->type(twt => 'text/tweet');

METHODS

Mojolicious inherits all methods from Mojo and implements the following new ones.

new

my $app = Mojolicious->new;

Construct a new Mojolicious application, calling ${mode}_mode and startup in the process. Will automatically detect your home directory and set up logging based on your current operating mode. Also sets up the renderer, static dispatcher and a default set of plugins.

These hooks are currently available and are emitted in the listed order:

after_build_tx

Emitted right after the transaction is built and before the HTTP request gets parsed.

$app->hook(after_build_tx => sub {
my ($tx, $app) = @_;
...
});

This is a very powerful hook and should not be used lightly, it makes some rather advanced features such as upload progress bars possible. Note that this hook will not work for embedded applications. (Passed the transaction and application object)

before_dispatch

Emitted right before the static dispatcher and router start their work.

$app->hook(before_dispatch => sub {
my $c = shift;
...
});

Very useful for rewriting incoming requests and other preprocessing tasks. (Passed the default controller object)

after_static_dispatch

Emitted in reverse order after the static dispatcher determined if a static file should be served and before the router starts its work.

Emitted in reverse order after a response has been rendered. Note that this hook can trigger before after_static_dispatch due to its dynamic nature, and with embedded applications will only work for the application rendering the response.

$app->hook(after_dispatch => sub {
my $c = shift;
...
});

Useful for rewriting outgoing responses and other post-processing tasks. (Passed the current controller object)

around_dispatch

Emitted right before the before_dispatch hook and wraps around the whole dispatch process, so you have to manually forward to the next hook if you want to continue the chain. Default exception handling with "render_exception" in Mojolicious::Controller is the first hook in the chain and a call to dispatch the last, yours will be in between.

This is a very powerful hook and should not be used lightly, it allows you to customize application wide exception handling for example, consider it the sledgehammer in your toolbox. (Passed a callback leading to the next hook and the default controller object)