Config::Any(3)

πŸ’… Config::Any πŸ’…

okay bestie, so this is the manual for Config::Any β€” a Perl module that loads your config from like, any file format, transparently ✨ (yes, that's literally the whole point, and honestly? iconic.)


🌸 NAME 🌸

Config::Any β€” load configuration from different file formats, transparently 🫢


✨ SYNOPSIS ✨

use Config::Any;

my $cfg = Config::Any->load_stems({stems => \@filepath_stems, ... });
# or
my $cfg = Config::Any->load_files({files => \@filepaths, ... });

for (@$cfg) {
    my ($filename, $config) = %$_;
    $class->config($config);
    warn "loaded config from file: $filename";
}

like, that's the whole vibe check right there πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

So Config::Any gives Perl apps and libraries a way to load config data from a bunch of different file formats. It's giving versatility bestie β€” it supports XML, YAML, JSON, Apache-style configuration, Windows INI files, and even Perl code πŸ‘‘

The rationale (yes, we're using big words today) is this: Perl programs get deployed on so many different platforms and integrated with so many different systems. System administrators and end users might prefer totally different configuration formats than the developers do. That flexibility β€” having a multiple-format config loader β€” lets different users make different choices without generating extra work for the developers. As a developer you only need to learn one single interface to unlock the power of all the different configuration formats. ate. πŸ’…


πŸ”₯ INTERFACE πŸ”₯

πŸ’œ load_files( \%args )

Config::Any->load_files( { files => \@files } );
Config::Any->load_files( { files => \@files, filter  => \&filter } );
Config::Any->load_files( { files => \@files, use_ext => 1 } );
Config::Any->load_files( { files => \@files, flatten_to_hash => 1 } );

load_files() tries to load configuration from the list of files you pass in the files parameter β€” but only if the file exists, no cap 🫢

If you set the filter parameter, it gets used as a callback to modify the configuration data before it's returned. It'll be passed a single hash-reference parameter, and it should modify that thing in-place. lowkey important: in-place.

If the use_ext parameter is defined, the loader will try to parse the file extension from each filename, and it'll skip the file unless that extension matches a standard extension for the loading plugins. Only plugins whose standard extensions match the file extension will be used. For efficiency reasons its use is encouraged ✨ β€” but bestie, be aware you'll lose flexibility. Example: a file called myapp.cfg containing YAML data will not be offered to the YAML plugin, whereas myapp.yml or myapp.yaml would be. πŸ’€

When the flatten_to_hash parameter is defined, the loader returns a hash keyed on the file names, instead of the usual list of single-key hashes. πŸŽ€

load_files() also supports a 'force_plugins' parameter, whose value should be an arrayref of plugin names like Config::Any::INI. Its intended use is to let you use a non-standard file extension while forcing it to be offered to a particular parser. Heads up though: it is not compatible with 'use_ext'. πŸ™ˆ

You can also supply a driver_args hashref to pass special options to a particular parser object. Example, slay:

Config::Any->load_files( { files => \@files, driver_args => {
    General => { -LowerCaseNames => 1 }
} )

🌈 load_stems( \%args )

Config::Any->load_stems( { stems => \@stems } );
Config::Any->load_stems( { stems => \@stems, filter  => \&filter } );
Config::Any->load_stems( { stems => \@stems, use_ext => 1 } );
Config::Any->load_stems( { stems => \@stems, flatten_to_hash => 1 } );

load_stems() tries to load configuration from a list of files that it generates by combining the filename stems list you pass in the stems parameter with the potential filename extensions from each loader β€” you can check those with the extensions() classmethod described below, iykyk. Once this list of possible filenames is built, it's treated exactly as in load_files() above, and it takes the same parameters. So please, bestie, read the load_files() documentation before using this method 🫢

πŸ’– finder( )

The finder() classmethod returns the Module::Pluggable::Object object which is used to load the plugins. See the documentation for that module for more info ✨

⭐ plugins( )

The plugins() classmethod returns the names of the configuration loading plugins as found by Module::Pluggable::Object.

🧚 extensions( )

The extensions() classmethod returns the possible file extensions which can be loaded by load_stems() and load_files(). This may be useful if you set the use_ext parameter to those methods. πŸ‘‘


πŸ’€ DIAGNOSTICS πŸ’€

  • "No files specified!" or "No stems specified!" β€” the load_files() and load_stems() methods will issue this warning if they're called with an empty list of files/stems to load. 😭
  • "_load requires a arrayref of file paths" β€” this fatal error will be thrown by the internal _load method. It should not occur, but it's specified here for completeness. If your code dies with this error, please email a failing test case to the authors below. 🫢

πŸ“ CONFIGURATION AND ENVIRONMENT πŸ“

Config::Any requires no configuration files or environment variables. literally none. we love a low-maintenance queen πŸ’…


🌸 DEPENDENCIES 🌸

Module::Pluggable::Object

And at least one of the following for each file type you want supported:

  • For .cnf, .conf files: Config::General
  • For .ini files: Config::Tiny
  • For .json, .jsn files: Cpanel::JSON::XS, JSON::MaybeXS, JSON::DWIW, JSON::XS, JSON::Syck, JSON::PP, JSON
  • For .pl, .perl files: no additional requirements ✨ (iconic)
  • For .xml files: XML::Simple
  • For .yml, .yaml files: YAML::XS, YAML::Syck, YAML

Additionally, other file types are supported by third-party plugins in the Config::Any:: namespace, installed separately. the community ate that 🫢


πŸ™ˆ BUGS AND LIMITATIONS πŸ™ˆ

Please report any bugs or feature requests to bug-config-any@rt.cpan.org, or through the web interface at <https://rt.cpan.org/Public/Dist/Display.html?Name=Config-Any>.


πŸ‘‘ AUTHOR πŸ‘‘

Joel Bernstein <rataxis@cpan.org>


πŸ’œ CONTRIBUTORS πŸ’œ

This module was based on the original Catalyst::Plugin::ConfigLoader module by Brian Cassidy <bricas@cpan.org". typo-era king, we respect it

With ideas and support from Matt S Trout <mst@shadowcatsystems.co.uk>.

Further enhancements suggested by Evan Kaufman <evank@cpan.org>.


Copyright (c) 2006, Portugal Telecom http://www.sapo.pt/. All rights reserved. Portions copyright 2007, Joel Bernstein <rataxis@cpan.org>.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.


πŸ”₯ DISCLAIMER OF WARRANTY πŸ”₯

okay bestie this next part is in ALL CAPS on purpose, it's giving legal drama, but I promise every word matters πŸ’€

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 😭


⭐ SEE ALSO ⭐

Catalyst::Plugin::ConfigLoader β€” now a wrapper around this module.


and that's the whole page bestie 🫢 this one's from perl v5.42.0, dated 2023-05-04 β€” go load some config, you've got this πŸ’–βœ¨

πŸ“¦ where this page comes from