NAME

OpenPlugin::Config - Plugin for reading and writing config data

SYNOPSIS

# Load in the config file config.conf
my $OP = OpenPlugin->new( config => { src    => '/path/to/config.conf' });

# Pass in the config file type as an argument
my $OP = OpenPlugin->new( config => { src    => '/etc/config',
                                      type   => 'conf' });

# Pass in the configuration data as an argument
my $OP = OpenPlugin->new( config => { config => \%config_data });

# Retrieve settings which have been loaded by any of the above methods
$username = $OP->config->{datasource}{main}{username};
$session_config = $OP->config->{plugin}{session};

DESCRIPTION

A configuration file is a method of providing a predefined set of data to an application. Represented as an Apache-style conf file, it might look like:

<Section>
   <one>
       key     = value
       another = value-another
   </one>
   <two>
       key     = value-two
       another = value-another-two
   </two>
</Section>

This plugin's job is to accept a config file, and make it available for programs to access. Reading in and using the above file would look like:

my $OP = OpenPlugin->new( config => { src => 'sample_config.conf' } );
print $OP->config->{'Section'}{'one'}{'key'};     # print's "value"
print $OP->config->{'Section'}{'two'}{'another'}; # print's "value-another-two"

The driver used to read the file is based on the file's extension. If your config file has a .conf extension, the conf driver will be used. If this isn't what you want, you can pass in an explicit "type" as a parameter to tell the Config plugin what driver to use.

METHODS

read( [ $source, ... ])

This function is used to load a configuration. This can be done by passing in a file, or a hash reference containing the data.

It is called for you when you instanciate a new OpenPlugin object.

Returns: config object.

write( $destination )

Writes the current configuration data out to $destination.

Returns: true if configuration written successfully, false if not.

meta_config_dir()

Returns: the directory from which your configuration was read.

meta_config_file()

Returns: the filename from which your configuration was read.

sections()

Return a list of the top-level sections in the configuration. In the future this may include sub-sections as well.

get( $section, $param )

get( $section, $sub_section, $param )

Returns: the value for $param in either $section or $section and $sub_section if $sub_section is specified.

set( $section, $param, $value )

set( $section, $sub_section, $param, $value )

Sets the parameter $param to value $value in either $section or $section and $sub_section if $sub_section is specified.

Returns: the value set.

delete( $section )

delete( $section, $param )

delete( $section, $sub_section )

delete( $section, $sub_section, $param )

Deletes the $section, a parameter in $section, $sub_section of $section or a parameter in $sub_section of $section.

Returns: whatever was deleted.

get_config_driver( $config_src [, $config_type ] )

Retrieves the driver used for a particular configuration source. Generally we can tell what type of driver is necessary from the file extension, but you can force a type by passing in the optional second argument.

Returns: class matching the configuration type. If the config type is unknown, returns undef.

BUGS

None known.

TO DO

Currently, you can include at most one file. Parts of the Config plugin, particularly the include logic, should be rewritten to be a bit more flexible (such as to handle more than one included file, etc). One way to do this might be to use Hash::Merge.

SEE ALSO

See the individual driver documentation for settings and parameters specific to that driver.

COPYRIGHT

Copyright (c) 2001-2003 Eric Andreychek. All rights reserved.

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

AUTHORS

Eric Andreychek <eric@openthought.net>

Chris Winters <chris@cwinters.com>