WebService/TDWTF.pm

filter: Statementstmt 100% 65 / 65 Branchbran 78.5% 11 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 19 / 19 Podpod 100% 5 / 5 totaltotal 94.4% 102 / 108 CC 9 SCAR 7.2
CC
9
Cov
95%
_query
4.2
article
4.0
_objectify
2.0
CRAP 2.1
« App/TDWTF.pm ↑ Summary WebService/TDWTF/Article.pm »
1 package WebService::TDWTF;
2  
3 2 ▶use 5.014000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use parent qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use JSON::MaybeXS qw/decode_json/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Scalar::Util qw/looks_like_number/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use WebService::TDWTF::Article;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 my @subs = qw/article list_recent list_series list_author series/;
15 2 our @EXPORT = map { "tdwtf_$_" } @subs;
16 2 our @EXPORT_OK = (@EXPORT, @subs);
17 2 our %EXPORT_TAGS = (all => [@EXPORT_OK]);
18 2 our $VERSION = '0.003';
19 2 our $AGENT = "WebService-TDWTF/$VERSION";
20 2 our $BASE_URL = 'http://thedailywtf.com/api';
21  
22 13 ▶sub _ht { HTTP::Tiny->new(agent => $AGENT) }
Subroutine _ht: called CC=1 SCAR=0.0
23  
24 13 ▶sub _query {
Subroutine _query: called CC=4 SCAR=14.2
25 13 my ($url) = @_;
26  
27 13 my $ht = _ht;
28 13 my $response = $ht->get($url);
29 13 ▶ croak $response->{reason} unless $response->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $response->{"success"} 0 13 13
30 13 $response = decode_json $response->{content};
31 13 ▶ croak $response->{Status} if ref $response eq 'HASH' && !exists $response->{BodyHtml};
Branch: 1 branch
BranchTrueFalseTotal
if ref $response eq "HASH" and not exists $response->{"BodyHtml"} 0 13 13
Condition66%2/3
ref $response eq "HASH" and not exists $response->{"BodyHtml"}
!ll&&!rl&&r
850
MC/DC0%0/2
ref $response eq "HASH" and not exists $response->{"BodyHtml"}
ref $response eq "HASH" not exists $response->{"BodyHtml"}
Truth table66%2/3
A and not(B)
A= ref $response eq "HASH"B= not exists $response->{"BodyHtml"}
ABresult
0X0
100
111
32  
33 13 $response
34 }
35  
36 58 ▶sub _objectify {
Subroutine _objectify: called CC=2 SCAR=6.9
37 58 my ($response) = @_;
38  
39 58 ▶ return map { _objectify($_) } @$response if ref $response eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $response eq "ARRAY" 6 52 58
40 52 WebService::TDWTF::Article->new($response)
41 }
42  
43 5 ▶sub article {
Subroutine article: called CC=4 SCAR=13.9
Pod documented
44 5 my ($id_or_slug, $only_body_and_html) = @_;
45 5 my $url = "$BASE_URL/articles/";
46 5 ▶ $url .= @_ == 0 ? 'random' : looks_like_number $id_or_slug ? "/id/$id_or_slug" : "/slug/$id_or_slug";
Branch: 2 branches
BranchTrueFalseTotal
@_ == 0 ? : 1 4 5
&looks_like_number($id_or_slug) ? : 3 1 4
47 5 ▶ $url .= '/true' if $only_body_and_html;
Branch: 1 branch
BranchTrueFalseTotal
if $only_body_and_html 0 5 5
48 5 _objectify _query $url
49 }
50  
51 6 ▶sub _list {
Subroutine _list: called CC=1 SCAR=0.0
52 6 my $url = join '/', $BASE_URL, @_;
53 6 _objectify _query $url
54 }
55  
56 4 ▶sub list_recent { my $url = @_ == 2 ? 'articles' : 'articles/recent'; _list $url, @_ }
Subroutine list_recent: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 1 3 4
57 1 ▶sub list_series { _list 'series', @_ }
Subroutine list_series: called CC=1 SCAR=0.0
Pod documented
58 1 ▶sub list_author { _list 'author', @_ }
Subroutine list_author: called CC=1 SCAR=0.0
Pod documented
59  
60 2 ▶sub series { @{_query "$BASE_URL/series/"} }
Subroutine series: called CC=1 SCAR=0.0
Pod documented
61  
62 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
63 2 *tdwtf_article = \&article;
64 2 *tdwtf_list_recent = \&list_recent;
65 2 *tdwtf_list_series = \&list_series;
66 2 *tdwtf_list_author = \&list_author;
67 2 *tdwtf_series = \&series;
68 }
69  
70 2 1;
71 __END__
« App/TDWTF.pm ↑ Summary WebService/TDWTF/Article.pm »