Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Giving LWP its well deserved golden watch

Giving LWP its well deserved golden watch

Examine the history of LWP, consider 4 alternatives and discuss some features of the various alternatives.

Jade Allen

July 24, 2013
Tweet

More Decks by Jade Allen

Other Decks in Programming

Transcript

  1. Giving LWP::UserAgent ! Its Well Deserved ! Golden Watch! !

    ! Mark Allen! [email protected]! @bytemeorg! http://byte-me.org! https://github.com/mrallen1! https://speakerdeck.com/mrallen1!
  2. Talk Goals! •  HTTP client history! •  Compare alternatives! • 

    Choose a client with a good fit for your problem space!
  3. HTTP client history! Perl  5  released  (Oct  1994)   LWP

     (for  Perl  5)  0.01  (Jul  '95)   CPAN  introduced  (Oct  '95)   LWP::UserAgent  sugar  (May  2001)   Handlers   (Sep  2008)  
  4. HTTP client history! We owe LWP a debt because Gisle

    and others pioneered scripted user agents...!
  5. Pop quiz:! ! What does Rutherford B. Hayes have to

    do with HTTP client libraries?!
  6. Requests per second! 0   2000   4000   6000

      8000   10000   12000   14000   16000   18000   Simple  GET   100k  GET   POST   hQps://github.com/mrallen1/perl-­‐UA-­‐Bench  
  7. Mojo::UserAgent! •  Built in DOM, XML, JSON parsing! •  Pure

    perl - 5.8 and later! •  Mind blowing one-liners!
  8. Mojo::UserAgent! •  SSL, cookies and! •  Thin object layer (Mojo::Base)!

    •  Maybe don't want the rest of the Mojolicious stack!
  9. Mojo::UserAgent! perl -C -S -MTime::Piece -Mojo -E '$i=1; mkdir $dir=$ENV{HOME}!

    ."/tunes.io/".localtime->ymd; ! say $_->text and g($_->attrs("href"))! ->max_message_size(25600000)! ->content->asset->move_to! ("$dir/${\$i++} ${\$_->text}.mp3") for g("tunes.io")->dom("ul a")->each'!
  10. Mojo::UserAgent! perl -C -S -MTime::Piece -Mojo -E '$i=1; mkdir $dir=$ENV{HOME}!

    ."/tunes.io/".localtime->ymd; ! say $_->text and g($_->attrs("href"))! ->max_message_size(25600000)! ->content->asset->move_to! ("$dir/${\$i++} ${\$_->text}.mp3") for g("tunes.io")->dom("ul a")->each'!
  11. Mojo::UserAgent! perl -C -S -MTime::Piece -Mojo -E '$i=1; mkdir $dir=$ENV{HOME}!

    ."/tunes.io/".localtime->ymd; ! say $_->text and g($_->attrs("href"))! ->max_message_size(25600000)! ->content->asset->move_to! ("$dir/${\$i++} ${\$_->text}.mp3") for g("tunes.io")->dom("ul a")->each'!
  12. Mojo::UserAgent! perl -C -S -MTime::Piece -Mojo -E '$i=1; mkdir $dir=$ENV{HOME}!

    ."/tunes.io/".localtime->ymd; ! say $_->text and g($_->attrs("href"))! ->max_message_size(25600000)! ->content->asset->move_to! ("$dir/${\$i++} ${\$_->text}.mp3") for g("tunes.io")->dom("ul a")->each'!
  13. Mojo::UserAgent! perl -C -S -MTime::Piece -Mojo -E '$i=1; mkdir $dir=$ENV{HOME}!

    ."/tunes.io/".localtime->ymd; ! say $_->text and g($_->attrs("href"))! ->max_message_size(25600000)! ->content->asset->move_to! ("$dir/${\$i++} ${\$_->text}.mp3") for g("tunes.io")->dom("ul a")->each'!
  14. Mojo::UserAgent! perl -C -S -MTime::Piece -Mojo -E '$i=1; mkdir $dir=$ENV{HOME}!

    ."/tunes.io/".localtime->ymd; ! say $_->text and g($_->attrs("href"))! ->max_message_size(25600000)! ->content->asset->move_to! ("$dir/${\$i++} ${\$_->text}.mp3") for g("tunes.io")->dom("ul a")->each'!
  15. HTTP::Tiny! •  Comes with core perl (5.14)! •  Fulfills "::Tiny"

    promise! •  Easy SSL configuration! •  No request / response objects (see HTTP::Thin)! •  Pure perl!
  16. HTTP::Tiny! •  No request / response objects (see HTTP::Thin)! • 

    Pure perl! •  I use this one 90% of the time!
  17. Furl! •  Japanese Perl community! •  Request / response objects!

    •  HTTP response parser uses XS (if possible)!
  18. LWP::Curl! •  Curl is a great HTTP client library, but

    terrible interface.! •  LWPish interface on top of Net::Curl!
  19. LWP::Curl! •  Super fast! •  2000% faster than LWP! • 

    100% faster than Furl! •  No request/response objects! •  No cookie support! •  LWP::Protocol::Net::Curl!
  20. Summary! •  LWP has been around as long as Perl

    itself.! •  There are a lot of great HTTP client choices, so compare alternatives.! •  Choose a client with a good fit for your problem space!