1Config::Any(3)        User Contributed Perl Documentation       Config::Any(3)
2
3
4

NAME

6       Config::Any - Load configuration from different file formats,
7       transparently
8

SYNOPSIS

10           use Config::Any;
11
12           my $cfg = Config::Any->load_stems({stems => \@filepath_stems, ... });
13           # or
14           my $cfg = Config::Any->load_files({files => \@filepaths, ... });
15
16           for (@$cfg) {
17               my ($filename, $config) = %$_;
18               $class->config($config);
19               warn "loaded config from file: $filename";
20           }
21

DESCRIPTION

23       Config::Any provides a facility for Perl applications and libraries to
24       load configuration data from multiple different file formats. It
25       supports XML, YAML, JSON, Apache-style configuration, Windows INI
26       files, and even Perl code.
27
28       The rationale for this module is as follows: Perl programs are deployed
29       on many different platforms and integrated with many different systems.
30       Systems administrators and end users may prefer different configuration
31       formats than the developers. The flexibility inherent in a multiple
32       format configuration loader allows different users to make different
33       choices, without generating extra work for the developers. As a
34       developer you only need to learn a single interface to be able to use
35       the power of different configuration formats.
36

INTERFACE

38   load_files( \%args )
39           Config::Any->load_files( { files => \@files } );
40           Config::Any->load_files( { files => \@files, filter  => \&filter } );
41           Config::Any->load_files( { files => \@files, use_ext => 1 } );
42           Config::Any->load_files( { files => \@files, flatten_to_hash => 1 } );
43
44       "load_files()" attempts to load configuration from the list of files
45       passed in the "files" parameter, if the file exists.
46
47       If the "filter" parameter is set, it is used as a callback to modify
48       the configuration data before it is returned. It will be passed a
49       single hash-reference parameter which it should modify in-place.
50
51       If the "use_ext" parameter is defined, the loader will attempt to parse
52       the file extension from each filename and will skip the file unless it
53       matches a standard extension for the loading plugins. Only plugins
54       whose standard extensions match the file extension will be used. For
55       efficiency reasons, its use is encouraged, but be aware that you will
56       lose flexibility -- for example, a file called "myapp.cfg" containing
57       YAML data will not be offered to the YAML plugin, whereas "myapp.yml"
58       or "myapp.yaml" would be.
59
60       When the "flatten_to_hash" parameter is defined, the loader will return
61       a hash keyed on the file names, as opposed to the usual list of single-
62       key hashes.
63
64       "load_files()" also supports a 'force_plugins' parameter, whose value
65       should be an arrayref of plugin names like "Config::Any::INI". Its
66       intended use is to allow the use of a non-standard file extension while
67       forcing it to be offered to a particular parser.  It is not compatible
68       with 'use_ext'.
69
70       You can supply a "driver_args" hashref to pass special options to a
71       particular parser object. Example:
72
73           Config::Any->load_files( { files => \@files, driver_args => {
74               General => { -LowerCaseNames => 1 }
75           } )
76
77   load_stems( \%args )
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           Config::Any->load_stems( { stems => \@stems, flatten_to_hash => 1 } );
82
83       "load_stems()" attempts to load configuration from a list of files
84       which it generates by combining the filename stems list passed in the
85       "stems" parameter with the potential filename extensions from each
86       loader, which you can check with the "extensions()" classmethod
87       described below. Once this list of possible filenames is built it is
88       treated exactly as in "load_files()" above, as which it takes the same
89       parameters. Please read the "load_files()" documentation before using
90       this method.
91
92   finder( )
93       The "finder()" classmethod returns the Module::Pluggable::Object object
94       which is used to load the plugins. See the documentation for that
95       module for more information.
96
97   plugins( )
98       The "plugins()" classmethod returns the names of configuration loading
99       plugins as found by Module::Pluggable::Object.
100
101   extensions( )
102       The "extensions()" classmethod returns the possible file extensions
103       which can be loaded by "load_stems()" and "load_files()". This may be
104       useful if you set the "use_ext" parameter to those methods.
105

DIAGNOSTICS

107       "No files specified!" or "No stems specified!"
108           The "load_files()" and "load_stems()" methods will issue this
109           warning if called with an empty list of files/stems to load.
110
111       "_load requires a arrayref of file paths"
112           This fatal error will be thrown by the internal "_load" method. It
113           should not occur but is specified here for completeness. If your
114           code dies with this error, please email a failing test case to the
115           authors below.
116

CONFIGURATION AND ENVIRONMENT

118       Config::Any requires no configuration files or environment variables.
119

DEPENDENCIES

121       Module::Pluggable::Object
122
123       And at least one of the following: Config::General Config::Tiny JSON
124       YAML JSON::Syck YAML::Syck XML::Simple
125

INCOMPATIBILITIES

127       None reported.
128

BUGS AND LIMITATIONS

130       No bugs have been reported.
131
132       Please report any bugs or feature requests to
133       "bug-config-any@rt.cpan.org", or through the web interface at
134       <https://rt.cpan.org/Public/Dist/Display.html?Name=Config-Any>.
135

AUTHOR

137       Joel Bernstein <rataxis@cpan.org>
138

CONTRIBUTORS

140       This module was based on the original Catalyst::Plugin::ConfigLoader
141       module by Brian Cassidy "<bricas@cpan.org>".
142
143       With ideas and support from Matt S Trout
144       "<mst@shadowcatsystems.co.uk>".
145
146       Further enhancements suggested by Evan Kaufman "<evank@cpan.org>".
147
149       Copyright (c) 2006, Portugal Telecom "http://www.sapo.pt/". All rights
150       reserved.  Portions copyright 2007, Joel Bernstein
151       "<rataxis@cpan.org>".
152
153       This module is free software; you can redistribute it and/or modify it
154       under the same terms as Perl itself. See perlartistic.
155

DISCLAIMER OF WARRANTY

157       BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
158       FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
159       WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
160       PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND,
161       EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
162       WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
163       ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
164       YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
165       NECESSARY SERVICING, REPAIR, OR CORRECTION.
166
167       IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
168       WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
169       REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE
170       TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR
171       CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
172       SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
173       RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
174       FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
175       SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
176       DAMAGES.
177

SEE ALSO

179       Catalyst::Plugin::ConfigLoader -- now a wrapper around this module.
180
181
182
183perl v5.32.1                      2021-01-27                    Config::Any(3)
Impressum