File Coverage

blib/lib/URL/Exists.pm
Criterion Covered Total %
statement 15 20 75.0
branch 0 2 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 20 29 68.9


line stmt bran cond sub pod time code
1             package URL::Exists;
2             $URL::Exists::VERSION = '0.02';
3 1     1   673 use 5.006;
  1         3  
  1         34  
4 1     1   4 use strict;
  1         1  
  1         33  
5 1     1   12 use warnings;
  1         1  
  1         28  
6 1     1   4 use base 'Exporter';
  1         1  
  1         183  
7 1     1   648 use HTTP::Tiny 0.014;
  1         409848  
  1         113  
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 - function that returns true if URL is present
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