Dancer is a micro framework used for writing Web applications. It is modelled after a Ruby framework called as ‘Sinatra’ that constructs web applications by building a list of HTTPs, URLs and different methods to handle that type of traffic to that specific URL.
Required Perl Modules
Dancer, Template Toolkit, File::Slurp, DBD::SQLite.
- Template Toolkit : Front-end module to the template toolkit.
- File:: Slurp : Simple and Efficient Reading/Writing/Modifying of complete
- DBD::SQLite : It is a self contained RDBMS in a DBI Driver. SQLite is a
public domain file-based relational database engine.
- ‘cpanminus’ is mostly recommended for installing the Dancer.
- “curl -L http://cpanmin.us | perl – –sudo Dancer”
How to create an Application
- $ dancer -a MyWeb::App
- + MyWeb-App
- + MyWeb-App/bin
- + MyWeb-App/bin/app.pl
- + MyWeb-App/config.yml
- + MyWeb-App/environments
- + MyWeb-App/environments/development.yml
- + MyWeb-App/environments/production.yml
- + MyWeb-App/views
- + MyWeb-App/views/index.tt
- + MyWeb-App/views/layouts
- + MyWeb-App/views/layouts/main.tt
- + MyWeb-App/lib
- + MyWeb-App/lib/MyWeb
- + MyWeb-App/lib/MyWeb/App.pm
- + MyWeb-App/public
- + MyWeb-App/public/css
- + MyWeb-App/public/css/style.css
- + MyWeb-App/public/css/error.css
- + MyWeb-App/public/images
- + MyWeb-App/public/500.html
- + MyWeb-App/public/404.html
- + MyWeb-App/public/dispatch.fcgi
- + MyWeb-App/public/dispatch.cgi
- + MyWeb-App/Makefile.PL
- + MyWeb-App/t
- + MyWeb-App/t/002_index_route.t
- + MyWeb-App/t/001_base.t
Dancer v/s Other Frameworks:
- Work with all major web servers.
- Consists of Integrated Development Servers.
- Dependencies is very high when compared with Dancer.
- Feature rich and highly flexible
- Main level of abstraction is the Controller.
- Dancer supports PSGI specification.
- Includes a standalone development server that can be used for developing and testing applications.
- Few Dependencies – Dancer mainly depends on few CPAN modules that makes installation process easier.
- lightweight and easy to use.
- Route is the main level of abstraction.
- JSON and HTML/XML parser with CSS selector support.
- Automatic CGI and PSGI detection.
- No dependencies – It is optimized for user-friendliness and development speed, without compromises
- User friendly and flexible
- The integrated template engine is fast and fits very well to user needs
Deploying Dancer in CGI:
Common Gateway Interface (CGI) is a standard method for web server software to delegate the generation of web content to executable files. Such files are known as CGI scripts or simply CGIs; they are usually written in a scripting language.
Dancer::Deployment module is mainly used for deploying the Dancer in CGI. Dancer and Plack should be installed for deploying Perl dancer.
CGI execution of Apache is allowed by the providers. At the same time one is not permitted to edit httpd.conf or override certain values. Some requirements are to be taken care, in which user/company should install the latest Plack or Dancer with the modules that use in the web applications.
Now let us discuss about the preparation of the above process. First off all, there will be one public folder name ‘public/’ of our dancer application. Locate ‘dispatch.cgi’ inside the ‘public/’ folder. A personal link has been created which creates a symbolic link towards the ‘dispatch.cgi’. This link specifies how we want the url to display
PSGI / Plack :
PSGI and Plack was created by Tatsuhiko Miyagawa, which helps developers to write their code and deploy in different ways including CGI, mod_perl, FastCGI, nginx and Starman. It is almost a complicated task to create a plain PSGI or Plack code, hence most of us uses one of the frameworks used for developing the web applications.
Perl Dancer supports the PSGI specification, hence it can be run on any compliant PSGI server.
PSGI is an interface between Perl web applications and web servers, and Plack is a Perl module and toolkit that contains PSGI middleware, helpers and adapters to web servers.