| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package LLEval; |
|
2
|
2
|
|
|
2
|
|
64739
|
use 5.008_001; |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
69
|
|
|
3
|
2
|
|
|
2
|
|
3228
|
use Mouse; |
|
|
2
|
|
|
|
|
79275
|
|
|
|
2
|
|
|
|
|
11
|
|
|
4
|
2
|
|
|
2
|
|
2500
|
use MouseX::StrictConstructor; |
|
|
2
|
|
|
|
|
530
|
|
|
|
2
|
|
|
|
|
10
|
|
|
5
|
2
|
|
|
2
|
|
2438
|
use JSON; |
|
|
2
|
|
|
|
|
33570
|
|
|
|
2
|
|
|
|
|
12
|
|
|
6
|
2
|
|
|
2
|
|
2205
|
use Furl; |
|
|
2
|
|
|
|
|
67991
|
|
|
|
2
|
|
|
|
|
69
|
|
|
7
|
2
|
|
|
2
|
|
1575
|
use URI::Escape qw(uri_escape_utf8); |
|
|
2
|
|
|
|
|
2760
|
|
|
|
2
|
|
|
|
|
1313
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has api_host => ( |
|
12
|
|
|
|
|
|
|
is => 'ro', |
|
13
|
|
|
|
|
|
|
isa => 'Str', |
|
14
|
|
|
|
|
|
|
default => 'api.dan.co.jp', |
|
15
|
|
|
|
|
|
|
); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has api_pathq_base => ( |
|
18
|
|
|
|
|
|
|
is => 'ro', |
|
19
|
|
|
|
|
|
|
isa => 'Str', |
|
20
|
|
|
|
|
|
|
default => '/lleval.cgi', |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has _furl => ( |
|
24
|
|
|
|
|
|
|
is => 'ro', |
|
25
|
|
|
|
|
|
|
isa => 'Object', |
|
26
|
|
|
|
|
|
|
default => sub { |
|
27
|
|
|
|
|
|
|
return Furl->new( agent => "LLEval-Client/$VERSION" ), |
|
28
|
|
|
|
|
|
|
}, |
|
29
|
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has _json => ( |
|
32
|
|
|
|
|
|
|
is => 'ro', |
|
33
|
|
|
|
|
|
|
isa => 'Object', |
|
34
|
|
|
|
|
|
|
default => sub { |
|
35
|
|
|
|
|
|
|
return JSON->new->utf8->pretty; |
|
36
|
|
|
|
|
|
|
}, |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub call { |
|
40
|
1
|
|
|
1
|
0
|
3
|
my($self, %args) = @_; |
|
41
|
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
4
|
my $path_query = $self->api_pathq_base . '?'; |
|
43
|
1
|
|
|
|
|
4
|
while(my($key, $value) = each %args) { |
|
44
|
2
|
50
|
|
|
|
97
|
next unless defined $value; |
|
45
|
2
|
|
|
|
|
10
|
$path_query .= sprintf '&%s=%s', |
|
46
|
|
|
|
|
|
|
uri_escape_utf8($key), uri_escape_utf8($value); |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
#warn $path_query; |
|
49
|
1
|
|
|
|
|
30
|
my $res = $self->_furl->request( |
|
50
|
|
|
|
|
|
|
host => $self->api_host, |
|
51
|
|
|
|
|
|
|
path_query => $path_query, |
|
52
|
|
|
|
|
|
|
); |
|
53
|
1
|
50
|
|
|
|
728855
|
if($res->code != 200) { |
|
54
|
0
|
|
|
|
|
0
|
confess "API Error: ", $res->status_line; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
1
|
|
|
|
|
22
|
return $self->_json->decode($res->content); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub call_eval { |
|
60
|
1
|
|
|
1
|
0
|
2
|
my($self, $source, $lang) = @_; |
|
61
|
1
|
|
|
|
|
3
|
return $self->call( s => $source, l => $lang ); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub eval { |
|
65
|
1
|
|
|
1
|
0
|
6
|
my($self, $source, $lang, $stdout_to, $stderr_to) = @_; |
|
66
|
1
|
|
|
|
|
4
|
my $data = $self->call_eval($source, $lang); |
|
67
|
|
|
|
|
|
|
|
|
68
|
1
|
50
|
|
|
|
81
|
if(defined $stdout_to) { |
|
69
|
1
|
|
|
|
|
3
|
${$stdout_to} = $data->{stdout}; |
|
|
1
|
|
|
|
|
4
|
|
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
else { |
|
72
|
0
|
|
|
|
|
0
|
print $data->{stdout}; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
1
|
50
|
|
|
|
5
|
if(defined $stderr_to) { |
|
75
|
1
|
|
|
|
|
2
|
${$stderr_to} = $data->{stderr}; |
|
|
1
|
|
|
|
|
4
|
|
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
else { |
|
78
|
0
|
|
|
|
|
0
|
Carp::carp($data->{stderr}); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
1
|
|
|
|
|
7
|
return $data->{status}; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# list of supported languages |
|
84
|
|
|
|
|
|
|
sub languages { |
|
85
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
|
86
|
0
|
|
|
|
|
|
my $data = $self->call(q => 1); |
|
87
|
0
|
|
|
|
|
|
delete $data->{error}; |
|
88
|
0
|
|
|
|
|
|
return $data; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub pretty { |
|
92
|
0
|
|
|
0
|
0
|
|
my($self, $data) = @_; |
|
93
|
0
|
|
|
|
|
|
return $self->_json->encode($data); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
2
|
|
|
2
|
|
16
|
no Mouse; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
25
|
|
|
97
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
|
98
|
|
|
|
|
|
|
__END__ |