-
Notifications
You must be signed in to change notification settings - Fork 2
/
api.pl
executable file
·46 lines (41 loc) · 1.2 KB
/
api.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env perl
use Dir::Self;
use lib __DIR__ . "/lib";
use Data::Dumper;
use hin;
use common::parser qw(get_parser initialize_langs);
use MIME::Base64;
use Mojolicious::Lite;
use strict;
use warnings;
any '/parse' => sub {
my $c = shift;
my $lang = $c->param('lang');
my %args = %{$c->req->params->to_hash};
my $parser = get_parser($lang);
my $final_result = $parser->parse(%args);
if (exists $args{"pretty"}) {
my $final_string = join "\n", map { "$_:\n$final_result->{$_}" } keys %$final_result;
$c->render(template => 'pretty', result => $final_string);
} else {
$c->render(json => $final_result);
}
};
any '/parse/:lang' => sub {
my $c = shift;
my $lang = $c->param('lang');
my %args = %{$c->req->params->to_hash};
my $parser = get_parser($lang);
my $final_result = $parser->parse(%args);
if (exists $args{"pretty"}) {
my $final_string = join "\n", map { "$_:\n$final_result->{$_}" } keys %$final_result;
$c->render(template => 'pretty', result => $final_string);
} else {
$c->render(json => $final_result);
}
};
initialize_langs();
app->start;
__DATA__
@@ pretty.html.ep
<pre><%= $result %></pre>