line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HON::Http::UrlChecker::Service; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
96890
|
use 5.006; |
|
4
|
|
|
|
|
11
|
|
4
|
4
|
|
|
4
|
|
18
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
84
|
|
5
|
4
|
|
|
4
|
|
14
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
108
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
1538
|
use URI; |
|
4
|
|
|
|
|
14337
|
|
|
4
|
|
|
|
|
107
|
|
8
|
4
|
|
|
4
|
|
24
|
use Carp; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
279
|
|
9
|
4
|
|
|
4
|
|
2039
|
use Readonly; |
|
4
|
|
|
|
|
10693
|
|
|
4
|
|
|
|
|
189
|
|
10
|
4
|
|
|
4
|
|
2428
|
use LWP::UserAgent; |
|
4
|
|
|
|
|
95819
|
|
|
4
|
|
|
|
|
217
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
HON::Http::UrlChecker::Service - HTTP Status Code Checker |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 VERSION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Version 0.01 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use HON::Http::UrlChecker::Service; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my @listOfStatus = checkUrl('http://www.example.com'); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Check status code, response headers, redirect location and redirect chain |
33
|
|
|
|
|
|
|
of a HTTP connection. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
4
|
|
32
|
use base 'Exporter'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
1654
|
|
38
|
|
|
|
|
|
|
our @EXPORT_OK = qw/p_createUserAgent p_getUrl p_parseResponse checkUrl/; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Readonly::Scalar my $TIMEOUT => 1200; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Readonly::Scalar my $MAXREDIRECT => 10; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Readonly::Array my @HEADERFIELDS => qw( |
45
|
|
|
|
|
|
|
location |
46
|
|
|
|
|
|
|
server |
47
|
|
|
|
|
|
|
content-type |
48
|
|
|
|
|
|
|
title |
49
|
|
|
|
|
|
|
date |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Readonly::Array my @RESPONSEFIELDS => qw( |
53
|
|
|
|
|
|
|
protocol |
54
|
|
|
|
|
|
|
code |
55
|
|
|
|
|
|
|
message |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 checkUrl( $url ) |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Check a url (status code, response headers, redirect location and |
63
|
|
|
|
|
|
|
redirect chain). |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub checkUrl { |
68
|
8
|
|
|
8
|
1
|
7825
|
my $url = shift; |
69
|
|
|
|
|
|
|
|
70
|
8
|
|
|
|
|
29
|
my $uri = URI->new($url); |
71
|
8
|
100
|
100
|
|
|
6678
|
if ( $uri->scheme and $uri->opaque ) { |
72
|
2
|
|
|
|
|
153
|
my $ua = p_createUserAgent(); |
73
|
2
|
|
|
|
|
5
|
my $response = p_getUrl( $ua, $url ); |
74
|
2
|
|
|
|
|
23054
|
my @listStatus = p_parseResponse($response); |
75
|
|
|
|
|
|
|
|
76
|
2
|
|
|
|
|
60
|
return @listStatus; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else { |
79
|
6
|
|
|
|
|
211
|
croak "Wrong url: $url"; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 PRIVATE SUBROUTINES/METHODS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 p_createUserAgent |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Return a LWP::UserAgent. |
88
|
|
|
|
|
|
|
LWP::UserAgent objects can be used to dispatch web requests. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub p_createUserAgent { |
93
|
3
|
|
|
3
|
1
|
2257
|
my $ua = LWP::UserAgent->new; |
94
|
|
|
|
|
|
|
|
95
|
3
|
|
|
|
|
4286
|
$ua->timeout($TIMEOUT); |
96
|
3
|
|
|
|
|
46
|
$ua->agent('HonBot'); |
97
|
3
|
|
|
|
|
136
|
$ua->env_proxy; |
98
|
3
|
|
|
|
|
21710
|
$ua->max_redirect($MAXREDIRECT); |
99
|
|
|
|
|
|
|
|
100
|
3
|
|
|
|
|
33
|
return $ua; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 p_getUrl |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Dispatch a GET request on the given $url |
106
|
|
|
|
|
|
|
The return value is a response object. See HTTP::Response for a description |
107
|
|
|
|
|
|
|
of the interface it provides. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub p_getUrl { |
112
|
4
|
|
|
4
|
1
|
29915
|
my ( $ua, $url ) = @_; |
113
|
|
|
|
|
|
|
|
114
|
4
|
|
|
|
|
15
|
return $ua->get($url); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 p_retrieveInfo |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Retrieve desired fields from an HTTP::Response |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub p_retrieveInfo { |
124
|
5
|
|
|
5
|
1
|
4
|
my $response = shift; |
125
|
|
|
|
|
|
|
|
126
|
5
|
|
|
|
|
7
|
my %locationStatus = (); |
127
|
5
|
|
|
|
|
21
|
foreach my $field (@HEADERFIELDS) { |
128
|
25
|
100
|
|
|
|
569
|
if ( defined $response->header($field) ) { |
129
|
8
|
|
|
|
|
182
|
$locationStatus{$field} = $response->header($field); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
5
|
|
|
|
|
117
|
foreach my $field (@RESPONSEFIELDS) { |
134
|
15
|
100
|
|
|
|
115
|
if ( defined $response->$field ) { |
135
|
9
|
|
|
|
|
77
|
$locationStatus{$field} = $response->$field; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
5
|
|
|
|
|
53
|
return %locationStatus; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 p_parseResponse |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Retrieve a list of Status from HTTP::Response |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub p_parseResponse { |
149
|
4
|
|
|
4
|
1
|
1136
|
my $response = shift; |
150
|
|
|
|
|
|
|
|
151
|
4
|
|
|
|
|
8
|
my @listStatus = (); |
152
|
4
|
|
|
|
|
9
|
my @redirects = $response->redirects; |
153
|
4
|
100
|
|
|
|
55
|
if ( scalar @redirects > 0 ) { |
154
|
1
|
|
|
|
|
3
|
foreach my $redirect (@redirects) { |
155
|
1
|
|
|
|
|
2
|
my %status = p_retrieveInfo($redirect); |
156
|
1
|
|
|
|
|
2
|
push @listStatus, \%status; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
4
|
|
|
|
|
10
|
my %status = p_retrieveInfo($response); |
160
|
4
|
|
|
|
|
21
|
push @listStatus, \%status; |
161
|
|
|
|
|
|
|
|
162
|
4
|
|
|
|
|
12
|
return @listStatus; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 AUTHOR |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
William Belle, C<< >> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
172
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
173
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 SUPPORT |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
perldoc HON::Http::UrlChecker::Service |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
You can also look for information at: |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=over 4 |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
L |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
L |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item * CPAN Ratings |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
L |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item * Search CPAN |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
L |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=back |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Copyright 2016 William Belle. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
This program is distributed under the MIT (X11) License: |
208
|
|
|
|
|
|
|
L |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person |
211
|
|
|
|
|
|
|
obtaining a copy of this software and associated documentation |
212
|
|
|
|
|
|
|
files (the "Software"), to deal in the Software without |
213
|
|
|
|
|
|
|
restriction, including without limitation the rights to use, |
214
|
|
|
|
|
|
|
copy, modify, merge, publish, distribute, sublicense, and/or sell |
215
|
|
|
|
|
|
|
copies of the Software, and to permit persons to whom the |
216
|
|
|
|
|
|
|
Software is furnished to do so, subject to the following |
217
|
|
|
|
|
|
|
conditions: |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be |
220
|
|
|
|
|
|
|
included in all copies or substantial portions of the Software. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
223
|
|
|
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
224
|
|
|
|
|
|
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
225
|
|
|
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
226
|
|
|
|
|
|
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
227
|
|
|
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
228
|
|
|
|
|
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
229
|
|
|
|
|
|
|
OTHER DEALINGS IN THE SOFTWARE. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=cut |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
1; # End of HON::Http::UrlChecker::Service |