On Jan 3, 2007, at 12:04 PM, Ash Berlin wrote:

Michael Reece wrote:
$c->uri_for() is great and all, but i usually am more interested in getting a uri for an action rather than a uri to a template (or public path). (incidentally, i feel uri_for would be better named uri_to, and the sub below named uri_for, but i digress.) the following code is what i have come up with. i present it here for feedback, comments, etc.
## my $uri = $c->uri_to( $controller_path, @path_args );
## my $uri = $c->uri_to( $controller_path, @path_args, \% query_args ); ## my $uri = $c->uri_to( $controller_path, @path_args, [EMAIL PROTECTED] ); # for :Regex() actions # $controller_path is '/controller/method' (preferred) or 'method' (in current $c->controller)
sub uri_to {
[..snip..]
    my $action = $c->dispatcher->get_action_by_path($path);
[..snip..]
    my $uri = $c->dispatcher->uri_for_action($action, @action_args);
[..snip..]
$uri = $c->uri_for("$uri", @path_args, @uri_args); # "stringify" important here
    return $uri;
}
there is a good chance i am re-inventing a wheel here!

Take a look at uri_for_aciton in http://dev.catalystframework.org/ browser/branches/Catalyst-Runtime-ctx-uri_for_action (see t/ unit_core_uri_for_action.t) and tell me if that does what you wanted or not.

Ash


i can't tell from reading the .t source, does that support $c- >uri_to_action('local_method') as well as $c->uri_to_action('/ controller/method'), similar to the way $c->forward() works?

reading the source at http://dev.catalystframework.org/browser/ branches/Catalyst-Runtime-ctx-uri_for_action/lib/Catalyst.pm, it looks like it would except that line 960 is commented out. or maybe that's part of what $dispatcher->contextual_uri_for_action is doing.



_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to