Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Perl Dancer Journées Perl 2010 11 juin 2010, Calais
Alexis Sukrieh Twitter : @sukria CPAN : sukria http://www.sukria.net
http://perldancer.org
$ sudo cpan m  Dancer
http://github.com/sukria/Dancer
framework   web pour Perl
Encore un ?
OUI
Pourquoi ?
Dépasser CGI.pm
Oublier CGI.pm
Sans devenir Catalyst
Apporter une différence
Ruby
Nouvelle approche
Pourquoi pas Perl ?
Dancer
Dancer est un framework...
un  micro  framework
<ul>Léger </ul>
<ul>Autonome </ul>
<ul>Peu de dépendances </ul>
<ul>Compatible PSGI/Plack </ul>
<ul>Facile </ul>
<ul>Evolutif </ul>
<ul>Hello World </ul>
package   MyApp ; use   Dancer; get   '/'   =>   sub   { 'Hello FPW 2010!' }; dance;
serveur web  embarqué
$ ./myApp.pl >> Listening on 127.0.0.1:3000 == Entering the development dance floor ...
Créer une application
Génération d'un squellette $  dancer -a  WebApp + WebApp/app.psgi + WebApp/config.yml + WebApp/environments [...] + WebApp...
Layout CPAN-friendly
Dancer::Test use Test::More tests => 3; use WebApp; use Dancer::Test; route_exists  [GET => '/']; response_status_is  ['GE...
Application pré-configurée config.yml environments/development.yml environments/production.yml
# config.yml layout: 'application' foo: 42 content_type: 'text/plain'
config.yml = Configuration globale
development.yml warnings: 1 show_errors: 1 auto_reload: 1
production.yml warnings: 0 show_errors: 0 auto_reload: 0
$ ./WebApp.pl -e production Démarre l'application avec l'environnement « production »
Ready to rock!
Les  route handlers
méthode HTTP
+ path
+ sub { }
get '/' => sub {  ... };
get  '/' => sub {  ... };
get  '/'  => sub {  ... };
get '/' =>  sub {  ... } ;
/foo /bar/:var /baz/* r('/stuff/([a-z0-9]+)/')
/foo /bar/:var /baz/* r('/stuff/([a-z0-9]+)/') qr{/stuff/([a-z0-9]+)/}  NEW
Chemins statiques / /foo /bar/baz
Chemins avec tokens /hello/:buddy my $name = params->{buddy}
Chemins avec jokers /show/*.* my ($file, $ext) = splat;
Chemins avec expressions régulières r('/post/([a-z0-9]+)') my ($post) = splat; # $1
Dancer est  un aiguilleur
Vers le bon  route handler
404 Si aucun ne correspond
$appdir/public
Route handler trouvé,  Execution de son code
Un seul objectif
La réponse
Contenu get '/showme' => sub { template  'showme', {  var => 'foo'}; };
Headers get '/' => sub { headers  'X-MyHead1' => 42; ... };
Requête get '/' => sub { my $path =  request ->path; my @uploads =  request ->uploads(); my $h1 =  request ->header('X-MyH...
Passer get '/lazy' => sub { pass ; };
Servir un fichier get '/dowload/:file' => sub { my $file = params->{file}; send_file $file; };
Déclencher une erreur get '/forbidden' => sub { send_error 'Nope'; };
Rediriger get '/forbidden' => sub { redirect '/better/place'; };
valeur de retour = contenu de la réponse
Fonctionnalités Avancées
Logs
Usage get '/' => sub { debug  'poupoutte' ; warning  'a warning' ; error  'an error' ; };
Configuration log  : core|debug|warning|error logger  : file|console|...
sukria@razor:/tmp/WebApp$ ./WebApp.pl  [28877]  core  @0.000011> loading application WebApp in ./WebApp.pl l. 3 [28877]  c...
Logger engines Dancer::Logger::File Dancer::Logger::Console Dancer::Logger::Syslog Dancer::Logger::LogHandler ...
Sessions
Interface universelle
Ecrire post '/login' => sub { ... if ($user) { session  'user' => $user; } };
Lire get '/home' => sub { ... unless ( session ('user')) { return redirect '/login'; } };
Session engines Dancer::Session::Simple Dancer::Session::YAML Dancer::Session::Memcache Dancer::Session::Storable Dancer::...
Filtres
Initialiser un contexte before  sub {  var 'foo' => 42; var 'dbh' =>  DBI->connect(...); };
Stopper l'execution before  sub {  ... return  halt ('stop here'); };
Contrôles systématiques before  sub {  if (not session('user')) { redirect '/login'; } };
Serializers
Valeur de retour Serialisée set serializer => 'JSON';
get => '/user/:id' => sub { ... return { user => $user }; };
Sans serializer $ curl http://0:3000/user/42 HASH(0x295d568)
Avec serializer $ curl http://0:3000/user/42 {&quot;name&quot;:&quot;Larry Wall&quot;,&quot;id&quot;:42}
Serializer engines Dancer::Serializer::JSON Dancer::Serializer::YAML Dancer::Serializer::Dumper Dancer::Serializer::Mutable
Plugins
Enrichir la syntaxe
Design patterns
use Dancer::Plugin:: Database ; get '/' =>sub { ... my $sth =  database ->prepare(...); };
Ecrire un plugin
package Dancer::Plugin::FPW2010;  use Dancer::Plugin; register ' add_fpw2010_route ' => sub { get '/fpw2010' => sub {  'Bo...
Deja plusieurs plugins sur CPAN Dancer::Plugin::Validation Dancer::Plugin::Database Dancer::Plugin::REST Dancer::Plugin::E...
Déploiement
Pour déployer Dancer  PSGI/Plack
Plack - Perl Rack - Ruby WSGI - Python
Adaptateur universel serveur / application
app.psgi connecteur Plack
$ plackup -a app.psgi &
Tous les serveurs web ont des adaptateurs PSGI
Apache (mod_psgi) Nginx Starman Perlbal HTTP::Server::PSGI HTTP::Server::Fast ...
Exemple Apache <Location /> SetHandler perl-script PerlResponseHandler Plack::Handler::Apache2 PerlSetVar psgi_app /path/t...
CGI : dispatch.cgi FastCGI : dispatch.fcgi Plack::Handler::AnyEvent Plack::Handler::Starman Plack::Handler::* ...
Ecosystème
Dancer::Cookbook Dancer::Deployment Dancer::Template::Simple Dancer::Template::TemplateToolkit Dancer::Test Dancer::Sessio...
GitHub 30 forks 130 followers
+50 distributions +10 auteurs
Communauté irc.perl.org/#dancer [email_address]
Docs  Dancer Dancer::Introduction Dancer::Cookbook Dancer::Deployment ...
http://perldancer.org
Upcoming SlideShare
Loading in …5
×

of

Perl Dancer, FPW 2010 Slide 1 Perl Dancer, FPW 2010 Slide 2 Perl Dancer, FPW 2010 Slide 3 Perl Dancer, FPW 2010 Slide 4 Perl Dancer, FPW 2010 Slide 5 Perl Dancer, FPW 2010 Slide 6 Perl Dancer, FPW 2010 Slide 7 Perl Dancer, FPW 2010 Slide 8 Perl Dancer, FPW 2010 Slide 9 Perl Dancer, FPW 2010 Slide 10 Perl Dancer, FPW 2010 Slide 11 Perl Dancer, FPW 2010 Slide 12 Perl Dancer, FPW 2010 Slide 13 Perl Dancer, FPW 2010 Slide 14 Perl Dancer, FPW 2010 Slide 15 Perl Dancer, FPW 2010 Slide 16 Perl Dancer, FPW 2010 Slide 17 Perl Dancer, FPW 2010 Slide 18 Perl Dancer, FPW 2010 Slide 19 Perl Dancer, FPW 2010 Slide 20 Perl Dancer, FPW 2010 Slide 21 Perl Dancer, FPW 2010 Slide 22 Perl Dancer, FPW 2010 Slide 23 Perl Dancer, FPW 2010 Slide 24 Perl Dancer, FPW 2010 Slide 25 Perl Dancer, FPW 2010 Slide 26 Perl Dancer, FPW 2010 Slide 27 Perl Dancer, FPW 2010 Slide 28 Perl Dancer, FPW 2010 Slide 29 Perl Dancer, FPW 2010 Slide 30 Perl Dancer, FPW 2010 Slide 31 Perl Dancer, FPW 2010 Slide 32 Perl Dancer, FPW 2010 Slide 33 Perl Dancer, FPW 2010 Slide 34 Perl Dancer, FPW 2010 Slide 35 Perl Dancer, FPW 2010 Slide 36 Perl Dancer, FPW 2010 Slide 37 Perl Dancer, FPW 2010 Slide 38 Perl Dancer, FPW 2010 Slide 39 Perl Dancer, FPW 2010 Slide 40 Perl Dancer, FPW 2010 Slide 41 Perl Dancer, FPW 2010 Slide 42 Perl Dancer, FPW 2010 Slide 43 Perl Dancer, FPW 2010 Slide 44 Perl Dancer, FPW 2010 Slide 45 Perl Dancer, FPW 2010 Slide 46 Perl Dancer, FPW 2010 Slide 47 Perl Dancer, FPW 2010 Slide 48 Perl Dancer, FPW 2010 Slide 49 Perl Dancer, FPW 2010 Slide 50 Perl Dancer, FPW 2010 Slide 51 Perl Dancer, FPW 2010 Slide 52 Perl Dancer, FPW 2010 Slide 53 Perl Dancer, FPW 2010 Slide 54 Perl Dancer, FPW 2010 Slide 55 Perl Dancer, FPW 2010 Slide 56 Perl Dancer, FPW 2010 Slide 57 Perl Dancer, FPW 2010 Slide 58 Perl Dancer, FPW 2010 Slide 59 Perl Dancer, FPW 2010 Slide 60 Perl Dancer, FPW 2010 Slide 61 Perl Dancer, FPW 2010 Slide 62 Perl Dancer, FPW 2010 Slide 63 Perl Dancer, FPW 2010 Slide 64 Perl Dancer, FPW 2010 Slide 65 Perl Dancer, FPW 2010 Slide 66 Perl Dancer, FPW 2010 Slide 67 Perl Dancer, FPW 2010 Slide 68 Perl Dancer, FPW 2010 Slide 69 Perl Dancer, FPW 2010 Slide 70 Perl Dancer, FPW 2010 Slide 71 Perl Dancer, FPW 2010 Slide 72 Perl Dancer, FPW 2010 Slide 73 Perl Dancer, FPW 2010 Slide 74 Perl Dancer, FPW 2010 Slide 75 Perl Dancer, FPW 2010 Slide 76 Perl Dancer, FPW 2010 Slide 77 Perl Dancer, FPW 2010 Slide 78 Perl Dancer, FPW 2010 Slide 79 Perl Dancer, FPW 2010 Slide 80 Perl Dancer, FPW 2010 Slide 81 Perl Dancer, FPW 2010 Slide 82 Perl Dancer, FPW 2010 Slide 83 Perl Dancer, FPW 2010 Slide 84 Perl Dancer, FPW 2010 Slide 85 Perl Dancer, FPW 2010 Slide 86 Perl Dancer, FPW 2010 Slide 87 Perl Dancer, FPW 2010 Slide 88 Perl Dancer, FPW 2010 Slide 89 Perl Dancer, FPW 2010 Slide 90 Perl Dancer, FPW 2010 Slide 91 Perl Dancer, FPW 2010 Slide 92 Perl Dancer, FPW 2010 Slide 93 Perl Dancer, FPW 2010 Slide 94 Perl Dancer, FPW 2010 Slide 95 Perl Dancer, FPW 2010 Slide 96 Perl Dancer, FPW 2010 Slide 97 Perl Dancer, FPW 2010 Slide 98 Perl Dancer, FPW 2010 Slide 99 Perl Dancer, FPW 2010 Slide 100 Perl Dancer, FPW 2010 Slide 101 Perl Dancer, FPW 2010 Slide 102 Perl Dancer, FPW 2010 Slide 103 Perl Dancer, FPW 2010 Slide 104 Perl Dancer, FPW 2010 Slide 105 Perl Dancer, FPW 2010 Slide 106 Perl Dancer, FPW 2010 Slide 107 Perl Dancer, FPW 2010 Slide 108 Perl Dancer, FPW 2010 Slide 109 Perl Dancer, FPW 2010 Slide 110 Perl Dancer, FPW 2010 Slide 111 Perl Dancer, FPW 2010 Slide 112 Perl Dancer, FPW 2010 Slide 113 Perl Dancer, FPW 2010 Slide 114
Upcoming SlideShare
Perl Dancer for Python programmers
Next
Download to read offline and view in fullscreen.

0 Likes

Share

Download to read offline

Perl Dancer, FPW 2010

Download to read offline

Développement Web avec Perl Dancer, Journées Perl 2010, 11 juin 2010, Calais

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

Perl Dancer, FPW 2010

  1. 1. Perl Dancer Journées Perl 2010 11 juin 2010, Calais
  2. 2. Alexis Sukrieh Twitter : @sukria CPAN : sukria http://www.sukria.net
  3. 3. http://perldancer.org
  4. 4. $ sudo cpan m Dancer
  5. 5. http://github.com/sukria/Dancer
  6. 6. framework web pour Perl
  7. 7. Encore un ?
  8. 8. OUI
  9. 9. Pourquoi ?
  10. 10. Dépasser CGI.pm
  11. 11. Oublier CGI.pm
  12. 12. Sans devenir Catalyst
  13. 13. Apporter une différence
  14. 14. Ruby
  15. 15. Nouvelle approche
  16. 16. Pourquoi pas Perl ?
  17. 17. Dancer
  18. 18. Dancer est un framework...
  19. 19. un micro framework
  20. 20. <ul>Léger </ul>
  21. 21. <ul>Autonome </ul>
  22. 22. <ul>Peu de dépendances </ul>
  23. 23. <ul>Compatible PSGI/Plack </ul>
  24. 24. <ul>Facile </ul>
  25. 25. <ul>Evolutif </ul>
  26. 26. <ul>Hello World </ul>
  27. 27. package MyApp ; use Dancer; get '/' => sub { 'Hello FPW 2010!' }; dance;
  28. 28. serveur web embarqué
  29. 29. $ ./myApp.pl >> Listening on 127.0.0.1:3000 == Entering the development dance floor ...
  30. 30. Créer une application
  31. 31. Génération d'un squellette $ dancer -a WebApp + WebApp/app.psgi + WebApp/config.yml + WebApp/environments [...] + WebApp/lib/WebApp.pm + WebApp/views + WebApp/views/index.tt [...] + WebApp/WebApp.pl + WebApp/t/002_index_route.t + WebApp/t/001_base.t + WebApp/Makefile.PL
  32. 32. Layout CPAN-friendly
  33. 33. Dancer::Test use Test::More tests => 3; use WebApp; use Dancer::Test; route_exists [GET => '/']; response_status_is ['GET' => '/'], 200;
  34. 34. Application pré-configurée config.yml environments/development.yml environments/production.yml
  35. 35. # config.yml layout: 'application' foo: 42 content_type: 'text/plain'
  36. 36. config.yml = Configuration globale
  37. 37. development.yml warnings: 1 show_errors: 1 auto_reload: 1
  38. 38. production.yml warnings: 0 show_errors: 0 auto_reload: 0
  39. 39. $ ./WebApp.pl -e production Démarre l'application avec l'environnement « production »
  40. 40. Ready to rock!
  41. 41. Les route handlers
  42. 42. méthode HTTP
  43. 43. + path
  44. 44. + sub { }
  45. 45. get '/' => sub { ... };
  46. 46. get '/' => sub { ... };
  47. 47. get '/' => sub { ... };
  48. 48. get '/' => sub { ... } ;
  49. 49. /foo /bar/:var /baz/* r('/stuff/([a-z0-9]+)/')
  50. 50. /foo /bar/:var /baz/* r('/stuff/([a-z0-9]+)/') qr{/stuff/([a-z0-9]+)/} NEW
  51. 51. Chemins statiques / /foo /bar/baz
  52. 52. Chemins avec tokens /hello/:buddy my $name = params->{buddy}
  53. 53. Chemins avec jokers /show/*.* my ($file, $ext) = splat;
  54. 54. Chemins avec expressions régulières r('/post/([a-z0-9]+)') my ($post) = splat; # $1
  55. 55. Dancer est un aiguilleur
  56. 56. Vers le bon route handler
  57. 57. 404 Si aucun ne correspond
  58. 58. $appdir/public
  59. 59. Route handler trouvé, Execution de son code
  60. 60. Un seul objectif
  61. 61. La réponse
  62. 62. Contenu get '/showme' => sub { template 'showme', { var => 'foo'}; };
  63. 63. Headers get '/' => sub { headers 'X-MyHead1' => 42; ... };
  64. 64. Requête get '/' => sub { my $path = request ->path; my @uploads = request ->uploads(); my $h1 = request ->header('X-MyHead1'); ... };
  65. 65. Passer get '/lazy' => sub { pass ; };
  66. 66. Servir un fichier get '/dowload/:file' => sub { my $file = params->{file}; send_file $file; };
  67. 67. Déclencher une erreur get '/forbidden' => sub { send_error 'Nope'; };
  68. 68. Rediriger get '/forbidden' => sub { redirect '/better/place'; };
  69. 69. valeur de retour = contenu de la réponse
  70. 70. Fonctionnalités Avancées
  71. 71. Logs
  72. 72. Usage get '/' => sub { debug 'poupoutte' ; warning 'a warning' ; error 'an error' ; };
  73. 73. Configuration log  : core|debug|warning|error logger  : file|console|...
  74. 74. sukria@razor:/tmp/WebApp$ ./WebApp.pl [28877] core @0.000011> loading application WebApp in ./WebApp.pl l. 3 [28877] core @0.002561> loading Standalone handler in /usr/local/share/perl/5.10.1/Dancer.pm l. 193 [28877] core @0.000054> request: GET / in /usr/local/share/perl/5.10.1/Dancer/Handler/Standalone.pm l. 39 [28877] debug @0.000326> [hit #1] a debug in /tmp/WebApp/lib/WebApp.pm l. 7
  75. 75. Logger engines Dancer::Logger::File Dancer::Logger::Console Dancer::Logger::Syslog Dancer::Logger::LogHandler ...
  76. 76. Sessions
  77. 77. Interface universelle
  78. 78. Ecrire post '/login' => sub { ... if ($user) { session 'user' => $user; } };
  79. 79. Lire get '/home' => sub { ... unless ( session ('user')) { return redirect '/login'; } };
  80. 80. Session engines Dancer::Session::Simple Dancer::Session::YAML Dancer::Session::Memcache Dancer::Session::Storable Dancer::Session::Cookie ...
  81. 81. Filtres
  82. 82. Initialiser un contexte before sub { var 'foo' => 42; var 'dbh' => DBI->connect(...); };
  83. 83. Stopper l'execution before sub { ... return halt ('stop here'); };
  84. 84. Contrôles systématiques before sub { if (not session('user')) { redirect '/login'; } };
  85. 85. Serializers
  86. 86. Valeur de retour Serialisée set serializer => 'JSON';
  87. 87. get => '/user/:id' => sub { ... return { user => $user }; };
  88. 88. Sans serializer $ curl http://0:3000/user/42 HASH(0x295d568)
  89. 89. Avec serializer $ curl http://0:3000/user/42 {&quot;name&quot;:&quot;Larry Wall&quot;,&quot;id&quot;:42}
  90. 90. Serializer engines Dancer::Serializer::JSON Dancer::Serializer::YAML Dancer::Serializer::Dumper Dancer::Serializer::Mutable
  91. 91. Plugins
  92. 92. Enrichir la syntaxe
  93. 93. Design patterns
  94. 94. use Dancer::Plugin:: Database ; get '/' =>sub { ... my $sth = database ->prepare(...); };
  95. 95. Ecrire un plugin
  96. 96. package Dancer::Plugin::FPW2010; use Dancer::Plugin; register ' add_fpw2010_route ' => sub { get '/fpw2010' => sub { 'Bonjour FPW 2010 !'  }; }; register_plugin;
  97. 97. Deja plusieurs plugins sur CPAN Dancer::Plugin::Validation Dancer::Plugin::Database Dancer::Plugin::REST Dancer::Plugin::Email ...
  98. 98. Déploiement
  99. 99. Pour déployer Dancer PSGI/Plack
  100. 100. Plack - Perl Rack - Ruby WSGI - Python
  101. 101. Adaptateur universel serveur / application
  102. 102. app.psgi connecteur Plack
  103. 103. $ plackup -a app.psgi &
  104. 104. Tous les serveurs web ont des adaptateurs PSGI
  105. 105. Apache (mod_psgi) Nginx Starman Perlbal HTTP::Server::PSGI HTTP::Server::Fast ...
  106. 106. Exemple Apache <Location /> SetHandler perl-script PerlResponseHandler Plack::Handler::Apache2 PerlSetVar psgi_app /path/to/app.psgi </Location>
  107. 107. CGI : dispatch.cgi FastCGI : dispatch.fcgi Plack::Handler::AnyEvent Plack::Handler::Starman Plack::Handler::* ...
  108. 108. Ecosystème
  109. 109. Dancer::Cookbook Dancer::Deployment Dancer::Template::Simple Dancer::Template::TemplateToolkit Dancer::Test Dancer::Session::YAML Dancer::Session::Simple Dancer::Introduction Dancer::Template::Alloy Dancer::Template::TemplateSandbox Dancer::Template::Tenjin Task::Dancer Dancer::Plugin::Database Dancer::Template::HtmlTemplate Dancer::Logger::Syslog Dancer::Session::Storable Dancer::Plugin::REST Dancer::Plugin::Validation Dancer::Template::Tiny Dancer::Plugin::SiteMap Dancer::Plugin::Email Dancer::Template::Haml Dancer::Serializer::YAML Dancer::Template::Mason Dancer::Session::Memcache Dancer::Template::MicroTemplate Dancer::Session::Memcache Dancer::Session::Cookie Dancer::Serializer::XML Dancer::Serializer::Mutable Dancer::Serializer::JSON Dancer::Logger::LogHandler ...
  110. 110. GitHub 30 forks 130 followers
  111. 111. +50 distributions +10 auteurs
  112. 112. Communauté irc.perl.org/#dancer [email_address]
  113. 113. Docs Dancer Dancer::Introduction Dancer::Cookbook Dancer::Deployment ...
  114. 114. http://perldancer.org

Développement Web avec Perl Dancer, Journées Perl 2010, 11 juin 2010, Calais

Views

Total views

25,027

On Slideshare

0

From embeds

0

Number of embeds

14,016

Actions

Downloads

48

Shares

0

Comments

0

Likes

0

×