SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
Dancer
(the Effortless Perl Web Framework)
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/
Perl web recap




    1995
    CGI
Perl web recap



               2010
    Many frameworks
(including micro-frameworks like Dancer)
The big web religions, illustrated
Ruby – the fanboys
Python – the sticklers
PHP – the nonsensical
Perl – the nutcases
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
Flask (Pythonese)
from flask import Flask
app = Flask(__name__)


@app.route("/", methods=['GET'])
def hello():
    return "Hello World!"


if __name__ == "__main__":
    app.run()
Dancer (Perlesque)
use Dancer;


get “/hi” => sub {
    “Hello, World!”
};


dance;
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;
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)
Recipe for Dancing
●   Take an HTTP method
●   Add a path to that
●   Mix with a subroutine
●   And sprinkle plugins and keywords on top
Dancer route structure
get     '/path' => sub { … };
post    '/path' => sub { … };
put     '/path' => sub { … };
del     '/path' => sub { … };
options '/path' => sub { … };
any     '/path' => sub { … };
Dancer
●   Paths can contain variables
    get '/hello/:entity/'


●   Paths can be Regular Expressions
    get qr{/ (w+) / d{2,3} (.+)? }x
Dancer login example
post '/login' => sub {
    # Validate the username and password
    if ( params­>{user} eq 'bob' &&
         params­>{pass} eq 'LetMeIn' ) {


        session user => params­>{user};
        redirect params­>{path} || '/';
    } else {
        redirect '/login?failed=1';
    }
 };
Templating
get '/' => sub {
    template index => {
        greeting => 'welcome'
    }
};
More nifty stuff
●   headers 'My­X­Header' => '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
Dancer as Perl philosophy
●   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)
Oh yeah, route caching...
Dancer::Plugin::REST
get '/user/:id.:format' => sub {
    UserRS­>find( params­>{id} );
};
# curl http://mywebservice/user/42.json
{ "id": 42, "name": "John Foo",             
"email": "john.foo@hopkins.com" }
# curl http://mywebservice/user/42.yml
­­
id: 42
name: "John Foo"
email: "john.foo@hopkins.com"
Dancer::Plugin::SiteMap
    use Dancer::Plugin::SiteMap;


●   You get: /sitemap and /sitemap.xml
●   “Yup, it's that simple.”
Dancer::Plugin::Email
post '/contact' => sub {
    email {
        to      => 'a@b.com',
        subject => 'Test',
        message => $msg,
        attach  => [ path => 'name' ],
    }
};
Dancer::Plugin::Authorize
post '/login' => sub {
    my $user = params­>{'user'};
    my $pass = params­>{'pass'};
    if ( auth( $user, $pass ) ) {
        if ( auth_asa('guest')  ) {...}
        if ( auth_can('create') ) {...}
    }
};
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
Dancer::Plugin::DBIC
●   DBIC (DBIx::Class) – a sophisticated ORM
●   Configure the connection in the config file
●   Make the ResultSets available in routes
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,
       };
    };
In culmination
  Dancer is beautiful and fun
The way programming should be



        PerlDancer.org
search.cpan.org/perldoc?Dancer
Perl Dancer for Python programmers

Mais conteúdo relacionado

Mais procurados

Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
Jeremy Kendall
 
優しいWAFの作り方
優しいWAFの作り方優しいWAFの作り方
優しいWAFの作り方
techmemo
 
Your own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with RubyYour own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with Ruby
Lindsay Holmwood
 

Mais procurados (20)

Developing apps using Perl
Developing apps using PerlDeveloping apps using Perl
Developing apps using Perl
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro framework
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and Knockout
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Quality Use Of Plugin
Quality Use Of PluginQuality Use Of Plugin
Quality Use Of Plugin
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
 
JSON and the APInauts
JSON and the APInautsJSON and the APInauts
JSON and the APInauts
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
How to develop modern web application framework
How to develop modern web application frameworkHow to develop modern web application framework
How to develop modern web application framework
 
優しいWAFの作り方
優しいWAFの作り方優しいWAFの作り方
優しいWAFの作り方
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
 
Your own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with RubyYour own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with Ruby
 

Semelhante a Perl Dancer for Python programmers

Refactoring.the.ruby.way
Refactoring.the.ruby.wayRefactoring.the.ruby.way
Refactoring.the.ruby.way
Shouichi KAMIYA
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
guestcf9240
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
Lin Yo-An
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 

Semelhante a Perl Dancer for Python programmers (20)

PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Laravel5 Introduction and essentials
Laravel5 Introduction and essentialsLaravel5 Introduction and essentials
Laravel5 Introduction and essentials
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
Sprockets
SprocketsSprockets
Sprockets
 
Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & Express
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHP
 
Refactoring.the.ruby.way
Refactoring.the.ruby.wayRefactoring.the.ruby.way
Refactoring.the.ruby.way
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Modern php
Modern phpModern php
Modern php
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
 
Practical pig
Practical pigPractical pig
Practical pig
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Rails 2010 Workshop
Rails 2010 WorkshopRails 2010 Workshop
Rails 2010 Workshop
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Perl Moderno
Perl ModernoPerl Moderno
Perl Moderno
 

Mais de xSawyer

Mais de xSawyer (13)

do_this and die();
do_this and die();do_this and die();
do_this and die();
 
XS Fun
XS FunXS Fun
XS Fun
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
 
Asynchronous programming FTW!
Asynchronous programming FTW!Asynchronous programming FTW!
Asynchronous programming FTW!
 
Moose - YAPC::NA 2012
Moose - YAPC::NA 2012Moose - YAPC::NA 2012
Moose - YAPC::NA 2012
 
Our local state, my, my - Understanding Perl variables
Our local state, my, my - Understanding Perl variablesOur local state, my, my - Understanding Perl variables
Our local state, my, my - Understanding Perl variables
 
Your first website in under a minute with Dancer
Your first website in under a minute with DancerYour first website in under a minute with Dancer
Your first website in under a minute with Dancer
 
Moose talk at FOSDEM 2011 (Perl devroom)
Moose talk at FOSDEM 2011 (Perl devroom)Moose talk at FOSDEM 2011 (Perl devroom)
Moose talk at FOSDEM 2011 (Perl devroom)
 
When Perl Met Android (YAPC::EU 2010)
When Perl Met Android (YAPC::EU 2010)When Perl Met Android (YAPC::EU 2010)
When Perl Met Android (YAPC::EU 2010)
 
Perl Dancer on Android (first attempt)
Perl Dancer on Android (first attempt)Perl Dancer on Android (first attempt)
Perl Dancer on Android (first attempt)
 
Source Code Management systems
Source Code Management systemsSource Code Management systems
Source Code Management systems
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)
 
Red Flags in Programming
Red Flags in ProgrammingRed Flags in Programming
Red Flags in Programming
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Perl Dancer for Python programmers