Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
Python, Lua, Tcl, C and C++ training - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, Ruby, MySQL and Linux / Tomcat systems
 
Perl Dancer - a Perl Framework - Installation and first test

The most commonly requested Web Frameworks for our training courses are CodeIgniter and Zend (using PHP), Django (using Python) and Rails (using Ruby). However, Perl is also an excellent language for web use - in fact it was the original predominant web language prior to the growth of those other languages. For large projects, Perl 5 may no longer be the optimum language to use... but for smaller and medium size it's still a good choice - especially where the web use of code is ancillary to substantial data munging. But should you use a Framework in Perl, and if so, which one?

To answer the first question - if you want templates, sessions, URL routing in your application... if you want to separate out the look and feel from the computational work... then, yes, you should consider using a framework. Someone else has done the hard work to implement those features shared between many applications, and you'll be more efficient in your code development if you make use of that hard work rather than repeating it. Further savings come later on, when extra elements can be easily added, and upgrades to the framework can be reflected in upgrades to the application - in both features and security.

So - which framework for Perl applications? Over the last couple of days, I've taken a look at Perl Dancer - at http://www.perldancer.org/.

From the Dance web site:

What is Dancer?

Dancer is a simple but powerful web application framework for Perl

Key features

Dead Simple - Intuitive, minimalist and very expressive syntax
Flexible - PSGI support, plugins and modular design allow for strong scalability
Few dependencies - Dancer depends on as few CPAN modules as possible making it easy to install


Yes - it is simple. But much of the documentation is written for people who are already Perl and web experts, and for newcomers or even intermediates, there's a feeling of "help, how do I do this", "can I have some more examples", and "why do I need so many extra CPAN modules" in spite of what the headlines say.

So let's take a look at...
(a) installation
(b) first application
(c) scaling up the web server
for the newcomer

• installation

First, get the software...

Download, unpack... we used Dancer-1.3113
cd to directory created

You then need to build the software, but:

  munchkin:Dancer-1.3113 grahamellis$ perl Makefile.PL
  Checking if your kit is complete...
  Looks good
  Warning: prerequisite HTTP::Body 1.07 not found.
  Warning: prerequisite HTTP::Server::Simple::PSGI 0.11 not found.
  Warning: prerequisite MIME::Types 0 not found.
  Warning: prerequisite Module::Runtime 0 not found.
  Warning: prerequisite URI 1.59 not found. We have 1.56.
  Writing Makefile for Dancer
  munchkin:Dancer-1.3113 grahamellis


That's a series of packages that aren't in the standard Perl disrtibution and need to be sourced from the CPAN... so as adminsitrator / root

install prerequisites:

  munchkin:Dancer-1.3113 grahamellis$ perl -MCPAN -e shell
  cpan[1]> install HTTP::Body
  [lots of output]
  etc for all the other prerequistites, includind URI
  cpan[7]> quit


And you can then work out how to build... and build... and install

  munchkin:Dancer-1.3113 grahamellis$ perl Makefile.PL
  Writing Makefile for Dancer
  munchkin:Dancer-1.3113 grahamellis$


  munchkin:Dancer-1.3113 grahamellis$ make
  cp lib/Dancer/Session/Abstract.pm blib/lib/Dancer/Session/Abstract.pm
  cp lib/Dancer/SharedData.pm blib/lib/Dancer/SharedData.pm
  cp lib/Dancer/Serializer/Mutable.pm blib/lib/Dancer/Serializer/Mutable.pm
  cp lib/Dancer/Route.pm blib/lib/Dancer/Route.pm
  etc


  munchkin:Dancer-1.3113 grahamellis$ sudo make install
  Password:
  Installing /Library/Perl/5.12/Dancer.pm
  Installing /Library/Perl/5.12/Dancer/App.pm


• first application

Having installed Dancer, we can now generate our first application and try it out. The application generation script makes a default "hello" application - we'll do that to test our installation, then we'll tailor it to do what we need in a next lesson.

So:

  munchkin:Dancer-1.3113 grahamellis$ ./script/dancer -a MyWeb::App
  + MyWeb-App
  + MyWeb-App/bin
  + MyWeb-App/bin/app.pl
  + MyWeb-App/config.yml
  + MyWeb-App/environments
  etc
  *****
  WARNING: YAML.pm is not installed. This is not a full dependency, but is highly
  recommended; in particular, the scaffolded Dancer app being created will not be
  able to read settings from the config file without YAML.pm being installed.
  
  To resolve this, simply install YAML from CPAN, for instance using one of the
  following commands:
  
    cpan YAML
    perl -MCPAN -e 'install YAML'
    curl -L http://cpanmin.us | perl - --sudo YAML
  *****
  munchkin:Dancer-1.3113 grahamellis$


It's going to be a good idea to install YAML:

  munchkin:Dancer-1.3113 grahamellis$ sudo perl -MCPAN -e shell
  cpan[1]> install YAML
  cpan[2]> quit
  munchkin:Dancer-1.3113 grahamellis


We can then test the application though the built in server (well - actually the server we downloaded from the CPAN!)

  munchkin:MyWeb-App grahamellis$ ./bin/app.pl
  [9296] core @0.000022> loading Dancer::Handler::Standalone handler in /Library/Perl/5.12/Dancer/Handler.pm l. 45
  [9296] core @0.000326> loading handler 'Dancer::Handler::Standalone' in /Library/Perl/5.12/Dancer.pm l. 483
  >> Dancer 1.3113 server 9296 listening on http://0.0.0.0:3000
  == Entering the development dance floor...


And we then browse to view the page:



and you'll find the following extra lines in the window that's running the server:

  [9296] core @0.000218> request: GET / from 127.0.0.1 in /Library/Perl/5.12/Dancer/Handler.pm l. 56
  [9296] core @0.000797> [hit #1]Trying to match 'GET /' against /^\/$/ (generated from '/') in /Library/Perl/5.12/Dancer/Route.pm l. 84


Next lesson to follow... tailoring the standard application to do what you want!
(written 2013-05-23, updated 2013-05-25)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
P408 - Perl - Standard Web Modules
  [4100] Perl Dancer - from installation to your first real application - (2013-05-24)
  [3485] Perl - retrieving and caching web resources - (2011-10-18)
  [2416] Automating access to a page obscured behind a holding page - (2009-09-23)
  [2402] Automated Browsing in Perl - (2009-09-11)
  [2229] Do not re-invent the wheel - use a Perl module - (2009-06-11)
  [975] Answering ALL the delegate's Perl questions - (2006-12-09)


Back to
Using object orientation for non-physical objects
Previous and next
or
Horse's mouth home
Forward to
Perl Dancer - from installation to your first real application
Some other Articles
Questions from children about Melksham Campus
Installing Lua 5.2.2 on Mac OS X 10.7.4
POETS day at Well House Manor
Perl Dancer - a Perl Framework - Installation and first test
Using object orientation for non-physical objects
Melksham Chamber of Commerce - Report for AGM, 21st May 2013
Perl design patterns example
Django - first steps - Updated
Python Properties - how and why
4754 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2017: 404 The Spa • Melksham, Wiltshire • United Kingdom • SN12 6QL
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4099_Per ... -test.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat