Server - Contents

Dancer2 - Extras

Ex1: Perlbrew

On the server, Perlbrew offers a much improved environment to manage Perl modules and it is higly recommended. To install Perlbrew, do the following:

sammy@imega:$ sudo apt install perlbrew
sammy@imega:$ perlbrew init
sammy@imega:$ nano .profile
// at the end of this file, paste: source ~/perl5/perlbrew/etc/bashrc
sammy@imega:$ source .profile // refresh the shell.
sammy@imega:$ perlbrew install-cpanm

Installing and activating Perlbrew enables one to, among the many options, replace the the CPAN install command for modules: 'perl -MCPAN -e shell' with simply: 'cpanm -S [module]' which installs any Perl modules into the server's existing set. Dropping the '-S', will place the module within a particular user's local directories (which unless a program is coded to search for, will be not be picked, say in a webserver-based app). When returning to one's user space, to re-activate Perlbrew, execute the following command:

sammy@imega:$ source .profile

Ex2: Setup Visitor Mail Contact and Private Pages to the Dancer2 site

Prequisites: to have the custom but basic Dancer2 Myexample App functional and rendered by the Apache2 webserver as described earlier on this website - with the iRedmail app setup using one's own domain.

For an office that requires the sharing of information to staff, there is a useful plugin: Dancer2::Plugin::Auth::Extensible whereby staff usernames, passwords and even roles can be configured through the app's config.yml file. A straighforward but simple example is explained at: PerlMaven-Protecting Pages in Dancer2. Note that the encrypted password facility doesn't function.
Lastly for the email function, create via 'iredadmin' two users: self and info based on your domain (eg. self@myexample.com and info@myexample.com). In the myexample(2) app in the myexample.pm file, change the default email addresses accordingly. For a functioning example, download the myexample2.zip, upload to your server, and after setting its permissions (775), the setup goes as follows:

sammy@imega:$ sudo apt-get update
sammy@imega:$ sudo apt-get install libdancer-plugin-auth-extensible-perl
sammy@imega:$ cpanm -S Dancer2::Plugin::Auth::Extensible
sammy@imega:$ cpanm -S Dancer2::Session::Cookie
sammy@imega:$ cpanm -S Dancer2::Plugin::Email
sammy@imega:$ cpanm -S Try::Tiny
sammy@imega:$ cpanm -S Email::Valid
sammy@imega:$ unzip myexample2.zip
sammy@imega:$ chmod -R 774 myexample/
// set permissions sammy@imega:$ cd myexample
sammy@imega: /myexample$plackup -p 5000 -r bin/app.psgi // Go to browser via link at:- http://([MyServerIP]or myexample.com):5000

Enter in the browser, one's domain at port:5000 (eg. http://[MySeverIP]:5000), the result should the appearance of the 3-page website. Type in the PuTTY console: 'ctl'+c to exit
For deployment, see the link below.

After ensuring a successful run with the Plackup server, switch it off and, with no change in the previous settings of Apache2 for the myexample app, restart the webserver.

Note: As mentioned earlier that in initial attempts of Apache2 to render the Dancer2 website, there maybe some links to the Perl modules that are appear missing. Check the Apache2 error log at Webmin: Tools-> System-> System Logs and view the entries. Install the missing modules via Webmin: Tools-> Perl Modules-> Install modules.

Ex3: Templates for Dancer2

For a simple usage example, see Alternative Dancer2 Templating Engines

Some useful constructions using the Template-Toolkit (note: /docs directory was added):
For images: img src="[% request.uri_base %]/images/mypic.jpg" alt="mypic" class="w3-image"
For docs: a href="[% request.uri_base %]/docs/sometext.txt" target="_blank"> sometext.txt /a

For a discussion on the template engine choices, consider this reference: MasonBook-Ch1

Note: If one chooses to use Mason2, Dancer2::Template::Mason2 is required to be installed and the line in config.yml is: template "mason2"

Dancer2 Dancer-PartB
Dancer-Deploy Dancer-Extras