SlideShare uma empresa Scribd logo
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

Mais conteúdo relacionado

Mais procurados

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
Tatsuhiko 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 Gulp
Matthew 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 Tools
Ryan Weaver
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
Adam Wiggins
 
PSGI/Plack OSDC.TW
PSGI/Plack OSDC.TWPSGI/Plack OSDC.TW
PSGI/Plack OSDC.TW
Tatsuhiko Miyagawa
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
Tatsuhiko Miyagawa
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
Tatsuhiko Miyagawa
 
Plack at OSCON 2010
Plack at OSCON 2010Plack at OSCON 2010
Plack at OSCON 2010
Tatsuhiko Miyagawa
 
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
LaunchAny
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
Yoshiki Kurihara
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
Emanuele DelBono
 
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
Brian Hogg
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + django
Nina 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 servers
Tatsuhiko Miyagawa
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
Marcus Ramberg
 
Mastering Grunt
Mastering GruntMastering Grunt
Mastering Grunt
Spencer Handley
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
sickill
 
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 Cucumber
Ben Mabey
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
Dave Cross
 

Mais procurados (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
 

Semelhante a Mojolicious

Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
Pablo 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 applications
João Moura
 
Deploy like a pro!
Deploy like a pro!Deploy like a pro!
Deploy like a pro!
Damian Serrano Thode
 
Hosting Your Own OTA Update Service
Hosting Your Own OTA Update ServiceHosting Your Own OTA Update Service
Hosting Your Own OTA Update Service
Quinlan Jung
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
Caldera Labs
 
Rock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsRock Solid Deployment of Web Applications
Rock Solid Deployment of Web Applications
Pablo Godel
 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011
tobiascrawley
 
A complete guide to Node.js
A complete guide to Node.jsA complete guide to Node.js
A complete guide to Node.js
Prabin 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
 
Capistrano Overview
Capistrano OverviewCapistrano Overview
Capistrano Overview
Travis Roberts
 
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
David Lukac
 
Sprockets
SprocketsSprockets
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
Antonio Peric-Mazar
 
Symfony 2.0
Symfony 2.0Symfony 2.0
Symfony 2.0
GrUSP
 
Torquebox Asheville.rb April 2011
Torquebox Asheville.rb April 2011Torquebox Asheville.rb April 2011
Torquebox Asheville.rb April 2011
Lance 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 Ruby
Fabio 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
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
Norberto Leite
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
Jim Jeffers
 

Semelhante a 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
 

Último

Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 

Último (20)

Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 

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

Notas do Editor