SlideShare une entreprise Scribd logo
1  sur  44
Télécharger pour lire hors ligne
Dancing Tutorial

Alberto Manuel Brand˜o Sim˜es
                    a     o
        ambs@perl.pt


      Braga Geek Nights
          March 1st




    Alberto Sim˜es
               o     Dancing Tutorial
Part 0: Ballet




                 Alberto Sim˜es
                            o     Dancing Tutorial
What’s Dancer?
A micro framework
for writing web applications
So, Yet Another Web Framework?
Well, yes!
CGI.pm webapps are spaghetti
Catalyst is HUGE
Ruby introduced something different
We needed something similar in Perl
Definitely
And they also imitated us!
Available at
http://perldancer.org
     and in GitHub.
Part 1: Tango




                Alberto Sim˜es
                           o     Dancing Tutorial
Installing



  §                                                        ¤
       $ sudo cpan Dancer
  ¦                                                        ¥
  or
  §                                                        ¤
       $ sudo cpan Task : : Dancer
  ¦                                                        ¥
  or yet
  §                                                        ¤
       $ cpanm −S Task : : Dancer
  ¦                                                        ¥




                       Alberto Sim˜es
                                  o     Dancing Tutorial
Bootstrap application
 §                                                           ¤
      $   dancer −a MyApp
      +   MyApp / bin / app . pl
      +   MyApp / config . yml
      +   MyApp / environments / development . yml
      +   MyApp / environments / production . yml
      +   MyApp / views / index . tt
      +   MyApp / views / layouts / main . tt
      +   MyApp / lib / MyApp . pm
      +   MyApp / public / javascripts / jquery . js
      +   MyApp / public / css / style . css
      +   MyApp / public / css / error . css
      +   MyApp / public / images / . . .
      +   MyApp / public / 5 0 0 . html
      +   MyApp / public / 4 0 4 . html
      +   MyApp / public / dispatch . fcgi
      +   MyApp / public / dispatch . cgi
      +   MyApp / Makefile . PL
      +   MyApp /t /002 _index_route . t
      +   MyApp /t /001 _base . t
 ¦                                                           ¥
                         Alberto Sim˜es
                                    o     Dancing Tutorial
What’s inside

 §                                                              ¤
      + MyApp / bin / app . pl
 ¦                                                              ¥

      a standalone light server (starts server in port 3000);
      also used for fast-cgi or common cgi backends;

 §                                                              ¤
      + MyApp / config . yml
      + MyApp / environments / development . yml
      + MyApp / environments / production . yml
 ¦                                                              ¥

      main configuration file (plugins, modules, etc);
      configuration files for production and development:
           defines what to report, where to report, etc.



                         Alberto Sim˜es
                                    o     Dancing Tutorial
What’s inside

 §                                                              ¤
      + MyApp / bin / app . pl
 ¦                                                              ¥

      a standalone light server (starts server in port 3000);
      also used for fast-cgi or common cgi backends;

 §                                                              ¤
      + MyApp / config . yml
      + MyApp / environments / development . yml
      + MyApp / environments / production . yml
 ¦                                                              ¥

      main configuration file (plugins, modules, etc);
      configuration files for production and development:
           defines what to report, where to report, etc.



                         Alberto Sim˜es
                                    o     Dancing Tutorial
What’s inside
 §                                                              ¤
      + MyApp / views / index . tt
      + MyApp / views / layouts / main . tt
 ¦                                                              ¥
      Templates and layouts:
            templates are page portions/scraps;
            layouts are full page designs
            (they are automagically filled by the template);
 §                                                              ¤
      +   MyApp / public / javascripts / jquery . js
      +   MyApp / public / css / style . css
      +   MyApp / public / css / error . css
      +   MyApp / public / images / . . .
 ¦                                                              ¥

      public/static files:
            javascript (Dancer ships with jsquery);
            cascade style sheets;
            images (for default design);

                            Alberto Sim˜es
                                       o     Dancing Tutorial
What’s inside
 §                                                              ¤
      + MyApp / views / index . tt
      + MyApp / views / layouts / main . tt
 ¦                                                              ¥
      Templates and layouts:
            templates are page portions/scraps;
            layouts are full page designs
            (they are automagically filled by the template);
 §                                                              ¤
      +   MyApp / public / javascripts / jquery . js
      +   MyApp / public / css / style . css
      +   MyApp / public / css / error . css
      +   MyApp / public / images / . . .
 ¦                                                              ¥

      public/static files:
            javascript (Dancer ships with jsquery);
            cascade style sheets;
            images (for default design);

                            Alberto Sim˜es
                                       o     Dancing Tutorial
What’s inside

 §                                                            ¤
      + MyApp / public / 5 0 0 . html
      + MyApp / public / 4 0 4 . html
 ¦                                                            ¥

      pages for 500 and 404 errors;


 §                                                            ¤
      + MyApp / public / dispatch . fcgi
      + MyApp / public / dispatch . cgi
 ¦                                                            ¥
      wrappers to configure fast-cgi and cgi backends;
           will be back on this later (future talk?);




                          Alberto Sim˜es
                                     o     Dancing Tutorial
