Skip to content

Instantly share code, notes, and snippets.

@mawasak
Last active October 9, 2018 11:38
Show Gist options
  • Save mawasak/22b2acf30535ba0634dfb991bd8638db to your computer and use it in GitHub Desktop.
Save mawasak/22b2acf30535ba0634dfb991bd8638db to your computer and use it in GitHub Desktop.
package W::Controller::ApiController;
use Mojo::Base 'Mojolicious::Controller';
use Log::Log4perl qw(:easy);
use Data::Dumper;
use Data::Printer;
use Role::Tiny::With;
with("W::Controller::Role::FCommon");
sub foo {
my ($self) = @_;
return $self->action();
}
package W::Controller::Role::FCommon;
use Data::Printer;
use Mojo::Base -role;
sub action {
my ($self) = @_;
my $l = $self->param("SOME_PARAM");
$self->render_later;
#DO STH...
my $result = #promise... from model
$result->then(sub {
my $res = shift;
#...do sth
$self->render(template => template_name(), format => "json");
})->catch (sub {
my $err = shift->{message};
$self->render(template => "ErrorTemplate", format => "json", errorType => $err);
})->wait;
}
$api->get('/api/XXX/q/#param')->to('apiController#foo')->name("api_1");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment