| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package URL::Exists; |
|
2
|
|
|
|
|
|
|
$URL::Exists::VERSION = '0.03'; |
|
3
|
1
|
|
|
1
|
|
707
|
use 5.006; |
|
|
1
|
|
|
|
|
3
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
21
|
|
|
5
|
1
|
|
|
1
|
|
13
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
6
|
1
|
|
|
1
|
|
11
|
use base 'Exporter'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
93
|
|
|
7
|
1
|
|
|
1
|
|
4009
|
use HTTP::Tiny 0.014; |
|
|
1
|
|
|
|
|
64581
|
|
|
|
1
|
|
|
|
|
155
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ url_exists /; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $ua; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub url_exists |
|
14
|
|
|
|
|
|
|
{ |
|
15
|
0
|
|
|
0
|
0
|
|
my $url = shift; |
|
16
|
|
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
|
unless (defined $ua) { |
|
18
|
0
|
|
|
|
|
|
$ua = HTTP::Tiny->new(); |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my $response = $ua->head($url); |
|
22
|
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
return !!$response->{success}; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
1; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 NAME |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
URL::Exists - test whether a URL exists, when you don't care about the contents |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use URL::Exists qw/ url_exists /; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
if (url_exists($url)) { |
|
37
|
|
|
|
|
|
|
... |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
This module is useful where you're only interested in whether the |
|
43
|
|
|
|
|
|
|
file referenced by a URL is present, and don't actually care about |
|
44
|
|
|
|
|
|
|
the contents. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
At the moment it just supports HTTP URLs, but I may add other |
|
47
|
|
|
|
|
|
|
schemes, if there's any demand / interest. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 REPOSITORY |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
L |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 AUTHOR |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Neil Bowers Eneilb@cpan.orgE |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Neil Bowers . |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
62
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
63
|
|
|
|
|
|
|
|