1Config::Any(3) User Contributed Perl Documentation Config::Any(3)
2
3
4
6 Config::Any - Load configuration from different file formats, transpar‐
7 ently
8
10 This document describes Config::Any version 0.0.8
11
13 use Config::Any;
14
15 my $cfg = Config::Any->load_stems({stems => \@filepath_stems, ... });
16 # or
17 my $cfg = Config::Any->load_files({files => \@filepaths, ... });
18
19 for (@$cfg) {
20 my ($filename, $config) = each %$_;
21 $class->config($config);
22 warn "loaded config from file: $filename";
23 }
24
26 Config::Any provides a facility for Perl applications and libraries to
27 load configuration data from multiple different file formats. It sup‐
28 ports XML, YAML, JSON, Apache-style configuration, Windows INI files,
29 and even Perl code.
30
31 The rationale for this module is as follows: Perl programs are deployed
32 on many different platforms and integrated with many different systems.
33 Systems administrators and end users may prefer different configuration
34 formats than the developers. The flexibility inherent in a multiple
35 format configuration loader allows different users to make different
36 choices, without generating extra work for the developers. As a devel‐
37 oper you only need to learn a single interface to be able to use the
38 power of different configuration formats.
39
41 load_files( )
42
43 Config::Any->load_files({files => \@files});
44 Config::Any->load_files({files => \@files, filter => \&filter});
45 Config::Any->load_files({files => \@files, use_ext => 1});
46
47 "load_files()" attempts to load configuration from the list of files
48 passed in the "files" parameter, if the file exists.
49
50 If the "filter" parameter is set, it is used as a callback to modify
51 the configuration data before it is returned. It will be passed a sin‐
52 gle hash-reference parameter which it should modify in-place.
53
54 If the "use_ext" parameter is defined, the loader will attempt to parse
55 the file extension from each filename and will skip the file unless it
56 matches a standard extension for the loading plugins. Only plugins
57 whose standard extensions match the file extension will be used. For
58 efficiency reasons, its use is encouraged, but be aware that you will
59 lose flexibility -- for example, a file called "myapp.cfg" containing
60 YAML data will not be offered to the YAML plugin, whereas "myapp.yml"
61 or "myapp.yaml" would be.
62
63 "load_files()" also supports a 'force_plugins' parameter, whose value
64 should be an arrayref of plugin names like "Config::Any::INI". Its
65 intended use is to allow the use of a non-standard file extension while
66 forcing it to be offered to a particular parser. It is not compatible
67 with 'use_ext'.
68
69 You can supply a "driver_args" hashref to pass special options to a
70 particular parser object. Example:
71
72 Config::Any->load_files( { files => \@files, driver_args => {
73 General => { -LowerCaseNames => 1 }
74 } )
75
76 load_stems( )
77
78 Config::Any->load_stems({stems => \@stems]});
79 Config::Any->load_stems({stems => \@stems, filter => \&filter});
80 Config::Any->load_stems({stems => \@stems, use_ext => 1});
81
82 "load_stems()" attempts to load configuration from a list of files
83 which it generates by combining the filename stems list passed in the
84 "stems" parameter with the potential filename extensions from each
85 loader, which you can check with the "extensions()" classmethod
86 described below. Once this list of possible filenames is built it is
87 treated exactly as in "load_files()" above, as which it takes the same
88 parameters. Please read the "load_files()" documentation before using
89 this method.
90
91 finder( )
92
93 The "finder()" classmethod returns the Module::Pluggable::Object object
94 which is used to load the plugins. See the documentation for that mod‐
95 ule for more information.
96
97 plugins( )
98
99 The "plugins()" classmethod returns the names of configuration loading
100 plugins as found by Module::Pluggable::Object.
101
102 extensions( )
103
104 The "extensions()" classmethod returns the possible file extensions
105 which can be loaded by "load_stems()" and "load_files()". This may be
106 useful if you set the "use_ext" parameter to those methods.
107
109 "no files specified" or "no stems specified"
110 The "load_files()" and "load_stems()" methods will issue this warn‐
111 ing if called with an empty list of files/stems to load.
112
113 "_load requires a arrayref of file paths"
114 This fatal error will be thrown by the internal "_load" method. It
115 should not occur but is specified here for completeness. If your
116 code dies with this error, please email a failing test case to the
117 authors below.
118
120 Config::Any requires no configuration files or environment variables.
121
123 Module::Pluggable
124
125 And at least one of the following: Config::General Config::Tiny JSON
126 YAML JSON::Syck YAML::Syck XML::Simple
127
129 None reported.
130
132 No bugs have been reported.
133
134 Please report any bugs or feature requests to "bug-con‐
135 fig-any@rt.cpan.org", or through the web interface at
136 <http://rt.cpan.org>.
137
139 Joel Bernstein <rataxis@cpan.org>
140
142 This module was based on the original Catalyst::Plugin::ConfigLoader
143 module by Brian Cassidy "<bricas@cpan.org>".
144
145 With ideas and support from Matt S Trout "<mst@shadowcatsys‐
146 tems.co.uk>".
147
148 Further enhancements suggested by Evan Kaufman "<evank@cpan.org>".
149
151 Copyright (c) 2006, Portugal Telecom "http://www.sapo.pt/". All rights
152 reserved. Portions copyright 2007, Joel Bernstein
153 "<rataxis@cpan.org>".
154
155 This module is free software; you can redistribute it and/or modify it
156 under the same terms as Perl itself. See perlartistic.
157
159 BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
160 FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
161 WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
162 PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND,
163 EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
164 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
165 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
166 YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
167 NECESSARY SERVICING, REPAIR, OR CORRECTION.
168
169 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
170 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
171 REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE
172 TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CON‐
173 SEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFT‐
174 WARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
175 INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF
176 THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER
177 OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
178
180 Catalyst::Plugin::ConfigLoader -- now a wrapper around this module.
181
182
183
184perl v5.8.8 2007-08-23 Config::Any(3)