| 1 | # | ||||||||||||||||||||||||||||
| 2 | # This file is part of WWW-Shorten-SCK | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # This software is copyright (c) 2013 by celogeek <me@celogeek.com>. | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | package WWW::Shorten::SCK; | ||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use LWP::Protocol::https; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use URI::Escape qw/uri_escape_utf8/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | our $VERSION = '0.7'; # VERSION | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # ABSTRACT: Perl interface to sck.pm | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use parent qw( WWW::Shorten::generic Exporter ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use vars qw(@EXPORT_OK %EXPORT_TAGS); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 2 | @EXPORT_OK = qw( makeashorterlink makealongerlink ); | |||||||||||||||||||||||||||
| 24 | 2 | %EXPORT_TAGS = ( all => [@EXPORT_OK] ); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub makeashorterlink { | ||||||||||||||||||||||||||||
| 29 | 1 | ▶ | my $url = shift or croak 'No URL passed to makeashorterlink'; | ||||||||||||||||||||||||||
|
Subroutine
makeashorterlink: called CC=5 SCAR=26.7
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 1 | my $ua = __PACKAGE__->ua(); | |||||||||||||||||||||||||||
| 31 | 1 | my $sck_url = 'https://api.sck.pm'; | |||||||||||||||||||||||||||
| 32 | 1 | my $resp = $ua->get( $sck_url . '/shorten?' . $url, ); | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | return unless $resp->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | my $content = decode_json( $resp->content ); | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | if ( ref $content && $content->{status} eq 'OK' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $content and $content->{"status"} eq "OK"
MC/DC0%0/2
ref $content and $content->{"status"} eq "OK"
ref $content
$content->{"status"} eq "OK"
Truth table0%0/3
A and B
A= ref $contentB= $content->{"status"} eq "OK"
| |||||||||||||||||||||||||||||
| 36 | 0 | return $content->{short_url}; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 0 | return; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | sub makealongerlink { | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | my $sck_url = shift | ||||||||||||||||||||||||||
|
Subroutine
makealongerlink: not called CC=6 SCAR=37.4
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | or croak 'No SCK key / URL passed to makealongerlink'; | ||||||||||||||||||||||||||||
| 44 | 0 | my $ua = __PACKAGE__->ua(); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | #call api to get long url from the short | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ( $sck_url =~ /^https?:\/\/sck.pm\/(.*)$/x ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | $sck_url = $1; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | my $resp = $ua->get( "https://api.sck.pm/expand?" . $sck_url ); | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | return unless $resp->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | my $content = decode_json( $resp->content ); | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ( ref $content && $content->{status} eq 'OK' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $content and $content->{"status"} eq "OK"
MC/DC0%0/2
ref $content and $content->{"status"} eq "OK"
ref $content
$content->{"status"} eq "OK"
Truth table0%0/3
A and B
A= ref $contentB= $content->{"status"} eq "OK"
| |||||||||||||||||||||||||||||
| 55 | 0 | return $content->{url}; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 0 | return; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 2 | 1; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||||||||||