Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • You might want to look at chained actions: Catalyst::DispatchType::Chained [].

    That gives you an easy way to have URIs like


    And you can set the URI via:

    my $action = $ctx->controller('Foo')->action_for('edit');
    my $uri = $ctx->uri_for($action, \@captures, @arguments);

    What goes into captures and what into arguments depends on your application design.

    While the version of uri_for() that uses an action object instead of a string seems a bit more work, it gives you one huge advantage: If you change your application's URIs later on (imagine wanting to move /st/$id to /stories/$id for SEO purposes), you can do that via the applications configuration file, and if you use action objects instead of giving it an explicit string path, Catalyst will from then on generate the new, correct, URIs without you needing to touch one link.

    If you just want to type less, it might be the simplest thing to build yourself a utility method. One possibility would be to do this in a controller subclass:

    sub uri_closure_for {
        my ($self, $ctx, $action) = @_;

        my $action_obj = $self->action_for($action);

        return sub {
            $ctx->uri_for($action_obj, @_);

    and in the actual controller you could do:

    sub foo : ... {
        my ($self, $ctx) = @_;

        $ctx->stash(make_edit_uri => $self->uri_closure_for('edit'));

    and then in the template

    [% make_edit_uri([2, 3], 4) %]

    where [2, 3] would be the captures and the 4 would be the argument.

    HTH, phaylon

    PS: Note that the code is just quickly hacked up and untested, of course.

    Ordinary morality is for ordinary people. -- Aleister Crowley