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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
|
=head1 NAME
Catalyst::Plugin::ConfigLoader::Manual - Guide to using the ConfigLoader plugin
=head1 BASIC USAGE
package MyApp;
use Catalyst qw( ConfigLoader ... );
=head1 ENVIRONMENT VARIABLES
=over 4
=item * C<MYAPP_CONFIG> - specific config file to load for "MyApp"
=item * C<CATALYST_CONFIG_LOCAL_SUFFIX> - global suffix for extra config files
=item * C<MYAPP_CONFIG_LOCAL_SUFFIX> - suffix specifically for "MyApp"
=back
=head1 CONFIG FORMATS
=head2 Config::General
=head3 Extensions
=over 4
=item * cnf
=item * conf
=back
=head3 Example Config
name = TestApp
<Component Controller::Foo>
foo bar
</Component>
<Model Baz>
qux xyzzy
</Model>
=head2 INI
=head3 Extensions
=over 4
=item * ini
=back
=head3 Example Config
name=TestApp
[Controller::Foo]
foo=bar
[Model::Baz]
qux=xyzzy
=head2 JSON
=head3 Extensions
=over 4
=item * jsn
=item * json
=back
=head3 Example Config
{
"name": "TestApp",
"Controller::Foo": {
"foo": "bar"
},
"Model::Baz": {
"qux": "xyzzy"
}
}
=head2 Perl
=head3 Extensions
=over 4
=item * pl
=item * perl
=back
=head3 Example Config
{
name => 'TestApp',
'Controller::Foo' => {
foo => 'bar'
},
'Model::Baz' => {
qux => 'xyzzy'
}
}
=head2 XML
=head3 Extensions
=over 4
=item * xml
=back
=head3 Example Config
<config>
<name>MyApp::CMS</name>
<paths>
<upload_dir>/var/www/docs/myapp-cms/uploads</upload_dir>
</paths>
<model name="DB">
<connect_info>dbi:mysql:cmsdb</connect_info>
<connect_info>user</connect_info>
<connect_info>password</connect_info>
</model>
<component name="View::TT">
<INCLUDE_PATH>__path_to(root,templates)__</INCLUDE_PATH>
<ENCODING>UTF-8</ENCODING>
<TRIM>1</TRIM>
<PRE_CHOMP>2</PRE_CHOMP>
<POST_CHOMP>2</POST_CHOMP>
</component>
</config>
Note that the name attribute for the C<model> tag should be the relative
namespace of the Catalyst model, not the absolute one. That is for
C<MyApp::Model::Something> the C<name> attribute should be C<Something>.
=head2 YAML
=head3 Extensions
=over 4
=item * yml
=item * yaml
=back
=head3 Example Config
---
name: TestApp
Controller::Foo:
foo: bar
Model::Baz:
qux: xyzzy
=head1 COOKBOOK
=head2 Configuring a Catalyst::Model::DBIC::Schema model from a YAML config
Model::MyModel:
schema_class: MyApp::MySchema
connect_info:
- dbi:SQLite:myapp.db
- ''
- ''
- AutoCommit: 1
=head2 Converting your existing config to Config::General format
As of L<Catalyst::Devel> 1.07, a newly created application will use
L<Config::General> for configuration. If you wish to convert your existing
config, run the following one-liner (replacing MyApp with your app's name):
perl -Ilib -MMyApp -MConfig::General -e 'Config::General->new->save_file("myapp.conf", MyApp->config);'
=head2 Using UTF-8 strings in a Config::General file
If you have UTF-8 strings in your L<Config::General>-based config file, you
should add the following config information to MyApp.pm:
__PACKAGE__->config( 'Plugin::ConfigLoader' => {
driver => {
'General' => { -UTF8 => 1 },
}
} );
=head2 Using a local configuration file
When ConfigLoader reads configurations, it starts by reading the configuration
file for C<myapp> with one of the supported extensions as listed
L<above|/CONFIG FORMATS>.
For example, A L<Config::General> config file is F<myapp.conf>.
If a configuration file called C<myapp_local> exists with one of the supported
file extensions, it will also be read, and values from that file will
override values from the main config file.
A L<Config::General> local configuration file would be called
F<myapp_local.conf>.
The C<local> suffix can be changed. See
L<Catalyst::Plugin::ConfigLoader/get_config_local_suffix> for the details of
how.
This is useful because it allows different people or environments to have
different configuration files. A project with three developers,
I<Tom>, I<Dick>, and I<Harry> as well as a production environment can have
a F<myapp_tom.conf>, a F<myapp_dick.conf>, a F<myapp_harry.conf>, and a
F<myapp_production.conf>.
Each developer, and the web server, would set the environment variable
to load their proper configuration file. All of the configurations can
be stored properly in source control.
If there is no F<myapp_local.ext> (where C<.ext> is a supported extension), and
the individual configuration files contain something required to start the
application, such as the Model's data source definition, the applicaton won't
start unless the environment variable is set properly.
=cut
|