What’s inside

 §                                                            ¤
      + MyApp / public / 5 0 0 . html
      + MyApp / public / 4 0 4 . html
 ¦                                                            ¥

      pages for 500 and 404 errors;


 §                                                            ¤
      + MyApp / public / dispatch . fcgi
      + MyApp / public / dispatch . cgi
 ¦                                                            ¥
      wrappers to configure fast-cgi and cgi backends;
           will be back on this later (future talk?);




                          Alberto Sim˜es
                                     o     Dancing Tutorial
What’s inside

 §                                                            ¤
      + MyApp / Makefile . PL
      + MyApp /t /002 _index_route . t
      + MyApp /t /001 _base . t
 ¦                                                            ¥
      Main module Makefile:
           usefull to make module of your application
      Your test suite;


 §                                                            ¤
      + MyApp / lib / MyApp . pm
 ¦                                                            ¥

      Your application!



                          Alberto Sim˜es
                                     o     Dancing Tutorial
What’s inside

 §                                                            ¤
      + MyApp / Makefile . PL
      + MyApp /t /002 _index_route . t
      + MyApp /t /001 _base . t
 ¦                                                            ¥
      Main module Makefile:
           usefull to make module of your application
      Your test suite;


 §                                                            ¤
      + MyApp / lib / MyApp . pm
 ¦                                                            ¥

      Your application!



                          Alberto Sim˜es
                                     o     Dancing Tutorial
Part 2: Flamenco




                   Alberto Sim˜es
                              o     Dancing Tutorial
Traffic Control



  Your MyApp/lib/MyApp.pm includes:
 §                                                                 ¤
  p a c k a g e MyApp ;
  u s e Dancer ’ : s y n t a x ’ ;

  our $VERSION = ’ 0 . 1 ’ ;

  get ’ / ’ => sub {
      template ’ i n d e x ’ ;
  };

  true ;
 ¦                                                                 ¥




                               Alberto Sim˜es
                                          o     Dancing Tutorial
How to test it?

  Start the standalone server,
 §                                                                                                  ¤
  [ ambs@rachmaninoff MyApp ] $ bin / app . pl
 ¦                                                                                                  ¥



  that shows debug info,
 §                                                                                                  ¤
  [ 9 3 8 7 ] core @0 .000017 > loading Dancer : : Handler : : Standalone
  handler in / opt / lib / perl5 / site_perl / 5 . 1 2 . 3 / Dancer / Handler . pm l . 39
  [ 9 3 8 7 ] core @0 .000442 > loading handler ’ Dancer : : Handler : :
  Standalone ’ in / opt / l o c a l / lib / perl5 / site_perl / 5 . 1 2 . 3 / Dancer . pm l . 230
  >> Dancer 1 . 3 0 1 1 server 9387 listening on http : / / 0 . 0 . 0 . 0 : 3 0 0 0
   subsection { Entering the development dance floor . . . }
 ¦                                                                                                  ¥



  and open a browser in the specified port.


                                       Alberto Sim˜es
                                                  o         Dancing Tutorial
It Works!
Route Handlers


     A Dancer app is a collection of route handlers;
     A route handler is, basically, a sub;
     It is bound to an http method;
     And to a path or a path pattern;

  Example

        get ’ / ’ => sub { . . .            };

        post ’ / s u b m i t / : f i l e ’ => sub { . . .            };

        del ’ / r e s o u r c e /∗ ’ => sub { . . .             };




                           Alberto Sim˜es
                                      o          Dancing Tutorial
Route Handlers


     A Dancer app is a collection of route handlers;
     A route handler is, basically, a sub;
     It is bound to an http method;
     And to a path or a path pattern;

  Example

        get ’ / ’ => sub { . . .            };

        post ’ / s u b m i t / : f i l e ’ => sub { . . .            };

        del ’ / r e s o u r c e /∗ ’ => sub { . . .             };




                           Alberto Sim˜es
                                      o          Dancing Tutorial
Route Handlers

     Static patterns (paths):
     §                                                                     ¤
          get ’ / ’ => sub { . . .        };

          get ’ / a b o u t ’ => sub { . . .       };
     ¦                                                                     ¥
     Patterns with named tokens:
     §                                                                     ¤
          get ’ / book / : i d ’ => sub {
             # do s o m e t h i n g w i t h params −>{i d }
             ...
          };

          get ’ / u s e r / : g r o u p / : u i d ’ => sub {
             # u s e params −>{u i d } and params −>{g r o u p } h e r e
          };
     ¦                                                                     ¥



                         Alberto Sim˜es
                                    o     Dancing Tutorial
Route Handlers

     Static patterns (paths):
     §                                                                     ¤
          get ’ / ’ => sub { . . .        };

          get ’ / a b o u t ’ => sub { . . .       };
     ¦                                                                     ¥
     Patterns with named tokens:
     §                                                                     ¤
          get ’ / book / : i d ’ => sub {
             # do s o m e t h i n g w i t h params −>{i d }
             ...
          };

          get ’ / u s e r / : g r o u p / : u i d ’ => sub {
             # u s e params −>{u i d } and params −>{g r o u p } h e r e
          };
     ¦                                                                     ¥



                         Alberto Sim˜es
                                    o     Dancing Tutorial
