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.
Dancer A  micro framework  for  writing web applications Alexis Sukrieh OSDCfr 2009
Alexis Sukrieh http://sukria.net http://twitter.com/sukria http://search.cpan.org/~sukria/
Dancer http://dancer.sukria.net $ sudo cpan Dancer http://github.com/sukria/Dancer
Description Syntax Application Tree Environments Deployment
webapp  framework  for Perl
Again, another one !!?
YES.
Why ?
Web Development in Perl can be :
CGI.pm : fat webapp junkfood
Catalyst : it's huge, but, it's huge.
Plenty of other frameworks alike
Ruby introduced something else
A new approach to  webapp development
Perl needed the same
definetly
Kindly stolen from Ruby
So, Dancer is a framework ...
a  micro  framework
<ul>Lightweight </ul>
<ul>Standalone </ul>
<ul>PSGI/Plack compliant </ul>
<ul>expressive syntax </ul>
<ul>few configuration </ul>
<ul>painless  for the developer </ul>
<ul>enough talking, let's dance </ul>
 
<ul>Sorry, I mean ... </ul>
package   MyApp ; use  Dancer; get  '/'  =>  sub  { 'Hello OSDCfr 2009!' }; dance;
A dancer script is a webserver
$ ./myApp.pl >> Listening on 127.0.0.1:3000 == Entering the development dance floor ...
Working webapp ready to be hacked
» happiness : he can WSFC now
Description Syntax Application Tree Environments Deployment
A Dancer app is defined with  route handlers
a route handler is basically a  sub
bound to an HTTP  method   (typically ' get ' or ' post ')
with a path  pattern
/foo /bar/:var /baz/* r('/stuff/([a-z0-9]+)/')
Static pattern (path) / /foo /bar/baz
pattern with named tokens /hello/:buddy my $name = params->{buddy}
pattern with anonymous tokens /show/*.* my ($file, $ext) = splat;
pseudo-regexp-defined patterns r('/post/([a-z0-9]+)') my ($post) = splat; # $1
processing a request = finding a  matching route handler
404 No matching route handler » no joy
Route handler found » Joy
When found,  a route handler is executed
it can alter the response headers get '/' => sub { content_type  'text/plain'; return 'this is plain text'  };
pass to the next matching handler get '/lazy' => sub { pass  and return false; };
serve a static file get '/dowload/:file' => sub { my $file = params->{file}; if (! -f $file) {  pass and return false;  } ...
throw an error get '/forbidden' => sub { send_error 'Nope'; };
redirect to somewhere else get '/forbidden' => sub { redirect  '/better/place'  };
and of course, render a content get '/showme' => sub { template 'showme', {  var => 'foo'}; };
return value  = content to render
logging ?
get '/' => sub { # ... debug 'here it is'; }; » logs/development.log
pre-processing ?
before sub {  do_some_init_stuff(); params->{foo} = 'beenthere'; };
static file serving ?
existing file  in  $appdir/public = file served , no handler needed
Description Syntax Application Tree Environments Deployment
app.pl
app.pl views/ index.tt
app.pl views/ index.tt layouts/ main.tt
app.pl views/ index.tt layouts/ main.tt config.yml
app.pl views/ index.tt layouts/ main.tt config.yml environments/ development.yml production.yml
app.pl views/ index.tt layouts/ main.tt config.yml environments/ development.yml production.yml public/
bootstraping ?
$ dancer -a MyApp
+ MyApp + MyApp/views + MyApp/views/index.tt + MyApp/views/layouts + MyApp/views/layouts/main.tt + MyApp/environments + My...
» Working webapp, pre-configured, pre-designed and waiting for your hacks
Description Syntax Application Tree Environments Deployment
settings : customizing the app
settings in the app code
use Dancer; set layout => 'application' set foo => 42; set content_type =>'text/plain';
handy at first, but dirty
YAML config files: goodness
# config.yml layout: 'application' foo: 42 content_type: 'text/plain'
config.yml = global configuration
environments/foo.yml « foo » configuration
$ dancer -e foo runs the app in « foo » environment
development.yml warnings: 1 show_errors: 1 ...
production.yml warnings: 0 show_errors: 0 ...
show_errors: 1
show_errors: 0
Description Syntax Application Tree Environments Deployment
For production needs,  use PSGI/Plack
Plack is to Perl : what Rack is to Ruby what WSGI is to Python
universal  server <-> application  gateway
PSGI/Plack miyagawa http://plackperl.org
Dancer supports Plack since 0.9904
app.psgi tells Plack how to dance
use CGI::PSGI; use MyApp; my $handler = sub { my $env = shift; my $cgi = CGI::PSGI->new($env); Dancer->dance($cgi); };
The app is now PSGI/Plack aware
$ plackup -a app.psgi &
Webservers have PSGI adapters
Apache (mod_psgi) nginx Perlbal HTTP::Server::Fast Plack (standalone)
Conf example with Apache  <Location /> SetHandler perl-script PerlHandler  Plack::Server::Apache2 PerlSetVar psgi_app /pat...
Works pretty well
enjoy web development with Perl
DANCE!
Upcoming SlideShare
Loading in …5
×

of

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

19 Likes

Share

Download to read offline

Writing webapps with Perl Dancer

Download to read offline

Dancer is a micro framework for Perl, this presentation describes it and show how to use it.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Writing webapps with Perl Dancer

  1. 1. Dancer A micro framework for writing web applications Alexis Sukrieh OSDCfr 2009
  2. 2. Alexis Sukrieh http://sukria.net http://twitter.com/sukria http://search.cpan.org/~sukria/
  3. 3. Dancer http://dancer.sukria.net $ sudo cpan Dancer http://github.com/sukria/Dancer
  4. 4. Description Syntax Application Tree Environments Deployment
  5. 5. webapp framework for Perl
  6. 6. Again, another one !!?
  7. 7. YES.
  8. 8. Why ?
  9. 9. Web Development in Perl can be :
  10. 10. CGI.pm : fat webapp junkfood
  11. 11. Catalyst : it's huge, but, it's huge.
  12. 12. Plenty of other frameworks alike
  13. 13. Ruby introduced something else
  14. 14. A new approach to webapp development
  15. 15. Perl needed the same
  16. 16. definetly
  17. 17. Kindly stolen from Ruby
  18. 18. So, Dancer is a framework ...
  19. 19. a micro framework
  20. 20. <ul>Lightweight </ul>
  21. 21. <ul>Standalone </ul>
  22. 22. <ul>PSGI/Plack compliant </ul>
  23. 23. <ul>expressive syntax </ul>
  24. 24. <ul>few configuration </ul>
  25. 25. <ul>painless for the developer </ul>
  26. 26. <ul>enough talking, let's dance </ul>
  27. 28. <ul>Sorry, I mean ... </ul>
  28. 29. package MyApp ; use Dancer; get '/' => sub { 'Hello OSDCfr 2009!' }; dance;
  29. 30. A dancer script is a webserver
  30. 31. $ ./myApp.pl >> Listening on 127.0.0.1:3000 == Entering the development dance floor ...
  31. 32. Working webapp ready to be hacked
  32. 33. » happiness : he can WSFC now
  33. 34. Description Syntax Application Tree Environments Deployment
  34. 35. A Dancer app is defined with route handlers
  35. 36. a route handler is basically a sub
  36. 37. bound to an HTTP method (typically ' get ' or ' post ')
  37. 38. with a path pattern
  38. 39. /foo /bar/:var /baz/* r('/stuff/([a-z0-9]+)/')
  39. 40. Static pattern (path) / /foo /bar/baz
  40. 41. pattern with named tokens /hello/:buddy my $name = params->{buddy}
  41. 42. pattern with anonymous tokens /show/*.* my ($file, $ext) = splat;
  42. 43. pseudo-regexp-defined patterns r('/post/([a-z0-9]+)') my ($post) = splat; # $1
  43. 44. processing a request = finding a matching route handler
  44. 45. 404 No matching route handler » no joy
  45. 46. Route handler found » Joy
  46. 47. When found, a route handler is executed
  47. 48. it can alter the response headers get '/' => sub { content_type 'text/plain'; return 'this is plain text'  };
  48. 49. pass to the next matching handler get '/lazy' => sub { pass and return false; };
  49. 50. serve a static file get '/dowload/:file' => sub { my $file = params->{file}; if (! -f $file) { pass and return false; } send_file $file; };
  50. 51. throw an error get '/forbidden' => sub { send_error 'Nope'; };
  51. 52. redirect to somewhere else get '/forbidden' => sub { redirect '/better/place'  };
  52. 53. and of course, render a content get '/showme' => sub { template 'showme', { var => 'foo'}; };
  53. 54. return value = content to render
  54. 55. logging ?
  55. 56. get '/' => sub { # ... debug 'here it is'; }; » logs/development.log
  56. 57. pre-processing ?
  57. 58. before sub { do_some_init_stuff(); params->{foo} = 'beenthere'; };
  58. 59. static file serving ?
  59. 60. existing file in $appdir/public = file served , no handler needed
  60. 61. Description Syntax Application Tree Environments Deployment
  61. 62. app.pl
  62. 63. app.pl views/ index.tt
  63. 64. app.pl views/ index.tt layouts/ main.tt
  64. 65. app.pl views/ index.tt layouts/ main.tt config.yml
  65. 66. app.pl views/ index.tt layouts/ main.tt config.yml environments/ development.yml production.yml
  66. 67. app.pl views/ index.tt layouts/ main.tt config.yml environments/ development.yml production.yml public/
  67. 68. bootstraping ?
  68. 69. $ dancer -a MyApp
  69. 70. + MyApp + MyApp/views + MyApp/views/index.tt + MyApp/views/layouts + MyApp/views/layouts/main.tt + MyApp/environments + MyApp/environments/development.yml + MyApp/environments/production.yml + MyApp/config.yml + MyApp/app.psgi + MyApp/MyApp.pm + MyApp/MyApp.pl + MyApp/public + MyApp/public/css + MyApp/public/css/style.css + MyApp/public/css/error.css + MyApp/public/images + MyApp/public/404.html + MyApp/public/500.html
  70. 71. » Working webapp, pre-configured, pre-designed and waiting for your hacks
  71. 72. Description Syntax Application Tree Environments Deployment
  72. 73. settings : customizing the app
  73. 74. settings in the app code
  74. 75. use Dancer; set layout => 'application' set foo => 42; set content_type =>'text/plain';
  75. 76. handy at first, but dirty
  76. 77. YAML config files: goodness
  77. 78. # config.yml layout: 'application' foo: 42 content_type: 'text/plain'
  78. 79. config.yml = global configuration
  79. 80. environments/foo.yml « foo » configuration
  80. 81. $ dancer -e foo runs the app in « foo » environment
  81. 82. development.yml warnings: 1 show_errors: 1 ...
  82. 83. production.yml warnings: 0 show_errors: 0 ...
  83. 84. show_errors: 1
  84. 85. show_errors: 0
  85. 86. Description Syntax Application Tree Environments Deployment
  86. 87. For production needs, use PSGI/Plack
  87. 88. Plack is to Perl : what Rack is to Ruby what WSGI is to Python
  88. 89. universal server <-> application gateway
  89. 90. PSGI/Plack miyagawa http://plackperl.org
  90. 91. Dancer supports Plack since 0.9904
  91. 92. app.psgi tells Plack how to dance
  92. 93. use CGI::PSGI; use MyApp; my $handler = sub { my $env = shift; my $cgi = CGI::PSGI->new($env); Dancer->dance($cgi); };
  93. 94. The app is now PSGI/Plack aware
  94. 95. $ plackup -a app.psgi &
  95. 96. Webservers have PSGI adapters
  96. 97. Apache (mod_psgi) nginx Perlbal HTTP::Server::Fast Plack (standalone)
  97. 98. Conf example with Apache <Location /> SetHandler perl-script PerlHandler Plack::Server::Apache2 PerlSetVar psgi_app /path/app.psgi </Location>
  98. 99. Works pretty well
  99. 100. enjoy web development with Perl
  100. 101. DANCE!
  • DesireeMontana

    Nov. 25, 2021
  • jeanclaudedalot1

    Feb. 16, 2019
  • MilindNayse

    Apr. 12, 2016
  • vdumitrica

    Jan. 19, 2015
  • wirelessinternet

    Dec. 1, 2014
  • zarthustra7

    Sep. 14, 2012
  • prayagupd

    Jun. 13, 2012
  • taiju

    Mar. 18, 2012
  • invent

    Feb. 20, 2012
  • billywoo

    Nov. 21, 2011
  • _anaio

    Oct. 23, 2011
  • EricMiller5

    Aug. 7, 2011
  • kingu

    Sep. 28, 2010
  • thomasfahle

    Aug. 19, 2010
  • banb

    Apr. 23, 2010
  • mrluanma

    Apr. 19, 2010
  • chsanch

    Apr. 14, 2010
  • miyagawa

    Oct. 4, 2009
  • davidpaccoud

    Oct. 3, 2009

Dancer is a micro framework for Perl, this presentation describes it and show how to use it.

Views

Total views

45,787

On Slideshare

0

From embeds

0

Number of embeds

15,923

Actions

Downloads

211

Shares

0

Comments

0

Likes

19

×