Commit | Line | Data |
6955a293 |
1 | package LolCatalyst::Lite::Controller::Translate; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use parent qw(Catalyst::Controller); |
6 | |
7 | sub base :Chained('/') :PathPart('translate') :CaptureArgs(0) { |
8 | my ($self, $c) = @_; |
9 | $c->stash(collection => $c->model('SnippetStore')); |
10 | } |
11 | |
12 | sub create :Chained('base') :PathPart('') :Args(0) { |
13 | my ($self, $c) = @_; |
14 | my $req = $c->req; |
15 | if ($req->method eq 'POST' && (my $lol = $req->body_params->{lol})) { |
16 | my $snippet = $c->stash->{collection}->create({ text => $lol }); |
17 | $c->stash(object => $snippet); |
18 | $c->detach('view'); |
19 | } |
20 | } |
21 | |
22 | sub object :Chained('base') :PathPart('') :CaptureArgs(1) { |
23 | my ($self, $c, $id) = @_; |
24 | my $object = $c->stash->{collection}->find($id); |
25 | $c->detach('/error_404') unless $object; |
26 | $c->stash(object => $object); |
27 | } |
28 | |
29 | sub view :Chained('object') :PathPart('') :Args(0) { |
30 | my ($self, $c) = @_; |
31 | my $object = $c->stash->{object}; |
32 | $c->stash( |
33 | result => $c->model('Translator') |
34 | ->translate($object->{text}) |
35 | ); |
36 | } |
37 | |
38 | 1; |