Route Handlers

     Patterns with anonymous tokens:
     §                                                     ¤
         get ’ / f i l e / ∗ . ∗ ’ => sub {
           my ( $file , $ext ) = splat ;
           ...
         }

          get ’ / show /∗/∗ ’ => sub {
             my ( $cat , $subcat ) = splat ;
          };
     ¦                                                     ¥
     Regular expressions:
     §                                                     ¤
         get qr { post / (  d+)−(d+)−(d+)} => sub {
            my ( $year , $month , $day ) = splat ;
         }
     ¦                                                     ¥



                       Alberto Sim˜es
                                  o     Dancing Tutorial
Route Handlers

     Patterns with anonymous tokens:
     §                                                     ¤
         get ’ / f i l e / ∗ . ∗ ’ => sub {
           my ( $file , $ext ) = splat ;
           ...
         }

          get ’ / show /∗/∗ ’ => sub {
             my ( $cat , $subcat ) = splat ;
          };
     ¦                                                     ¥
     Regular expressions:
     §                                                     ¤
         get qr { post / (  d+)−(d+)−(d+)} => sub {
            my ( $year , $month , $day ) = splat ;
         }
     ¦                                                     ¥



                       Alberto Sim˜es
                                  o     Dancing Tutorial
Part 3: Mambo




                Alberto Sim˜es
                           o     Dancing Tutorial
Templating



  Dancer has plugins for most templating systems:
      Mason, Template Toolkit and others.
      Default is a Simple template system, built-in Dancer.

  Use the template inside the route:
 §                                                                  ¤
      get ’ / u s e r / : name ’ => sub {
         template ’ p r o f i l e ’ => { username => params−>{name } } ;
      };
 ¦                                                                  ¥




                        Alberto Sim˜es
                                   o     Dancing Tutorial
Templating



  Dancer has plugins for most templating systems:
      Mason, Template Toolkit and others.
      Default is a Simple template system, built-in Dancer.

  Use the template inside the route:
 §                                                                  ¤
      get ’ / u s e r / : name ’ => sub {
         template ’ p r o f i l e ’ => { username => params−>{name } } ;
      };
 ¦                                                                  ¥




                        Alberto Sim˜es
                                   o     Dancing Tutorial
Rerouting


  You can reroute by:

  Passing the control to the next matching handler:
 §                                                               ¤
      get ’ / l a z y ’ => sub {
         pass and r e t u r n false ;
      };
 ¦                                                               ¥

  Redirecting to other URI:
 §                                                               ¤
      get ’ / f o r b i d d e n ’ => sub {
         r e t u r n redirect ’ / b e t t e r / p l a c e ’
      };
 ¦                                                               ¥




                             Alberto Sim˜es
                                        o     Dancing Tutorial
Rerouting


  You can reroute by:

  Passing the control to the next matching handler:
 §                                                               ¤
      get ’ / l a z y ’ => sub {
         pass and r e t u r n false ;
      };
 ¦                                                               ¥

  Redirecting to other URI:
 §                                                               ¤
      get ’ / f o r b i d d e n ’ => sub {
         r e t u r n redirect ’ / b e t t e r / p l a c e ’
      };
 ¦                                                               ¥




                             Alberto Sim˜es
                                        o     Dancing Tutorial
Rerouting


  You can reroute by:

  Passing the control to the next matching handler:
 §                                                               ¤
      get ’ / l a z y ’ => sub {
         pass and r e t u r n false ;
      };
 ¦                                                               ¥

  Redirecting to other URI:
 §                                                               ¤
      get ’ / f o r b i d d e n ’ => sub {
         r e t u r n redirect ’ / b e t t e r / p l a c e ’
      };
 ¦                                                               ¥




                             Alberto Sim˜es
                                        o     Dancing Tutorial
Serving Files

  You can serve a static file:
 §                                                              ¤
       get ’ / dowload / : f i l e ’ => sub {
         my $file = params−>{file } ;

            pass and r e t u r n false u n l e s s −f $file ;

            send_file $file ;
       };
 ¦                                                              ¥

  If the content is generated, just change content-type:
 §                                                              ¤
       get ’ / readme . t x t ’ => sub {
          content_type ’ t e x t / p l a i n ’ ;
          return ’ this is plain text ’
       };
 ¦                                                              ¥


                            Alberto Sim˜es
                                       o     Dancing Tutorial
Serving Files

  You can serve a static file:
 §                                                              ¤
       get ’ / dowload / : f i l e ’ => sub {
         my $file = params−>{file } ;

            pass and r e t u r n false u n l e s s −f $file ;

            send_file $file ;
       };
 ¦                                                              ¥

  If the content is generated, just change content-type:
 §                                                              ¤
       get ’ / readme . t x t ’ => sub {
          content_type ’ t e x t / p l a i n ’ ;
          return ’ this is plain text ’
       };
 ¦                                                              ¥


                            Alberto Sim˜es
                                       o     Dancing Tutorial
