line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package LWP::Simple; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
107685
|
use strict; |
|
2
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
121
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '6.29'; |
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
|
|
485
|
use HTTP::Status; |
|
2
|
|
|
|
|
6230
|
|
|
2
|
|
|
|
|
406
|
|
16
|
|
|
|
|
|
|
push(@EXPORT, @HTTP::Status::EXPORT); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import |
19
|
|
|
|
|
|
|
{ |
20
|
2
|
|
|
2
|
|
18
|
my $pkg = shift; |
21
|
2
|
|
|
|
|
5
|
my $callpkg = caller; |
22
|
2
|
|
|
|
|
3302
|
Exporter::export($pkg, $callpkg, @_); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
2
|
|
797
|
use LWP::UserAgent (); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
53
|
|
26
|
2
|
|
|
2
|
|
14
|
use HTTP::Date (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
975
|
|
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
|
688
|
my $response = $ua->get(shift); |
35
|
1
|
50
|
|
|
|
4
|
return $response->decoded_content if $response->is_success; |
36
|
0
|
|
|
|
|
0
|
return undef; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub head ($) |
41
|
|
|
|
|
|
|
{ |
42
|
2
|
|
|
2
|
1
|
2126
|
my($url) = @_; |
43
|
2
|
|
|
|
|
7
|
my $request = HTTP::Request->new(HEAD => $url); |
44
|
2
|
|
|
|
|
197
|
my $response = $ua->request($request); |
45
|
|
|
|
|
|
|
|
46
|
2
|
50
|
|
|
|
6
|
if ($response->is_success) { |
47
|
2
|
100
|
|
|
|
25
|
return $response unless wantarray; |
48
|
1
|
|
|
|
|
4
|
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
|
1689
|
my($url) = @_; |
62
|
1
|
|
|
|
|
8
|
my $request = HTTP::Request->new(GET => $url); |
63
|
1
|
|
|
|
|
3985
|
local($\) = ""; # ensure standard $OUTPUT_RECORD_SEPARATOR |
64
|
1
|
|
|
1
|
|
5
|
my $callback = sub { print $_[0] }; |
|
1
|
|
|
|
|
7
|
|
65
|
1
|
50
|
|
|
|
5
|
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
|
|
|
|
|
5
|
my $response = $ua->request($request, $callback); |
69
|
1
|
50
|
|
|
|
2
|
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
|
1629
|
my($url, $file) = @_; |
79
|
1
|
|
|
|
|
7
|
my $request = HTTP::Request->new(GET => $url); |
80
|
1
|
|
|
|
|
90
|
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__ |