CatalystX::UriForStatic - Implements an uri_for_static method for Catalyst applications!
Version 0.01
Returns an URI for static files. It distinguishes between a local and productive environment so it can return an URI pointing to a different host (eg. to a CDN) for productive environments.
package MyApp; use Moose; use namespace::autoclean; extends 'Catalyst'; with 'CatalystX::UriForStatic'; __PACKAGE__->config( envkey => 'sysenv', # optional, this is the default local_value => 'local', # optional, this is the default static_host => 'http://static.example.net', sysenv => 'local', ); # In your template <% $c->uri_for_static('/static/foo.png') %>
Pass a path like you would do to "uri_for" in Catalyst. Doesn't accept Controller paths or blessed references etc.
On a local environment it calls "uri_for" in Catalyst and returns what it returns.
local
On any other environment it prepends the static_host to the path while it doesn't care about SSL or if your passed path is valid.
static_host
To work properly, CatalystX::UriForStatic needs some small configuration.
Specifies the key in the config that is responsible for defining if the environment is a development or production environment. The default is sysenv.
Specifies what the value of the envkey is when the environment is a development/local environment. The default is local.
This key's name is whatever envkey is set to! Change this to the value of local_value to tell CatalystX::UriForStatic if the environment is a development/local environment. If it differs from local_value the environment is considered as production.
CatalystX::UriForStatic
Contains the URI to the static files and should include the protocol (http or https) and as well the domain. Shouldn't contain a trailing slash.
Examples:
Matthias Dietrich, <perl@rainboxx.de>
<perl@rainboxx.de>
http://www.rainboxx.de
Copyright 2011 Matthias Dietrich.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install CatalystX::UriForStatic, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CatalystX::UriForStatic
CPAN shell
perl -MCPAN -e shell install CatalystX::UriForStatic
For more information on module installation, please visit the detailed CPAN module installation guide.