Catalyst::Plugin::ConfigLoader::Manual - Guide to using the ConfigLoader plugin
Contents
Basic Usage
package MyApp;
use Catalyst qw( ConfigLoader ... );
Config Formats
Config::GeneralExtensions
• cnf
• conf
ExampleConfig
name = TestApp
<Component Controller::Foo>
foo bar
</Component>
<Model Baz>
qux xyzzy
</Model>
INIExtensions
• ini
ExampleConfig
name=TestApp
[Controller::Foo]
foo=bar
[Model::Baz]
qux=xyzzy
JSONExtensions
• jsn
• json
ExampleConfig
{
"name": "TestApp",
"Controller::Foo": {
"foo": "bar"
},
"Model::Baz": {
"qux": "xyzzy"
}
}
PerlExtensions
• pl
• perl
ExampleConfig
{
name => 'TestApp',
'Controller::Foo' => {
foo => 'bar'
},
'Model::Baz' => {
qux => 'xyzzy'
}
}
XMLExtensions
• xml
ExampleConfig
<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 "model" tag should be the relative namespace of the Catalyst model,
not the absolute one. That is for "MyApp::Model::Something" the "name" attribute should be "Something".
YAMLExtensions
• yml
• yaml
ExampleConfig
---
name: TestApp
Controller::Foo:
foo: bar
Model::Baz:
qux: xyzzy
Cookbook
ConfiguringaCatalyst::Model::DBIC::SchemamodelfromaYAMLconfig
Model::MyModel:
schema_class: MyApp::MySchema
connect_info:
- dbi:SQLite:myapp.db
- ''
- ''
- AutoCommit: 1
ConvertingyourexistingconfigtoConfig::Generalformat
As of Catalyst::Devel 1.07, a newly created application will use 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);'
UsingUTF-8stringsinaConfig::Generalfile
If you have UTF-8 strings in your Config::General-based config file, you should add the following config
information to MyApp.pm:
__PACKAGE__->config( 'Plugin::ConfigLoader' => {
driver => {
'General' => { -UTF8 => 1 },
}
} );
Usingalocalconfigurationfile
When ConfigLoader reads configurations, it starts by reading the configuration file for "myapp" with one
of the supported extensions as listed above.
For example, A Config::General config file is myapp.conf.
If a configuration file called "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 Config::General local configuration file would be called myapp_local.conf.
The "local" suffix can be changed. See "get_config_local_suffix" in Catalyst::Plugin::ConfigLoader 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, Tom, Dick, and Harry as well as a production environment can have a
myapp_tom.conf, a myapp_dick.conf, a myapp_harry.conf, and a 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 myapp_local.ext (where ".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.
perl v5.30.3 2020-07-30 Catalyst::Plugi...gLoader::Manual(3pm)
Environment Variables
• "MYAPP_CONFIG" - specific config file to load for "MyApp"
• "CATALYST_CONFIG_LOCAL_SUFFIX" - global suffix for extra config files
• "MYAPP_CONFIG_LOCAL_SUFFIX" - suffix specifically for "MyApp"
Name
Catalyst::Plugin::ConfigLoader::Manual - Guide to using the ConfigLoader plugin
