blib/lib/WWW/Expand.pm

filter: Statementstmt 100% 27 / 27 Branchbran 50.0% 3 / 6 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 81.2% 39 / 48 CC 5 SCAR 12.2
CC
5
Cov
84%
expand
5.8
BEGIN
1.0
BEGIN
1.0
CRAP 3.4
↑ Summary
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"
l!l
10
MC/DC0%0/1
our $VERSION ||= "DEV"
our $VERSION
Truth table50%1/2
A
A= our $VERSION
Aresult
11
00
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
BranchTrueFalseTotal
if %options 0 11 11
22  
23 11 ▶ unless (ref $agent && $agent->isa('LWP::UserAgent')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $agent and $agent->isa("LWP::UserAgent")) 11 0 11
Condition33%1/3
ref $agent and $agent->isa("LWP::UserAgent")
!ll&&!rl&&r
1100
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")
ABresult
0X0
100
111
24 11 ▶ my $text_agent = defined $agent ? $agent : $DEFAULT_USERAGENT;
Branch: 1 branch
BranchTrueFalseTotal
defined $agent ? : 0 11 11
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.
↑ Summary