How to install Mojolicious?

Posted by Ashutosh on March 23, 2020


Getting Started with Mojolicious

After working on Perl Catalyst for many years I started using Mojolicious couple of months ago and, falls in love with it. Mojolicious is a web framework written in Perl and developed by Sebastian Riedel. He is the same guy who developed Perl Catalyst framework.

Mojolicious is a very flexible framework where we can make it as light as Dancer2 (Another Perl framework) and, we can also write big applications like we do in Catalyst. The Mojolicious requires core Perl modules so its safe from CPAN changes.

Installation

Installation is very simple and can be achieved from using the following:

cpan Mojolicious

If cpanm is present the use

cpanm Mojolicious

On ActivePerl

ppm install Mojolicious

After the installation is complete, verify the installation using the mojo command

mojo version

The output is more or less like the same

=> mojo version
CORE
  Perl        (v5.28.0, darwin)
  Mojolicious (8.25, Supervillain)

OPTIONAL
  Cpanel::JSON::XS 4.09+  (4.18)
  EV 4.0+                 (n/a)
  IO::Socket::Socks 0.64+ (n/a)
  IO::Socket::SSL 2.009+  (2.066)
  Net::DNS::Native 0.15+  (n/a)
  Role::Tiny 2.000001+    (2.000006)
  
You might want to update your Mojolicious to 8.34!

 

Setting up the Application

Create a file 'myFirstApp.pl' and write the following content in it.

use Mojolicious::Lite;

get '/' => {text => 'Welcome to the mojolicious'};

app->start;

That's all. These 3 lines what we need to write to start with our basic application in Mojolicious.

To start the application go the command line and write

morbo myFirstApp.pl

Morbo is websocket development server for Mojolicious application.

Alternate way

There is an alternative to start our application (Mojolicious) and that's the most standard way of doing it.

use Mojolicious::Lite;

get '/' => sub {
	my $self = shift;
	
	$self->render(text => 'Welcome to the mojolicious framework.')
};

app->start;

Open the browser the and visit http://localhost:3000/


It is very easy to install and start your project easily in Mojolicious. Stay tuned for more.