Dynamically define a controller #2183
Unanswered
please-fill-out-this-field
asked this question in
Q&A
Replies: 1 comment 3 replies
-
I think it's better to explain, what you want to achieve in the end. I would think there is no benefit in creating a class. What is your purpose? If you just want to route to certain methods on plugin registration, just use callbacks like $app->routes->post('/foo/create')->to(cb => sub { shift->render(text => 'create' )}) If you want to add the routes for several paths or use "action" like routing, you can add a shortcut on registration, like $app->routes->add_shortcut(
mycrud => sub {
my $r = shift;
$r->post('/')->to(
cb => sub { shift->render(text => 'create') }
);
$r->get('/')->to(
cb => sub { shift->render(text => 'read') }
);
....
}
); |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to write a Mojolicious plugin that adds a
Foo
controller to the app that doesn't have such controller (i.e. there is nolib/MyApp/Controller/Foo.pm
).Is it possible without dirty hacks?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions