You are on page 1of 43

Mojo as a HTTP Client

A new beginning

Tuesday, October 5, 2010

In the beginning there was LWP


Tuesday, October 5, 2010

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.

Tuesday, October 5, 2010

Became wildly popular, default choice for HTTP in Perl.


Tuesday, October 5, 2010

Starting to show its age


Tuesday, October 5, 2010

Clunky API No Async No Web Socket ...


Tuesday, October 5, 2010

The time is ripe for a new beginning.


Tuesday, October 5, 2010

perl -Mojo -e' g("vg.no/") ->dom(".articlecontent h3 a") ->each(sub { b(shift->text) ->decode->say })'
Tuesday, October 5, 2010

Actually, it didnt happen just like that.

Tuesday, October 5, 2010

Sebastian Riedel @kraih


Tuesday, October 5, 2010

Took over Maypole. Wanted to make radical changes


Tuesday, October 5, 2010

Got Booted
Tuesday, October 5, 2010

Created Catalyst. Wanted to make radical changes


Tuesday, October 5, 2010

Got Booted
Tuesday, October 5, 2010

Made Mojolicious. Wanted to target PHP devs & Perl 6


Tuesday, October 5, 2010

Ease of install/Porting Only Perl5 core deps


Tuesday, October 5, 2010

Wrote an async HTTP 1.1 compliant stack


Tuesday, October 5, 2010

Mojo::Transaction Mojo::Message::Response Mojo::Cookie Mojo::URL +++


Tuesday, October 5, 2010

RFC Driven Development


Tuesday, October 5, 2010

Test Driven Development


Tuesday, October 5, 2010

Next logical step: Add a client on top of this stack.


Tuesday, October 5, 2010

Mojo == Lego Built from resuable bricks.


Tuesday, October 5, 2010

Parallel requests
Tuesday, October 5, 2010

my $callback = sub { print shift>res>body }; $client>get('http:// mojolicious.org' => $callback); $client>get('http:// search.cpan.org' => $callback); $client>start;

Tuesday, October 5, 2010

Form Handling
Tuesday, October 5, 2010

# 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"; }

Tuesday, October 5, 2010

Web Sockets
Tuesday, October 5, 2010

$client>websocket( 'ws://websockets.org:8787' => sub { my $client = shift; $client>on_message( sub { my ($client, $message) = @_; print "$message\n"; $client>nish; }); $client>send_message('hiya!'); })>start;

Tuesday, October 5, 2010

Oneliners
Tuesday, October 5, 2010

Collection of single letter commands.

Tuesday, October 5, 2010

g get d delete f form post p post u put w websocket


Tuesday, October 5, 2010

Special Cases b byte stream, a Lite app

Tuesday, October 5, 2010

#ojo module my $res = g( 'http://mojolicio.us', {'ContentType' => '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.storytitle")->each(sub { say pop, ". ", shift>text })' # Undocumented o(fun) Mojolicious cloud function: perl -Mojo -e 'oO("http://www.reddit.com")->dom>nd("a.title")->each(sub { Oo(pop . ". " . shift->text)->say })'

Tuesday, October 5, 2010

Mojo::DOM
Tuesday, October 5, 2010

Liberal XML Parser


Tuesday, October 5, 2010

Supports all CSS3 selectors that make sense


Tuesday, October 5, 2010

* E[foo=bar] E:checked E:empty E:nth-child E:rst-of-type E:not(s) E F E > F ++++


Tuesday, October 5, 2010

SOME RANDOM BITS


Tuesday, October 5, 2010

DEBUG MODE ENV VARIABLE MOJO_CLIENT_DEBUG=1 \ perl -Mojo -E...

Tuesday, October 5, 2010

# 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);

Tuesday, October 5, 2010

(temp storage on lesystem)


Tuesday, October 5, 2010

Big Body Just Works

$res->json Automatic JSON deserialization

Tuesday, October 5, 2010

Learn More Mojo mojolicious.org github.com/kraih/mojo #mojo on irc.perl.org groups.google.com/group/ mojolicious

Tuesday, October 5, 2010

You might also like