Thanks to Alexis Sukrieh
  (I stole some slides)

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 FrameworkJeremy Kendall
 
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 frameworkJeremy Kendall
 
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 RubyLindsay Holmwood
 
Intro to Rails
Intro to Rails Intro to Rails
Intro to Rails epiineg1
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with DancerDave Cross
 
Task 1
Task 1Task 1
Task 1EdiPHP
 
Magical WordPress Development with Vagrant
Magical WordPress Development with VagrantMagical WordPress Development with Vagrant
Magical WordPress Development with VagrantChris Olbekson
 
Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkVance Lucas
 
Silex, the microframework
Silex, the microframeworkSilex, the microframework
Silex, the microframeworkInviqa
 
CoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copyCoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copyPatrick Devins
 
Interface de Voz con Rails
Interface de Voz con RailsInterface de Voz con Rails
Interface de Voz con RailsSvet Ivantchev
 
PerlでWeb API入門
PerlでWeb API入門PerlでWeb API入門
PerlでWeb API入門Yusuke Wada
 
Hubot: a look inside our robot friend
Hubot: a look inside our robot friendHubot: a look inside our robot friend
Hubot: a look inside our robot friendajacksified
 

Tendances (20)

Sprockets
SprocketsSprockets
Sprockets
 
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
 
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
 
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
 
Intro to Rails
Intro to Rails Intro to Rails
Intro to Rails
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
JSON and the APInauts
JSON and the APInautsJSON and the APInauts
JSON and the APInauts
 
Task 1
Task 1Task 1
Task 1
 
Magical WordPress Development with Vagrant
Magical WordPress Development with VagrantMagical WordPress Development with Vagrant
Magical WordPress Development with Vagrant
 
Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-Framework
 
Silex, the microframework
Silex, the microframeworkSilex, the microframework
Silex, the microframework
 
Engines
EnginesEngines
Engines
 
I motion
I motionI motion
I motion
 
CoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copyCoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copy
 
Interface de Voz con Rails
Interface de Voz con RailsInterface de Voz con Rails
Interface de Voz con Rails
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
PerlでWeb API入門
PerlでWeb API入門PerlでWeb API入門
PerlでWeb API入門
 
Hubot: a look inside our robot friend
Hubot: a look inside our robot friendHubot: a look inside our robot friend
Hubot: a look inside our robot friend
 

Similaire à Dancing Tutorial

Generic Setup De-Mystified
Generic Setup De-MystifiedGeneric Setup De-Mystified
Generic Setup De-MystifiedClayton Parker
 
Merb Slices
Merb SlicesMerb Slices
Merb Sliceshassox
 
Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!cloudbring
 
Buildout: Fostering Repeatability
Buildout: Fostering RepeatabilityBuildout: Fostering Repeatability
Buildout: Fostering RepeatabilityClayton Parker
 
Advanced Topics in Continuous Deployment
Advanced Topics in Continuous DeploymentAdvanced Topics in Continuous Deployment
Advanced Topics in Continuous DeploymentMike Brittain
 
5 best practices for (web/ software) development (2010)
5 best practices for (web/ software) development (2010)5 best practices for (web/ software) development (2010)
5 best practices for (web/ software) development (2010)Erwin Elling
 
Using Buildout to Develop and Deploy Python Projects
Using Buildout to Develop and Deploy Python ProjectsUsing Buildout to Develop and Deploy Python Projects
Using Buildout to Develop and Deploy Python ProjectsClayton Parker
 
An Introduction To Shoes
An Introduction To ShoesAn Introduction To Shoes
An Introduction To ShoesTobias Pfeiffer
 
Troubleshooting Plone
Troubleshooting PloneTroubleshooting Plone
Troubleshooting PloneRicado Alves
 
Hacking Movable Type Training - Day 1
Hacking Movable Type Training - Day 1Hacking Movable Type Training - Day 1
Hacking Movable Type Training - Day 1Byrne Reese
 
Abusing the Cloud for Fun and Profit
Abusing the Cloud for Fun and ProfitAbusing the Cloud for Fun and Profit
Abusing the Cloud for Fun and ProfitAlan Pinstein
 
Makefiles in 2020 — Why they still matter
Makefiles in 2020 — Why they still matterMakefiles in 2020 — Why they still matter
Makefiles in 2020 — Why they still matterSimon Brüggen
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsDylan Jay
 
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFabio Akita
 
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)Fabien Potencier
 
Monitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagiosMonitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagiosLindsay Holmwood
 
Bubbles & Trees with jQuery
Bubbles & Trees with jQueryBubbles & Trees with jQuery
Bubbles & Trees with jQueryBastian Feder
 

Similaire à Dancing Tutorial (20)

Generic Setup De-Mystified
Generic Setup De-MystifiedGeneric Setup De-Mystified
Generic Setup De-Mystified
 
Merb Slices
Merb SlicesMerb Slices
Merb Slices
 
Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!
 
Buildout: Fostering Repeatability
Buildout: Fostering RepeatabilityBuildout: Fostering Repeatability
Buildout: Fostering Repeatability
 
Shoes lightning
Shoes lightningShoes lightning
Shoes lightning
 
