Mojolicious, real-time web framework
Upcoming SlideShare
Loading in...5

Mojolicious, real-time web framework






Total Views
Views on SlideShare
Embed Views



1 Embed 1 1



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Mojolicious, real-time web framework Mojolicious, real-time web framework Presentation Transcript

  • 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 as client
  • mojolicious - what? who?“real-time web application framework”written by Sebastian Riedel (sri) &cwho also wrote Catalystcurrent core: ams, tempire, mramberg
  • 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
  • installation no dependencies # cpanm Mojolicious easy curl recipe # curl | 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 => “Hello $name”);};# 200 OK, text/html, Hello Lars
  • 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
  • placeholders and routes,next level slurpy placeholders wildcard placeholders formats (‘.html’, ‘.txt’) bridging routes conditional routes
  • 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’);
  • 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) { ... <%= $i %> ... % }
  • 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->stash(template => ‘hello’); defaults to name of router get ‘/welcome’ => ‘hello’;
  • auto renderno need to call render() yourselfif you don’t, mojo will do it for you get ‘/’ => ‘index’; __DATA__ @@ index.html.ep
  • layouts__DATA__@@ index.html.ep% layout ‘default’Hello, World!@@ layouts/default.html.ep<html> <head><title>moo</title></head> <body><%= $content %></body></html>
  • 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 controller class testing with Test::Mojo
  • 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,...} by tempire incl wiki
  • thank you :) tagg @ irc taggg @ twitter