line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::HTTPStatus; |
2
|
3
|
|
|
3
|
|
140089
|
use strict; |
|
3
|
|
|
|
|
24
|
|
|
3
|
|
|
|
|
94
|
|
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
80
|
|
5
|
3
|
|
|
3
|
|
14
|
no warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
114
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=encoding utf8 |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Test::HTTPStatus - check an HTTP status |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Test::HTTPStatus tests => 2; |
16
|
|
|
|
|
|
|
use Apache::Constants qw(:http); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
http_ok( 'https://www.perl.org', HTTP_OK ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
http_ok( $url, $status ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Check the HTTP status for a resource. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
3
|
|
|
3
|
|
37
|
use v5.10.1; # Mojolicious is v5.10.1 and later |
|
3
|
|
|
|
|
12
|
|
29
|
|
|
|
|
|
|
our $VERSION = '2.05'; |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
3
|
|
1408
|
use parent 'Test::Builder::Module'; |
|
3
|
|
|
|
|
966
|
|
|
3
|
|
|
|
|
17
|
|
32
|
|
|
|
|
|
|
|
33
|
3
|
|
|
3
|
|
201
|
use Carp qw(carp); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
144
|
|
34
|
3
|
|
|
3
|
|
1282
|
use HTTP::SimpleLinkChecker; |
|
3
|
|
|
|
|
1410693
|
|
|
3
|
|
|
|
|
176
|
|
35
|
3
|
|
|
3
|
|
30
|
use Test::Builder::Module; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
36
|
|
36
|
3
|
|
|
3
|
|
115
|
use Mojo::URL; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
14
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $Test = __PACKAGE__->builder; |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
3
|
|
143
|
use constant NO_URL => -1; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
170
|
|
41
|
3
|
|
|
3
|
|
19
|
use constant INVALID_URL => -2; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
135
|
|
42
|
3
|
|
|
3
|
|
17
|
use constant HTTP_OK => 200; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
150
|
|
43
|
3
|
|
|
3
|
|
20
|
use constant HTTP_NOT_FOUND => 404; |
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
265
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub import { |
46
|
3
|
|
|
3
|
|
22
|
my $self = shift; |
47
|
3
|
|
|
|
|
9
|
my $caller = caller; |
48
|
3
|
|
|
3
|
|
23
|
no strict 'refs'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
1290
|
|
49
|
3
|
|
|
|
|
8
|
*{$caller.'::http_ok'} = \&http_ok; |
|
3
|
|
|
|
|
19
|
|
50
|
3
|
|
|
|
|
7
|
*{$caller.'::NO_URL'} = \&NO_URL; |
|
3
|
|
|
|
|
13
|
|
51
|
3
|
|
|
|
|
8
|
*{$caller.'::INVALID_URL'} = \&INVALID_URL; |
|
3
|
|
|
|
|
10
|
|
52
|
3
|
|
|
|
|
8
|
*{$caller.'::HTTP_OK'} = \&HTTP_OK; |
|
3
|
|
|
|
|
10
|
|
53
|
3
|
|
|
|
|
6
|
*{$caller.'::HTTP_NOT_FOUND'} = \&HTTP_NOT_FOUND; |
|
3
|
|
|
|
|
10
|
|
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
22
|
$Test->exported_to($caller); |
56
|
3
|
|
|
|
|
42
|
$Test->plan(@_); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 FUNCTIONS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=over 4 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item http_ok( URL [, HTTP_STATUS] ) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Print the ok message if the URL's HTTP status matches the specified |
66
|
|
|
|
|
|
|
HTTP_STATUS. If you don't specify a status, it assumes you mean |
67
|
|
|
|
|
|
|
HTTP_OK (from Apache::Constants). |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub http_ok { |
72
|
1
|
|
|
1
|
1
|
97
|
my $url = shift; |
73
|
1
|
|
50
|
|
|
4
|
my $expected = shift || HTTP_OK; |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
3
|
my $hash = _get_status( $url ); |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
4
|
my $status = $hash->{status}; |
78
|
|
|
|
|
|
|
|
79
|
1
|
50
|
33
|
|
|
12
|
if( defined $expected and $expected eq $status ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
80
|
1
|
|
|
|
|
14
|
$Test->ok( 1, "Expected [$expected], got [$status] for [$url]" ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
elsif( $status == NO_URL ) { |
83
|
0
|
|
|
|
|
0
|
$Test->ok( 0, "[$url] does not appear to be anything" ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
elsif( $status == INVALID_URL ) { |
86
|
0
|
|
|
|
|
0
|
$Test->ok( 0, "[$url] does not appear to be a valid URL" ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
0
|
|
|
|
|
0
|
$Test->ok( 0, "Mysterious failure for [$url] with status [$status]" ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _get_status { |
94
|
5
|
|
|
5
|
|
345871
|
my $string = shift; |
95
|
|
|
|
|
|
|
|
96
|
5
|
100
|
|
|
|
37
|
return { status => NO_URL } unless defined $string; |
97
|
|
|
|
|
|
|
|
98
|
4
|
|
|
|
|
40
|
my $url = Mojo::URL->new( $string ); |
99
|
4
|
100
|
|
|
|
834
|
return { status => undef } unless $url->host; |
100
|
|
|
|
|
|
|
|
101
|
3
|
|
|
|
|
34
|
my $status = HTTP::SimpleLinkChecker::check_link( $url ); |
102
|
|
|
|
|
|
|
|
103
|
3
|
|
|
|
|
965981
|
return { url => $url, status => $status }; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=back |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 SEE ALSO |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L, L |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHORS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
brian d foy, C<< >> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Maintained by Nigel Horne, C<< >> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SUPPORT |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
perldoc Test::HTTPStatus |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
You can also look for information at: |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=over 4 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * MetaCPAN |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
L |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * CPANTS |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * CPAN Testers' Matrix |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * CPAN Ratings |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * CPAN Testers Dependencies |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=back |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This program is released under the following licence: GPL2 |
157
|
|
|
|
|
|
|
Copyright © 2002-2019, brian d foy . All rights reserved. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
160
|
|
|
|
|
|
|
it under the terms of the Artistic License 2.0. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; |