Advanced Topics in Continuous Deployment
Advanced Topics in Continuous DeploymentAdvanced Topics in Continuous Deployment
Advanced Topics in Continuous Deployment
 
5 best practices for (web/ software) development (2010)
5 best practices for (web/ software) development (2010)5 best practices for (web/ software) development (2010)
5 best practices for (web/ software) development (2010)
 
Using Buildout to Develop and Deploy Python Projects
Using Buildout to Develop and Deploy Python ProjectsUsing Buildout to Develop and Deploy Python Projects
Using Buildout to Develop and Deploy Python Projects
 
An Introduction To Shoes
An Introduction To ShoesAn Introduction To Shoes
An Introduction To Shoes
 
Troubleshooting Plone
Troubleshooting PloneTroubleshooting Plone
Troubleshooting Plone
 
Hacking Movable Type Training - Day 1
Hacking Movable Type Training - Day 1Hacking Movable Type Training - Day 1
Hacking Movable Type Training - Day 1
 
Sinatra
SinatraSinatra
Sinatra
 
Elixir on Containers
Elixir on ContainersElixir on Containers
Elixir on Containers
 
Abusing the Cloud for Fun and Profit
Abusing the Cloud for Fun and ProfitAbusing the Cloud for Fun and Profit
Abusing the Cloud for Fun and Profit
 
Makefiles in 2020 — Why they still matter
Makefiles in 2020 — Why they still matterMakefiles in 2020 — Why they still matter
Makefiles in 2020 — Why they still matter
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web apps
 
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
 
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
 
Monitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagiosMonitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagios
 
Bubbles & Trees with jQuery
Bubbles & Trees with jQueryBubbles & Trees with jQuery
Bubbles & Trees with jQuery
 

Plus de Alberto Simões

Language Identification: A neural network approach
Language Identification: A neural network approachLanguage Identification: A neural network approach
Language Identification: A neural network approachAlberto Simões
 
Making the most of a 100-year-old dictionary
Making the most of a 100-year-old dictionaryMaking the most of a 100-year-old dictionary
Making the most of a 100-year-old dictionaryAlberto Simões
 
Dictionary Alignment by Rewrite-based Entry Translation
Dictionary Alignment by Rewrite-based Entry TranslationDictionary Alignment by Rewrite-based Entry Translation
Dictionary Alignment by Rewrite-based Entry TranslationAlberto Simões
 
EMLex-A5: Specialized Dictionaries
EMLex-A5: Specialized DictionariesEMLex-A5: Specialized Dictionaries
EMLex-A5: Specialized DictionariesAlberto Simões
 
Aula 04 - Introdução aos Diagramas de Sequência
Aula 04 - Introdução aos Diagramas de SequênciaAula 04 - Introdução aos Diagramas de Sequência
Aula 04 - Introdução aos Diagramas de SequênciaAlberto Simões
 
Aula 03 - Introdução aos Diagramas de Atividade
Aula 03 - Introdução aos Diagramas de AtividadeAula 03 - Introdução aos Diagramas de Atividade
Aula 03 - Introdução aos Diagramas de AtividadeAlberto Simões
 
Aula 02 - Engenharia de Requisitos
Aula 02 - Engenharia de RequisitosAula 02 - Engenharia de Requisitos
Aula 02 - Engenharia de RequisitosAlberto Simões
 
Aula 01 - Planeamento de Sistemas de Informação
Aula 01 - Planeamento de Sistemas de InformaçãoAula 01 - Planeamento de Sistemas de Informação
Aula 01 - Planeamento de Sistemas de InformaçãoAlberto Simões
 
Building C and C++ libraries with Perl
Building C and C++ libraries with PerlBuilding C and C++ libraries with Perl
Building C and C++ libraries with PerlAlberto Simões
 
Processing XML: a rewriting system approach
Processing XML: a rewriting system approachProcessing XML: a rewriting system approach
Processing XML: a rewriting system approachAlberto Simões
 
Arquitecturas de Tradução Automática
Arquitecturas de Tradução AutomáticaArquitecturas de Tradução Automática
Arquitecturas de Tradução AutomáticaAlberto Simões
 
Extracção de Recursos para Tradução Automática
Extracção de Recursos para Tradução AutomáticaExtracção de Recursos para Tradução Automática
Extracção de Recursos para Tradução AutomáticaAlberto Simões
 

Plus de Alberto Simões (20)

Source Code Quality
Source Code QualitySource Code Quality
Source Code Quality
 
Language Identification: A neural network approach
Language Identification: A neural network approachLanguage Identification: A neural network approach
Language Identification: A neural network approach
 
Google Maps JS API
Google Maps JS APIGoogle Maps JS API
Google Maps JS API
 
Making the most of a 100-year-old dictionary
Making the most of a 100-year-old dictionaryMaking the most of a 100-year-old dictionary
Making the most of a 100-year-old dictionary
 
Dictionary Alignment by Rewrite-based Entry Translation
Dictionary Alignment by Rewrite-based Entry TranslationDictionary Alignment by Rewrite-based Entry Translation
Dictionary Alignment by Rewrite-based Entry Translation
 
