| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #line 1 | 
| 2 |  |  |  |  |  |  | package LWP::Simple; | 
| 3 | 4 |  |  | 4 |  | 1576 |  | 
|  | 4 |  |  |  |  | 4 |  | 
|  | 4 |  |  |  |  | 132 |  | 
| 4 | 4 |  |  | 4 |  | 12 | use strict; | 
|  | 4 |  |  |  |  | 4 |  | 
|  | 4 |  |  |  |  | 362 |  | 
| 5 |  |  |  |  |  |  | use vars qw($ua %loop_check $FULL_LWP @EXPORT @EXPORT_OK $VERSION); | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | require Exporter; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | @EXPORT = qw(get head getprint getstore mirror); | 
| 10 |  |  |  |  |  |  | @EXPORT_OK = qw($ua); | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | # I really hate this.  I was a bad idea to do it in the first place. | 
| 13 |  |  |  |  |  |  | # Wonder how to get rid of it???  (It even makes LWP::Simple 7% slower | 
| 14 | 4 |  |  | 4 |  | 5632 | # for trivial tests) | 
|  | 4 |  |  |  |  | 11572 |  | 
|  | 4 |  |  |  |  | 1188 |  | 
| 15 |  |  |  |  |  |  | use HTTP::Status; | 
| 16 |  |  |  |  |  |  | push(@EXPORT, @HTTP::Status::EXPORT); | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | $VERSION = "5.827"; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | sub import | 
| 21 | 4 |  |  | 4 |  | 80 | { | 
| 22 | 4 |  |  |  |  | 8 | my $pkg = shift; | 
| 23 | 4 |  |  |  |  | 1356 | my $callpkg = caller; | 
| 24 |  |  |  |  |  |  | Exporter::export($pkg, $callpkg, @_); | 
| 25 |  |  |  |  |  |  | } | 
| 26 | 4 |  |  | 4 |  | 6768 |  | 
|  | 4 |  |  |  |  | 154882 |  | 
|  | 4 |  |  |  |  | 214 |  | 
| 27 | 4 |  |  | 4 |  | 34 | use LWP::UserAgent (); | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 40 |  | 
| 28 | 4 |  |  | 4 |  | 14 | use HTTP::Status (); | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 1742 |  | 
| 29 |  |  |  |  |  |  | use HTTP::Date (); | 
| 30 |  |  |  |  |  |  | $ua = new LWP::UserAgent;  # we create a global UserAgent object | 
| 31 |  |  |  |  |  |  | $ua->agent("LWP::Simple/$VERSION "); | 
| 32 |  |  |  |  |  |  | $ua->env_proxy; | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | sub get ($) | 
| 36 | 4 |  |  | 4 | 1 | 7007478 | { | 
| 37 | 4 | 50 |  |  |  | 698705 | my $response = $ua->get(shift); | 
| 38 | 0 |  |  |  |  |  | return $response->decoded_content if $response->is_success; | 
| 39 |  |  |  |  |  |  | return undef; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | sub head ($) | 
| 44 | 0 |  |  | 0 | 1 |  | { | 
| 45 | 0 |  |  |  |  |  | my($url) = @_; | 
| 46 | 0 |  |  |  |  |  | my $request = HTTP::Request->new(HEAD => $url); | 
| 47 |  |  |  |  |  |  | my $response = $ua->request($request); | 
| 48 | 0 | 0 |  |  |  |  |  | 
| 49 | 0 | 0 |  |  |  |  | if ($response->is_success) { | 
| 50 | 0 |  |  |  |  |  | return $response unless wantarray; | 
| 51 |  |  |  |  |  |  | return (scalar $response->header('Content-Type'), | 
| 52 |  |  |  |  |  |  | scalar $response->header('Content-Length'), | 
| 53 |  |  |  |  |  |  | HTTP::Date::str2time($response->header('Last-Modified')), | 
| 54 |  |  |  |  |  |  | HTTP::Date::str2time($response->header('Expires')), | 
| 55 |  |  |  |  |  |  | scalar $response->header('Server'), | 
| 56 |  |  |  |  |  |  | ); | 
| 57 | 0 |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  | return; | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | sub getprint ($) | 
| 63 | 0 |  |  | 0 | 1 |  | { | 
| 64 | 0 |  |  |  |  |  | my($url) = @_; | 
| 65 | 0 |  |  |  |  |  | my $request = HTTP::Request->new(GET => $url); | 
| 66 | 0 |  |  | 0 |  |  | local($\) = ""; # ensure standard $OUTPUT_RECORD_SEPARATOR | 
|  | 0 |  |  |  |  |  |  | 
| 67 | 0 | 0 |  |  |  |  | my $callback = sub { print $_[0] }; | 
| 68 | 0 |  |  | 0 |  |  | if ($^O eq "MacOS") { | 
|  | 0 |  |  |  |  |  |  | 
| 69 | 0 |  |  |  |  |  | $callback = sub { $_[0] =~ s/\015?\012/\n/g; print $_[0] } | 
| 70 | 0 |  |  |  |  |  | } | 
| 71 | 0 | 0 |  |  |  |  | my $response = $ua->request($request, $callback); | 
| 72 | 0 |  |  |  |  |  | unless ($response->is_success) { | 
| 73 |  |  |  |  |  |  | print STDERR $response->status_line, " \n"; | 
| 74 | 0 |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  | $response->code; | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | sub getstore ($$) | 
| 80 | 0 |  |  | 0 | 1 |  | { | 
| 81 | 0 |  |  |  |  |  | my($url, $file) = @_; | 
| 82 | 0 |  |  |  |  |  | my $request = HTTP::Request->new(GET => $url); | 
| 83 |  |  |  |  |  |  | my $response = $ua->request($request, $file); | 
| 84 | 0 |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | $response->code; | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | sub mirror ($$) | 
| 90 | 0 |  |  | 0 | 1 |  | { | 
| 91 | 0 |  |  |  |  |  | my($url, $file) = @_; | 
| 92 | 0 |  |  |  |  |  | my $response = $ua->mirror($url, $file); | 
| 93 |  |  |  |  |  |  | $response->code; | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | 1; | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | __END__ |