Notes + extra test for EPO workshop and YAPC::EU 2009
[catagits/catbook-code.git] / lib / LolCatalyst / Lite / Controller / Root.pm
CommitLineData
cc003be0 1package LolCatalyst::Lite::Controller::Root;
2
3use strict;
4use warnings;
5use parent 'Catalyst::Controller';
6
7__PACKAGE__->config->{namespace} = '';
8
9sub index :Path :Args(0) {
10 my ( $self, $c ) = @_;
11}
12
13sub default :Path {
14 my ( $self, $c ) = @_;
ae0e112b 15 $c->detach('/error_404');
16}
17
18sub error_404 :Private {
19 my ( $self, $c ) = @_;
cc003be0 20 $c->response->status(404);
21 $c->response->body( 'Page not found' );
22}
23
6955a293 24sub 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
36sub translate_service : Local {
37 my ($self, $c) = @_;
38 $c->forward('translate');
39 $c->stash->{current_view} = 'Service';
40}
41
42sub 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
541;