Dynamically set the controller in "under"

30 views
Skip to first unread message

Stefan Adams

unread,
Mar 15, 2020, 10:28:48 PM3/15/20
to mojolicious
I'm wanting to dynamically set the controller in, for example, an under

my $admin = $self->routes->under('/admin' => sub { ... });

The only way I have found is like so

my $admin = $self->routes->under('/admin' => sub {
  shift->match->stack->[-1]->{controller} = 'something';
});

Is this the right way?  The best way?  The only way?

I could have sworn it was possible to set the controller in an under by simply setting it in the stash, but that is not working for me.

Dan Book

unread,
Mar 15, 2020, 10:41:28 PM3/15/20
to mojol...@googlegroups.com
Mojolicious does not support dynamic routing. Once a route has matched, the only thing an under can determine is if the dispatch chain continues or stops.

-Dan

--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/CACyQ%2BFTGpPNNfc5E9oPj-KzV6nD4-%3DBXQHyz-iJHwoeWCi3bjg%40mail.gmail.com.

Stefan Adams

unread,
Mar 15, 2020, 11:39:27 PM3/15/20
to mojolicious
Thanks, Dan! Does that mean, then, that what I provided as a solution is actually a bad idea and may not always work as I'm anticipating?

Dan Book

unread,
Mar 15, 2020, 11:43:59 PM3/15/20
to mojol...@googlegroups.com
Correct, if it works in any sense it's accidental.

-Dan

Reply all
Reply to author
Forward
0 new messages