EMLex-A5: Specialized Dictionaries
EMLex-A5: Specialized DictionariesEMLex-A5: Specialized Dictionaries
EMLex-A5: Specialized Dictionaries
 
Modelação de Dados
Modelação de DadosModelação de Dados
Modelação de Dados
 
Aula 04 - Introdução aos Diagramas de Sequência
Aula 04 - Introdução aos Diagramas de SequênciaAula 04 - Introdução aos Diagramas de Sequência
Aula 04 - Introdução aos Diagramas de Sequência
 
Aula 03 - Introdução aos Diagramas de Atividade
Aula 03 - Introdução aos Diagramas de AtividadeAula 03 - Introdução aos Diagramas de Atividade
Aula 03 - Introdução aos Diagramas de Atividade
 
Aula 02 - Engenharia de Requisitos
Aula 02 - Engenharia de RequisitosAula 02 - Engenharia de Requisitos
Aula 02 - Engenharia de Requisitos
 
Aula 01 - Planeamento de Sistemas de Informação
Aula 01 - Planeamento de Sistemas de InformaçãoAula 01 - Planeamento de Sistemas de Informação
Aula 01 - Planeamento de Sistemas de Informação
 
Building C and C++ libraries with Perl
Building C and C++ libraries with PerlBuilding C and C++ libraries with Perl
Building C and C++ libraries with Perl
 
PLN em Perl
PLN em PerlPLN em Perl
PLN em Perl
 
Classification Systems
Classification SystemsClassification Systems
Classification Systems
 
Redes de Pert
Redes de PertRedes de Pert
Redes de Pert
 
Processing XML: a rewriting system approach
Processing XML: a rewriting system approachProcessing XML: a rewriting system approach
Processing XML: a rewriting system approach
 
Sistemas de Numeração
Sistemas de NumeraçãoSistemas de Numeração
Sistemas de Numeração
 
Álgebra de Boole
Álgebra de BooleÁlgebra de Boole
Álgebra de Boole
 
Arquitecturas de Tradução Automática
Arquitecturas de Tradução AutomáticaArquitecturas de Tradução Automática
Arquitecturas de Tradução Automática
 
Extracção de Recursos para Tradução Automática
Extracção de Recursos para Tradução AutomáticaExtracção de Recursos para Tradução Automática
Extracção de Recursos para Tradução Automática
 

Dernier

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 productivityPrincipled Technologies
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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 MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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 MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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 slidevu2urc
 
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...Drew Madelung
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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...Igalia
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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 WorkerThousandEyes
 

Dernier (20)

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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
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...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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
 

