| 1 | package WWW::Expand; | ||||||||||||||||||||||||||||
| 2 | 1 | $WWW::Expand::VERSION = '0.1.5'; | |||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strictures 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Exporter qw/import/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # When version isn't specified, assume DEV. | ||||||||||||||||||||||||||||
| 10 | 1 | ▶ | our $VERSION ||= 'DEV'; | ||||||||||||||||||||||||||
|
Condition50%1/2
our $VERSION ||= "DEV"
MC/DC0%0/1
our $VERSION ||= "DEV"
our $VERSION
Truth table50%1/2
A
A= our $VERSION
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | our @EXPORT = our @EXPORT_OK = qw/expand/; | |||||||||||||||||||||||||||
| 13 | 1 | our $DEFAULT_USERAGENT = "URL::Expand/$VERSION (https://metacpan.org/module/URL::Expand)"; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 11 | ▶ | sub expand { | ||||||||||||||||||||||||||
|
Subroutine
expand: called CC=5 SCAR=17.5
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 11 | my ($url, %options) = @_; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Get hash value and remove it | ||||||||||||||||||||||||||||
| 19 | 11 | my $agent = delete $options{agent}; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 11 | ▶ | Carp::croak "Unknown options: ", join " ", keys %options if %options; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 11 | ▶ | unless (ref $agent && $agent->isa('LWP::UserAgent')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $agent and $agent->isa("LWP::UserAgent")
MC/DC0%0/2
ref $agent and $agent->isa("LWP::UserAgent")
ref $agent
$agent->isa("LWP::UserAgent")
Truth table33%1/3
A and B
A= ref $agentB= $agent->isa("LWP::UserAgent")
| |||||||||||||||||||||||||||||
| 24 | 11 | ▶ | my $text_agent = defined $agent ? $agent : $DEFAULT_USERAGENT; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 11 | $agent = LWP::UserAgent->new(agent => $text_agent); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 11 | $agent->request(HTTP::Request->new(HEAD => $url))->request->uri; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 1 | "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<Exporter>. 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<LWP::UserAgent> 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<WWW::Lengthen>. | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | L<WWW::Lengthen>, L<WWW::Shorten> | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | Konrad Borowski <glitchmr@myopera.com> | ||||||||||||||||||||||||||||
| 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. | ||||||||||||||||||||||||||||