| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package LWP::Simple; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
133408
|
use strict; |
|
|
2
|
|
|
|
|
18
|
|
|
|
2
|
|
|
|
|
131
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '6.34'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT = qw(get head getprint getstore mirror); |
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw($ua); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# I really hate this. It 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
|
|
|
|
|
|
|
# for trivial tests) |
|
15
|
2
|
|
|
2
|
|
798
|
use HTTP::Status; |
|
|
2
|
|
|
|
|
7573
|
|
|
|
2
|
|
|
|
|
438
|
|
|
16
|
|
|
|
|
|
|
push(@EXPORT, @HTTP::Status::EXPORT); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import |
|
19
|
|
|
|
|
|
|
{ |
|
20
|
2
|
|
|
2
|
|
19
|
my $pkg = shift; |
|
21
|
2
|
|
|
|
|
5
|
my $callpkg = caller; |
|
22
|
2
|
|
|
|
|
4610
|
Exporter::export($pkg, $callpkg, @_); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
2
|
|
|
2
|
|
1062
|
use LWP::UserAgent (); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
39
|
|
|
26
|
2
|
|
|
2
|
|
11
|
use HTTP::Date (); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
816
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $ua = LWP::UserAgent->new; # we create a global UserAgent object |
|
29
|
|
|
|
|
|
|
$ua->agent("LWP::Simple/$VERSION "); |
|
30
|
|
|
|
|
|
|
$ua->env_proxy; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub get ($) |
|
33
|
|
|
|
|
|
|
{ |
|
34
|
1
|
|
|
1
|
1
|
691
|
my $response = $ua->get(shift); |
|
35
|
1
|
50
|
|
|
|
12
|
return $response->decoded_content if $response->is_success; |
|
36
|
0
|
|
|
|
|
0
|
return undef; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub head ($) |
|
41
|
|
|
|
|
|
|
{ |
|
42
|
2
|
|
|
2
|
1
|
2287
|
my($url) = @_; |
|
43
|
2
|
|
|
|
|
7
|
my $request = HTTP::Request->new(HEAD => $url); |
|
44
|
2
|
|
|
|
|
168
|
my $response = $ua->request($request); |
|
45
|
|
|
|
|
|
|
|
|
46
|
2
|
50
|
|
|
|
6
|
if ($response->is_success) { |
|
47
|
2
|
100
|
|
|
|
29
|
return $response unless wantarray; |
|
48
|
1
|
|
|
|
|
5
|
return (scalar $response->header('Content-Type'), |
|
49
|
|
|
|
|
|
|
scalar $response->header('Content-Length'), |
|
50
|
|
|
|
|
|
|
HTTP::Date::str2time($response->header('Last-Modified')), |
|
51
|
|
|
|
|
|
|
HTTP::Date::str2time($response->header('Expires')), |
|
52
|
|
|
|
|
|
|
scalar $response->header('Server'), |
|
53
|
|
|
|
|
|
|
); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
0
|
|
|
|
|
0
|
return; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub getprint ($) |
|
60
|
|
|
|
|
|
|
{ |
|
61
|
1
|
|
|
1
|
1
|
2169
|
my($url) = @_; |
|
62
|
1
|
|
|
|
|
7
|
my $request = HTTP::Request->new(GET => $url); |
|
63
|
1
|
|
|
|
|
4890
|
local($\) = ""; # ensure standard $OUTPUT_RECORD_SEPARATOR |
|
64
|
1
|
|
|
1
|
|
6
|
my $callback = sub { print $_[0] }; |
|
|
1
|
|
|
|
|
14
|
|
|
65
|
1
|
50
|
|
|
|
4
|
if ($^O eq "MacOS") { |
|
66
|
0
|
|
|
0
|
|
0
|
$callback = sub { $_[0] =~ s/\015?\012/\n/g; print $_[0] } |
|
|
0
|
|
|
|
|
0
|
|
|
67
|
0
|
|
|
|
|
0
|
} |
|
68
|
1
|
|
|
|
|
8
|
my $response = $ua->request($request, $callback); |
|
69
|
1
|
50
|
|
|
|
4
|
unless ($response->is_success) { |
|
70
|
0
|
|
|
|
|
0
|
print STDERR $response->status_line, " \n"; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
1
|
|
|
|
|
8
|
$response->code; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub getstore ($$) |
|
77
|
|
|
|
|
|
|
{ |
|
78
|
1
|
|
|
1
|
1
|
1744
|
my($url, $file) = @_; |
|
79
|
1
|
|
|
|
|
6
|
my $request = HTTP::Request->new(GET => $url); |
|
80
|
1
|
|
|
|
|
88
|
my $response = $ua->request($request, $file); |
|
81
|
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
3
|
$response->code; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub mirror ($$) |
|
87
|
|
|
|
|
|
|
{ |
|
88
|
0
|
|
|
0
|
1
|
|
my($url, $file) = @_; |
|
89
|
0
|
|
|
|
|
|
my $response = $ua->mirror($url, $file); |
|
90
|
0
|
|
|
|
|
|
$response->code; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |