File Coverage

blib/lib/URL/Exists.pm
Criterion Covered Total %
statement 15 19 78.9
branch n/a
condition 0 3 0.0
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.01';
3 1     1   512 use 5.006;
  1         2  
  1         32  
4 1     1   4 use strict;
  1         1  
  1         28  
5 1     1   10 use warnings;
  1         1  
  1         27  
6 1     1   3 use base 'Exporter';
  1         1  
  1         89  
7 1     1   1639 use HTTP::Tiny 0.014;
  1         43895  
  1         128  
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       $ua //= HTTP::Tiny->new();
18 0           my $response = $ua->head($url);
19              
20 0           return !!$response->{success};
21             }
22              
23             1;
24              
25             =head1 NAME
26              
27             URL::Exists - function that returns true if URL is present
28              
29             =head1 SYNOPSIS
30              
31             use URL::Exists qw/ url_exists /;
32              
33             if (url_exists($url)) {
34             ...
35             }
36              
37             =head1 DESCRIPTION
38              
39             This module is useful where you're only interested in whether the
40             file referenced by a URL is present, and don't actually care about
41             the contents.
42              
43             At the moment it just supports HTTP URLs, but I may add other
44             schemes, if there's any demand / interest.
45              
46             =head1 REPOSITORY
47              
48             L
49              
50             =head1 AUTHOR
51              
52             Neil Bowers Eneilb@cpan.orgE
53              
54             =head1 COPYRIGHT AND LICENSE
55              
56             This software is copyright (c) 2014 by Neil Bowers .
57              
58             This is free software; you can redistribute it and/or modify it under
59             the same terms as the Perl 5 programming language system itself.
60