Mojolicious
Upcoming SlideShare
Loading in...5
×
 

Mojolicious

on

  • 10,810 views

A introduction to the Mojolicious web framework.

A introduction to the Mojolicious web framework.

Statistics

Views

Total Views
10,810
Views on SlideShare
9,834
Embed Views
976

Actions

Likes
11
Downloads
82
Comments
0

8 Embeds 976

http://marcus.nordaaker.com 924
http://www.slideshare.net 45
https://si0.twimg.com 2
http://dev.thefeed.no:3000 1
http://localhost:3001 1
http://a0.twimg.com 1
http://translate.googleusercontent.com 1
http://www.linkedin.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

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.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Mojolicious Mojolicious Presentation Transcript

  • Mojolicious - Web development rethought Marcus Ramberg Nordaaker
  • Sebastian Riedel
  • Sebastian Riedel • twitter.com/kraih
  • Sebastian Riedel • twitter.com/kraih • Creator of Catalyst
  • Sebastian Riedel • twitter.com/kraih • Creator of Catalyst • Went over to the dark side (*cough*RoR*cough*)
  • Sebastian Riedel • twitter.com/kraih • Creator of Catalyst • Went over to the dark side (*cough*RoR*cough*) • This is what he brought back
  • mojolicious.org
  • Installation
  • Installation • cpan Mojolicious
  • Installation • cpan Mojolicious • There is no step 2
  • Installation • cpan Mojolicious • There is no step 2 • No dependencies beyond Perl 5.8.1+
  • Installation • cpan Mojolicious • There is no step 2 • No dependencies beyond Perl 5.8.1+ • Could also easily be bundled with your app.
  • With an unconfigured Perl
  • With an unconfigured Perl ★ $ curl -L cpanmin.us | perl - Mojolicious Fetching http://search.cpan.org/CPAN/ authors/id/K/KR/KRAIH/ Mojolicious-0.999922.tar.gz ... OK Configuring Mojolicious-0.999922 ... OK Building and testing Mojolicious-0.999922 for Mojolicious ... OK Successfully installed Mojolicious-0.999922
  • With an unconfigured Perl ★ $ curl -L cpanmin.us | perl - Mojolicious Fetching http://search.cpan.org/CPAN/ authors/id/K/KR/KRAIH/ Mojolicious-0.999922.tar.gz ... OK Configuring Mojolicious-0.999922 ... OK Building and testing Mojolicious-0.999922 for Mojolicious ... OK Successfully installed Mojolicious-0.999922 ★ Gratuitous App::cpanminus plug :)
  • $ mojolicious generate lite_app [exist] /Users/marcus [write] /Users/marcus/foosball [chmod] foosball 744 That was easy. Now let’s check out the contents of the file
  • Lite app #!/usr/bin/env perl use Mojolicious::Lite; get '/' => 'index'; get '/:groovy' => sub { my $self = shift; $self->render_text( $self->param('groovy')); }; shagadelic;
  • Lite app (enterprise edition) #!/usr/bin/env perl use Mojolicious::Lite; get '/' => 'index'; get '/:synergy' => sub { my $self = shift; $self->render_text( $self->param('synergy')); }; app->start;
  • View __DATA__ @@ index.html.ep % layout 'funky'; Yea baby! @@ layouts/funky.html.ep <!doctype html><html> <head><title>Funky!</title></head> <body><%== content %></body> </html>
  • Let’s fire her up: $ ./foosball usage: foosball COMMAND [OPTIONS] These commands are currently available: generate Generate files and directories from templates. routes Show available routes. cgi Start application with CGI backend. daemon Start application with HTTP 1.1 backend. daemon_prefork Start application with preforking HTTP 1.1 backend. fastcgi Start application with FastCGI backend. get Get file from URL. psgi Start application with PSGI backend. test Run unit tests. version Show versions of installed modules. See 'foosball help COMMAND' for more information on a specific command. $ ./foosball daemon Server available at http://Command-Central.local:3000.
  • Handles 3 different urls •/ • /* • /*/*
  • Features
  • Features ★ A powerful routes based dispatcher
  • Features ★ A powerful routes based dispatcher ★ Full HTTP 1/1 implementation (Client/ Server)
  • Features ★ A powerful routes based dispatcher ★ Full HTTP 1/1 implementation (Client/ Server) ★ Simple Template System
  • Features ★ A powerful routes based dispatcher ★ Full HTTP 1/1 implementation (Client/ Server) ★ Simple Template System ★ JSON support built-in
  • Features ★ A powerful routes based dispatcher ★ Full HTTP 1/1 implementation (Client/ Server) ★ Simple Template System ★ JSON support built-in ★ Elegant plugin system
  • Features ★ A powerful routes based dispatcher ★ Full HTTP 1/1 implementation (Client/ Server) ★ Simple Template System ★ JSON support built-in ★ Elegant plugin system ★ Class reloader
  • Features ★ A powerful routes based dispatcher ★ Full HTTP 1/1 implementation (Client/ Server) ★ Simple Template System ★ JSON support built-in ★ Elegant plugin system ★ Class reloader ★ And a lot more
  • Routes - snakes and ladders # ::Lite get ‘/’ => ‘index’; # sub refs for functions post ‘/login’ => sub { .. }; # Placeholders & Actions: get ‘/:foo’ => sub {},‘ctrl’ # All together get '/everything/:stuff' => [stuff => qr/d+/] => {stuff => 23} => sub { shift->render('welcome'); }
  • Routes - snakes and ladders ladder sub { my $self = shift # Authenticated my $name = $self->param('name') || ''; return 1 if $name eq 'Bender'; # Not authenticated $self->render('denied'); return; }
  • More routes $r->route(‘/’)->to (controller=>‘foo’,action=> ‘bar’); ('lists#new', id => 1)->name('new'); ('/:controller/:action/:id')->to ('example#welcome', id => 1) # Bridges my $auth=$r->bridge->to(‘auth#check’); $auth->route(...)
  • HTTP 1.1 stack • HTTP Stack implemented based on RFCs • Full HTTP implementation, including pipelining • Does not use LWP, No request body in memory.
  • Classes Mojo::Base Mojo::ByteStream Mojo::Template, Mojo::JSON Mojo::Loader,Mojo::Log,Mojo::Path Mojo::URL,Mojo::Parameters Mojo::Content Mojo::Message::Request Mojo::Message::Response Mojo::Headers,Mojo::Cookie, Mojo::Date
  • Base Classes Mojo::Base Mojo::ByteStream Mojo::Template, Mojo::JSON Mojo::Loader,Mojo::Log,Mojo::Path Mojo::URL,Mojo::Parameters Mojo::Content Mojo::Message::Request Mojo::Message::Response Mojo::Headers,Mojo::Cookie, Mojo::Date
  • Mojo::Template % my $player=$self->stash(‘players’); %= $player; # print %== $player; # raw <%= player %> # inline style % # Normal comment <% # inline comment %> .ep - prepopulates stash for you .epl - same templates, less magic
  • Base Classes Mojo::Base Mojo::ByteStream Mojo::Template, Mojo::JSON Mojo::Loader,Mojo::Log,Mojo::Path Mojo::URL,Mojo::Parameters Mojo::Content Mojo::Message::Request Mojo::Message::Response Mojo::Headers,Mojo::Cookie, Mojo::Date
  • JSON support use Mojo::JSON; my $json=Mojo::JSON->new; my $str=$json->encode({foo => ‘bar’}); my $strct=$json->decode (‘[“foo”,”bar”’]);
  • Classes Mojo::Base Mojo::ByteStream Mojo::Template, Mojo::JSON Mojo::Loader,Mojo::Log,Mojo::Path Mojo::URL,Mojo::Parameters Mojo::Content Mojo::Message::Request Mojo::Message::Response Mojo::Headers,Mojo::Cookie, Mojo::Date
  • More Classes Mojo::Transaction, Mojo::Stateful Mojo::IOLoop Mojo::Client, Mojo::Server Mojo::Server::CGI Mojo::Server::FastCGI Mojo::Server::PSGI Mojo::Server::Daemon, ::Prefork Mojo::Command::*
  • More Classes Mojo::Transaction, Mojo::Stateful Mojo::IOLoop Mojo::Client, Mojo::Server Mojo::Server::CGI Mojo::Server::FastCGI Mojo::Server::PSGI Mojo::Server::Daemon, ::Prefork Mojo::Command::*
  • HTTP Client my $client=Mojo::Client->new; $client->get( ‘http://iusethis.com/new.rss’ => sub { my ($self,$tx)=@_; say $tx->res; })->process; #inside mojolicious $self->client->post(...); # also works with the ioloop.
  • Mojolicious classes Mojolicious Mojolicios::Lite Mojolicious::Command::* Mojolicious::Plugins Mojolicious::Plugin::* Mojolicious::Controller
  • Mojolicious classes Mojolicious Mojolicios::Lite Mojolicious::Command::* Mojolicious::Plugins Mojolicious::Plugin::* Mojolicious::Controller
  • Plugin system ★ Hook based ★ before_dispatch ★ after_dispatch ★ after_static_dispatch ★ after_build_tx ★ Also apropriate place to add types & renders & custom routes extension.
  • Mojolicious classes Mojolicious Mojolicios::Lite Mojolicious::Command::* Mojolicious::Plugins Mojolicious::Plugin::* Mojolicious::Controller
  • Mojolicious default plugins ★ Mojolicious::Plugin::AgentCondition - Agent Condition   ★ Mojolicious::Plugin::Charset - Default Charset   ★ Mojolicious::Plugin::DefaultHelpers - Default Helpers   ★ Mojolicious::Plugin::EpRenderer - EP Renderer   ★ Mojolicious::Plugin::EplRenderer -EPL Renderer  ★ Mojolicious::Plugin::HeaderCondition - Header Condition  ★ Mojolicious::Plugin::I18n Internationalization Plugin   ★ Mojolicious::Plugin::JsonConfig - JSON Configuration  ★ Mojolicious::Plugin::PodRenderer - POD Renderer  ★ Mojolicious::Plugin::PoweredBy - Powered By Plugin    ★ Mojolicious::Plugin::RequestTimer - Time requests
  • Mojolicious default plugins ★ Mojolicious::Plugin::AgentCondition - Agent Condition   ★ Mojolicious::Plugin::Charset - Default Charset   ★ Mojolicious::Plugin::DefaultHelpers - Default Helpers   ★ Mojolicious::Plugin::EpRenderer - EP Renderer   ★ Mojolicious::Plugin::EplRenderer -EPL Renderer  ★ Mojolicious::Plugin::HeaderCondition - Header Condition  ★ Mojolicious::Plugin::I18n Internationalization Plugin   ★ Mojolicious::Plugin::JsonConfig - JSON Configuration  ★ Mojolicious::Plugin::PodRenderer - POD Renderer  ★ Mojolicious::Plugin::PoweredBy - Powered By Plugin    ★ Mojolicious::Plugin::RequestTimer - Time requests
  • default helpers ★ dumper ★ param ★ stash ★ layout ★ include ★ content ★ extends ★ url_for
  • Mojolicious classes Mojolicious Mojolicios::Lite Mojolicious::Command::* Mojolicious::Plugins Mojolicious::Plugin::* Mojolicious::Controller
  • Mojolicious::Controller ->render ->render(template=>‘foo/bar’) ->render(controller=>‘foo’,action=>‘bar’) ->render(‘foo#bar’) ->render_text ->render_json ->render_inner ->render_partial ->pause / ->resume ->redirect_to / ->url_for
  • STOP THE PRESS! WEBSOCKET! HTML5 protocol for long running processes Mojo first Perl framework to add support perl -MMojolicious::Lite -e "websocket '/' => sub {shift->receive_message(sub { shift- >send_message(shift)})}; shagadelic 'daemon'"
  • Get the source • http://github.com/kraih/ mojo • Pull requests welcome • Just fork and play
  • Questions?
  • Questions? • Thanks for listening
  • Questions? • Thanks for listening • marcus@nordaaker.com