Dancing Tutorial

  • 1. Dancing Tutorial Alberto Manuel Brand˜o Sim˜es a o ambs@perl.pt Braga Geek Nights March 1st Alberto Sim˜es o Dancing Tutorial
  • 2. Part 0: Ballet Alberto Sim˜es o Dancing Tutorial
  • 4. A micro framework for writing web applications
  • 5. So, Yet Another Web Framework?
  • 7. CGI.pm webapps are spaghetti
  • 10.
  • 11. We needed something similar in Perl
  • 13. And they also imitated us!
  • 15. Part 1: Tango Alberto Sim˜es o Dancing Tutorial
  • 16. Installing § ¤ $ sudo cpan Dancer ¦ ¥ or § ¤ $ sudo cpan Task : : Dancer ¦ ¥ or yet § ¤ $ cpanm −S Task : : Dancer ¦ ¥ Alberto Sim˜es o Dancing Tutorial
  • 17. Bootstrap application § ¤ $ dancer −a MyApp + MyApp / bin / app . pl + MyApp / config . yml + MyApp / environments / development . yml + MyApp / environments / production . yml + MyApp / views / index . tt + MyApp / views / layouts / main . tt + MyApp / lib / MyApp . pm + MyApp / public / javascripts / jquery . js + MyApp / public / css / style . css + MyApp / public / css / error . css + MyApp / public / images / . . . + MyApp / public / 5 0 0 . html + MyApp / public / 4 0 4 . html + MyApp / public / dispatch . fcgi + MyApp / public / dispatch . cgi + MyApp / Makefile . PL + MyApp /t /002 _index_route . t + MyApp /t /001 _base . t ¦ ¥ Alberto Sim˜es o Dancing Tutorial
  • 18. What’s inside § ¤ + MyApp / bin / app . pl ¦ ¥ a standalone light server (starts server in port 3000); also used for fast-cgi or common cgi backends; § ¤ + MyApp / config . yml + MyApp / environments / development . yml + MyApp / environments / production . yml ¦ ¥ main configuration file (plugins, modules, etc); configuration files for production and development: defines what to report, where to report, etc. Alberto Sim˜es o Dancing Tutorial
  • 19. What’s inside § ¤ + MyApp / bin / app . pl ¦ ¥ a standalone light server (starts server in port 3000); also used for fast-cgi or common cgi backends; § ¤ + MyApp / config . yml + MyApp / environments / development . yml + MyApp / environments / production . yml ¦ ¥ main configuration file (plugins, modules, etc); configuration files for production and development: defines what to report, where to report, etc. Alberto Sim˜es o Dancing Tutorial
  • 20. What’s inside § ¤ + MyApp / views / index . tt + MyApp / views / layouts / main . tt ¦ ¥ Templates and layouts: templates are page portions/scraps; layouts are full page designs (they are automagically filled by the template); § ¤ + MyApp / public / javascripts / jquery . js + MyApp / public / css / style . css + MyApp / public / css / error . css + MyApp / public / images / . . . ¦ ¥ public/static files: javascript (Dancer ships with jsquery); cascade style sheets; images (for default design); Alberto Sim˜es o Dancing Tutorial
  • 21. What’s inside § ¤ + MyApp / views / index . tt + MyApp / views / layouts / main . tt ¦ ¥ Templates and layouts: templates are page portions/scraps; layouts are full page designs (they are automagically filled by the template); § ¤ + MyApp / public / javascripts / jquery . js + MyApp / public / css / style . css + MyApp / public / css / error . css + MyApp / public / images / . . . ¦ ¥ public/static files: javascript (Dancer ships with jsquery); cascade style sheets; images (for default design); Alberto Sim˜es o Dancing Tutorial
  • 22. What’s inside § ¤ + MyApp / public / 5 0 0 . html + MyApp / public / 4 0 4 . html ¦ ¥ pages for 500 and 404 errors; § ¤ + MyApp / public / dispatch . fcgi + MyApp / public / dispatch . cgi ¦ ¥ wrappers to configure fast-cgi and cgi backends; will be back on this later (future talk?); Alberto Sim˜es o Dancing Tutorial
  • 23. What’s inside § ¤ + MyApp / public / 5 0 0 . html + MyApp / public / 4 0 4 . html ¦ ¥ pages for 500 and 404 errors; § ¤ + MyApp / public / dispatch . fcgi + MyApp / public / dispatch . cgi ¦ ¥ wrappers to configure fast-cgi and cgi backends; will be back on this later (future talk?); Alberto Sim˜es o Dancing Tutorial
  • 24. What’s inside § ¤ + MyApp / Makefile . PL + MyApp /t /002 _index_route . t + MyApp /t /001 _base . t ¦ ¥ Main module Makefile: usefull to make module of your application Your test suite; § ¤ + MyApp / lib / MyApp . pm ¦ ¥ Your application! Alberto Sim˜es o Dancing Tutorial
  • 25. What’s inside § ¤ + MyApp / Makefile . PL + MyApp /t /002 _index_route . t + MyApp /t /001 _base . t ¦ ¥ Main module Makefile: usefull to make module of your application Your test suite; § ¤ + MyApp / lib / MyApp . pm ¦ ¥ Your application! Alberto Sim˜es o Dancing Tutorial
  • 26. Part 2: Flamenco Alberto Sim˜es o Dancing Tutorial
  • 27. Traffic Control Your MyApp/lib/MyApp.pm includes: § ¤ p a c k a g e MyApp ; u s e Dancer ’ : s y n t a x ’ ; our $VERSION = ’ 0 . 1 ’ ; get ’ / ’ => sub { template ’ i n d e x ’ ; }; true ; ¦ ¥ Alberto Sim˜es o Dancing Tutorial
  • 28. How to test it? Start the standalone server, § ¤ [ ambs@rachmaninoff MyApp ] $ bin / app . pl ¦ ¥ that shows debug info, § ¤ [ 9 3 8 7 ] core @0 .000017 > loading Dancer : : Handler : : Standalone handler in / opt / lib / perl5 / site_perl / 5 . 1 2 . 3 / Dancer / Handler . pm l . 39 [ 9 3 8 7 ] core @0 .000442 > loading handler ’ Dancer : : Handler : : Standalone ’ in / opt / l o c a l / lib / perl5 / site_perl / 5 . 1 2 . 3 / Dancer . pm l . 230 >> Dancer 1 . 3 0 1 1 server 9387 listening on http : / / 0 . 0 . 0 . 0 : 3 0 0 0 subsection { Entering the development dance floor . . . } ¦ ¥ and open a browser in the specified port. Alberto Sim˜es o Dancing Tutorial
  • 30. Route Handlers A Dancer app is a collection of route handlers; A route handler is, basically, a sub; It is bound to an http method; And to a path or a path pattern; Example get ’ / ’ => sub { . . . }; post ’ / s u b m i t / : f i l e ’ => sub { . . . }; del ’ / r e s o u r c e /∗ ’ => sub { . . . }; Alberto Sim˜es o Dancing Tutorial
  • 31. Route Handlers A Dancer app is a collection of route handlers; A route handler is, basically, a sub; It is bound to an http method; And to a path or a path pattern; Example get ’ / ’ => sub { . . . }; post ’ / s u b m i t / : f i l e ’ => sub { . . . }; del ’ / r e s o u r c e /∗ ’ => sub { . . . }; Alberto Sim˜es o Dancing Tutorial
  • 32. Route Handlers Static patterns (paths): § ¤ get ’ / ’ => sub { . . . }; get ’ / a b o u t ’ => sub { . . . }; ¦ ¥ Patterns with named tokens: § ¤ get ’ / book / : i d ’ => sub { # do s o m e t h i n g w i t h params −>{i d } ... }; get ’ / u s e r / : g r o u p / : u i d ’ => sub { # u s e params −>{u i d } and params −>{g r o u p } h e r e }; ¦ ¥ Alberto Sim˜es o Dancing Tutorial
  • 33. Route Handlers Static patterns (paths): § ¤ get ’ / ’ => sub { . . . }; get ’ / a b o u t ’ => sub { . . . }; ¦ ¥ Patterns with named tokens: § ¤ get ’ / book / : i d ’ => sub { # do s o m e t h i n g w i t h params −>{i d } ... }; get ’ / u s e r / : g r o u p / : u i d ’ => sub { # u s e params −>{u i d } and params −>{g r o u p } h e r e }; ¦ ¥ Alberto Sim˜es o Dancing Tutorial
  • 34. Route Handlers Patterns with anonymous tokens: § ¤ get ’ / f i l e / ∗ . ∗ ’ => sub { my ( $file , $ext ) = splat ; ... } get ’ / show /∗/∗ ’ => sub { my ( $cat , $subcat ) = splat ; }; ¦ ¥ Regular expressions: § ¤ get qr { post / ( d+)−(d+)−(d+)} => sub { my ( $year , $month , $day ) = splat ; } ¦ ¥ Alberto Sim˜es o Dancing Tutorial
  • 35. Route Handlers Patterns with anonymous tokens: § ¤ get ’ / f i l e / ∗ . ∗ ’ => sub { my ( $file , $ext ) = splat ; ... } get ’ / show /∗/∗ ’ => sub { my ( $cat , $subcat ) = splat ; }; ¦ ¥ Regular expressions: § ¤ get qr { post / ( d+)−(d+)−(d+)} => sub { my ( $year , $month , $day ) = splat ; } ¦ ¥ Alberto Sim˜es o Dancing Tutorial
  • 36. Part 3: Mambo Alberto Sim˜es o Dancing Tutorial
  • 37. Templating Dancer has plugins for most templating systems: Mason, Template Toolkit and others. Default is a Simple template system, built-in Dancer. Use the template inside the route: § ¤ get ’ / u s e r / : name ’ => sub { template ’ p r o f i l e ’ => { username => params−>{name } } ; }; ¦ ¥ Alberto Sim˜es o Dancing Tutorial
  • 38. Templating Dancer has plugins for most templating systems: Mason, Template Toolkit and others. Default is a Simple template system, built-in Dancer. Use the template inside the route: § ¤ get ’ / u s e r / : name ’ => sub { template ’ p r o f i l e ’ => { username => params−>{name } } ; }; ¦ ¥ Alberto Sim˜es o Dancing Tutorial
  • 39. Rerouting You can reroute by: Passing the control to the next matching handler: § ¤ get ’ / l a z y ’ => sub { pass and r e t u r n false ; }; ¦ ¥ Redirecting to other URI: § ¤ get ’ / f o r b i d d e n ’ => sub { r e t u r n redirect ’ / b e t t e r / p l a c e ’ }; ¦ ¥ Alberto Sim˜es o Dancing Tutorial
  • 40. Rerouting You can reroute by: Passing the control to the next matching handler: § ¤ get ’ / l a z y ’ => sub { pass and r e t u r n false ; }; ¦ ¥ Redirecting to other URI: § ¤ get ’ / f o r b i d d e n ’ => sub { r e t u r n redirect ’ / b e t t e r / p l a c e ’ }; ¦ ¥ Alberto Sim˜es o Dancing Tutorial
  • 41. Rerouting You can reroute by: Passing the control to the next matching handler: § ¤ get ’ / l a z y ’ => sub { pass and r e t u r n false ; }; ¦ ¥ Redirecting to other URI: § ¤ get ’ / f o r b i d d e n ’ => sub { r e t u r n redirect ’ / b e t t e r / p l a c e ’ }; ¦ ¥ Alberto Sim˜es o Dancing Tutorial
  • 42. Serving Files You can serve a static file: § ¤ get ’ / dowload / : f i l e ’ => sub { my $file = params−>{file } ; pass and r e t u r n false u n l e s s −f $file ; send_file $file ; }; ¦ ¥ If the content is generated, just change content-type: § ¤ get ’ / readme . t x t ’ => sub { content_type ’ t e x t / p l a i n ’ ; return ’ this is plain text ’ }; ¦ ¥ Alberto Sim˜es o Dancing Tutorial
  • 43. Serving Files You can serve a static file: § ¤ get ’ / dowload / : f i l e ’ => sub { my $file = params−>{file } ; pass and r e t u r n false u n l e s s −f $file ; send_file $file ; }; ¦ ¥ If the content is generated, just change content-type: § ¤ get ’ / readme . t x t ’ => sub { content_type ’ t e x t / p l a i n ’ ; return ’ this is plain text ’ }; ¦ ¥ Alberto Sim˜es o Dancing Tutorial
  • 44. Thanks to Alexis Sukrieh (I stole some slides)