Mojolicious, real-time web framework

  • 614 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
614
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
12
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. mojoliciousreal-time web frameworkNPW2012, Stockholm Lars Thegler
  • 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. agendaMojolicious::Lite routes and placeholders templates and layouts graduating from ::Lite to Mojolicious properMojo as client
  • 4. mojolicious - what? who?“real-time web application framework”written by Sebastian Riedel (sri) &cwho also wrote Catalystcurrent core: ams, tempire, mramberg
  • 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. installation no dependencies # cpanm Mojolicious easy curl recipe # curl get.mojolicio.us | sh
  • 7. executionbuiltin (simple, morbo, hypnotoad)nginxapache/mod_proxy, CGIPSGI/plack
  • 8. anatomy of aweb frameworkincoming request => dispatcher => action code => outgoing response
  • 9. dispatchersmall languagematching incoming request => action code“routes”
  • 10. getting started# GET /get / => sub { my $self = shift; $self->render(text => Hello);};# 200 OK, text/html, Hello
  • 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. 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. placeholders and routes,next level slurpy placeholders wildcard placeholders formats (‘.html’, ‘.txt’) bridging routes conditional routes
  • 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. templatebuiltin ‘Embedded Perl’variables in templates from stashinstantiated as normal values Hello, <%= $name %>
  • 16. structures in templates It’s all Perl, so Perl control structures just work: % for my $i (0..3) { ... <%= $i %> ... % }
  • 17. inline templates__DATA__@@ hello.html.epHello, World!@@ goodbye.html.epGoodbye, and thanks!
  • 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. auto renderno need to call render() yourselfif you don’t, mojo will do it for you get ‘/’ => ‘index’; __DATA__ @@ index.html.ep
  • 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. templates, next level includes partial templates 404, 500 pages blocks template inheritance ...
  • 22. sessionsbuilt indata stored in cookies, client-sidecookie signed to prevent tamperingyou can use something else, if you want
  • 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. but wait, there’s more! Mojo::UserAgent nice web client Mojo::DOM excellent HTML/XML parser ojo for one-liners
  • 25. resourceshttp://mojolicio.usMojolicious::Guides::{Routing,Rendering,Growing,...}http://mojocasts.com by tempirehttps://github.com/kraih/mojo incl wiki
  • 26. thank you :) tagg @ irc taggg @ twitter lars@thegler.dk LTHEGLER@cpan.org lth@FreeBSD.org lars.thegler@teliasonera.com