Application::Config - configuration for applications that makes less work
package Foo; use Application::Config; package Some::Other::Package; my $config = Foo->config;
I find myself writing methods that fetch a config file for an application from disk and return it all the time. I come from the small-tools loosely joined school of thought, which means I'm writing little applications all the time. This really sucks. Application::Config solves that problem for me. It might solve it for you. Who knows.
When Application::Config is imported into a package it creates a two class methods for the package. The first, config, returns a Config::Tiny object for the entire config file. The second, pkgconfig, returns a hash reference that contains the part of the config file relevent to the calling package. For example the config file:
foo=bar baz=bash [My::Test::Class] foo=baz
Would result in the config method returning a data structure that looks something like:
{ '_' => { 'foo' => 'bar', 'baz' => 'bash' } 'My::Test::Class' => { 'foo' => 'baz' } }
Calling pkgconfig from the My::Test::Class package would return only the structure under the My::Test::Class key.
My::Test::Class
Application config looks, in this order, for a config file:
The actual filename varies based on the name of the package requiring the Application::Config module. For example the code:
package MyPackage; use Application::Config;
would look for the filename mypackage.conf (or .mypackage.conf in the first instance).
package Another::MyPackage; use Application::Config;
Would look for the same config file. This can be altered by providing an argument to the Application::Config require line:
package Another::MyPackage; use Application::Config 'myconfigfile.conf';
All three of these uses would install the config and pkgconfig methods into the requiring package. If you'd like the methods to be installed somewhere else, you can simply add a second argument to the require line that is the package to install the methods in.
config
pkgconfig
Config::Tiny
James A. Duncan <james@reasonablysmart.com>
Contributions from Scott McWhirter <smcwhirter |AT| joyent {DOT} com>
This module is released under the MIT license
To install Application::Config, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Application::Config
CPAN shell
perl -MCPAN -e shell install Application::Config
For more information on module installation, please visit the detailed CPAN module installation guide.