From m at mikegrb.pm Mon Jul 16 11:03:20 2012 From: m at mikegrb.pm (Michael Greb) Date: Mon, 16 Jul 2012 14:03:20 -0400 Subject: [AC::PM] Reminder: Meeting Thursday July 19, 7pm Message-ID: Our next meeting will be this Thursday, July 19th at 7pm. The topic is Mojolicious for HTTP client applications. Mojolicious is a Perl web framework but also includes many useful tools for HTTP clients both in scripts and from the command line. The meeting will be at the usual place, the conference room at the Linode offices: 329 E Jimmy Leeds Rd, Galloway NJ, 08205 http://goo.gl/maps/kY1M From m at mikegrb.pm Thu Jul 19 16:47:17 2012 From: m at mikegrb.pm (Michael Greb) Date: Thu, 19 Jul 2012 19:47:17 -0400 Subject: [AC::PM] Mojolicious::UserAgent Slides Message-ID: Hey guys, I didn't forget to send my slides this time! # This is a sample Vroom input file. It should help you get started. # # Edit this file with your content. Then run `vroom --vroom` to start # the show! # # See `perldoc Vroom` for complete details. # ---- config # Basic config options. title: mojolicious the client strikes back indent: 5 #height: 18 #width: 69 auto_size: 1 skip: 0 # The following options are for Gvim usage. # vim: mvim # gvimrc: | # set fuopt=maxhorz,maxvert # set guioptions=egmLtT # set guifont=Bitstream_Vera_Sans_Mono:h18 # set guicursor=a:blinkon0-ver25-Cursor # colorscheme default ---- center mojolicious the client strikes back by @mikegrb ---- == mojolicious * A next generation web framework for the Perl programming language. * The web, in a box * zero dependencies * JSON encoder/decoder * HTTP Client ---- == Mojo::UserAgent * HTTP Client with mojolicious's everything included approach * DOM parser w/ CSS Selectors * JSON decoder ---- == A quick diversion CSS Selectors In CSS, pattern matching rules determine which style rules apply to elements in the document tree. These patterns, called selectors, may range from simple element names to rich contextual patterns. ---- == Groking CSS Selectors * http://net.tutsplus.com/tutorials/html-css-techniques/the-30-css-selectors-you-must-memorize/ * http://j.mp/LyrUhB * http://www.selectorgadget.com/ ---- == Select by ID * '#X' *
---- == Select by Class * '.x' *
---- == Select by Tag * 'x' * urmom ---- == Descendant * x y * ---- perl use 5.010; use Mojo::UserAgent; my $ua = Mojo::UserAgent->new(max_redirects => 5); say $ua->get("metacpan.org/module/Vroom") ->res() ->dom("#index a") ->pluck("text") ->map(sub{ return ucfirst(lc(shift)) } ) ->join("\n"); ---- == JSON * pretty popular for webservice APIs these days * mojo has your back ---- perl use 5.010; use Mojo::UserAgent; binmode STDOUT, ':utf8'; my $ua = Mojo::UserAgent->new(); my $t = $ua->get("search.twitter.com/search.json?q=perl") ->res()->json->{results}; say join "\n\n", map { "\@$_->{from_user} $_->{text}" } @$t[0 .. 4]; ---- == Debugging Mojo::UserAgent Really easy, set MOJO_USERAGENT_DEBUG=1: $ MOJO_USERAGENT_DEBUG=1 ./myscript.pl ---- == CLI? This stuff is sweet, I could use it from CLI all the time! ---- == mojo's got your back ojo.pm Let's you do: $ perl -Mojo -E ... ---- shell perl -Mojo -E 'say g("metacpan.org/search?q=mojo")->dom("big a")->pluck("text")->join("\n")' ---- == it get's better! * if you act now, mojo(1) will be included at no extra charge ---- shell mojo get -r 'metacpan.org/search?q=mojo' 'big a' text ---- shell mojo get www.linode.com 'head > title' text ---- shell mojo get -r metacpan.org/module/Vroom '#index a' text From stan at schwertly.com Sat Jul 21 12:37:27 2012 From: stan at schwertly.com (Stan) Date: Sat, 21 Jul 2012 15:37:27 -0400 Subject: [AC::PM] Mojolicious::UserAgent Slides In-Reply-To: References: Message-ID: <2C5899E2-8265-4E14-8BEC-920879F18EED@schwertly.com> On Jul 19, 2012, at 7:47 PM, Michael Greb wrote: > Hey guys, I didn't forget to send my slides this time! Thanks Mike! I actually just had to use the binmode trick. Also, if you're as slow as I am, you'll want to make sure your version of Mojolicious is up to date. I had 2.95 and the 'pluck' command wasn't working for me. It was added in v3.02, which was released just this month! (2012-07-03). Stan