Installing Dancer
Install Dancer via CPAN:
$ sudo cpan Dancer
Creating an application
Since version 0.9904, a helper is shipped with the distribution which lets you create an application with a single command:
$ dancer -a mywebapp + mywebapp/app.psgi + mywebapp/config.yml + mywebapp/environments + mywebapp/environments/development.yml + mywebapp/environments/production.yml + mywebapp/views + mywebapp/views/index.tt + mywebapp/views/layouts + mywebapp/views/layouts/main.tt + mywebapp/mywebapp.pl + mywebapp/lib + mywebapp/lib/mywebapp.pm + mywebapp/lib/mywebapp + mywebapp/public + mywebapp/public/css + mywebapp/public/css/style.css + mywebapp/public/css/error.css + mywebapp/public/images + mywebapp/public/404.html + mywebapp/public/dispatch.fcgi + mywebapp/public/dispatch.cgi + mywebapp/public/500.html + mywebapp/t + mywebapp/t/002_index_route.t + mywebapp/t/001_base.t + mywebapp/Makefile.PL
Everything is ready and works out of the box. It's already a working "Hello World" application waiting to be hacked into whatever you like.
Hacking into the routes
# myapp.pm
use Dancer;
get '/' => sub {
'Hello world!'
};
# add other routes here and there...
dance;
Running the dance
$ cd mywebapp $ ./mywebapp.pl >> Listening on 127.0.0.1:3000 == Entering the dance floor ...
The above shows Dancer acting as a mini web server, but of course Dancer webapps can also run from nearly any web server using Plack/PSGI.