~ubuntu-branches/ubuntu/edgy/libwww-perl/edgy

« back to all changes in this revision

Viewing changes to lib/LWP.pm

  • Committer: Bazaar Package Importer
  • Author(s): Jay Bonci
  • Date: 2005-02-13 18:45:32 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050213184532-67qvopi4wre3010u
Tags: 5.803-4
* Make GET/POST/HEAD symlinks (Closes: #294597)
* lwp-requests now honors -b when dumping links (Closes: #294595)
  - Thanks to giuseppe bonacci for the patch
* Moved symlinks to a libwww-perl.links file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
2
 
# $Id: LWP.pm,v 1.118 2002/02/09 18:45:42 gisle Exp $
 
2
# $Id: LWP.pm,v 1.146 2004/12/11 15:41:44 gisle Exp $
3
3
 
4
4
package LWP;
5
5
 
6
 
$VERSION = "5.64";
 
6
$VERSION = "5.803";
7
7
sub Version { $VERSION; }
8
8
 
9
 
require 5.004;
 
9
require 5.005;
10
10
require LWP::UserAgent;  # this should load everything you need
11
11
 
12
12
1;
76
76
 
77
77
=item *
78
78
 
 
79
Supports parsing of HTML forms.
 
80
 
 
81
=item *
 
82
 
79
83
Implements HTTP content negotiation algorithm that can
80
84
be used both in protocol modules and in server scripts (like CGI
81
85
scripts).
86
90
 
87
91
=item *
88
92
 
89
 
A simple command line client application called C<lwp-request>.
 
93
Some simple command line clients, for instance C<lwp-request> and C<lwp-download>.
90
94
 
91
95
=back
92
96
 
298
302
  $ua->agent("MyApp/0.1 ");
299
303
 
300
304
  # Create a request
301
 
  my $req = HTTP::Request->new(POST => 'http://www.perl.com/cgi-bin/BugGlimpse');
 
305
  my $req = HTTP::Request->new(POST => 'http://search.cpan.org/search');
302
306
  $req->content_type('application/x-www-form-urlencoded');
303
 
  $req->content('match=www&errors=0');
 
307
  $req->content('query=libwww-perl&mode=dist');
304
308
 
305
309
  # Pass request to the user agent and get a response back
306
310
  my $res = $ua->request($req);
308
312
  # Check the outcome of the response
309
313
  if ($res->is_success) {
310
314
      print $res->content;
311
 
  } else {
312
 
      print "Bad luck this time\n";
 
315
  }
 
316
  else {
 
317
      print $res->status_line, "\n";
313
318
  }
314
319
 
315
320
The $ua is created once when the application starts up.  New request
346
351
The library automatically adds a "Host" and a "Content-Length" header
347
352
to the HTTP request before it is sent over the network.
348
353
 
349
 
For GET request you might want to add a "If-Modified-Since" or
 
354
For a GET request you might want to add a "If-Modified-Since" or
350
355
"If-None-Match" header to make the request conditional.
351
356
 
352
 
For POST request you should add the "Content-Type" header.  When you
 
357
For a POST request you should add the "Content-Type" header.  When you
353
358
try to emulate HTML E<lt>FORM> handling you should usually let the value
354
359
of the "Content-Type" header be "application/x-www-form-urlencoded".
355
360
See L<lwpcook> for examples of this.
491
496
  $req->header(Subject => "subscribe");
492
497
  $req->content("Please subscribe me to the libwww-perl mailing list!\n");
493
498
 
 
499
=head2 CPAN Requests
 
500
 
 
501
URLs with scheme C<cpan:> are redirected to the a suitable CPAN
 
502
mirror.  If you have your own local mirror of CPAN you might tell LWP
 
503
to use it for C<cpan:> URLs by an assignment like this:
 
504
 
 
505
  $LWP::Protocol::cpan::CPAN = "file:/local/CPAN/";
 
506
 
 
507
Suitable CPAN mirrors are also picked up from the configuration for
 
508
the CPAN.pm, so if you have used that module a suitable mirror should
 
509
be picked automatically.  If neither of these apply, then a redirect
 
510
to the generic CPAN http location is issued.
 
511
 
 
512
Example request to download the newest perl:
 
513
 
 
514
  $req = HTTP::Request->new(GET => "cpan:src/latest.tar.gz");
 
515
 
494
516
 
495
517
=head1 OVERVIEW OF CLASSES AND PACKAGES
496
518
 
574
596
=item PERL_HTTP_URI_CLASS
575
597
 
576
598
Used to decide what URI objects to instantiate.  The default is C<URI>.
577
 
You might want to set it to C<URI::URL> for compatiblity with old times.
 
599
You might want to set it to C<URI::URL> for compatibility with old times.
578
600
 
579
601
=back
580
602
 
581
 
=head1 BUGS
582
 
 
583
 
The library can not handle multiple simultaneous requests yet.  Also,
584
 
check out what's left in the TODO file.
585
 
 
586
 
=head1 ACKNOWLEDGEMENTS
587
 
 
588
 
This package owes a lot in motivation, design, and code, to the
589
 
libwww-perl library for Perl 4, maintained by Roy Fielding
590
 
E<lt>fielding@ics.uci.edu>.
591
 
 
592
 
That package used work from Alberto Accomazzi, James Casey, Brooks
593
 
Cutter, Martijn Koster, Oscar Nierstrasz, Mel Melchner, Gertjan van
594
 
Oosten, Jared Rhine, Jack Shirazi, Gene Spafford, Marc VanHeyningen,
595
 
Steven E. Brenner, Marion Hakanson, Waldemar Kebsch, Tony Sanders, and
596
 
Larry Wall; see the libwww-perl-0.40 library for details.
597
 
 
598
 
The primary architect for this Perl 5 library is Martijn Koster and
599
 
Gisle Aas, with lots of help from Graham Barr, Tim Bunce, Andreas
600
 
Koenig, Jared Rhine, and Jack Shirazi.
601
 
 
 
603
=head1 AUTHORS
 
604
 
 
605
LWP was made possible by contributions from Adam Newby, Albert
 
606
Dvornik, Alexandre Duret-Lutz, Andreas Gustafsson, Andreas K�nig,
 
607
Andrew Pimlott, Andy Lester, Ben Coleman, Benjamin Low, Ben Low, Ben
 
608
Tilly, Blair Zajac, Bob Dalgleish, BooK, Brad Hughes, Brian
 
609
J. Murrell, Brian McCauley, Charles C. Fu, Charles Lane, Chris Nandor,
 
610
Christian Gilmore, Chris W. Unger, Craig Macdonald, Dale Couch, Dan
 
611
Kubb, Dave Dunkin, Dave W. Smith, David Coppit, David Dick, David
 
612
D. Kilzer, Doug MacEachern, Edward Avis, erik, Gary Shea, Gisle Aas,
 
613
Graham Barr, Gurusamy Sarathy, Hans de Graaff, Harald Joerg, Harry
 
614
Bochner, Hugo, Ilya Zakharevich, INOUE Yoshinari, Ivan Panchenko, Jack
 
615
Shirazi, James Tillman, Jan Dubois, Jared Rhine, Jim Stern, John Klar,
 
616
Johnny Lee, Josh Kronengold, Joshua Chamas, Joshua Hoblitt, Kartik
 
617
Subbarao, Keiichiro Nagano, Ken Williams, KONISHI Katsuhiro, Lee T
 
618
Lindley, Liam Quinn, Marc Hedlund, Marc Langheinrich, Mark
 
619
D. Anderson, Marko Asplund, Mark Stosberg, Markus B Kr�ger, Markus
 
620
Laker, Martijn Koster, Martin Thurn, Matthew Eldridge, Matt Sergeant,
 
621
Michael A. Chase, Michael Quaranta, Michael Thompson, Mike Schilli,
 
622
Moshe Kaminsky, Nathan Torkington, Nicolai Langfeldt, Norton Allen,
 
623
Olly Betts, Paul J. Schinder, peterm, Philip GuentherDaniel Buenzli,
 
624
Pon Hwa Lin, Radoslaw Zielinski, Radu Greab, Randal L. Schwartz,
 
625
Richard Chen, Robin Barker, Roy Fielding, Sander van Zoest, Sean
 
626
M. Burke, shildreth, Slaven Rezic, Steve A Fink, Steve Hay, Steven
 
627
Butler, Steve_Kilbane, Takanori Ugai, Thomas Lotterer, Tim Bunce, Tom
 
628
Hughes, Tony Finch, Ville Skytt�, Ward Vandewege, William York, Yale
 
629
Huang, and Yitzchak Scott-Thoennes.
 
630
 
 
631
LWP owes a lot in motivation, design, and code, to the libwww-perl
 
632
library for Perl4 by Roy Fielding, which included work from Alberto
 
633
Accomazzi, James Casey, Brooks Cutter, Martijn Koster, Oscar
 
634
Nierstrasz, Mel Melchner, Gertjan van Oosten, Jared Rhine, Jack
 
635
Shirazi, Gene Spafford, Marc VanHeyningen, Steven E. Brenner, Marion
 
636
Hakanson, Waldemar Kebsch, Tony Sanders, and Larry Wall; see the
 
637
libwww-perl-0.40 library for details.
602
638
 
603
639
=head1 COPYRIGHT
604
640
 
605
 
  Copyright 1995-2001, Gisle Aas
 
641
  Copyright 1995-2004, Gisle Aas
606
642
  Copyright 1995, Martijn Koster
607
643
 
608
644
This library is free software; you can redistribute it and/or