Professional Documents
Culture Documents
A new beginning
perl -Mojo -e' g("vg.no/") ->dom(".articlecontent h3 a") ->each(sub { b(shift->text) ->decode->say })'
Tuesday, October 5, 2010
Got Booted
Tuesday, October 5, 2010
Got Booted
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;
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"; }
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;
Oneliners
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 })'
Mojo::DOM
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);