dfe372ce16800203b6c85f8fa5df9a055ee932d8
[catagits/catbook-code.git] / lib / LolCatalyst / Lite / Controller / Root.pm
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 ) = @_;
15     $c->response->status(404);
16     $c->response->body( 'Page not found' );
17 }
18
19 sub translate :Local {
20      my ($self, $c) = @_;
21      my $lol = $c->req->body_params->{lol}; # only for a POST request
22          # $c->req->params->{lol} would catch GET or POST
23          # $c->req->query_params would catch GET params only
24      $c->stash(
25        lol => $lol,
26        result => $c->model('Translate')->translate($lol),
27        template => 'index.tt',
28      );
29 }
30
31 sub translate_service : Local {
32     my ($self, $c) = @_;
33     $c->forward('translate');
34     $c->stash->{current_view} = 'Service';
35 }
36
37 sub end : ActionClass('RenderView') {
38     my ($self, $c) = @_;
39     my $errors = scalar @{$c->error};
40     if ($errors) {
41         $c->res->status(500);
42         $c->res->body('internal server error');
43         $c->clear_errors;
44     }
45 }
46
47 1;