Catalyst-Plugin-URI
view release on metacpan or search on metacpan
README.mkdn view on Meta::CPAN
MyApp->setup;
Then you can use it in your controllers:
package MyApp::Controller::Example;
use base 'Catalyst::Controller';
sub make_a_url :Local {
my ($self, $c) = @_;
my $url = $c->uri("$controller.$action", \@args, \%query, \$fragment);
}
This is just a shortcut with stronger error messages for:
sub make_a_url :Local {
my ($self, $c) = @_;
my $url = $c->url_for(
$c->controller($controller)->action_for($action),
\@args, \%query, \$fragment);
}
# DESCRIPTION
**NOTE** Starting with version '0.003' I changed that way this works. If you want
or need the old API for backcompatibility please set the following configuration
flag:
MyApp->config('Plugin::URI' => { use_v1 => 1 });
Currently if you want to create a URL to a controller's action properly the formal
syntax is rather verbose:
my $url = $c->uri(
$c->controller($controller)->action_for($action),
\@args, \%query, \$fragment);
Which is verbose enough that it probably encourages people to do the wrong thing
and use a hard coded link path. This might later bite you if you need to change
your controllers and URL hierarchy.
Also, this can lead to weird error messages that don't make if clear that your
$controller and $action are actually wrong. This plugin is an attempt to both
make the proper formal syntax a bit more tidy and to deliver harder error messages
if you get the names wrong.
# METHODS
This plugin adds the following methods to your context
## uri
Example:
$c->uri("$controller:$action", \@parts, \%query, \$fragment);
This is a sugar method which works the same as:
my $url = $c->uri_for(
$c->controller($controller)->action_for($action),
\@args, \%query, \$fragment);
Just a bit shorter, and also we check to make sure the $controller and
$action actually exist (and raise a hard fail if they don't with an error
message that is I think more clear than the longer version.
You can also use a 'relative' specification for the action, which assumes
the current controller. For example:
$c->uri(":$action", \@parts, \%query, \$fragment);
Basically the same as:
my $url = $c->uri_for(
$self->action_for($action),
\@args, \%query, \$fragment);
We also support a corrected version of what 'uri\_for\_action' meant to achieve:
$c->uri("$action", @args);
Basically the same as:
my $url = $c->uri_for($self->action_for($action), @args);
Where the $action string is the full or relative (to the current controller) private
lib/Catalyst/Plugin/URI.pm view on Meta::CPAN
MyApp->setup;
Then you can use it in your controllers:
package MyApp::Controller::Example;
use base 'Catalyst::Controller';
sub make_a_url :Local {
my ($self, $c) = @_;
my $url = $c->uri("$controller.$action", \@args, \%query, \$fragment);
}
This is just a shortcut with stronger error messages for:
sub make_a_url :Local {
my ($self, $c) = @_;
my $url = $c->url_for(
$c->controller($controller)->action_for($action),
\@args, \%query, \$fragment);
}
=head1 DESCRIPTION
B<NOTE> Starting with version C<0.003> I changed that way this works. If you want
or need the old API for backcompatibility please set the following configuration
flag:
MyApp->config('Plugin::URI' => { version => 1 });
lib/Catalyst/Plugin/URI.pm view on Meta::CPAN
and older Catalyst without core support for named actions and need the old behavior
you can set it like this:
MyApp->config('Plugin::URI' => { version => 1 });
Currently if you want to create a URL to a controller's action properly the formal
syntax is rather verbose:
my $url = $c->uri(
$c->controller($controller)->action_for($action),
\@args, \%query, \$fragment);
Which is verbose enough that it probably encourages people to do the wrong thing
and use a hard coded link path. This might later bite you if you need to change
your controllers and URL hierarchy.
Also, this can lead to weird error messages that don't make if clear that your
$controller and $action are actually wrong. This plugin is an attempt to both
make the proper formal syntax a bit more tidy and to deliver harder error messages
if you get the names wrong.
=head1 METHODS
This plugin adds the following methods to your context
=head2 uri
Example:
$c->uri("$controller:$action", \@parts, \%query, \$fragment);
This is a sugar method which works the same as:
my $url = $c->uri_for(
$c->controller($controller)->action_for($action),
\@args, \%query, \$fragment);
Just a bit shorter, and also we check to make sure the $controller and
$action actually exist (and raise a hard fail if they don't with an error
message that is I think more clear than the longer version.
You can also use a 'relative' specification for the action, which assumes
the current controller. For example:
$c->uri(":$action", \@parts, \%query, \$fragment);
Basically the same as:
my $url = $c->uri_for(
$self->action_for($action),
\@args, \%query, \$fragment);
We also support a corrected version of what 'uri_for_action' meant to achieve:
$c->uri("$action", @args);
Basically the same as:
my $url = $c->uri_for($self->action_for($action), @args);
Where the $action string is the full or relative (to the current controller) private
( run in 1.244 second using v1.01-cache-2.11-cpan-364913b4093 )