Home »
Perl
Introduction to Perl dancer framework
In this tutorial, we are going to learn about the introduction to Perl dancer framework.
Submitted by Godwill Tetah, on December 03, 2020
In this tutorial, we will get started with Perl Dancer. Perl Dancer is a web framework written in Perl used to build websites or web applications. Dancer is just one of the awesome frameworks written in Perl used to build web applications. There are other Perl frameworks used too.
Dancer is quite simple to understand for anyone who has done web development before. More about Dancer or more Perl modules can be found on metacpan.org. Just open the website and search for any module you wish to know more about by typing it in the search box.
I want you to understand that there are several ways to do that same thing in computer science, but we will simplify it for better comprehension.
Installation
Remember Dancer is a framework that doesn't come in-built with Perl, so it must be installed as a Perl module before usage.
In this tutorial, we will install Dancer through "cpanminus".
Cpanminus enables Perl developers to install Perl modules from their command line.
To install cpanminus, run the command below on your command line and wait till it displays successful installation. Internet connection is required when installing any module from Perl's ecosystem of modules.
Now that we are done installing cpanminus, we will move on to installing Dancer using cpanminus. To achieve this, run the command;
Wait until it displays a message showing that installation complete.
Now let's see if it was finally installed by running a short code. After installation, coding and development can now be done offline. We're just on development mode!
index.pl
use Dancer;
get '/' => sub {
return "hello world!, i can now use Perl for web dev";
};
dance;
Above is a simple code in the file index.pl. Start the web page by simply running the command below; perl index.pl where index.pl is the file name.
The output on the console means everything is successful and can be opened in localhost:3000 in a browser.
Output:
And finally, that's the expected output.