mojoliciousreal-time web frameworkNPW2012, Stockholm        Lars Thegler
metaI’m not a mojolicious expertI will talk about how to startI will talk about what to expectI will hint at how to continue
agendaMojolicious::Lite  routes and placeholders  templates and layouts  graduating from ::Lite to Mojolicious properMojo ...
mojolicious -	 what? who?“real-time web application framework”written by Sebastian Riedel (sri) &cwho also wrote Catalystc...
timeline first release 0.2 2008-09-24 release 1.0 ‘snowflake’ 2010-12-26 release 2.0 ‘leaf fluttering in the wind’ 2011-10-17...
installation no dependencies # cpanm Mojolicious easy curl recipe # curl get.mojolicio.us | sh
executionbuiltin (simple, morbo, hypnotoad)nginxapache/mod_proxy, CGIPSGI/plack
anatomy of aweb frameworkincoming request =>  dispatcher =>    action code =>      outgoing response
dispatchersmall languagematching incoming request => action code“routes”
getting started# GET /get / => sub {  my $self = shift;  $self->render(text => Hello);};# 200 OK, text/html, Hello
placeholder# /hello/Larsget /hello/:name => sub {  my $self = shift;  my $name = $self->param(‘name’);  $self->render(text...
url parameters# /hello/Lars?greet=Hejget /hello/:name => sub {  my $self = shift;  my $name = $self->param(‘name’);  my $g...
placeholders and routes,next level slurpy placeholders wildcard placeholders formats (‘.html’, ‘.txt’) bridging routes con...
stashnonpresistent data storekeep data for the duration of the requestcarries data from action code to templatewith a bunc...
templatebuiltin ‘Embedded Perl’variables in templates from stashinstantiated as normal values           Hello, <%= $name %>
structures in templates It’s all Perl, so Perl control structures just work:            % for my $i (0..3) {              ...
inline templates__DATA__@@ hello.html.epHello, World!@@ goodbye.html.epGoodbye, and thanks!
template selection explicit template name in render() call  $self->render(template => ‘hello’); name in stash  $self->stas...
auto renderno need to call render() yourselfif you don’t, mojo will do it for you            get ‘/’ => ‘index’;          ...
layouts__DATA__@@ index.html.ep% layout ‘default’Hello, World!@@ layouts/default.html.ep<html>  <head><title>moo</title></...
templates, next level includes partial templates 404, 500 pages blocks template inheritance ...
sessionsbuilt indata stored in cookies, client-sidecookie signed to prevent tamperingyou can use something else, if you want
growing out of ::Lite inflate inline templates into proper files move routes into application class move action code into co...
but wait, there’s more! Mojo::UserAgent   nice web client Mojo::DOM   excellent HTML/XML parser ojo   for one-liners
resourceshttp://mojolicio.usMojolicious::Guides::{Routing,Rendering,Growing,...}http://mojocasts.com by tempirehttps://git...
thank you :) tagg @ irc taggg @ twitter lars@thegler.dk LTHEGLER@cpan.org lth@FreeBSD.org lars.thegler@teliasonera.com
Upcoming SlideShare
Loading in...5
×

Mojolicious, real-time web framework

753

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
753
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
15
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Mojolicious, real-time web framework

  1. 1. mojoliciousreal-time web frameworkNPW2012, Stockholm Lars Thegler
  2. 2. metaI’m not a mojolicious expertI will talk about how to startI will talk about what to expectI will hint at how to continue
  3. 3. agendaMojolicious::Lite routes and placeholders templates and layouts graduating from ::Lite to Mojolicious properMojo as client
  4. 4. mojolicious - what? who?“real-time web application framework”written by Sebastian Riedel (sri) &cwho also wrote Catalystcurrent core: ams, tempire, mramberg
  5. 5. timeline first release 0.2 2008-09-24 release 1.0 ‘snowflake’ 2010-12-26 release 2.0 ‘leaf fluttering in the wind’ 2011-10-17 release 3.0 ‘rainbow’ 2012-06-25 release 3.46 2012-10-11
  6. 6. installation no dependencies # cpanm Mojolicious easy curl recipe # curl get.mojolicio.us | sh
  7. 7. executionbuiltin (simple, morbo, hypnotoad)nginxapache/mod_proxy, CGIPSGI/plack
  8. 8. anatomy of aweb frameworkincoming request => dispatcher => action code => outgoing response
  9. 9. dispatchersmall languagematching incoming request => action code“routes”
  10. 10. getting started# GET /get / => sub { my $self = shift; $self->render(text => Hello);};# 200 OK, text/html, Hello
  11. 11. placeholder# /hello/Larsget /hello/:name => sub { my $self = shift; my $name = $self->param(‘name’); $self->render(text => “Hello $name”);};# 200 OK, text/html, Hello Lars
  12. 12. url parameters# /hello/Lars?greet=Hejget /hello/:name => sub { my $self = shift; my $name = $self->param(‘name’); my $greet = $self->param(‘greet’); $self->render(text => “$greet $name”);} => ‘greeting’;# 200 OK, text/html, Hej Lars
  13. 13. placeholders and routes,next level slurpy placeholders wildcard placeholders formats (‘.html’, ‘.txt’) bridging routes conditional routes
  14. 14. stashnonpresistent data storekeep data for the duration of the requestcarries data from action code to templatewith a bunch of reserved keysformat, text, template, ... $self->stash(name => ‘Lars’);
  15. 15. templatebuiltin ‘Embedded Perl’variables in templates from stashinstantiated as normal values Hello, <%= $name %>
  16. 16. structures in templates It’s all Perl, so Perl control structures just work: % for my $i (0..3) { ... <%= $i %> ... % }
  17. 17. inline templates__DATA__@@ hello.html.epHello, World!@@ goodbye.html.epGoodbye, and thanks!
  18. 18. template selection explicit template name in render() call $self->render(template => ‘hello’); name in stash $self->stash(template => ‘hello’); defaults to name of router get ‘/welcome’ => ‘hello’;
  19. 19. auto renderno need to call render() yourselfif you don’t, mojo will do it for you get ‘/’ => ‘index’; __DATA__ @@ index.html.ep
  20. 20. layouts__DATA__@@ index.html.ep% layout ‘default’Hello, World!@@ layouts/default.html.ep<html> <head><title>moo</title></head> <body><%= $content %></body></html>
  21. 21. templates, next level includes partial templates 404, 500 pages blocks template inheritance ...
  22. 22. sessionsbuilt indata stored in cookies, client-sidecookie signed to prevent tamperingyou can use something else, if you want
  23. 23. growing out of ::Lite inflate inline templates into proper files move routes into application class move action code into controller class testing with Test::Mojo
  24. 24. but wait, there’s more! Mojo::UserAgent nice web client Mojo::DOM excellent HTML/XML parser ojo for one-liners
  25. 25. resourceshttp://mojolicio.usMojolicious::Guides::{Routing,Rendering,Growing,...}http://mojocasts.com by tempirehttps://github.com/kraih/mojo incl wiki
  26. 26. thank you :) tagg @ irc taggg @ twitter lars@thegler.dk LTHEGLER@cpan.org lth@FreeBSD.org lars.thegler@teliasonera.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×