| 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::Load; | ||||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | ▶ | use Carp 'croak'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 1 | my $groonga_http_client = undef; | |||||||||
| 26 | 1 | my $command_args = ""; | |||||||||
| 27 | 1 | my $n_loaded_records = undef; | |||||||||
| 28 | 1 | my @records; | |||||||||
| 29 | 1 | my $use_drilldown = 0; | |||||||||
| 30 | 1 | my @load_arguments = ( | |||||||||
| 31 | 'table', | ||||||||||
| 32 | 'values' | ||||||||||
| 33 | ); | ||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 36 | 0 | my ($class, %args) = @_; | |||||||||
| 37 | 0 | my $self = {%args}; | |||||||||
| 38 | |||||||||||
| 39 | 0 | $groonga_http_client = $self->{client}; | |||||||||
| 40 | 0 | $command_args = _parse_arguments($self); | |||||||||
| 41 | |||||||||||
| 42 | 0 | return bless $self, $class; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | sub _is_valid_arguments { | ||||||||
|
Subroutine
_is_valid_arguments: not called CC=4 SCAR=30.0
| |||||||||||
| 46 | 0 | my $args = shift; | |||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | while (my ($key, $value) = each %{$args}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | ▶ | if ($key eq 'client') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | next; | |||||||||
| 51 | } | ||||||||||
| 52 | 0 | ▶ | if (!(grep {$_ eq $key} @load_arguments)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | croak "Invalid arguments: ${key}"; | |||||||||
| 54 | } | ||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | return 1; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 0 | ▶ | sub _parse_arguments { | ||||||||
|
Subroutine
_parse_arguments: not called CC=2 SCAR=17.9
| |||||||||||
| 61 | 0 | my $args = shift; | |||||||||
| 62 | 0 | my %parsed_arguments = (); | |||||||||
| 63 | |||||||||||
| 64 | 0 | _is_valid_arguments($args); | |||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | if (exists($args->{'table'})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | $parsed_arguments{'table'} = $args->{'table'}; | |||||||||
| 68 | } | ||||||||||
| 69 | 0 | $parsed_arguments{'values'} = encode_json($args->{'values'}); | |||||||||
| 70 | |||||||||||
| 71 | 0 | return \%parsed_arguments; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 0 | ▶ | sub _parse_result { | ||||||||
|
Subroutine
_parse_result: not called CC=1 SCAR=6.9
| |||||||||||
| 75 | 0 | my $result = shift; | |||||||||
| 76 | 0 | my %result_set = (); | |||||||||
| 77 | |||||||||||
| 78 | 0 | $result_set{'n_loaded_records'} = $result; | |||||||||
| 79 | |||||||||||
| 80 | 0 | return \%result_set; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 0 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 84 | 0 | ▶ | if (defined $groonga_http_client) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | return _parse_result($groonga_http_client->send_post( | ||||||||||
| 86 | 'load', | ||||||||||
| 87 | "?table=$command_args->{'table'}", | ||||||||||
| 88 | 0 | $command_args->{'values'} | |||||||||
| 89 | ) | ||||||||||
| 90 | ); | ||||||||||
| 91 | } | ||||||||||
| 92 | 0 | return; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | 1 | 1; | |||||||||