• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

lib/Config/H23-Apr-2017-1,165358

maint/H23-Apr-2017-118

t/H23-Apr-2017-900725

xt/author/H23-Apr-2017-1610

ChangesH A D23-Apr-20175.3 KiB150117

MANIFESTH A D23-Apr-20171.2 KiB5554

META.jsonH A D23-Apr-20172 KiB7574

META.ymlH A D23-Apr-2017764 2726

Makefile.PLH A D09-Apr-20173.1 KiB10491

READMEH A D23-Apr-20177.5 KiB174137

README

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