SlideShare a Scribd company logo
Mojo as a HTTP
  A new beginning
I am Marcus
 I work here
In the beginning
 there was LWP
First Changelog Entry:

Thu 18 May 1995   Martijn Koster
<m.koster@nexor.co.uk>

 o Mentioned on libwww-perl that I had
changed the classes around lots.
Became wildly popular,
  default choice for
    HTTP in Perl.
Starting to
show it’s age
Clunky API
  No Async
No Web Socket
     ...
The time is ripe for
 a new beginning.
perl -Mojo -e'
g("vg.no/")
->dom(".article-content h3
a")
->each(sub {
b(shift->text)
->decode->say })'
Actually, it didn’t
happen just like that.
Sebastian Riedel
    @kraih
Took over Maypole.
 Wanted to make
  radical changes
Got
Booted
Created Catalyst.
Wanted to make
 radical changes
Got
Booted
Made Mojolicious.
  Wanted to target
PHP developers & Perl
         6
Ease of install/porting
          ➜
   Only Perl5 core
    dependencies
Bootstrapping:
 curl -L cpanmin.us |
sudo perl - Mojolicious
Wrote an async
   HTTP 1.1
compliant stack
Mojo::Transaction
Mojo::Message::Response
      Mojo::Cookie
       Mojo::URL
         +++
Test Driven
Development
RFC Driven
Development
PRAGMATIC
Next logical step:
Add a client on top of
     this stack.
Mojo == Lego
Built from reusable
       bricks.
Parallel
requests
my $callback = sub {

 print shift−>res−>body
};
$client−>get('http://mojolicious.org' =>
$callback);
$client−>get('http://search.cpan.org' =>
$callback);
$client−>start;
Form Handling
# Form post with exception handling
my $cpan = 'http://search.cpan.org/search';
my $search = {q => 'mojo'};
my $tx = $client−>post_form($cpan => $search);
if (my $res = $tx−>success) {
   print $res−>body
} else {
   my ($message, $code) = $tx−>error;
   print "Error: $message";
}
Web Sockets
$client−>websocket(
'ws://websockets.org:8787' =>
sub {
  my $client = shift;
  $client−>on_message( sub {
    my ($client, $message) = @_;
    print "$messagen";
    $client−>finish;
  });
  $client−>send_message('hiya!');
})−>start;
Oneliners
Collection of single
 letter commands.
g ➜ get
  d ➜ delete
f ➜ form post
   p ➜ post
    u ➜ put
w ➜ websocket
Special Cases
b ➜ byte stream,
  a ➜ Lite app
#ojo module
my $res = g( 'http://mojolicio.us',
         {'Content−Type' => 'text/plain'},
         'Hello!' );

perl -Mojo -e 'b(g("mojolicio.us")->dom->at("title")->text)->say'

perl -Mojo -E'g("bloomberg.com")->dom("a.story_link")->each(sub { say
shift->text; })'

perl -Mojo -E'g("digg.com")->dom("a.story-title")->each(sub { say pop, ". ",
shift->text })'

# Undocumented o(fun) Mojolicious cloud function:
perl -Mojo -e 'oO("http://www.reddit.com")->dom->find("a.title")-
>each(sub { Oo(pop . ". " . shift->text)->say })'
Mojo::DOM
Liberal XML Parser
Supports all CSS3
  selectors that
   make sense
*
 E[foo=”bar”]
   E:checked
    E:empty
  E:nth-child
E:first-of-type
    E:not(s)
       EF
      E>F
     ++++
o(fun)
If you need performance
       use libXML
SOME RANDOM
    BITS
Supports IPV6,
TLS,proxies, epoll,
     kqueue
DEBUG MODE
    ENV VARIABLE
MOJO_CLIENT_DEBUG=1 
   perl -Mojo -E’...’
# Streaming response
my $tx = $client−>build_tx(GET =>
       'http://mojolicious.org');
$tx−>res−>body(sub { print $_[1] });
$client−>start($tx);

# Custom socket
my $tx = $client−>build_tx(GET =>
       'http://mojolicious.org');
$tx−>connection($socket);
$client−>start($tx);
Big Body
  Just Works
(temp storage on
   filesystem)
$res->json
Automatic JSON
deserialization
o(fun)
Every file in the distro
  has a Simpsons or
   Futurama quote.
Now also handles
  disconnected keep-alive
         gracefully.
(this was not the case when
     we started using it).
Test Driven
Development
You provide
failing test. kraih
   provides fix.
Learn More Mojo
           mojolicious.org
      github.com/kraih/mojo
         #mojo on irc.perl.org

groups.google.com/group/mojolicious

More Related Content

ZIP
Web Apps in Perl - HTTP 101
PDF
Perl web frameworks
PPTX
Webrtc mojo
PDF
Inside Bokete: Web Application with Mojolicious and others
PDF
Developing apps using Perl
PDF
RESTful web services
PDF
Asynchronous programming patterns in Perl
PDF
Mojolicious
Web Apps in Perl - HTTP 101
Perl web frameworks
Webrtc mojo
Inside Bokete: Web Application with Mojolicious and others
Developing apps using Perl
RESTful web services
Asynchronous programming patterns in Perl
Mojolicious

