Evan Carroll
Evan Carroll

Reputation: 1

How can I internally redirect with Mojo?

Catalyst supported redirects internal to the framework (forward and detach), and external (HTTP) redirects (res->redirect). Internal redirects essentially just redispatched to a new path,

Lets say I set up two paths,

sub register ( $self, $app, $conf ) {
    my $r = $app->routes;
    $r->any( 'foo',  => \&foo_baz );
    $r->any( 'bar',  => \&bar_baz );
}

How would I tell foo after it does some stuff, to internally redirect to bar?

sub foo_baz ($c) {
  ; stuff
  bar_baz($c)
}

Is there a better way than calling bar_baz($c) directly? These routes are declared in a Mojo Plugin.

Upvotes: 2

Views: 386

Answers (1)

Grinnz
Grinnz

Reputation: 9231

Discussed on IRC, but: Mojolicious does not support the dynamic routing of internal redirects as Catalyst does. The common suggestion is to abstract out your code to avoid duplication while not directly calling another route. So instead of route A calling route B, both of them would call a helper or method to complete the common functionality using their current controller object.

Upvotes: 5

Related Questions