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)

PPT
Teaching material agriculture food technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Approach and Philosophy of On baking technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Mushroom cultivation and it's methods.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
Teaching material agriculture food technology
Encapsulation_ Review paper, used for researhc scholars
MIND Revenue Release Quarter 2 2025 Press Release
Heart disease approach using modified random forest and particle swarm optimi...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
TLE Review Electricity (Electricity).pptx
SOPHOS-XG Firewall Administrator PPT.pptx
Assigned Numbers - 2025 - Bluetooth® Document
cloud_computing_Infrastucture_as_cloud_p
Advanced methodologies resolving dimensionality complications for autism neur...
Building Integrated photovoltaic BIPV_UPV.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Programs and apps: productivity, graphics, security and other tools
Approach and Philosophy of On baking technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Artificial Intelligence
Mushroom cultivation and it's methods.pdf
Unlocking AI with Model Context Protocol (MCP)

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.