line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Groonga::HTTP; |
2
|
2
|
|
|
2
|
|
23598
|
use 5.008005; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
66
|
|
3
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
4
|
2
|
|
|
2
|
|
22
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
93
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
2175
|
use JSON::XS qw(encode_json); |
|
2
|
|
|
|
|
15446
|
|
|
2
|
|
|
|
|
144
|
|
9
|
2
|
|
|
2
|
|
2052
|
use Furl; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use URI; |
11
|
|
|
|
|
|
|
use Net::Groonga::HTTP::Response; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Mouse; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has end_point => ( is => 'ro', required => 1 ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has ua => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
default => sub { |
20
|
|
|
|
|
|
|
Furl->new( |
21
|
|
|
|
|
|
|
agent => "Net::Groonga::HTTP/$VERSION", |
22
|
|
|
|
|
|
|
timeout => 3 |
23
|
|
|
|
|
|
|
) |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
no Mouse; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub construct_api_url { |
30
|
|
|
|
|
|
|
my ($self, $name, %args) = @_; |
31
|
|
|
|
|
|
|
my $url = $self->end_point; |
32
|
|
|
|
|
|
|
$url =~ s!/$!!; |
33
|
|
|
|
|
|
|
my $uri = URI->new("$url/$name"); |
34
|
|
|
|
|
|
|
$uri->query_form(%args); |
35
|
|
|
|
|
|
|
$uri; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub call { |
39
|
|
|
|
|
|
|
my ($self, $function, %args) = @_; |
40
|
|
|
|
|
|
|
my $url = $self->construct_api_url($function, %args); |
41
|
|
|
|
|
|
|
my $res = $self->ua->get($url); |
42
|
|
|
|
|
|
|
return Net::Groonga::HTTP::Response->new( |
43
|
|
|
|
|
|
|
function => $function, |
44
|
|
|
|
|
|
|
http_response => $res, |
45
|
|
|
|
|
|
|
args => \%args, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my @functions = qw( |
50
|
|
|
|
|
|
|
table_create |
51
|
|
|
|
|
|
|
column_create |
52
|
|
|
|
|
|
|
status |
53
|
|
|
|
|
|
|
select |
54
|
|
|
|
|
|
|
delete |
55
|
|
|
|
|
|
|
dump |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
for my $function (@functions) { |
58
|
|
|
|
|
|
|
no strict 'refs'; |
59
|
|
|
|
|
|
|
*{__PACKAGE__ . "::${function}"} = sub { |
60
|
|
|
|
|
|
|
my ($self, %args) = @_; |
61
|
|
|
|
|
|
|
$self->call($function, %args); |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub load { |
66
|
|
|
|
|
|
|
my ($self, %args) = @_; |
67
|
|
|
|
|
|
|
$args{values} = encode_json($args{values}) if ref $args{values}; |
68
|
|
|
|
|
|
|
return $self->call('load', %args); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
__END__ |