The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

  Application::Config - configuration for applications that makes less work
  

SYNOPSIS

  package Foo;
  
  use Application::Config;
  
  package Some::Other::Package;
  
  my $config = Foo->config;
  

DESCRIPTION

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.

USAGE

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.

WHERE ARE THE CONFIG FILES ON DISK?

Application config looks, in this order, for a config file:

~/.<filename>
./.<filename>
./etc/<filename>
/etc/<filename>

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';
  

INSTALLING THE METHODS INTO ANOTHER PACKAGE

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.

SEE ALSO

Config::Tiny

AUTHOR

James A. Duncan <james@reasonablysmart.com>

Contributions from Scott McWhirter <smcwhirter |AT| joyent {DOT} com>

LICENSE

This module is released under the MIT license