Pixela/Graph.pm

filter: Statementstmt 94.0% 94 / 100 Branchbran 76.7% 43 / 56 Conditioncond 56.5% 13 / 23 MC/DCmcdc 33.3% 5 / 15 Subroutinesub 93.7% 15 / 16 Podpod 81.8% 9 / 11 totaltotal 81.0% 179 / 221 CC 37 SCAR 18.5
CC
37
Cov
84%
delete
12.0
create
10.0
update
9.8
CRAP 6.4
↑ Summary Pixela/Webhook.pm »
1 package WebService::Pixela::Graph;
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 Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 our $VERSION = "0.021";
8  
9 44 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
10 44 my ($class,$pixela_client) = @_;
11 44 return bless +{
12 client => $pixela_client,
13 }, $class;
14 }
15  
16  
17 29 ▶sub client {
Subroutine client: called CC=1 SCAR=0.0
Pod undocumented
18 29 my $self = shift;
19 29 return $self->{client};
20 }
21  
22 48 ▶sub id {
Subroutine id: called CC=2 SCAR=6.9
Pod documented
23 48 my $self = shift;
24 48 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 16 32 48
25 16 $self->{id} = shift;
26 16 return $self;
27 }
28 32 return $self->{id};
29 }
30  
31 8 ▶sub create {
Subroutine create: called CC=10 SCAR=23.0
Pod documented
32 8 my ($self,%args) = @_;
33 8 my $params = {};
34  
35 #check id
36 8 ▶ $params->{id} = $args{id} // $self->id();
Condition66%2/3
$args{"id"} // $self->id
l!l&&r!l&&!r
701
MC/DC50%1/2
$args{"id"} // $self->id
$args{"id"} $self->id
Truth table66%2/3
A // B
A= $args{"id"}B= $self->id
ABresult
1X1
011
000
37 8 ▶ croak 'require id' unless $params->{id};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"id"} 1 7 8
38  
39 #check name unit
40 7 ▶ map { $params->{$_} = $args{$_} // croak "require $_" } (qw/name unit/);
Condition100%2/2
$args{$_} // croak("require $_")
l!l
112
MC/DC100%1/1
$args{$_} // croak("require $_")
$args{$_}
Truth table100%2/2
A
A= $args{$_}
Aresult
11
00
41  
42 # check type
43 5 ▶ croak 'require type' unless $args{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"type"} 1 4 5
44 map {
45 4 ▶ if ( $args{type} =~ /^$_$/i){
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"type"} =~ /^$_$/i) 3 5 8
46 3 $params->{type} = lc($args{type});
47 }
48 } (qw/int float/);
49  
50 4 ▶ croak 'invalid type' unless $params->{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"type"} 1 3 4
51  
52 # check color
53 3 ▶ croak 'require color' unless $args{color};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"color"} 1 2 3
54 2 $params->{color} = _color_validate($args{color});
55 2 ▶ croak 'invalid color' unless $params->{color};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"color"} 1 1 2
56  
57 #no check timezone...
58 1 ▶ $params->{timezone} = $args{timezone} if $args{timezone};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"timezone"} 0 1 1
59  
60 1 my $path = 'users/'.$self->client->username.'/graphs';
61 1 $self->id($params->{id});
62 1 return $self->client->request_with_xuser_in_header('POST',$path,$params);
63 }
64  
65  
66 2 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod documented
67 2 my $self = shift;
68 2 my $res = $self->client->request_with_xuser_in_header('GET',('users/'.$self->client->username.'/graphs'));
69 2 ▶ return $self->client->decode() ? $res->{graphs} : $res;
Branch: 1 branch
BranchTrueFalseTotal
$self->client->decode ? : 1 1 2
70 }
71  
72  
73 4 ▶sub get_svg {
Subroutine get_svg: called CC=5 SCAR=16.1
Pod documented
74 4 my ($self, %args) = @_;
75 4 ▶ my $id = $args{id} // $self->id;
Condition100%3/3
$args{"id"} // $self->id
l!l&&r!l&&!r
121
MC/DC100%2/2
$args{"id"} // $self->id
$args{"id"} $self->id
Truth table100%3/3
A // B
A= $args{"id"}B= $self->id
ABresult
1X1
011
000
76 4 ▶ croak 'require graph id' unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 1 3 4
77  
78 3 my $query = {};
79 3 ▶ $query->{date} = $args{date} if $args{date};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"date"} 2 1 3
80 3 ▶ $query->{mode} = $args{mode} if $args{mode};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"mode"} 2 1 3
81  
82 3 my $path = 'users/'.$self->client->username.'/graphs/'.$id;
83  
84 3 return $self->client->query_request('GET',$path,$query);
85 }
86  
87 2 ▶sub update {
Subroutine update: called CC=9 SCAR=22.8
Pod documented
88 2 my ($self,%arg) = @_;
89 2 my $client = $self->client;
90  
91 2 ▶ my $id = $arg{id} // $self->id;
Condition66%2/3
$arg{"id"} // $self->id
l!l&&r!l&&!r
101
MC/DC50%1/2
$arg{"id"} // $self->id
$arg{"id"} $self->id
Truth table66%2/3
A // B
A= $arg{"id"}B= $self->id
ABresult
1X1
011
000
92 2 ▶ croak 'require graph id' unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 1 1 2
93  
94 1 my $params = {};
95 1 ▶ map { $params->{$_} = $arg{$_} if $arg{$_} } (qw/name unit timezone/);
Branch: 1 branch
BranchTrueFalseTotal
if $arg{$_} 2 1 3
96  
97 #color invalid -> croak
98 1 ▶ if ($arg{color}){
Branch: 1 branch
BranchTrueFalseTotal
if ($arg{"color"}) 1 0 1
99 1 $params->{color} = _color_validate($arg{color});
100 1 ▶ croak 'invalid color' unless $params->{color};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"color"} 0 1 1
101 }
102  
103 1 ▶ if ($arg{purge_cache_urls}){
Branch: 1 branch
BranchTrueFalseTotal
if ($arg{"purge_cache_urls"}) 1 0 1
104 1 ▶ if (ref($arg{purge_cache_urls}) ne 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg{"purge_cache_urls"} ne "ARRAY") 0 1 1
105 0 croak 'invalid types for purge_cache_urls';
106 }
107 1 $params->{purgeCacheURLs} = $arg{purge_cache_urls};
108 }
109  
110 1 ▶ $params->{selfSufficient} = $arg{self_sufficient} if defined $arg{self_sufficient};
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg{"self_sufficient"} 1 0 1
111  
112 1 return $client->request_with_xuser_in_header('PUT',('users/'.$client->username.'/graphs/'.$id),$params);
113 }
114  
115 0 ▶sub delete {
Subroutine delete: not called CC=3 SCAR=24.8
Pod documented
116 0 my ($self,$id) = @_;
117 0 my $client = $self->client;
118  
119 0 ▶ $id //= $self->id;
Condition0%0/3
$id //= $self->id
l!l&&r!l&&!r
000
MC/DC0%0/2
$id //= $self->id
$id $self->id
Truth table0%0/3
A //= B
A= $idB= $self->id
ABresult
1X1
011
000
120 0 ▶ croak 'require graph id' unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
121  
122 0 return $client->request_with_xuser_in_header('DELETE',('users/'.$client->username.'/graphs/'.$id));
123 }
124  
125 3 ▶sub html {
Subroutine html: called CC=4 SCAR=14.0
Pod documented
126 3 my ($self,%args) = @_;
127  
128 3 my $client = $self->client;
129  
130 3 ▶ my $id = $args{id} // $self->id;
Condition66%2/3
$args{"id"} // $self->id
l!l&&r!l&&!r
210
MC/DC0%0/2
$args{"id"} // $self->id
$args{"id"} $self->id
Truth table66%2/3
A // B
A= $args{"id"}B= $self->id
ABresult
1X1
011
000
131 3 ▶ croak 'require graph id' unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 3 3
132  
133 3 my $path = $client->base_url . 'v1/users/'.$client->username.'/graphs/'.$id.'.html';
134  
135 3 ▶ if ($args{line}){
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"line"}) 1 2 3
136 1 $path .= '?mode=line';
137 }
138  
139 3 return $path;
140 }
141  
142 2 ▶sub pixels {
Subroutine pixels: called CC=6 SCAR=18.8
Pod documented
143 2 my ($self,%args) = @_;
144  
145 2 ▶ my $id = $args{id} // $self->id;
Condition33%1/3
$args{"id"} // $self->id
l!l&&r!l&&!r
200
MC/DC0%0/2
$args{"id"} // $self->id
$args{"id"} $self->id
Truth table33%1/3
A // B
A= $args{"id"}B= $self->id
ABresult
1X1
011
000
146 2 ▶ croak 'require id' unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 2 2
147  
148 2 my $params = {};
149 2 ▶ $params->{to} = $args{to} if $args{to};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"to"} 2 0 2
150 2 ▶ $params->{from} = $args{from} if $args{from};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"from"} 2 0 2
151  
152 2 my $path = 'users/'.$self->client->username.'/graphs/'.$id.'/pixels';
153 2 my $res = $self->client->request_with_xuser_in_header('GET',$path,$params);
154  
155 2 ▶ return $self->client->decode() ? $res->{pixels} : $res;
Branch: 1 branch
BranchTrueFalseTotal
$self->client->decode ? : 1 1 2
156 }
157  
158 1 ▶sub stats {
Subroutine stats: called CC=3 SCAR=11.6
Pod documented
159 1 my ($self, $id) = @_;
160  
161 1 my $client = $self->client;
162  
163 1 ▶ $id //= $self->id;
Condition33%1/3
$id //= $self->id
l!l&&r!l&&!r
100
MC/DC0%0/2
$id //= $self->id
$id $self->id
Truth table33%1/3
A //= B
A= $idB= $self->id
ABresult
1X1
011
000
164 1 ▶ croak 'require graph id' unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 1 1
165  
166 1 my $path = 'users/'.$self->client->username.'/graphs/'.$id.'/stats';
167 1 return $self->client->request('GET',$path);
168 }
169  
170 3 ▶sub _color_validate {
Subroutine _color_validate: called CC=2 SCAR=6.9
171 3 my $check_color = shift;
172 map {
173 3 ▶ if ($check_color =~ /^$_$/i){
Branch: 1 branch
BranchTrueFalseTotal
if ($check_color =~ /^$_$/i) 2 10 12
174 2 return lc($check_color);
175 }
176 } (qw/shibafu momiji sora ichou ajisai kuro/);
177 1 return undef;
178 }
179  
180 6 1;
181 __END__
↑ Summary Pixela/Webhook.pm »