SlideShare une entreprise Scribd logo
1  sur  114
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
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
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/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
Layout CPAN-friendly
Dancer::Test use Test::More tests => 3; use WebApp; use Dancer::Test; route_exists  [GET => '/']; response_status_is  ['GET' => '/'], 200;
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-MyHead1'); ... };
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]  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
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::Session::Cookie ...
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 {"name":"Larry Wall","id":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 {  'Bonjour FPW 2010 !'   }; }; register_plugin;
Deja plusieurs plugins sur CPAN Dancer::Plugin::Validation Dancer::Plugin::Database Dancer::Plugin::REST Dancer::Plugin::Email ...
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/to/app.psgi </Location>
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::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 ...
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

Contenu connexe

Tendances

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
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
優しい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
 

Tendances (20)

Developing apps using Perl
Developing apps using PerlDeveloping apps using Perl
Developing apps using Perl
 
Inside Bokete: Web Application with Mojolicious and others
Inside Bokete:  Web Application with Mojolicious and othersInside Bokete:  Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and others
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
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
 
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
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
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の作り方
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and Knockout
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
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
 
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...
 
JSON and the APInauts
JSON and the APInautsJSON and the APInauts
JSON and the APInauts
 

Similaire à Perl Dancer, FPW 2010

Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Atlassian
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
Kar Juan
 
Ratpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web AppsRatpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web Apps
James Williams
 
Хокку про Heroku
Хокку про HerokuХокку про Heroku
Хокку про Heroku
GeeksLab Odessa
 
Exploiting the newer perl to improve your plugins
Exploiting the newer perl to improve your pluginsExploiting the newer perl to improve your plugins
Exploiting the newer perl to improve your plugins
Marian Marinov
 

Similaire à Perl Dancer, FPW 2010 (20)

Summit2011 satellites-robinf-20110605
Summit2011 satellites-robinf-20110605Summit2011 satellites-robinf-20110605
Summit2011 satellites-robinf-20110605
 
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
 
Writing Pluggable Software
Writing Pluggable SoftwareWriting Pluggable Software
Writing Pluggable Software
 
What's New in ZF 1.10
What's New in ZF 1.10What's New in ZF 1.10
What's New in ZF 1.10
 
Schenker - DSL for quickly creating web applications in Perl
Schenker - DSL for quickly creating web applications in PerlSchenker - DSL for quickly creating web applications in Perl
Schenker - DSL for quickly creating web applications in Perl
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web apps
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
Mojolicious on Steroids
Mojolicious on SteroidsMojolicious on Steroids
Mojolicious on Steroids
 
Nginx Workshop Aftermath
Nginx Workshop AftermathNginx Workshop Aftermath
Nginx Workshop Aftermath
 
Rush, a shell that will yield to you
Rush, a shell that will yield to youRush, a shell that will yield to you
Rush, a shell that will yield to you
 
Maintaining your own branch of Drupal core
Maintaining your own branch of Drupal coreMaintaining your own branch of Drupal core
Maintaining your own branch of Drupal core
 
Ratpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web AppsRatpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web Apps
 
Хокку про Heroku
Хокку про HerokuХокку про Heroku
Хокку про Heroku
 
Хокку про Heroku
Хокку про HerokuХокку про Heroku
Хокку про Heroku
 
Exploiting the newer perl to improve your plugins
Exploiting the newer perl to improve your pluginsExploiting the newer perl to improve your plugins
Exploiting the newer perl to improve your plugins
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
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
 
Sprockets
SprocketsSprockets
Sprockets
 
SugarCon 2010 - Best Practices for Creating Custom Apps in Sugar
SugarCon 2010 - Best Practices for Creating Custom Apps in SugarSugarCon 2010 - Best Practices for Creating Custom Apps in Sugar
SugarCon 2010 - Best Practices for Creating Custom Apps in Sugar
 

Dernier

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech 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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 

Perl Dancer, FPW 2010