File Coverage

blib/lib/WWW/Expand.pm
Criterion Covered Total %
statement 22 22 100.0
branch 3 6 50.0
condition 1 3 33.3
subroutine 6 6 100.0
pod 1 1 100.0
total 33 38 86.8


line stmt bran cond sub pod time code
1             package WWW::Expand;
2             $WWW::Expand::VERSION = '0.1.5';
3 1     1   39668 use strictures 1;
  1         7  
  1         30  
4 1     1   68 use Exporter qw/import/;
  1         2  
  1         34  
5 1     1   3293 use LWP::UserAgent;
  1         739556  
  1         40  
6 1     1   11 use HTTP::Request;
  1         2  
  1         23  
7 1     1   5 use Carp ();
  1         2  
  1         266  
8              
9             # When version isn't specified, assume DEV.
10             our $VERSION ||= 'DEV';
11              
12             our @EXPORT = our @EXPORT_OK = qw/expand/;
13             our $DEFAULT_USERAGENT = "URL::Expand/$VERSION (https://metacpan.org/module/URL::Expand)";
14              
15             sub expand {
16 11     11 1 4593421 my ($url, %options) = @_;
17              
18             # Get hash value and remove it
19 11         37 my $agent = delete $options{agent};
20              
21 11 50       66 Carp::croak "Unknown options: ", join " ", keys %options if %options;
22              
23 11 50 33     69 unless (ref $agent && $agent->isa('LWP::UserAgent')) {
24 11 50       54 my $text_agent = defined $agent ? $agent : $DEFAULT_USERAGENT;
25 11         110 $agent = LWP::UserAgent->new(agent => $text_agent);
26             }
27            
28 11         8669 $agent->request(HTTP::Request->new(HEAD => $url))->request->uri;
29             }
30             "https://github.com/xfix";
31              
32             =head1 NAME
33              
34             WWW::Expand - Expand any URL shortener link
35              
36             =head1 SYNOPSIS
37              
38             use 5.010;
39             use strictures 1;
40             use WWW::Expand;
41            
42             print expand 'http://git.io/github';
43              
44             =head1 DESCRIPTION
45              
46             `expand()` is a function that expands any URL from URL shortener.
47              
48             =head1 EXPORTS
49              
50             All functions are exported using L. If you don't want this
51             (but why you would use this module then) try importing it using empty
52             list of functions.
53              
54             use WWW::Expand ();
55              
56             =over 4
57              
58             =item expand $url, %options
59              
60             The only function in this module. It expands C<$url> from URL shortener.
61             It supports one option in C<%options>.
62              
63             =over 4
64              
65             =item agent
66              
67             Can be either instance of L or string containing user
68             agent name.
69              
70             =back
71              
72             =back
73              
74             =head1 CAVEATS
75              
76             This module tries to expand every URL, even if it isn't from URL
77             shortener. This could be what you want, but if not, try module such
78             as L.
79              
80             =head1 SEE ALSO
81              
82             L, L
83              
84             =head1 AUTHOR
85            
86             Konrad Borowski
87            
88             =head1 COPYRIGHT AND LICENSE
89            
90             This software is copyright (c) 2012 by Konrad Borowski.
91            
92             This is free software; you can redistribute it and/or modify it under
93             the same terms as the Perl 5 programming language system itself.