Pixela.pm

filter: Statementstmt 90.5% 77 / 85 Branchbran 70.0% 7 / 10 Conditioncond 52.6% 10 / 19 MC/DCmcdc 36.3% 4 / 11 Subroutinesub 90.4% 19 / 21 Podpod 28.5% 2 / 7 totaltotal 77.7% 119 / 153 CC 14 SCAR 10.1
CC
14
Cov
82%
request_with_content_length_in_header
6.0
request_with_dual_in_header
6.0
new
5.0
CRAP 2.7
« Pixela/Webhook.pm ↑ Summary Pixela/Pixel.pm »
1 package WebService::Pixela;
2 6 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use WebService::Pixela::User;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use WebService::Pixela::Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use WebService::Pixela::Pixel;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use WebService::Pixela::Webhook;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Class::Accessor::Lite(
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 new => 0,
15 ro => [qw/
16 user
17 graph
18 pixel
19 webhook
20 _agent
21 /],
22 rw => [qw/
23 username
24 token
25 base_url
26 /],
27 6 );
28  
29 6 our $VERSION = "0.021";
30  
31 44 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
32 44 my ($class,%args) = @_;
33 44 my $self = bless +{}, $class;
34  
35 # initalize
36 44 ▶ $self->{username} = $args{username} // croak 'require username';
Condition100%2/2
$args{"username"} // croak("require username")
l!l
431
MC/DC100%1/1
$args{"username"} // croak("require username")
$args{"username"}
Truth table100%2/2
A
A= $args{"username"}
Aresult
11
00
37 43 ▶ $self->{token} = $args{token} // (carp('not input token'), undef);
Condition66%2/3
$args{"token"} // (carp("not input token"), undef)
l!l&&r!l&&!r
4201
MC/DC50%1/2
$args{"token"} // (carp("not input token"), undef)
$args{"token"} (carp("not input token"), undef)
Truth table66%2/3
A // B
A= $args{"token"}B= (carp("not input token"), undef)
ABresult
1X1
011
000
38 43 ▶ $self->{base_url} = $args{base_url} // "https://pixe.la/";
Condition100%2/2
$args{"base_url"} // "https://pixe.la/"
l!l
142
MC/DC100%1/1
$args{"base_url"} // "https://pixe.la/"
$args{"base_url"}
Truth table100%2/2
A
A= $args{"base_url"}
Aresult
11
00
39 43 ▶ $self->{decode} = $args{decode} // 1;
Condition100%2/2
$args{"decode"} // 1
l!l
142
MC/DC100%1/1
$args{"decode"} // 1
$args{"decode"}
Truth table100%2/2
A
A= $args{"decode"}
Aresult
11
00
40 43 $self->{_agent} = HTTP::Tiny->new();
41  
42 #WebService::Pixela instances
43 43 $self->{user} = WebService::Pixela::User->new($self);
44 43 $self->{graph} = WebService::Pixela::Graph->new($self);
45 43 $self->{pixel} = WebService::Pixela::Pixel->new($self);
46 43 $self->{webhook} = WebService::Pixela::Webhook->new($self);
47  
48 43 return $self;
49 }
50  
51 20 ▶sub decode {
Subroutine decode: called CC=2 SCAR=6.9
Pod documented
52 20 my $self = shift;
53 20 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 7 13 20
54 7 $self->{decode} = shift;
55 7 return $self;
56 }
57 13 return $self->{decode};
58 }
59  
60 2 ▶sub _decode_or_simple_return_from_json {
Subroutine _decode_or_simple_return_from_json: called CC=2 SCAR=6.9
61 2 my ($self,$rev_json) = @_;
62  
63 2 ▶ unless ($self->decode){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->decode) 1 1 2
64 1 return $rev_json;
65 }
66  
67 1 return decode_json($rev_json);
68 }
69  
70 1 ▶sub _request {
Subroutine _request: called CC=1 SCAR=0.0
71 1 my ($self,$method,$path,$params) = @_;
72  
73 1 my $uri = URI->new('v1/'.$path)->abs($self->base_url);
74  
75 1 my $receive_json = $self->_agent->request($method, $uri->as_string, $params)->{"content"};
76  
77 1 return $self->_decode_or_simple_return_from_json($receive_json);
78 }
79  
80 1 ▶sub query_request {
Subroutine query_request: called CC=2 SCAR=7.0
Pod undocumented
81 1 my ($self,$method,$path,$query) = @_;
82  
83 1 my $uri = URI->new('v1/'.$path)->abs($self->base_url);
84  
85 1 ▶ if ($query){
Branch: 1 branch
BranchTrueFalseTotal
if ($query) 1 0 1
86 1 $uri->query_form($query);
87 }
88  
89 1 return $self->_agent->request($method, $uri->as_string)->{"content"};
90 }
91  
92  
93 1 ▶sub request {
Subroutine request: called CC=3 SCAR=11.8
Pod undocumented
94 1 my ($self,$method,$path,$content) = @_;
95  
96 1 my $params = {};
97 1 ▶ if (defined $content && %$content){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content and %$content) 1 0 1
Condition33%1/3
defined $content and %$content
!ll&&!rl&&r
001
MC/DC0%0/2
defined $content and %$content
defined $content %$content
Truth table33%1/3
A and B
A= defined $contentB= %$content
ABresult
0X0
100
111
98 1 $params->{content} = encode_json($content);
99 }
100  
101 1 return $self->_request($method,$path,$params);
102 }
103  
104 1 ▶sub request_with_xuser_in_header {
Subroutine request_with_xuser_in_header: called CC=3 SCAR=11.8
Pod undocumented
105 1 my ($self,$method,$path,$content) = @_;
106  
107 1 my $params = {
108 headers => { 'X-USER-TOKEN' => $self->token },
109 };
110  
111 1 ▶ if (defined $content && %$content){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content and %$content) 1 0 1
Condition33%1/3
defined $content and %$content
!ll&&!rl&&r
001
MC/DC0%0/2
defined $content and %$content
defined $content %$content
Truth table33%1/3
A and B
A= defined $contentB= %$content
ABresult
0X0
100
111
112 1 $params->{content} = encode_json($content);
113 }
114  
115 1 return $self->_request($method,$path,$params);
116 }
117  
118 0 ▶sub request_with_content_length_in_header {
Subroutine request_with_content_length_in_header: not called CC=2 SCAR=17.9
Pod undocumented
119 0 my ($self,$method,$path,$length) = @_;
120  
121 0 ▶ $length //= 0;
Condition0%0/2
$length //= 0
l!l
00
MC/DC0%0/1
$length //= 0
$length
Truth table0%0/2
A
A= $length
Aresult
11
00
122  
123 0 my $params = {
124 headers => { 'Content-Length' => $length },
125 };
126  
127 0 return $self->_request($method,$path);
128 }
129  
130 0 ▶sub request_with_dual_in_header {
Subroutine request_with_dual_in_header: not called CC=2 SCAR=17.9
Pod undocumented
131 0 my ($self,$method,$path,$length) = @_;
132  
133 0 ▶ $length //= 0;
Condition0%0/2
$length //= 0
l!l
00
MC/DC0%0/1
$length //= 0
$length
Truth table0%0/2
A
A= $length
Aresult
11
00
134  
135 0 my $params = {
136 headers => {
137 'X-USER-TOKEN' => $self->token,
138 'Content-Length' => $length,
139 },
140 };
141  
142 0 return $self->_request($method,$path,$params);
143 }
144  
145  
146 6 1;
147 __END__
« Pixela/Webhook.pm ↑ Summary Pixela/Pixel.pm »