1Catalyst::Plugin::ConfiUgsLeoradCeorn(t3r)ibuted Perl DoCcautmaelnytsatt:i:oPnlugin::ConfigLoader(3)
2
3
4
6 Catalyst::Plugin::ConfigLoader - Load config files of various types
7
9 package MyApp;
10
11 # ConfigLoader should be first in your list so
12 # other plugins can get the config information
13 use Catalyst qw( ConfigLoader ... );
14
15 # by default myapp.* will be loaded
16 # you can specify a file if you'd like
17 __PACKAGE__->config( 'Plugin::ConfigLoader' => { file => 'config.yaml' } );
18
19 In the file, assuming it's in YAML format:
20
21 foo: bar
22
23 Accessible through the context object, or the class itself
24
25 $c->config->{foo} # bar
26 MyApp->config->{foo} # bar
27
29 This module will attempt to load find and load a configuration file of
30 various types. Currently it supports YAML, JSON, XML, INI and Perl
31 formats. Special configuration for a particular driver format can be
32 stored in "MyApp->config->{ 'Plugin::ConfigLoader' }->{ driver }". For
33 example, to pass arguments to Config::General, use the following:
34
35 __PACKAGE__->config( 'Plugin::ConfigLoader' => {
36 driver => {
37 'General' => { -LowerCaseNames => 1 }
38 }
39 } );
40
41 See Config::Any's "driver_args" parameter for more information.
42
43 To support the distinction between development and production
44 environments, this module will also attemp to load a local config (e.g.
45 myapp_local.yaml) which will override any duplicate settings. See
46 "get_config_local_suffix" for details on how this is configured.
47
49 setup( )
50 This method is automatically called by Catalyst's setup routine. It
51 will attempt to use each plugin and, once a file has been successfully
52 loaded, set the config() section.
53
54 load_config
55 This method handles loading the configuration data into the Catalyst
56 context object. It does not return a value.
57
58 find_files
59 This method determines the potential file paths to be used for config
60 loading. It returns an array of paths (up to the filename less the
61 extension) to pass to Config::Any for loading.
62
63 get_config_path
64 This method determines the path, filename prefix and file extension to
65 be used for config loading. It returns the path (up to the filename
66 less the extension) to check and the specific extension to use (if it
67 was specified).
68
69 The order of preference is specified as:
70
71 • $ENV{ MYAPP_CONFIG }
72
73 • $ENV{ CATALYST_CONFIG }
74
75 • "$c->config->{ 'Plugin::ConfigLoader' }->{ file }"
76
77 • "$c->path_to( $application_prefix )"
78
79 If either of the first two user-specified options are directories, the
80 application prefix will be added on to the end of the path.
81
82 get_config_local_suffix
83 Determines the suffix of files used to override the main config. By
84 default this value is "local", which will load "myapp_local.conf". The
85 suffix can be specified in the following order of preference:
86
87 • $ENV{ MYAPP_CONFIG_LOCAL_SUFFIX }
88
89 • $ENV{ CATALYST_CONFIG_LOCAL_SUFFIX }
90
91 • "$c->config->{ 'Plugin::ConfigLoader' }->{ config_local_suffix }"
92
93 The first one of these values found replaces the default of "local" in
94 the name of the local config file to be loaded.
95
96 For example, if $ENV{ MYAPP_CONFIG_LOCAL_SUFFIX } is set to "testing",
97 ConfigLoader will try and load myapp_testing.conf instead of
98 myapp_local.conf.
99
100 finalize_config
101 This method is called after the config file is loaded. It can be used
102 to implement tuning of config values that can only be done at runtime.
103 If you need to do this to properly configure any plugins, it's
104 important to load ConfigLoader before them. ConfigLoader provides a
105 default "finalize_config" method which walks through the loaded config
106 hash and calls the config_substitutions method on any string.
107
108 config_substitutions( $value )
109 This method substitutes macros found with calls to a function. There
110 are a number of default macros:
111
112 • "__HOME__" - replaced with "$c->path_to('')"
113
114 • "__ENV(foo)__" - replaced with the value of $ENV{foo}
115
116 • "__path_to(foo/bar)__" - replaced with "$c->path_to('foo/bar')"
117
118 • "__literal(__FOO__)__" - leaves __FOO__ alone (allows you to use
119 "__DATA__" as a config value, for example)
120
121 The parameter list is split on comma (","). You can override this
122 method to do your own string munging, or you can define your own macros
123 in "MyApp->config->{ 'Plugin::ConfigLoader' }->{ substitutions }".
124 Example:
125
126 MyApp->config->{ 'Plugin::ConfigLoader' }->{ substitutions } = {
127 baz => sub { my $c = shift; qux( @_ ); }
128 }
129
130 The above will respond to "__baz(x,y)__" in config strings.
131
133 Brian Cassidy <bricas@cpan.org>
134
136 The following people have generously donated their time to the
137 development of this module:
138
139 • Joel Bernstein <rataxis@cpan.org> - Rewrite to use Config::Any
140
141 • David Kamholz <dkamholz@cpan.org> - Data::Visitor integration
142
143 • Stuart Watt - Addition of ENV macro.
144
145 Work to this module has been generously sponsored by:
146
147 • Portugal Telecom <http://www.sapo.pt/> - Work done by Joel
148 Bernstein
149
151 Copyright 2006-2010 by Brian Cassidy
152
153 This library is free software; you can redistribute it and/or modify it
154 under the same terms as Perl itself.
155
157 • Catalyst
158
159 • Catalyst::Plugin::ConfigLoader::Manual
160
161 • Config::Any
162
163
164
165perl v5.36.0 2023-01-20 Catalyst::Plugin::ConfigLoader(3)