| 1 | package Acme::CPANAuthors::Utils::Kwalitee; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use HTTP::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use JSON::PP (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | my $ua; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | sub _uri { "https://api.cpanauthors.org/kwalitee/" . shift } | ||||||||||||||||||||||||||
|
Subroutine
_uri: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | sub _ua { | ||||||||||||||||||||||||||
|
Subroutine
_ua: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 13 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 14 | 1 | ▶ | $ua = $_[0] if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | $ua ||= HTTP::Tiny->new(env_proxy => 1); | ||||||||||||||||||||||||||
|
Condition33%1/3
$ua ||= "HTTP::Tiny"->new("env_proxy", 1)
MC/DC0%0/2
$ua ||= "HTTP::Tiny"->new("env_proxy", 1)
$ua
"HTTP::Tiny"->new("env_proxy", 1)
Truth table33%1/3
A ||= B
A= $uaB= "HTTP::Tiny"->new("env_proxy", 1)
| |||||||||||||||||||||||||||||
| 16 | 1 | $ua; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | sub fetch { | ||||||||||||||||||||||||||
|
Subroutine
fetch: called CC=5 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 1 | my ($class, $id) = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | return unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | my $res = $class->_ua->get(_uri(lc $id)); | |||||||||||||||||||||||||||
| 25 | 1 | ▶ | unless ($res->{success} && $res->{status} == 200) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$res->{"success"} and $res->{"status"} == 200
MC/DC0%0/2
$res->{"success"} and $res->{"status"} == 200
$res->{"success"}
$res->{"status"} == 200
Truth table33%1/3
A and B
A= $res->{"success"}B= $res->{"status"} == 200
| |||||||||||||||||||||||||||||
| 26 | 0 | $class->_error("$res->{status} $res->{reason}"); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | my $json = eval { JSON::PP::decode_json($res->{content}) }; | |||||||||||||||||||||||||||
| 30 | 1 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | $class->_error($@); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 1 | return $json; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub _error { | ||||||||||||||||||||||||||
|
Subroutine
_error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 37 | 0 | my ($class, $error) = @_; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | die "API SERVER ERROR\n" | |||||||||||||||||||||||||||
| 40 | . "Couldn't parse kwalitee info from the api server\n" | ||||||||||||||||||||||||||||
| 41 | . " $error\n" | ||||||||||||||||||||||||||||
| 42 | . "Sorry for the inconvenience. If this lingers long,\n" | ||||||||||||||||||||||||||||
| 43 | . "please drop a line to <ishigaki\@cpan.org>.\n"; | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 2 | 1; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | __END__ | ||||||||||||||||||||||||||||