sub translate_to :Chained('object') :PathPart('to') :Args(1) {
my ($self, $c, $to) = @_;
my $object = $c->stash->{object};
+ unless ($object->can_translate_to($to)) {
+ $c->detach('/error_404');
+ }
$c->stash(
result => $object->translated_to($to)
);
has 'text' => (is => 'ro', required => 1);
has '_translator' => (
is => 'ro', required => 1, init_arg => 'translator',
+ handles => [ 'can_translate_to' ],
);
sub translated {
$self->translate_to($self->default_target, $text);
}
+sub can_translate_to {
+ my ($self, $target) = @_;
+ return exists $self->_translators->{$target};
+}
+
sub translate_to {
my ($self, $target, $text) = @_;
$self->_translators->{$target}->translate($text);
ok( $response->is_success, 'Response Successful 2xx' );
like( $response->content, qr/CHEEZ/, "contains translated string");
+
+ok(
+ $response = request(GET 'http://localhost/translate/1/to/NONEXISTANT'),
+ 'Request for non-existant translation type'
+);
+
+cmp_ok( $response->code, '==', 404, '404 error returned');