[Catalyst] plugin for generating URIs that is chaining-aware

Nathan Gray kolibrie at cpan.org
Mon Jun 14 19:23:19 GMT 2021


I've been working on a Catalyst application, and have come
across a few places that appear difficult to generate a URI
for using uri_for().  I'm thinking of creating a plugin that
can provide the functionality I'm looking for.

In particular, when I am in a controller whose actions are
chained, I would like to be able to be able to generate URIs
for:
- actions in the parent controller (earlier in the chain)
- actions in the controller we are in
- actions in a child controller (later in the chain)
- actions in a non-related controller

I've been able to generate the URIs I want using uri_for(),
except for actions in a parent controller (earlier in the
chain).  The syntax to create some of the other URIs is a bit
complicated, and I find I have to look it up every time.  The
plugin Catalyst::Plugin::URI provides a simplified syntax.

My idea is to create a plugin with an interface something
like this:

    # URI for 'list' action on the current controller
    $c->internal_uri(action => 'list');

    # URI for 'view' action on the parent controller (up the chain)
    $c->internal_uri(controller => '..', action => 'view');

    # URI for 'list' action on a child or unrelated controller
    $c->internal_uri(controller => $name, action => 'list', captures =>
\@values);

Any advice or perspectives that would help me create such a
plugin, or make it more useful?

-kolibrie



More information about the Catalyst mailing list