lib/WWW/Stickam/API/Base.pm

filter: Statementstmt 78.9% 30 / 38 Branchbran 33.3% 2 / 6 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 85.7% 6 / 7 Podpod 100% 2 / 2 totaltotal 67.2% 41 / 61 CC 6 SCAR 17.3
CC
6
Cov
67%
call
10.1
response_check
2.0
BEGIN
1.0
CRAP 5.6
↑ Summary blib/lib/WWW/Stickam/API.pm »
1 package WWW::Stickam::API::Base;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use base qw/Class::Accessor::Fast/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 __PACKAGE__->mk_accessors(qw/error content/);
9  
10 13 ▶sub call {
Subroutine call: called CC=6 SCAR=23.1
Pod documented
11 13 my $s = shift;
12 13 ▶ my $args = shift || {};
Condition50%1/2
shift() || {}
l!l
130
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
13  
14 13 my $uri = '';
15 13 eval {
16 13 $uri = $s->uri( $args );
17 };
18  
19 13 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 13 13
20 0 $s->{error} = $@;
21 0 return ;
22 }
23  
24 13 my $u = URI->new( $uri );
25 13 $u->query_form( $args );
26  
27 13 my $ua = LWP::UserAgent->new();
28  
29 13 my $response = $ua->get( $u->as_string );
30  
31 13 ▶ if( $response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 13 13
32 0 ▶ if( length $response->content && $s->response_check( $response->content ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $response->content and $s->response_check($response->content)) { } 0 0 0
Condition0%0/3
length $response->content and $s->response_check($response->content)
!ll&&!rl&&r
000
MC/DC0%0/2
length $response->content and $s->response_check($response->content)
length $response->content $s->response_check($response->content)
Truth table0%0/3
A and B
A= length $response->contentB= $s->response_check($response->content)
ABresult
0X0
100
111
33 0 $s->{content} = $response->content;
34 0 return 1;
35 }
36 else {
37 # the site return empty when no found, should have been return reason you know.
38 0 $s->{error} = "I guess data is not found";
39 0 return ;
40 }
41 }else {
42 13 $s->{error} = $response->status_line;
43 13 return ;
44 }
45  
46 }
47  
48 0 ▶sub response_check { 1; }
Subroutine response_check: not called CC=1 SCAR=6.9
Pod documented
49  
50 9 1;
51  
52 =head1 NAME
53  
54 WWW::Stickam::API::Base - API base class
55  
56 =head1 DESCRIPTION
57  
58 Base module for API.
59  
60 =head1 METHOD
61  
62 =head2 call
63  
64 =head2 response_check
65  
66 =head1 AUTHOR
67  
68 Tomohiro Teranishi<tomohiro.teranishi@gmail.com>
69  
70 =cut
71  
↑ Summary blib/lib/WWW/Stickam/API.pm »