Codementor Events

Dancer2 Introduction and Installation

Published Jul 30, 2018

Dancer2 is a light-weight web framework in Perl. Dancer2 is simple but extremely powerful to develop complex web applications. It opts for a handful of modules to start developing web projects.

Before starting the Project in Dancer2, the following are the prerequisites for this tutorial:

  1. Perl version 5.24 or greater installed on your local machine. On Unix or Mac Operating System, Perl is available through the default OS installation packages, if you are using the windows machine, install it from here.

  2. Elementary knowledge of Perl (Not Object Oriented) is essential. If you are not accustomed to basic Perl, then you are not ready for this tutorial. I would recommend acquiring fundamental knowledge of Perl first and continue the tutorial.

  3. MySQL 5.0 onwards, must be installed on your system. If not, install it according to your flavoured OS:
     → Windows Installation Packages.
     → Debian/Ubuntu Unix Installation.
     → Redhat/CentOS/Fedora Installation.
     → MacOS Installation.

  4. MySQL fundamental knowledge.

  5. Basic knowledge of HTML, CSS, Bootstrap(Optional).

Installation of Dancer2

You are over here!!! You fulfilled all the prerequisites to get started with Dancer2 Application. Great!!!

Let’s start with the Dancer2 Installation.

From the Command line terminal,

sudo cpan install Dancer2

This command will install the Dancer2 on your local machine.

If CPAN is not configured, then following should work, on Unix or Unix-like systems:

wget -O - [http://cpanmin.us](http://cpanmin.us/) | sudo perl - Dancer2

The previous command will also work on Windows after installing CygWin.

If Operating system is Debian/Ubuntu, Dancer2 is available as repository package.

apt-get install libdancer2-perl

Once you execute the Dancer2 installation command, it took few minutes to install the package.

Quick Start Project in Dancer2

From the terminal execute the following:

dancer2 -a PForums

It creates a web Application in dancer2, PForums is the name of our Application. Along with the Project Folder, it creates the Skeleton of the Project to develop more Complex Web Application if required.

Typical Dancer2 Project Skeleton looks like:


Dancer2 Project Skeleton

In Dancer2 framework, one line is enough to create the Project. Isn’t is easy?

Application Launch

Dancer2 is a PSGI web application framework, plackup tool is used for launching the application.

→ Go to the Project Folder (PForums in our case.)
 → plackup -a bin/app.psgi

Command starts the Web Server at 5000 port. 
HTTP::Server::PSGI: Accepting connections at http://0:5000/

Go to the browser and launch http://localhost:5000/

Congratulation, you launch your first Dancer2 Web App.

In this tutorial we learn:

✔ Dancer2 Introduction
✔ Dancer2 Installation
✔ Setting-up the Project
✔ Launch the web application.

In the next tutorial, we learn about the routes and the setting up the database for our forum.

See you in the next tutorial.

Discover and read more posts from Ashutosh Kukreti
get started
post commentsBe the first to share your opinion
HenriBoehm
3 months ago

Thanks for sharing.

CAR ACCOUNT
3 months ago

The comprehensive guide to Dancer2 sets a solid foundation for web application development in Perl. The tutorial outlines clear prerequisites, ensuring a smooth onboarding process. The incorporation of MySQL and the optional use of HTML, CSS, and Bootstrap add versatility to project development. The installation instructions, whether through CPAN, Debian/Ubuntu repository, or CygWin for Windows, are well-explained, accommodating users with different setups. The quick start project command, ‘dancer2 -a PForums,’ exemplifies the simplicity and efficiency of Dancer2, setting the stage for developers to embark on a rewarding journey. The <a href=“https://returnspolicy.info/scheels-return-policy/”>return</a> on investment in learning and utilizing Dancer2 is evident in its lightweight yet powerful framework, making it a valuable asset for web developers.

Show more replies