Your SlideShare is downloading. ×
PerlDancer for Perlers (FOSDEM 2011)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

PerlDancer for Perlers (FOSDEM 2011)

5,863
views

Published on

This are the slides for the Dancer talk I gave at the Perl devroom at FOSDEM 2011. …

This are the slides for the Dancer talk I gave at the Perl devroom at FOSDEM 2011.

It is more up-to-date than the Pythoners version.

Published in: Technology

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,863
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
34
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Dancer (the Effortless Perl Web Framework)
  • 2. About me
    • Sawyer X
    • 3. Sysadmin / Perl Ninja
    • 4. Israel.pm / Haifa.pm / TelAviv.pm / Rehovot.pm
    • 5. I do system, networking, web, applications, etc.
    • 6. http://blogs.perl.org/users/sawyer_x/
    • 7. http://search.cpan.org/~xsawyerx/
  • 8. Perl web recap
      1995 CGI
  • 9. Perl web recap
      2010 Many frameworks (including micro-frameworks like Dancer ) credit to Dave Rolsky for this intro
  • 10. The big web religions, illustrated
  • 11. Ruby – the fanboys
  • 12. Python – the sticklers
  • 13. PHP – the nonsensical
  • 14. Perl – the nutcases
  • 15. Nutcases?
    • Yes , we are insane (but not LISP-insane)
    • 16. Insanity is a whole lot of fun!
    • 17. Insanity gives us flexibility
    • 18. Flexibility gives us cool stuff
    • 19. Like Moose and meta-programming
    • 20. Like DBIx::Class
    • 21. Like Dancer
  • 22. Flask (Pythonese)
      from flask import Flask app = Flask(__name__) @ app.route ( "/" , methods=[ 'GET' ] ) def hello (): return "Hello World!" if __name__ == "__main__" : app.run()
  • 23. Dancer (Perlesque)
      use Dancer; get “/” => sub { “ Hello, World!” }; dance ;
  • 24. In comparison
      from flask import Flask app = Flask(__name__) @ app.route ( "/" , methods=[ 'GET' ] ) def hello (): return "Hello World!" if __name__ == "__main__" : app.run()
      use Dancer; get “/” => sub { “ Hello, World!” }; dance ;
  • 25. Web development models
  • 26. CGI
    • Most common web programming model
    • 27. Easy to configure on a web server
    • 28. Programmer gets everything in %ENV
    • 29. First paragraph in output is for the browser
    • 30. Second paragraph is content for the browser
    • 31. Error prone, depressing, boring, long
  • 32. MVC
    • Separation of Model, View, Controller
    • 33. Much more flexible and scalable
    • 34. Uses “Namespace Matching”
    • 35. Sometimes an over-kill
    • 36. MVC framework example: Catalyst
  • 37. Route dispatching
  • 43. Dancer treats
    • Both read and write , easily!
    • 44. Route-based (started as a port of Sinatra)
    • 45. PSGI/Plack compliant
    • 46. Minimal dependencies
    • 47. Any app is also a web server
    • 48. CPAN-friendly (<3 CPAN)
  • 49. Recipe for Dancing
    • Take an HTTP method
    • 50. Add a path to that
    • 51. Mix with a subroutine
    • 52. And sprinkle plugins and keywords on top
  • 53. Dancer route structure
      get '/path' => sub { … }; post '/path' => sub { … }; put '/path' => sub { … }; del '/path' => sub { … }; options '/path' => sub { … }; any '/path' => sub { … };
  • 54. Dancer
    • Paths can contain variables
    • 55. get '/hello/:entity/'
    • 56. Support optional variables
    • 57. get '/hello/:entity?'
    • 58. Paths can be Regular Expressions
    • 59. get qr {/ (w+) / d {2,3} (.+)? } x
  • 60. 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' ; } };
  • 61. Templating
      get '/' => sub { template index => { greeting => 'welcome' } };
  • 62. More nifty stuff
    • headers 'My-X-Header' => 'Value'
    • 63. send_file ( 'report.tar.gz' )
    • 64. set_cookie name => 'value' ,
    • 65. expires => ( time + 3600 ),
    • 66. domain => 'foo.com'
    • 67. status 'not_found'
    • 68. to_json , to_yaml , to_xml
    • 69. my $file = upload ( 'file_input' )
    • 70. my $all_uploads = request ->uploads
  • 71. Dancer as Perl philosophy
    • Dancer is succinct, efficient and easy to work with
    • 72. Dancer is daring
    • 73. (Probably the only web framework with route caching)
    • 74. (Websockets in the works!)
    • 75. Dancer has a lot of plugins:
    • 76. (engines for sessions , logging , templates)
    • 77. Serializers (JSON , YAML , XML)
    • 78. Route filters (before , after , before_template)
  • 79. Oh yeah, route caching...
  • 80. Dancer::Plugin::REST
      get '/user/:id.:format' => sub { UserRS ->find( params ->{ id } ); }; # curl http://mywebservice/user/42.json { &quot;id&quot;: 42, &quot;name&quot;: &quot;John Foo&quot;, &quot;email&quot;: &quot;john.foo@hopkins.com&quot; } # curl http://mywebservice/user/42.yml -- id: 42 name: &quot;John Foo&quot; email: &quot;john.foo@hopkins.com&quot;
  • 81. Dancer::Plugin::SiteMap
      use Dancer::Plugin::SiteMap;
    • You get: /sitemap and /sitemap.xml
    • 82. “ Yup, it's that simple.”
  • 83. Dancer::Plugin::Email
      post '/contact' => sub { email { to => 'a@b.com' , subject => 'Test' , message => $msg , attach => [ path => 'name' ], } };
  • 84. Dancer::Plugin::Auth::RBAC
      post '/login' => sub { my $user = params ->{ 'user' }; my $pass = params ->{ 'pass' }; if ( auth ( $user , $pass ) ) { if ( auth_asa ( 'guest' ) ) {...} if ( auth_can ( 'create' ) ) {...} } };
  • 85. Dancer::Plugin::Ajax
      ajax '/check_for_update' => sub { # some ajax code };
    • Pass if X-Request-With not “XMLHttpRequest”
    • 86. Disable the layout
    • 87. The action built is a POST request
  • 88. Dancer::Plugin::DBIC
    • DBIC (DBIx::Class) – a sophisticated ORM
    • 89. Configure the connection in the config file
    • 90. Make the ResultSets available in routes
  • 91. Dancer::Plugin::Database
    • Database(s) connection in Dancer
    • 92. get '/widget/view/:id' => sub {
    • 93. my $sth = database ->prepare(
    • 94. 'select * from widgets where id = ?'
    • 95. );
    • 96. $sth ->execute( params ->{ id } );
    • 97. template display_widget => {
    • 98. widget => $sth ->fetchrow_hashref,
    • 99. };
    • 100. };
  • 101. Even more plugins
    • Dancer::Plugin::WebSocket
    • 102. Dancer::Plugin::FlashMessage
    • 103. Dancer::Plugin::Auth::Twitter
    • 104. Dancer::Plugin::MobileDevice
    • 105. Dancer::Plugin::Feed
    • 106. Dancer::Plugin::Redis
  • 107. In culmination Dancer is beautiful and fun The way programming should be PerlDancer.org search.cpan.org/perldoc?Dancer http://advent.perldancer.org/2010 (http://advent.perldancer.org/2010/2)
  • 108. Thank you!