Commit | Line | Data |
cc003be0 |
1 | package LolCatalyst::Lite::Controller::Root; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use parent 'Catalyst::Controller'; |
6 | |
7 | __PACKAGE__->config->{namespace} = ''; |
8 | |
9 | sub index :Path :Args(0) { |
10 | my ( $self, $c ) = @_; |
11 | } |
12 | |
13 | sub default :Path { |
14 | my ( $self, $c ) = @_; |
ae0e112b |
15 | $c->detach('/error_404'); |
16 | } |
17 | |
18 | sub error_404 :Private { |
19 | my ( $self, $c ) = @_; |
cc003be0 |
20 | $c->response->status(404); |
21 | $c->response->body( 'Page not found' ); |
22 | } |
23 | |
6955a293 |
24 | sub translate :Private { |
cc003be0 |
25 | my ($self, $c) = @_; |
26 | my $lol = $c->req->body_params->{lol}; # only for a POST request |
27 | # $c->req->params->{lol} would catch GET or POST |
28 | # $c->req->query_params would catch GET params only |
29 | $c->stash( |
30 | lol => $lol, |
2e909c0d |
31 | result => $c->model('Translator')->translate($lol), |
cc003be0 |
32 | template => 'index.tt', |
33 | ); |
34 | } |
35 | |
36 | sub translate_service : Local { |
37 | my ($self, $c) = @_; |
38 | $c->forward('translate'); |
39 | $c->stash->{current_view} = 'Service'; |
40 | } |
41 | |
42 | sub end : ActionClass('RenderView') { |
43 | my ($self, $c) = @_; |
44 | my $errors = scalar @{$c->error}; |
45 | if ($errors) { |
8f0c625d |
46 | $c->log->error("Errors in ${\$c->action}:"); |
47 | $c->log->error($_) for @{$c->error}; |
cc003be0 |
48 | $c->res->status(500); |
49 | $c->res->body('internal server error'); |
50 | $c->clear_errors; |
51 | } |
52 | } |
53 | |
54 | 1; |