line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (C) 2022 Horimoto Yasuhiro |
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 . |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package Groonga::Commands::Delete; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
8
|
use Carp 'croak'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
21
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
19
|
|
22
|
1
|
|
|
1
|
|
528
|
use Data::Dumper; |
|
1
|
|
|
|
|
5265
|
|
|
1
|
|
|
|
|
46
|
|
23
|
1
|
|
|
1
|
|
583
|
use JSON; |
|
1
|
|
|
|
|
6938
|
|
|
1
|
|
|
|
|
4
|
|
24
|
|
|
|
|
|
|
my $groonga_http_client = undef; |
25
|
|
|
|
|
|
|
my $command_args = ""; |
26
|
|
|
|
|
|
|
my @delete_arguments = ( |
27
|
|
|
|
|
|
|
'table', |
28
|
|
|
|
|
|
|
'key' |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub _is_valid_arguments { |
42
|
0
|
|
|
0
|
|
|
my $args = shift; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
while (my ($key, $value) = each %{$args}) { |
|
0
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if ($key eq 'client') { |
46
|
0
|
|
|
|
|
|
next; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
0
|
|
|
|
|
if (!(grep {$_ eq $key} @delete_arguments)) { |
|
0
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
croak "Invalid arguments: ${key}"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return 1; #true |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _parse_arguments { |
57
|
0
|
|
|
0
|
|
|
my $args = shift; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my %parsed_arguments = (); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
_is_valid_arguments($args); |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if (exists($args->{'table'})) { |
64
|
0
|
|
|
|
|
|
$parsed_arguments{'table'} = $args->{'table'}; |
65
|
|
|
|
|
|
|
} else { |
66
|
0
|
|
|
|
|
|
croak 'Missing a require argument "table"'; |
67
|
|
|
|
|
|
|
} |
68
|
0
|
0
|
|
|
|
|
if (exists($args->{'key'})) { |
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
|
|
|
|
|
|
|
sub _parse_result { |
78
|
0
|
|
|
0
|
|
|
my $result = shift; |
79
|
0
|
|
|
|
|
|
my %result_set = (); |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
if ($result == JSON::PP::true) { |
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
|
|
|
|
|
|
|
sub execute { |
92
|
0
|
0
|
|
0
|
0
|
|
if (defined $groonga_http_client) { |
93
|
0
|
|
|
|
|
|
return _parse_result($groonga_http_client->send('delete', $command_args)); |
94
|
|
|
|
|
|
|
} |
95
|
0
|
|
|
|
|
|
return; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |