$c->response->body( 'Page not found' );
}
-sub translate :Local {
+sub translate :Private {
my ($self, $c) = @_;
my $lol = $c->req->body_params->{lol}; # only for a POST request
# $c->req->params->{lol} would catch GET or POST
--- /dev/null
+package LolCatalyst::Lite::Controller::Translate;
+
+use strict;
+use warnings;
+use parent qw(Catalyst::Controller);
+
+sub base :Chained('/') :PathPart('translate') :CaptureArgs(0) {
+ my ($self, $c) = @_;
+ $c->stash(collection => $c->model('SnippetStore'));
+}
+
+sub create :Chained('base') :PathPart('') :Args(0) {
+ my ($self, $c) = @_;
+ my $req = $c->req;
+ if ($req->method eq 'POST' && (my $lol = $req->body_params->{lol})) {
+ my $snippet = $c->stash->{collection}->create({ text => $lol });
+ $c->stash(object => $snippet);
+ $c->detach('view');
+ }
+}
+
+sub object :Chained('base') :PathPart('') :CaptureArgs(1) {
+ my ($self, $c, $id) = @_;
+ my $object = $c->stash->{collection}->find($id);
+ $c->detach('/error_404') unless $object;
+ $c->stash(object => $object);
+}
+
+sub view :Chained('object') :PathPart('') :Args(0) {
+ my ($self, $c) = @_;
+ my $object = $c->stash->{object};
+ $c->stash(
+ result => $c->model('Translator')
+ ->translate($object->{text})
+ );
+}
+
+1;
--- /dev/null
+package LolCatalyst::Lite::Model::SnippetStore;
+
+use strict;
+use warnings;
+use aliased 'LolCatalyst::Lite::SnippetStore';
+
+sub COMPONENT { SnippetStore->new }
+
+1;
--- /dev/null
+[% IF result; INCLUDE translate/view.tt; END %]
+<form name="translate" method=POST action="translate">
+ <input type="text" name="lol" value="" title="enter text to translate">
+ <input type="submit" value="Translate">
+</form>