Opens in a new windowOpens an external websiteOpens an external website in a new window
We and our 11 IAB TCF partners store and access information on your device for the following purposes: store and/or access information on a device, advertising and content measurement, audience research, and services development, personalised advertising, and personalised content.
Personal data may be processed to do the following: use precise geolocation data and actively scan device characteristics for identification.
Our third party IAB TCF partners may store and access information on your device such as IP address and device characteristics. Our IAB TCF Partners may process this personal data on the basis of legitimate interest, or with your consent. You may change or withdraw your preferences at any time by clicking on the cookie icon or link; however, as a consequence, you may not see relevant ads or personalized content. To learn more, view the following link: Cookie Policy
This document introduces the Dancer web framework for Perl. It summarizes Dancer's key features, including its route-based and minimal design inspired by Sinatra, its PSGI/Plack compliance, and its large collection of plugins for features like templating, databases, REST, and more. The document advocates that Dancer allows for an efficient, succinct, and flexible approach to web development in Perl.
About me
● Sawyer X
● Sysadmin / Perl Ninja
● Israel.pm / Haifa.pm / TelAviv.pm / Rehovot.pm
● I do system, networking, web, applications, etc.
● http://blogs.perl.org/users/sawyer_x/
● http://search.cpan.org/~xsawyerx/
Nutcases?
● Yes, we are insane (but not LISP-insane)
● Insanity is a whole lot of fun!
● Insanity gives us flexibility
● Flexibility gives us cool stuff
● Like Moose and meta-programming
● Like DBIx::Class
● Like Dancer
In comparison
from flask import Flask use Dancer;
app = Flask(__name__)
@app.route("/", methods=['GET']) get “/” => sub {
def hello(): “Hello, World!”
return "Hello World!"
};
if __name__ == "__main__":
app.run() dance;
14.
Dancer treats
● Both read and write, easily!
● Route-based (started as a port of Sinatra)
● PSGI/Plack compliant (PSGI is our WSGI)
● Minimum dependencies
● Any app is also a web server
● CPAN-friendly (<3 CPAN)
15.
Recipe for Dancing
● Take an HTTP method
● Add a path to that
● Mix with a subroutine
● And sprinkle plugins and keywords on top
More nifty stuff
● headers 'MyXHeader' => 'Value'
● send_file('report.tar.gz')
● set_cookie name => 'value',
expires => ( time + 3600 ),
domain => 'foo.com'
● status 'not_found'
● to_json, to_yaml, to_xml
● my $file = upload('file_input')
● my $all_uploads = request>uploads
21.
Dancer as Perlphilosophy
● Dancer is succinct, efficient and easy to work with
● Dancer is daring
(Do you have route caching in Django?)
(Websockets in near future!)
● Dancer has a lot of plugins:
(engines for sessions, logging, templates)
● Serializers (JSON, YAML, XML)
● Route filters (before, after, before_template)
Dancer::Plugin::Ajax
ajax '/check_for_update' => sub {
# some ajax code
};
● Pass if X-Request-With not “XMLHttpRequest”
● Disable the layout
● The action built is a POST request
28.
Dancer::Plugin::DBIC
● DBIC (DBIx::Class) – a sophisticated ORM
● Configure the connection in the config file
● Make the ResultSets available in routes
29.
Dancer::Plugin::Database
● Database(s) connection in Dancer
get '/widget/view/:id' => sub {
my $sth = database>prepare(
'select * from widgets where id = ?'
);
$sth>execute( params>{id} );
template display_widget => {
widget => $sth>fetchrow_hashref,
};
};
30.
In culmination
Dancer is beautiful and fun
The way programming should be
PerlDancer.org
search.cpan.org/perldoc?Dancer