Pass the required values for multiple controllers
If you want to set the value globally, you can use the defaults method. However, sometimes you may want to use the value with just multiple controllers.
In such cases, use the following techniques.
my $r = $app->routes->to(val => $val); # The rest is the same $r->get('/ foo'); $r->get('/ bar');
The point is to use to when getting a router. The to method is usually used to write a combination of controller and action, but in fact you can also set a default value for the controller.
By doing this, the set value can be used on the controller side.
#In the controller my $val = $c->stash('val');