Pixela/Webhook.pm

filter: Statementstmt 100% 57 / 57 Branchbran 90.0% 18 / 20 Conditioncond 88.8% 8 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 12 / 12 Podpod 71.4% 5 / 7 totaltotal 93.6% 104 / 111 CC 14 SCAR 13.6
CC
14
Cov
97%
create
8.0
invoke
3.1
delete
3.0
CRAP 3.9
« Pixela/Graph.pm ↑ Summary Pixela.pm »
1 package WebService::Pixela::Webhook;
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 6 ▶use JSON qw/decode_json/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 our $VERSION = "0.021";
9  
10 44 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
11 44 my ($class,$pixela_client) = @_;
12 44 return bless +{
13 client => $pixela_client,
14 }, $class;
15 }
16  
17  
18 22 ▶sub client {
Subroutine client: called CC=1 SCAR=0.0
Pod undocumented
19 22 my $self = shift;
20 22 return $self->{client};
21 }
22  
23 16 ▶sub hash {
Subroutine hash: called CC=2 SCAR=6.9
Pod documented
24 16 my $self = shift;
25 16 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 6 10 16
26 6 $self->{hash} = shift;
27 6 return $self;
28 }
29 10 return $self->{hash};
30 }
31  
32 6 ▶sub create {
Subroutine create: called CC=8 SCAR=20.8
Pod documented
33 6 my ($self,%args) = @_;
34 6 my $params = {};
35  
36 #check graphID
37 6 ▶ $params->{graphID} = $args{graph_id} // $self->client->graph->id;
Condition100%3/3
$args{"graph_id"} // $self->client->graph->id
l!l&&r!l&&!r
411
MC/DC100%2/2
$args{"graph_id"} // $self->client->graph->id
$args{"graph_id"} $self->client->graph->id
Truth table100%3/3
A // B
A= $args{"graph_id"}B= $self->client->graph->id
ABresult
1X1
011
000
38 6 ▶ croak 'require graph_id' unless $params->{graphID};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"graphID"} 1 5 6
39  
40 #check type
41 5 ▶ croak 'require type' unless $args{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"type"} 1 4 5
42 map {
43 4 ▶ if( $args{type} =~ /^$_$/i){
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"type"} =~ /^$_$/i) 3 5 8
44 3 $params->{type} = lc($args{type});
45 }
46 } (qw/increment decrement/);
47 4 ▶ croak 'invalid type' unless $params->{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"type"} 1 3 4
48  
49 3 my $path = 'users/'.$self->client->username.'/webhooks';
50 3 my $res = $self->client->request_with_xuser_in_header('POST',$path,$params);
51  
52 3 ▶ my $res_json = $self->client->decode() ? $res : decode_json($res);
Branch: 1 branch
BranchTrueFalseTotal
$self->client->decode ? : 2 1 3
53  
54 3 ▶ if($res_json->{isSuccess}){
Branch: 1 branch
BranchTrueFalseTotal
if ($res_json->{"isSuccess"}) 3 0 3
55 3 $self->hash($res_json->{webhookHash});
56 }
57  
58 3 return $res;
59 }
60  
61 2 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod documented
62 2 my $self = shift;
63 2 my $client = $self->client;
64  
65 2 my $path = 'users/'.$client->username.'/webhooks/';
66 2 my $res = $client->request_with_xuser_in_header('GET',$path);
67  
68 2 ▶ return $client->decode() ? $res->{webhooks} : $res;
Branch: 1 branch
BranchTrueFalseTotal
$client->decode ? : 1 1 2
69 }
70  
71 2 ▶sub invoke {
Subroutine invoke: called CC=3 SCAR=11.2
Pod documented
72 2 my ($self,$hash) = @_;
73 2 my $client = $self->client;
74  
75 2 ▶ $hash //= $self->hash();
Condition66%2/3
$hash //= $self->hash
l!l&&r!l&&!r
110
MC/DC0%0/2
$hash //= $self->hash
$hash $self->hash
Truth table66%2/3
A //= B
A= $hashB= $self->hash
ABresult
1X1
011
000
76 2 ▶ croak 'require webhookHash' unless $hash;
Branch: 1 branch
BranchTrueFalseTotal
unless $hash 0 2 2
77  
78 2 my $path = 'users/'.$client->username.'/webhooks/'.$hash;
79 2 return $client->request_with_content_length_in_header('POST',$path,0);
80 }
81  
82 4 ▶sub delete {
Subroutine delete: called CC=3 SCAR=11.0
Pod documented
83 4 my ($self,$hash) = @_;
84 4 my $client = $self->client;
85  
86 4 ▶ $hash //= $self->hash();
Condition100%3/3
$hash //= $self->hash
l!l&&r!l&&!r
112
MC/DC100%2/2
$hash //= $self->hash
$hash $self->hash
Truth table100%3/3
A //= B
A= $hashB= $self->hash
ABresult
1X1
011
000
87 4 ▶ croak 'require webhookHash' unless $hash;
Branch: 1 branch
BranchTrueFalseTotal
unless $hash 2 2 4
88  
89 2 my $path = 'users/'.$client->username.'/webhooks/'.$hash;
90 2 return $self->client->request_with_xuser_in_header('DELETE',$path);
91 }
92  
93  
94 6 1;
95 __END__
« Pixela/Graph.pm ↑ Summary Pixela.pm »