SlideShare a Scribd company logo
1 of 56
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

More Related Content

What's hot

Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and GulpOptimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and GulpMatthew Davis
 
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsRyan Weaver
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientAdam Wiggins
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyLaunchAny
 
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIWordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIBrian Hogg
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + djangoNina Zakharenko
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversTatsuhiko Miyagawa
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Racksickill
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Alberto Perdomo
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with CucumberBen Mabey
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with DancerDave Cross
 

What's hot (20)

Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and GulpOptimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
 
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
PSGI/Plack OSDC.TW
PSGI/Plack OSDC.TWPSGI/Plack OSDC.TW
PSGI/Plack OSDC.TW
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
Plack at OSCON 2010
Plack at OSCON 2010Plack at OSCON 2010
Plack at OSCON 2010
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIWordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + django
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Mastering Grunt
Mastering GruntMastering Grunt
Mastering Grunt
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with Cucumber
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
 

Similar to Mojolicious

Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.catPablo Godel
 
Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)True-Vision
 
Socket applications
Socket applicationsSocket applications
Socket applicationsJoão Moura
 
Hosting Your Own OTA Update Service
Hosting Your Own OTA Update ServiceHosting Your Own OTA Update Service
Hosting Your Own OTA Update ServiceQuinlan Jung
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST APICaldera Labs
 
Rock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsRock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsPablo Godel
 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011tobiascrawley
 
A complete guide to Node.js
A complete guide to Node.jsA complete guide to Node.js
A complete guide to Node.jsPrabin Silwal
 
2018 the conf put git to work - increase the quality of your rails project...
2018 the conf   put git to work -  increase the quality of your rails project...2018 the conf   put git to work -  increase the quality of your rails project...
2018 the conf put git to work - increase the quality of your rails project...Rodrigo Urubatan
 
Automatisation in development and testing - within budget
Automatisation in development and testing - within budgetAutomatisation in development and testing - within budget
Automatisation in development and testing - within budgetDavid Lukac
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSAntonio Peric-Mazar
 
Symfony 2.0
Symfony 2.0Symfony 2.0
Symfony 2.0GrUSP
 
Torquebox Asheville.rb April 2011
Torquebox Asheville.rb April 2011Torquebox Asheville.rb April 2011
Torquebox Asheville.rb April 2011Lance Ball
 
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyConsegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyFabio Akita
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)James Titcumb
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsJim Jeffers
 

Similar to Mojolicious (20)

Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)
 
Socket applications
Socket applicationsSocket applications
Socket applications
 
Deploy like a pro!
Deploy like a pro!Deploy like a pro!
Deploy like a pro!
 
Hosting Your Own OTA Update Service
Hosting Your Own OTA Update ServiceHosting Your Own OTA Update Service
Hosting Your Own OTA Update Service
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
 
Rock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsRock Solid Deployment of Web Applications
Rock Solid Deployment of Web Applications
 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011
 
A complete guide to Node.js
A complete guide to Node.jsA complete guide to Node.js
A complete guide to Node.js
 
2018 the conf put git to work - increase the quality of your rails project...
2018 the conf   put git to work -  increase the quality of your rails project...2018 the conf   put git to work -  increase the quality of your rails project...
2018 the conf put git to work - increase the quality of your rails project...
 
Capistrano Overview
Capistrano OverviewCapistrano Overview
Capistrano Overview
 
Automatisation in development and testing - within budget
Automatisation in development and testing - within budgetAutomatisation in development and testing - within budget
Automatisation in development and testing - within budget
 
Sprockets
SprocketsSprockets
Sprockets
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJS
 
Symfony 2.0
Symfony 2.0Symfony 2.0
Symfony 2.0
 
Torquebox Asheville.rb April 2011
Torquebox Asheville.rb April 2011Torquebox Asheville.rb April 2011
Torquebox Asheville.rb April 2011
 
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyConsegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
 