What's hot (20)

KEY
Mojolicious - A new hope
KEY
Perl: Hate it for the Right Reasons
KEY
Keeping it small: Getting to know the Slim micro framework
PDF
Mojolicious. Веб в коробке!
PDF
Keeping it small - Getting to know the Slim PHP micro framework
PPTX
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
PDF
Mojolicious: what works and what doesn't
PPT
Slim RedBeanPHP and Knockout
KEY
Operation Oriented Web Applications / Yokohama pm7
PDF
YAPC::Asia 2010 Twitter解析サービス
PDF
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
PDF
Asynchronous PHP and Real-time Messaging
ODP
Mojolicious on Steroids
PDF
Any event intro
PDF
AnyMQ, Hippie, and the real-time web
PDF
A reviravolta do desenvolvimento web
PDF
Blog Hacks 2011
PDF
Mojolicious, real-time web framework
PDF
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
ODP
PHP5.5 is Here
Mojolicious - A new hope
Perl: Hate it for the Right Reasons
Keeping it small: Getting to know the Slim micro framework
Mojolicious. Веб в коробке!
Keeping it small - Getting to know the Slim PHP micro framework
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious: what works and what doesn't
Slim RedBeanPHP and Knockout
Operation Oriented Web Applications / Yokohama pm7
YAPC::Asia 2010 Twitter解析サービス
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Asynchronous PHP and Real-time Messaging
Mojolicious on Steroids
Any event intro
AnyMQ, Hippie, and the real-time web
A reviravolta do desenvolvimento web
Blog Hacks 2011
Mojolicious, real-time web framework
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
PHP5.5 is Here
Ad

Viewers also liked (7)

PDF
TELEMEDICINE OUR VISION TO FUTURE
PPT
Expresiones Regulares
PDF
Curscatalyst
PPT
andUNITE search groups - how to
PDF
A First Class Web Citizen
PPT
Blogging In The Library Revised Oct 16
ZIP
Mojolicious
TELEMEDICINE OUR VISION TO FUTURE
Expresiones Regulares
Curscatalyst
andUNITE search groups - how to
A First Class Web Citizen
Blogging In The Library Revised Oct 16
Mojolicious
Ad

Similar to Mojo as a_client (20)

ODP
The promise of asynchronous php
KEY
ODP
The promise of asynchronous php
KEY
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
PDF
Selenium sandwich-3: Being where you aren't.
KEY
Plack - LPW 2009
PPTX
PSGI and Plack from first principles
KEY
Psgi Plack Sfpm
KEY
Psgi Plack Sfpm
PDF
React PHP: the NodeJS challenger
PPTX
PHP in 2018 - Q4 - AFUP Limoges
ODP
The promise of asynchronous PHP
PDF
How to build a High Performance PSGI/Plack Server
PDF
Forget about index.php and build you applications around HTTP!
ZIP
AnyMQ, Hippie, and the real-time web
ODP
The promise of asynchronous PHP
PDF
Debugging: Rules And Tools - PHPTek 11 Version
PDF
Web 8 | Introduction to PHP
PDF
Forget about Index.php and build you applications around HTTP - PHPers Cracow
PDF
Dirty Secrets of the PHP SOAP Extension
The promise of asynchronous php
The promise of asynchronous php
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Selenium sandwich-3: Being where you aren't.
Plack - LPW 2009
PSGI and Plack from first principles
Psgi Plack Sfpm
Psgi Plack Sfpm
React PHP: the NodeJS challenger
PHP in 2018 - Q4 - AFUP Limoges
The promise of asynchronous PHP
How to build a High Performance PSGI/Plack Server
Forget about index.php and build you applications around HTTP!
AnyMQ, Hippie, and the real-time web
The promise of asynchronous PHP
Debugging: Rules And Tools - PHPTek 11 Version
Web 8 | Introduction to PHP
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Dirty Secrets of the PHP SOAP Extension

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Big Data Technologies - Introduction.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Network Security Unit 5.pdf for BCA BBA.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Big Data Technologies - Introduction.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Empathic Computing: Creating Shared Understanding
Spectral efficient network and resource selection model in 5G networks
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
MYSQL Presentation for SQL database connectivity
The Rise and Fall of 3GPP – Time for a Sabbatical?
The AUB Centre for AI in Media Proposal.docx
20250228 LYD VKU AI Blended-Learning.pptx
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Mobile App Security Testing_ A Comprehensive Guide.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Machine learning based COVID-19 study performance prediction
Network Security Unit 5.pdf for BCA BBA.

Mojo as a_client

Editor's Notes

  • #5: Much of this development was driven by Gisle Aas++ (Oslonett)
  • #8: Hard to update, because so much depend on the current broken behavior
  • #12: at Twitter
  • #13: Maypole was originally developed by Simon Cozens, but he fucked off to become a missionary in Japan.
  • #15: Catalyst had gathered steam. Core team of developers
  • #19: Runs in 30 seconds (time to download, run test suite and install files).
  • #21: All
  • #24: Tell about nginx and status phrases.