| 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 URI::Escape qw/uri_escape_utf8/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | our $VERSION = '0.5'; # VERSION | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # ABSTRACT: Perl interface to sck.pm | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use parent qw( WWW::Shorten::generic Exporter ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use vars qw(@EXPORT_OK %EXPORT_TAGS); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 2 | @EXPORT_OK = qw( makeashorterlink makealongerlink ); | |||||||||||||||||||||||||||
| 23 | 2 | %EXPORT_TAGS = ( all => [@EXPORT_OK] ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub makeashorterlink { | ||||||||||||||||||||||||||||
| 28 | 1 | ▶ | my $url = shift or croak 'No URL passed to makeashorterlink'; | ||||||||||||||||||||||||||
|
Subroutine
makeashorterlink: called CC=5 SCAR=26.7
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 1 | my $ua = __PACKAGE__->ua(); | |||||||||||||||||||||||||||
| 30 | 1 | my $sck_url = 'http://api.sck.pm'; | |||||||||||||||||||||||||||
| 31 | 1 | my $resp = $ua->get( $sck_url . '?url=' . uri_escape_utf8($url), ); | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | return unless $resp->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | my $content = decode_json( $resp->content ); | |||||||||||||||||||||||||||
| 34 | 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"
| |||||||||||||||||||||||||||||
| 35 | 0 | return 'http://sck.pm/' . $content->{short}; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 0 | return; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub makealongerlink { | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | my $sck_url = shift | ||||||||||||||||||||||||||
|
Subroutine
makealongerlink: not called CC=6 SCAR=37.4
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | or croak 'No SCK key / URL passed to makealongerlink'; | ||||||||||||||||||||||||||||
| 43 | 0 | my $ua = __PACKAGE__->ua(); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | #call api to get long url from the short | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $sck_url = substr( $sck_url, 14 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | if substr( $sck_url, 0, 14 ) eq 'http://sck.pm/'; | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | my $resp = $ua->get("http://api.sck.pm?surl=$sck_url"); | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | return unless $resp->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | my $content = decode_json( $resp->content ); | |||||||||||||||||||||||||||
| 52 | 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"
| |||||||||||||||||||||||||||||
| 53 | 0 | return $content->{url}; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 0 | return; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 2 | 1; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||