Catalyst::Plugin::SmartURI - Configurable URIs for Catalyst
Version 0.023
smarturi: disposition: hostless # application-wide $c->uri_disposition('absolute'); # per request <a href="[% c.uri_for('/foo').relative %]" ...
Configure whether $c->uri_for and $c->req->uri_with return absolute, hostless or relative URIs and/or configure which URI class to use, on an application or request basis.
This is useful in situations where you're for example, redirecting to a lighttpd from a firewall rule, instead of a real proxy, and you want your links and redirects to still work correctly.
This plugin allows you to configure, on a application and per-request basis, what URI class $c->uri_for and $c->req->uri_with use, as well as whether the URIs they produce are absolute, hostless or relative.
To use your own URI class, just subclass URI::SmartURI and set uri_class, or write a class that follows the same interface.
This plugin installs a custom $c->request_class, however it does so in a way that won't break if you've already set $c->request_class yourself (thanks mst!).
There will be a slight performance penalty for your first few requests, due to the way URI::SmartURI works, but after that you shouldn't notice it. The penalty is considerably smaller in perl 5.10+.
In myapp.yml:
smarturi: dispostion: absolute uri_class: 'URI::SmartURI'
One of 'absolute', 'hostless' or 'relative'. Defaults to 'absolute'.
The class to use for URIs, defaults to URI::SmartURI.
package MyAPP::Controller::RSSFeed; ... sub begin : Private { my ($self, $c) = @_; $c->uri_class('Your::URI::Class::For::Request'); $c->uri_disposition('absolute'); }
Set URI disposition to use for the duration of the request.
Set the URI class to use for $c->uri_for and $c->req->uri_with for the duration of the request.
$c->prepare_uri actually creates the URI, you can overload that to do as you please in your own plugins.
URI::SmartURI, Catalyst, URI
Rafael Kitover, <rkitover at cpan.org>
<rkitover at cpan.org>
Please report any bugs or feature requests to bug-catalyst-plugin-smarturi at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Plugin-SmartURI. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-catalyst-plugin-smarturi at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Catalyst::Plugin::SmartURI
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-SmartURI
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Catalyst-Plugin-SmartURI
CPAN Ratings
http://cpanratings.perl.org/d/Catalyst-Plugin-SmartURI
Search CPAN
http://search.cpan.org/dist/Catalyst-Plugin-SmartURI
from #catalyst:
vipul came up with the idea
mst came up with the design and implementation details for the current version
kd reviewed my code and offered suggestions
I'd like to extend on Catalyst::Plugin::RequireSSL, and make a plugin that rewrites URIs for actions with an SSL attribute.
Make a disposition that is based on the Host header.
Copyright (c) 2008 Rafael Kitover
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Catalyst::Plugin::SmartURI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Plugin::SmartURI
CPAN shell
perl -MCPAN -e shell install Catalyst::Plugin::SmartURI
For more information on module installation, please visit the detailed CPAN module installation guide.