Mojolicious is a popular asynchronous Web development framework for the Perl language. The Mojo framework is easy to install, and with CPAN there is less reliance on third party packages than for Dancer. According to my personal experience, Dancer installed with CPAN tends to get stuck in a particular package, and Mojo is very adaptable for both Windows and Linux.
Also, Mojolicious is very similar to Flask, so it’s safe to say that both Python and Flask are a breeze when you’re proficient with Mojo.
Here, we’ll start with Mojolicious::Lite, a module that lets you easily write a web page from a single file script.
#! /usr/bin/env perl use Mojolicious::Lite -signatures; Get '/' => sub ($c) {#get refers to the HTTP GET method. If you use the POST method, you can use 'POST'. #'/' is the HTTP path, for example, 'http://127.0.0.1/'. $c-bb0 render(text => 'Hello World! $c-bb0 render(text => ') '); # This is a fixed method of $c, mainly used to generate the return of the HTTP service, the 'text' keyword refers to the return text format. }; app->start; # Start the HTTP application
The above script can also be generated automatically from the command line:
$ mojo generate lite-app myapp.pl
Once you’ve written this script, how do you run it? There are several ways to do this:
$./myapp.pl daemon # This is the normal way to start, The default startup port is 3000 Web Application Available at http://127.0.0.1:3000 $./myapp.pl daemon-l bar # Specify the startup port number Web with the -l option Application available at http://127.0.0.1:8080 # These are examples of official documents. For normal development debugging, we need to use the hot load mode. # hot load mode, for example, we use daemon mode to start the process, if I need to return the text -- "hello world!" Modified to "Yes Mojolicious!" After the modification, we need Ctrl + C to terminate the script and then rerun the daemon command. While in hot load mode, we do not terminate and restart the script, after modification, # refresh, the new page will display "Yes Mojolicious!" . $morbo./myapp.pl Web application available at http://127.0.0.1:3000