Commands/Delete.pm

filter: Statementstmt 35.8% 19 / 53 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 5 / 10 Podpod 0.0% 0 / 2 totaltotal 30.3% 24 / 79 CC 8 SCAR 21.6
CC
8
Cov
28%
_is_valid_arguments
20.0
_parse_arguments
12.0
_parse_result
6.0
CRAP 8.6
« HTTP/Client.pm ↑ Summary Commands/Load.pm »
1 # Copyright (C) 2022 Horimoto Yasuhiro <horimoto@clear-code.com>
2 #
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
15  
16 package Groonga::Commands::Delete;
17  
18 1 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 my $groonga_http_client = undef;
25 1 my $command_args = "";
26 1 my @delete_arguments = (
27 'table',
28 'key'
29 );
30  
31 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
32 0 my ($class, %args) = @_;
33 0 my $self = {%args};
34  
35 0 $groonga_http_client = $self->{client};
36 0 $command_args = _parse_arguments($self);
37  
38 0 return bless $self, $class;
39 }
40  
41 0 ▶sub _is_valid_arguments {
Subroutine _is_valid_arguments: not called CC=4 SCAR=30.0
42 0 my $args = shift;
43  
44 0 ▶ while (my ($key, $value) = each %{$args}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$args;}) 0 0 0
45 0 ▶ if ($key eq 'client') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "client") 0 0 0
46 0 next;
47 }
48 0 ▶ if (!(grep {$_ eq $key} @delete_arguments)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $key;} @delete_arguments) 0 0 0
49 0 croak "Invalid arguments: ${key}";
50 }
51 }
52  
53 0 return 1; #true
54 }
55  
56 0 ▶sub _parse_arguments {
Subroutine _parse_arguments: not called CC=3 SCAR=24.8
57 0 my $args = shift;
58  
59 0 my %parsed_arguments = ();
60  
61 0 _is_valid_arguments($args);
62  
63 0 ▶ if (exists($args->{'table'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{'table'}) { } 0 0 0
64 0 $parsed_arguments{'table'} = $args->{'table'};
65 } else {
66 0 croak 'Missing a require argument "table"';
67 }
68 0 ▶ if (exists($args->{'key'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{'key'}) { } 0 0 0
69 0 $parsed_arguments{'key'} = $args->{'key'};
70 } else {
71 0 croak 'Missing a require argument "key"';
72 }
73  
74 0 return \%parsed_arguments;
75 }
76  
77 0 ▶sub _parse_result {
Subroutine _parse_result: not called CC=2 SCAR=17.9
78 0 my $result = shift;
79 0 my %result_set = ();
80  
81 0 ▶ if ($result == JSON::PP::true) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result == JSON::PP::true()) { } 0 0 0
82 0 $result = 1;
83 } else {
84 0 $result = 0;
85 }
86 0 $result_set{'is_success'} = $result;
87  
88 0 return \%result_set;
89 }
90  
91 0 ▶sub execute {
Subroutine execute: not called CC=2 SCAR=17.9
Pod undocumented
92 0 ▶ if (defined $groonga_http_client) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $groonga_http_client) 0 0 0
93 0 return _parse_result($groonga_http_client->send('delete', $command_args));
94 }
95 0 return;
96 }
97  
98 1 1;
« HTTP/Client.pm ↑ Summary Commands/Load.pm »