blib/lib/WWW/Shorten/Debli.pm

filter: Statementstmt 59.3% 19 / 32 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 49.0% 26 / 53 CC 7 SCAR 25.4
CC
7
Cov
43%
makeashorterlink
20.0
makealongerlink
20.0
BEGIN
1.0
CRAP 12.7
« privinc/My/Builder.pm ↑ Summary blib/lib/App/KGB/Change.pm »
1 =head1 NAME
2  
3 WWW::Shorten::Debli - Perl interface to deb.li
4  
5 =head1 SYNOPSIS
6  
7 use WWW::Shorten 'Debli';
8  
9 $short_url = makeashorterlink($long_url);
10  
11 $long_url = makealongerlink($short_url);
12  
13 =head1 DESCRIPTION
14  
15 A Perl interface to the web site L<https://deb.li>. Deb.li provides a URL
16 shortening service primarily for Debian contributors.
17  
18 =cut
19  
20 package WWW::Shorten::Debli;
21  
22 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 ▶use base qw( WWW::Shorten::generic Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 our @EXPORT = qw(makeashorterlink makealongerlink);
27 1 our $VERSION = '0.1';
28  
29 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use JSON::RPC::Client::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 1 our $RPC_URL = 'https://deb.li/rpc/json';
33  
34 =head1 Functions
35  
36 =over
37  
38 =item B<makeashorterlink>(I<URL>)
39  
40 The function C<makeashorterlink> will connect to deb.li passing it
41 the URL and will return the shortened variant.
42  
43 =cut
44  
45 0 ▶sub makeashorterlink {
Subroutine makeashorterlink: not called CC=4 SCAR=30.0
Pod documented
46 0 ▶ my $url = shift or croak 'No URL passed to makeashorterlink';
Branch: 1 branch
BranchTrueFalseTotal
my $url = shift() or croak("No URL passed to makeashorterlink") 0 0 0
47 0 my $rpc = JSON::RPC::Client::Any->new();
48 0 my $res
49 = $rpc->call( $RPC_URL => { method => 'add_url', params => [$url] } );
50 0 ▶ return undef unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
51 0 ▶ return undef if $res->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $res->is_error 0 0 0
52 0 return 'https://deb.li/' . $res->result;
53 }
54  
55 =item makealongerlink
56  
57 The function C<makealongerlink> does the reverse. It will accept as an argument
58 either the full deb.li URL or just the key.
59  
60 If anything goes wrong, then either function will return C<undef>.
61  
62 =back
63  
64 =cut
65  
66 0 ▶sub makealongerlink {
Subroutine makealongerlink: not called CC=4 SCAR=30.0
Pod documented
67 0 ▶ my $key = shift or croak 'No key / URL passed to makealongerlink';
Branch: 1 branch
BranchTrueFalseTotal
my $key = shift() or croak("No key / URL passed to makealongerlink") 0 0 0
68 0 $key =~ s,^https?://deb.li/,,;
69 0 my $rpc = JSON::RPC::Client::Any->new();
70 0 my $res
71 = $rpc->call( $RPC_URL => { method => 'get_url', params => [$key] } );
72 0 ▶ return undef unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
73 0 ▶ return undef if $res->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $res->is_error 0 0 0
74 0 return $res->result;
75 }
76  
77 1 1;
78  
79 __END__
« privinc/My/Builder.pm ↑ Summary blib/lib/App/KGB/Change.pm »