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