-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
82 lines (53 loc) · 2.71 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
=pod
Sometimes you are fetching static content like images, JavaScript code and CSS files from a
different server that your L<Catalyst> application is running on, let's say a CDN
(content delivery network).
For development, this often should not be the case because your local files may differ from
the files on your CDN. Changing the URIs to the static content everytime you upload a new
version of your application is not a solution and leads to mistakes.
Entering L<CatalystX::UriForStatic>:
=head2 CatalystX::UriForStatic takes care of your static host name
L<CatalystX::UriForStatic> either creates a local or production URI to your static files
depending on your configuration! If your differences are that simple so you just can switch
the host names, L<CatalystX::UriForStatic> is for you.
=head2 Example
=head3 Production environment
Let's pretend this is your L<Catalyst> application while C<sysenv> controls whether your
application is a development or production instance and C<static_host> defines the
host name of your static files for production environment:
package MyApp;
use Moose;
use namespace::autoclean;
extends 'Catalyst';
with 'CatalystX::UriForStatic';
__PACKAGE__->config(
static_host => 'http://static.example.net',
sysenv => 'production',
...
);
In your templates where you point to your images etc. change the URIs to:
<% $c->uri_for_static('/static/foo.png') %>
(Note this is Mason syntax.)
On your production environment like the one above this will return C<http://static.example.net/static/foo.png>.
=head3 Development or local environment
Leave everything as it and add a new config file C<myapp_local.yaml> (See L<Catalyst::Plugin::ConfigLoader>) with
the following configuration line:
sysenv local
Now, calling L<CatalystX::UriForStatic/uri_for_static> will return something like
C<http://localhost/static/foo.png> or whatever your local host name is.
=head2 Not perfect in either way
There are plenty of different ways of your specific CDN implementation like not having the same paths for both
systems. While adding a folder name to the C<static_host> configuration is not an issue, removing one from
the local path is. Suggestions are very welcome, as well as patches and so on.
=head2 Installation
To install this module, run the following commands:
perl Build.PL
./Build
./Build test
./Build install
=head2 License and Copyright
Copyright (C) 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 L<http://dev.perl.org/licenses/> for more information.