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
ch...
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:/...
Form Handling
# Form post with exception handling
my $cpan = 'http://search.cpan.org/search';
my $search = {q => 'mojo'};
my $tx = $clie...
Web Sockets
$client−>websocket(
'ws://websockets.org:8787' =>
sub {
  my $client = shift;
  $client−>on_message( sub {
    my ($client...
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 -Moj...
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] ...
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/g...
Upcoming SlideShare
Loading in...5
×

Mojo as a_client

3,603

Published on

Showing how to use mojo as the next LWP

Published in: Technology
0 Comments
12 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,603
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
30
Comments
0
Likes
12
Embeds 0
No embeds

No notes for slide



  • Much of this development was driven by Gisle Aas++ (Oslonett)


  • Hard to update, because so much depend on the current broken behavior



  • at Twitter
  • Maypole was originally developed by Simon Cozens, but he fucked off to become a missionary in Japan.

  • Catalyst had gathered steam.
    Core team of developers



  • Runs in 30 seconds (time to download, run test suite and install files).

  • All


  • Tell about nginx and status phrases.





























  • Mojo as a_client

    1. 1. Mojo as a HTTP A new beginning
    2. 2. I am Marcus I work here
    3. 3. In the beginning there was LWP
    4. 4. 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.
    5. 5. Became wildly popular, default choice for HTTP in Perl.
    6. 6. Starting to show it’s age
    7. 7. Clunky API No Async No Web Socket ...
    8. 8. The time is ripe for a new beginning.
    9. 9. perl -Mojo -e' g("vg.no/") ->dom(".article-content h3 a") ->each(sub { b(shift->text) ->decode->say })'
    10. 10. Actually, it didn’t happen just like that.
    11. 11. Sebastian Riedel @kraih
    12. 12. Took over Maypole. Wanted to make radical changes
    13. 13. Got Booted
    14. 14. Created Catalyst. Wanted to make radical changes
    15. 15. Got Booted
    16. 16. Made Mojolicious. Wanted to target PHP developers & Perl 6
    17. 17. Ease of install/porting ➜ Only Perl5 core dependencies
    18. 18. Bootstrapping: curl -L cpanmin.us | sudo perl - Mojolicious
    19. 19. Wrote an async HTTP 1.1 compliant stack
    20. 20. Mojo::Transaction Mojo::Message::Response Mojo::Cookie Mojo::URL +++
    21. 21. Test Driven Development
    22. 22. RFC Driven Development
    23. 23. PRAGMATIC
    24. 24. Next logical step: Add a client on top of this stack.
    25. 25. Mojo == Lego Built from reusable bricks.
    26. 26. Parallel requests
    27. 27. my $callback = sub { print shift−>res−>body }; $client−>get('http://mojolicious.org' => $callback); $client−>get('http://search.cpan.org' => $callback); $client−>start;
    28. 28. Form Handling
    29. 29. # 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"; }
    30. 30. Web Sockets
    31. 31. $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;
    32. 32. Oneliners
    33. 33. Collection of single letter commands.
    34. 34. g ➜ get d ➜ delete f ➜ form post p ➜ post u ➜ put w ➜ websocket
    35. 35. Special Cases b ➜ byte stream, a ➜ Lite app
    36. 36. #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 })'
    37. 37. Mojo::DOM
    38. 38. Liberal XML Parser
    39. 39. Supports all CSS3 selectors that make sense
    40. 40. * E[foo=”bar”] E:checked E:empty E:nth-child E:first-of-type E:not(s) EF E>F ++++
    41. 41. o(fun) If you need performance use libXML
    42. 42. SOME RANDOM BITS
    43. 43. Supports IPV6, TLS,proxies, epoll, kqueue
    44. 44. DEBUG MODE ENV VARIABLE MOJO_CLIENT_DEBUG=1 perl -Mojo -E’...’
    45. 45. # 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);
    46. 46. Big Body Just Works (temp storage on filesystem)
    47. 47. $res->json Automatic JSON deserialization
    48. 48. o(fun) Every file in the distro has a Simpsons or Futurama quote.
    49. 49. Now also handles disconnected keep-alive gracefully. (this was not the case when we started using it).
    50. 50. Test Driven Development
    51. 51. You provide failing test. kraih provides fix.
    52. 52. Learn More Mojo mojolicious.org github.com/kraih/mojo #mojo on irc.perl.org groups.google.com/group/mojolicious
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×