.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Mojolicious::Lite 3"
.TH Mojolicious::Lite 3 "2023-03-08" "perl v5.26.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Mojolicious::Lite \- Micro real\-time web framework
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 2
\& # Automatically enables "strict", "warnings", "utf8" and Perl 5.16 features
\& use Mojolicious::Lite \-signatures;
\&
\& # Route with placeholder
\& get \*(Aq/:foo\*(Aq => sub ($c) {
\& my $foo = $c\->param(\*(Aqfoo\*(Aq);
\& $c\->render(text => "Hello from $foo.");
\& };
\&
\& # Start the Mojolicious command system
\& app\->start;
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
Mojolicious::Lite is a tiny domain specific language built around Mojolicious, made up of only about a dozen Perl
functions.
.PP
On Perl 5.20+ you can also use a \f(CW\*(C`\-signatures\*(C'\fR flag to enable support for subroutine
signatures.
.PP
.Vb 1
\& use Mojolicious::Lite \-signatures;
\&
\& get \*(Aq/:foo\*(Aq => sub ($c) {
\& my $foo = $c\->param(\*(Aqfoo\*(Aq);
\& $c\->render(text => "Hello from $foo.");
\& };
\&
\& app\->start;
.Ve
.PP
See Mojolicious::Guides::Tutorial for more!
.SH "GROWING"
.IX Header "GROWING"
While Mojolicious::Guides::Growing will give you a detailed introduction to growing a Mojolicious::Lite prototype
into a well-structured Mojolicious application, here we have collected a few snippets that illustrate very well just
how similar both of them are.
.SS "Routes"
.IX Subsection "Routes"
The functions \*(L"get\*(R", \*(L"post\*(R" and friends all have equivalent methods.
.PP
.Vb 4
\& # Mojolicious::Lite
\& get \*(Aq/foo\*(Aq => sub ($c) {
\& $c\->render(text => \*(AqHello World!\*(Aq);
\& };
\&
\& # Mojolicious
\& sub startup ($self) {
\&
\& my $routes = $self\->routes;
\& $routes\->get(\*(Aq/foo\*(Aq => sub ($c) {
\& $c\->render(text => \*(AqHello World!\*(Aq);
\& });
\& }
.Ve
.SS "Application"
.IX Subsection "Application"
The application object you can access with the function \*(L"app\*(R" is the first argument passed to the \f(CW\*(C`startup\*(C'\fR
method.
.PP
.Vb 2
\& # Mojolicious::Lite
\& app\->max_request_size(16777216);
\&
\& # Mojolicious
\& sub startup ($self) {
\& $self\->max_request_size(16777216);
\& }
.Ve
.SS "Plugins"
.IX Subsection "Plugins"
Instead of the \*(L"plugin\*(R" function you just use the method \*(L"plugin\*(R" in Mojolicious.
.PP
.Vb 2
\& # Mojolicious::Lite
\& plugin \*(AqConfig\*(Aq;
\&
\& # Mojolicious
\& sub startup ($self) {
\& $self\->plugin(\*(AqConfig\*(Aq);
\& }
.Ve
.SS "Helpers"
.IX Subsection "Helpers"
Similar to plugins, instead of the \*(L"helper\*(R" function you just use the method \*(L"helper\*(R" in Mojolicious.
.PP
.Vb 4
\& # Mojolicious::Lite
\& helper two => sub ($c) {
\& return 1 + 1;
\& };
\&
\& # Mojolicious
\& sub startup ($self) {
\& $self\->helper(two => sub ($c) {
\& return 1 + 1;
\& });
\& }
.Ve
.SS "Under"
.IX Subsection "Under"
Instead of sequential function calls, we can use methods to build a tree with nested routes, that much better
illustrates how routes work internally.
.PP
.Vb 3
\& # Mojolicious::Lite
\& under \*(Aq/foo\*(Aq;
\& get \*(Aq/bar\*(Aq => sub ($c) {...};
\&
\& # Mojolicious
\& sub startup ($self) {
\&
\& my $routes = $self\->routes;
\& my $foo = $routes\->under(\*(Aq/foo\*(Aq);
\& $foo\->get(\*(Aq/bar\*(Aq => sub ($c) {...});
\& }
.Ve
.SH "FUNCTIONS"
.IX Header "FUNCTIONS"
Mojolicious::Lite implements the following functions, which are automatically exported.
.SS "any"
.IX Subsection "any"
.Vb 7
\& my $route = any \*(Aq/:foo\*(Aq => sub ($c) {...};
\& my $route = any \*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq;
\& my $route = any \*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...};
\& my $route = any \*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...};
\& my $route = any [\*(AqGET\*(Aq, \*(AqPOST\*(Aq] => \*(Aq/:foo\*(Aq => sub ($c) {...};
\& my $route = any [\*(AqGET\*(Aq, \*(AqPOST\*(Aq] => \*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...};
\& my $route = any [\*(AqGET\*(Aq, \*(AqPOST\*(Aq] => \*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...};
.Ve
.PP
Generate route with \*(L"any\*(R" in Mojolicious::Routes::Route, matching any of the listed \s-1HTTP\s0 request methods or all. See
Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
.SS "app"
.IX Subsection "app"
.Vb 1
\& my $app = app;
.Ve
.PP
Returns the Mojolicious::Lite application object, which is a subclass of Mojolicious.
.PP
.Vb 3
\& # Use all the available attributes and methods
\& app\->log\->level(\*(Aqerror\*(Aq);
\& app\->defaults(foo => \*(Aqbar\*(Aq);
.Ve
.SS "del"
.IX Subsection "del"
.Vb 5
\& my $route = del \*(Aq/:foo\*(Aq => sub ($c) {...};
\& my $route = del \*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq;
\& my $route = del \*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...};
\& my $route = del \*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...};
\& my $route = del \*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...};
.Ve
.PP
Generate route with \*(L"delete\*(R" in Mojolicious::Routes::Route, matching only \f(CW\*(C`DELETE\*(C'\fR requests. See
Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
.SS "get"
.IX Subsection "get"
.Vb 5
\& my $route = get \*(Aq/:foo\*(Aq => sub ($c) {...};
\& my $route = get \*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq;
\& my $route = get \*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...};
\& my $route = get \*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...};
\& my $route = get \*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...};
.Ve
.PP
Generate route with \*(L"get\*(R" in Mojolicious::Routes::Route, matching only \f(CW\*(C`GET\*(C'\fR requests. See
Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
.SS "group"
.IX Subsection "group"
.Vb 1
\& group {...};
.Ve
.PP
Start a new route group.
.SS "helper"
.IX Subsection "helper"
.Vb 1
\& helper foo => sub ($c, @args) {...};
.Ve
.PP
Add a new helper with \*(L"helper\*(R" in Mojolicious.
.SS "hook"
.IX Subsection "hook"
.Vb 1
\& hook after_dispatch => sub ($c) {...};
.Ve
.PP
Share code with \*(L"hook\*(R" in Mojolicious.
.SS "options"
.IX Subsection "options"
.Vb 5
\& my $route = options \*(Aq/:foo\*(Aq => sub ($c) {...};
\& my $route = options \*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq;
\& my $route = options \*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...};
\& my $route = options \*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...};
\& my $route = options \*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...};
.Ve
.PP
Generate route with \*(L"options\*(R" in Mojolicious::Routes::Route, matching only \f(CW\*(C`OPTIONS\*(C'\fR requests. See
Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
.SS "patch"
.IX Subsection "patch"
.Vb 5
\& my $route = patch \*(Aq/:foo\*(Aq => sub ($c) {...};
\& my $route = patch \*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq;
\& my $route = patch \*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...};
\& my $route = patch \*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...};
\& my $route = patch \*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...};
.Ve
.PP
Generate route with \*(L"patch\*(R" in Mojolicious::Routes::Route, matching only \f(CW\*(C`PATCH\*(C'\fR requests. See
Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
.SS "plugin"
.IX Subsection "plugin"
.Vb 1
\& plugin SomePlugin => {foo => 23};
.Ve
.PP
Load a plugin with \*(L"plugin\*(R" in Mojolicious.
.SS "post"
.IX Subsection "post"
.Vb 5
\& my $route = post \*(Aq/:foo\*(Aq => sub ($c) {...};
\& my $route = post \*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq;
\& my $route = post \*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...};
\& my $route = post \*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...};
\& my $route = post \*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...};
.Ve
.PP
Generate route with \*(L"post\*(R" in Mojolicious::Routes::Route, matching only \f(CW\*(C`POST\*(C'\fR requests. See
Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
.SS "put"
.IX Subsection "put"
.Vb 5
\& my $route = put \*(Aq/:foo\*(Aq => sub ($c) {...};
\& my $route = put \*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq;
\& my $route = put \*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...};
\& my $route = put \*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...};
\& my $route = put \*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...};
.Ve
.PP
Generate route with \*(L"put\*(R" in Mojolicious::Routes::Route, matching only \f(CW\*(C`PUT\*(C'\fR requests. See
Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
.SS "under"
.IX Subsection "under"
.Vb 6
\& my $route = under sub ($c) {...};
\& my $route = under \*(Aq/:foo\*(Aq => sub ($c) {...};
\& my $route = under \*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq};
\& my $route = under \*(Aq/:foo\*(Aq => [foo => qr/\ew+/];
\& my $route = under \*(Aq/:foo\*(Aq => (agent => qr/Firefox/);
\& my $route = under [format => [\*(Aqjson\*(Aq, \*(Aqyaml\*(Aq]];
.Ve
.PP
Generate nested route with \*(L"under\*(R" in Mojolicious::Routes::Route, to which all following routes are automatically
appended. See Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
.SS "websocket"
.IX Subsection "websocket"
.Vb 5
\& my $route = websocket \*(Aq/:foo\*(Aq => sub ($c) {...};
\& my $route = websocket \*(Aq/:foo\*(Aq => sub ($c) {...} => \*(Aqname\*(Aq;
\& my $route = websocket \*(Aq/:foo\*(Aq => {foo => \*(Aqbar\*(Aq} => sub ($c) {...};
\& my $route = websocket \*(Aq/:foo\*(Aq => [foo => qr/\ew+/] => sub ($c) {...};
\& my $route = websocket \*(Aq/:foo\*(Aq => (agent => qr/Firefox/) => sub ($c) {...};
.Ve
.PP
Generate route with \*(L"websocket\*(R" in Mojolicious::Routes::Route, matching only WebSocket handshakes. See
Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
.SH "ATTRIBUTES"
.IX Header "ATTRIBUTES"
Mojolicious::Lite inherits all attributes from Mojolicious.
.SH "METHODS"
.IX Header "METHODS"
Mojolicious::Lite inherits all methods from Mojolicious.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.