Perl DancerPerl Dancer
Мариян HackMan Маринов
<mm@1h.com>
Who am I?Who am I?
➢ Chief system architect of
➢ Sysadmin since the stone age
➢ Linux Sysadmin & Network security
courses in FMI Sofia and SoftUni
What is DancerWhat is Dancer
What is DancerWhat is Dancer
➢Dancer is a simple but powerful web application
framework for Perl.
➢http://www.perldancer.org
InstallationInstallation
RHEL/CentOs/Fedora:
# yum install cpan
# cpan Dancer2
Debian/Ubuntu:
# apt-get install perl
# cpan Dancer2
InstallationInstallation
Worst case you also need to do this:
# cpan -fi YAML File::ShareDir::Install Time::HiRes
MIME::Base64
How to create a projectHow to create a project
# dancer2 -a MyProject::Site
# cd MyProject-Site
# plackup bin/app.psgi
dancer2 ­a MyProject::Site      dancer2 ­a MyProject::Site      
-rw-rw-r-- 1 dance dance 442 Jul 3 20:01 MANIFEST
-rw-rw-r-- 1 dance dance 173 Jul 3 20:01 MANIFEST.SKIP
-rw-rw-r-- 1 dance dance 817 Jul 3 20:01 Makefile.PL
drwxrwxr-x 2 dance dance 4096 Jul 3 20:01 bin
-rw-rw-r-- 1 dance dance 797 Jul 3 20:01 config.yml
-rw-rw-r-- 1 dance dance 300 Jul 3 20:01 cpanfile
drwxrwxr-x 2 dance dance 4096 Jul 3 20:45 environments
drwxrwxr-x 3 dance dance 4096 Jul 3 20:01 lib
drwxrwxr-x 5 dance dance 4096 Jul 3 20:01 public
drwxrwxr-x 2 dance dance 4096 Jul 3 20:01 t
drwxrwxr-x 3 dance dance 4096 Jul 3 20:36 views
StructureStructure
➢bin
➢environments - configurations
➢lib - the actual logic of your site
➢public - static files
➢t - tests (if you write any)
➢views - templates for your site
What can we do now?What can we do now?
➢Routing
➢ What the hell is routing :)
http://example.com/path/path
/path/path - is route- is route
we need to connect this route towe need to connect this route to CODECODE
get 'get '/path/path' => sub {' => sub {
return "Hello mammy :)";return "Hello mammy :)";
};};
What can we do now?What can we do now?
➢Routing
➢ What the hell is routing :)
➢ GET, POST, PUT, DELETE
➢ ANY
➢ Combinations
➢Redirects
➢ once in a route you simply need to write:
redirect('/newpath');
Using paramsUsing params
get '/hello/:name' => sub {
"Hey " . param('name') . "... You are an idiot :)";
};
get '/hello/:name' => sub {
"Hey " . ( param('name') || “Idiot” );
};
Params in templatesParams in templates
[% IF session.logged_in %]
<form action="[% add_entry_url %]" method=post
class=add-entry>
Title:<input type=text size=30 name=title>
Text:<textarea name=text rows=5 cols=40></textarea>
<input type=submit value=Share>
</form>
[% END %]
Params in templatesParams in templates
<ul class=entries>
[% IF entries.size %]
[% FOREACH id IN entries.keys.nsort %]
<li><h2>[% entries.$id.title %]</h2>[% entries.$id.text %]
[% END %]
[% ELSE %]
<li><em>Unbelievable. No entries here so far</em>
[% END %]
</ul>
DocumentationDocumentation
$ perldoc Dancer2
$ perldoc Dancer2::Tutorial
$ perldoc Dancer2::Manual
$ perldoc Dancer2::Config
$ perldoc Dancer2::Plugins
Въпроси?Въпроси?
Мариян HackMan MarinovМариян HackMan Marinov
E-Mail:E-Mail: mm@1h.commm@1h.com
IRC: irc.freenode.net HackManIRC: irc.freenode.net HackMan
ICQ: 7556201ICQ: 7556201
Jabber/Gtalk:Jabber/Gtalk: hackman@jabber.orghackman@jabber.org
http://github.com/hackman/http://github.com/hackman/

Perl dancer