Server - Contents

Perl Dancer2 - Website Access based on Roles

A 3-page site example

Prerequisites: Basic Server (Debian 10.3 64bit) with Webmin, FTP, Firewall and Fail2Ban: a server linked with a domain name (eg. example.com) and familarity with creating and deploying a basic HTML website.

The Perl environment is very mature and comprehensive. A National Office may seek to have more comprehensive website with the power of Perl behind it. One choice is the MVC website framework Dancer2 which, if the website is to be developped on a WinPC, this would require a Perl-enabled environment.

Having understood the setup of the BasicSite , the following setup proposed here is to have a 3-page Dancer2 website up and running first on the PC then to have the same site established on the server (running iRedmail/Nginx) with the two sites synchronized via FTP (eg. FileZilla)

Part A: Creating the Perl/Dancer Environment on the PC

Step1: Install Perl on a PC (Windows)

Following this link: Strawberry-Perl and install the usual 64-bit version. It would be useful here to create a folder for Perl scripts under the Documents file; such as perlexamples.

Step 2: Install Dancer2
Install Dancer2, using these commands via 'PowerShell'[Win10] or in Win 7+, typing in 'cmd' after opening the Windows Start button.

perl -MCPAN -e shell // Its own shell command will open and type in the following:
install Dancer2 // allow time for the install.
exit // type this to return to PowerShell.

Step 3: Create a Dancer2 App
In the Powershell, go to your perlexamples directory and type the following :

dancer2 -a myexample // once complete, do the following:
cd myexample
plackup -p 5000 bin/app.psgi // Go to browser via link at:- http://localhost:5000

If all has gone well, one should find a default single Dancer2 webpage.

Step 4: Replace and Modify the Website
Download the demonstration app: myexample.zip. Unzip it into one's perlexamples directory and enter the myexample directory and that of /lib and open the file 'myexample.pm' in a text editor (eg. Notepad++), and one will see changes such as:

get '/' => sub {
template 'index' => { 'title' => 'MyWeb::App' };
};

now has become:

get '/' => sub { template 'index.tt', { 'title' => 'My First Example' }; };

As evident, the myexample.pm file establishes routes and whatever logic one may wish to incorporate. Now under views/layouts, the main.tt file sets the headers and footers and for these templates. Note that the power of the Template-Toolkit can be exploited in all these templates.

Recommended reading:
i. A good primer: Beginning.Perl.2012.Wrox.pdf (6.6Mb)
ii. A modern and responsive CSS, w3.css - by W3-Schools - a stylesheet used in this demo.

Open the console (via 'PowerShell'[Win10] or in Win 7+, typing in 'cmd')and to view this website, enter commands from your perlexamples directory:

cd myexample
plackup -p 5000 -r bin/app.psgi // Go to browser via link at:- http://localhost:5000

Note: Entries in a .yml file, like a python file, is sensitive to proper indentation. Each section requires relevant entries to align with each other.

Dancer2 Dancer-PartB
Dancer-Deploy Dancer-Extras