LWP

Chapter 7 - Great CPAN Modules
by?Sam Tregar?
Apress ? 2002
has companion web siteCompanion Web Site

The LWP module collection, written by Martijn Koster and Gisle Aas,[18] provides an interface to the network protocol of the World Wide Web—HTTP.[19] The project was originally based on Roy Fielding's[20] libwww-perl library for Perl 4. After the release of Perl 5, both Martijn and Gisle built their own Perl 5 version of libwwwperl. They decided to combine forces, and the result is the LWP module of today.

LWP modules have done for HTTP what Net::FTP did for FTP. It provides a simple and extensible implementation for writing HTTP clients. Given the explosive growth of the internet, LWP has come to hold a central place in the toolbox of many Perl hackers. If the data you want is on the Web, then you can use LWP to access it.

Another reason that LWP has been successful is that it goes to extreme lengths to make easy things easy while still making hard things possible. The LWP::Simple module that comes with LWP embodies this philosophy. For example, to fetch a copy of the cpan.org home page, this is all the code that's needed:

 use LWP::Simple qw(get); $contents = get('http://cpan.org'); 

It just doesn't get much simpler than that! But LWP doesn't end with LWP::Simple; for more complicated uses, it implements a fully object-oriented interface with classes for every component of the request and response (LWP::UserAgent, HTTP::Request, HTTP::Response, and so on). By providing two interfaces, one simple enough to learn in a day and the other powerful enough to address nearly any need, LWP can be used by both novices and experts.

LWP's object-oriented interface has provided a fruitful ground for extension modules. One popular example is LWP::Parallel by Marc Langheinrich, which extends LWP to allow users to make multiple requests simultaneously. Existing code that uses LWP can be modified to use LWP::Parallel very easily as most of the interfaces remain the same.

The LWP project has a homepage at http://www.linpro.no/lwp/. There you'll find links to the SourceForge-hosted CVS repository and bug tracker, development mailing list, and a list of applications built with LWP. You'll also find links to the LWPng project, which Gisle Aas started to revise the implementation of LWP to better support HTTP/1.1.

[18]With lots of help—see the Acknowledgments section of the LWP documentation for a virtual who's who of Perl development.

[19]LWP also supports HTTPS, FTP (using Net::FTP), Gopher, and NNTP, but HTTP is by far the most commonly used.

[20]See Roy Fielding's site at http://www.ics.uci.edu/~fielding/.



Writing Perl Modules for CPAN
Writing Perl Modules for CPAN
ISBN: 159059018X
EAN: 2147483647
Year: 2002
Pages: 110
Authors: Sam Tregar

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net