Recently uploaded

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Recently uploaded (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

Mojolicious

  • 1. Mojolicious - Web development rethought Marcus Ramberg Nordaaker
  • 5. Sebastian Riedel • twitter.com/kraih • Creator of Catalyst • Went over to the dark side (*cough*RoR*cough*)
  • 6. Sebastian Riedel • twitter.com/kraih • Creator of Catalyst • Went over to the dark side (*cough*RoR*cough*) • This is what he brought back
  • 11. Installation • cpan Mojolicious • There is no step 2 • No dependencies beyond Perl 5.8.1+
  • 12. Installation • cpan Mojolicious • There is no step 2 • No dependencies beyond Perl 5.8.1+ • Could also easily be bundled with your app.
  • 14. 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
  • 15. 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 :)
  • 16. $ 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
  • 17. Lite app #!/usr/bin/env perl use Mojolicious::Lite; get '/' => 'index'; get '/:groovy' => sub { my $self = shift; $self->render_text( $self->param('groovy')); }; shagadelic;
  • 18. 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;
  • 19. 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>
  • 20. 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.
  • 21. Handles 3 different urls •/ • /* • /*/*
  • 23. Features ★ A powerful routes based dispatcher
  • 24. Features ★ A powerful routes based dispatcher ★ Full HTTP 1/1 implementation (Client/ Server)
  • 25. Features ★ A powerful routes based dispatcher ★ Full HTTP 1/1 implementation (Client/ Server) ★ Simple Template System
  • 26. Features ★ A powerful routes based dispatcher ★ Full HTTP 1/1 implementation (Client/ Server) ★ Simple Template System ★ JSON support built-in
  • 27. Features ★ A powerful routes based dispatcher ★ Full HTTP 1/1 implementation (Client/ Server) ★ Simple Template System ★ JSON support built-in ★ Elegant plugin system
  • 28. 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
  • 29. 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
  • 30. 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'); }
  • 31. 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; }
  • 32. 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(...)
  • 33. HTTP 1.1 stack • HTTP Stack implemented based on RFCs • Full HTTP implementation, including pipelining • Does not use LWP, No request body in memory.
  • 34. 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
  • 35. 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
  • 36. 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
  • 37. 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
  • 38. JSON support use Mojo::JSON; my $json=Mojo::JSON->new; my $str=$json->encode({foo => ‘bar’}); my $strct=$json->decode (‘[“foo”,”bar”’]);
  • 39. 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
  • 40. 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::*
  • 41. 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::*
  • 42. 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.
  • 43. Mojolicious classes Mojolicious Mojolicios::Lite Mojolicious::Command::* Mojolicious::Plugins Mojolicious::Plugin::* Mojolicious::Controller
  • 44. Mojolicious classes Mojolicious Mojolicios::Lite Mojolicious::Command::* Mojolicious::Plugins Mojolicious::Plugin::* Mojolicious::Controller
  • 45. Plugin system ★ Hook based ★ before_dispatch ★ after_dispatch ★ after_static_dispatch ★ after_build_tx ★ Also apropriate place to add types & renders & custom routes extension.
  • 46. Mojolicious classes Mojolicious Mojolicios::Lite Mojolicious::Command::* Mojolicious::Plugins Mojolicious::Plugin::* Mojolicious::Controller
  • 47. 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
  • 48. 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
  • 49. default helpers ★ dumper ★ param ★ stash ★ layout ★ include ★ content ★ extends ★ url_for
  • 50. Mojolicious classes Mojolicious Mojolicios::Lite Mojolicious::Command::* Mojolicious::Plugins Mojolicious::Plugin::* Mojolicious::Controller
  • 51. 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
  • 52. 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'"
  • 53. Get the source • http://github.com/kraih/ mojo • Pull requests welcome • Just fork and play
  • 56. Questions? • Thanks for listening • marcus@nordaaker.com

Editor's Notes