Skip to content

Instantly share code, notes, and snippets.

@jjn1056
Last active May 22, 2023 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjn1056/e53dc2400a0ca49664d9d042955cdecc to your computer and use it in GitHub Desktop.
Save jjn1056/e53dc2400a0ca49664d9d042955cdecc to your computer and use it in GitHub Desktop.
package Camel::Controller::Dialog;
use Moose;
use MooseX::MethodAttributes;
use Camel::Syntax;
use Types::Standard qw/Int/;
extends 'Camel::Controller';
sub root :Via('../private') At('dialog/...') ($self, $c, $user) {
$c->action->next(my $collection = $user->dialog);
}
sub list :GET Via('root') At('') ($self, $c, $collection) {
return $self->view(
segments => $collection,
new_segment => $collection->build,
)->set_http_ok;
}
sub create :POST Via('root') At('') BodyModel ($self, $c, $collection, $r) {
$Camel::PSGI::stdout = '';
$Camel::PSGI::chat_process->stdin->write("@{[ $r->request ]}\n");
$Camel::PSGI::loop->loop_once while $Camel::PSGI::stdout eq '';
my $segment = $collection->create({
request => $r->request,
response => $Camel::PSGI::stdout,
});
$self->view_for('list',
segments => $collection,
new_segment => $segment->valid ? $collection->build : $segment,
);
return $segment->valid ?
$c->view->set_http_ok :
$c->view->set_http_bad_request;
}
__PACKAGE__->meta->make_immutable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment