Last active
October 9, 2018 11:38
-
-
Save mawasak/22b2acf30535ba0634dfb991bd8638db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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