From: Andrew Rodland Date: Wed, 29 Jul 2009 00:33:25 +0000 (+0000) Subject: Rewrite the POD for $c->uri_for(). X-Git-Tag: 5.80008~49 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=ee8963de51038687df873c7e95422cb3a3adf499 Rewrite the POD for $c->uri_for(). Reintroduce some bits of information that were lost in 5.7->5.8, and remove a misleading statement about $c->action. Recommend the use of uri_for_action with a private action path. --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 528b83c..304fff0 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1164,30 +1164,42 @@ sub setup_finalize { $class->setup_finished(1); } -=head2 $c->uri_for( $action, \@captures?, @args?, \%query_values? ) - =head2 $c->uri_for( $path, @args?, \%query_values? ) -=over - -=item $action - -A L object representing the Catalyst action you want to -create a URI for. To get one for an action in the current controller, -use C<< $c->action('someactionname') >>. To get one from a different -controller, fetch the controller using C<< $c->controller() >>, then -call Caction_for('name')"> on it. - -You can maintain the arguments captured by an action (e.g.: Regex, Chained) -using C<< $c->req->captures >>. +=head2 $c->uri_for( $action, \@captures?, @args?, \%query_values? ) - # For the current action - $c->uri_for($c->action, $c->req->captures); +Constructs an absolute L object based on the application root, the +provided path, and the additional arguments and query parameters provided. +When used as a string, provides a textual URI. + +If the first argument is a string, it is taken as a public URI path relative +to C<< $c->namespace >> (if it doesn't begin with a forward slash) or +relative to the application root (if it does). It is then merged with +C<< $c->request->base >>; any C<@args> are appended as additional path +components; and any C<%query_values> are appended as C parameters. + +If the first argument is a L it represents an action which +will have its path resolved using C<< $c->dispatcher->uri_for_action >>. The +optional C<\@captures> argument (an arrayref) allows passing the captured +variables that are needed to fill in the paths of Chained and Regex actions; +once the path is resolved, C continues as though a path was +provided, appending any arguments or parameters and creating an absolute +URI. + +The captures for the current request can be found in +C<< $c->request->captures >>, and actions can be resolved using +C<< Catalyst::Controller->action_for($name) >>. If you have a private action +path, use C<< $c->uri_for_action >> instead. + + # Equivalent to $c->req->uri + $c->uri_for($c->action, $c->req->captures, + @{ $c->req->args }, $c->req->params); # For the Foo action in the Bar controller - $c->uri_for($c->controller('Bar')->action_for('Foo'), $c->req->captures); + $c->uri_for($c->controller('Bar')->action_for('Foo')); -=back + # Path to a static resource + $c->uri_for('/static/images/logo.png'); =cut