NAME
Config::Options - Module to provide a configuration hash with option to read from file.
SYNOPSIS
use Config::Options;
my $options = Config::Options->new({ verbose => 1, optionb => 2, mood => "sardonic" });
# Access option as a hash... print "My mode is ", $options->{mood}, "\n";
# Merge a hash of options... $options->options({ optionc => 5, style => "poor"});
# Merge options from file
$options->{optionfile} = $ENV{HOME} . "/.myoptions.conf"; $options->fromfile_perl();
AUTHOR
Edward Allen, ealleniii _at_ cpan _dot_ org
DESCRIPTION
The motivation for this module was to provide an option hash with a little bit of brains. It's pretty simple and used mainly by other modules I have written.
METHODS
- new()
-
my $options = Config::Options->new({hash_of_startup_options});
Create new options hash. Pass it a hash ref to start with. Please note that this reference is copied, not blessed.
- clone()
-
my $newoptions = $options->clone();
Creates a clone of options object.
- options()
-
my $optionsb = $options->options; # Duplicates option file. Not very usefull. $options->options($hashref); # Same as $options->merge($hashref); my $value = $options->options("key") # Return option value. $options->options("key", "value") # Set an option.
This is a utility function for accessing options. If passed a hashref, merges it. If passed a scalar, returns the value. If passed two scalars, sets the option.
- merge()
-
$options->merge($hashref);
Merges values in $hashref and $options.
- deepmerge()
-
$options->deepmerge($hashref);
Same as merge, except when a value is a hash or array reference. For example:
my $options = Config::Options->new({ moods => [ qw(happy sad angry) ] }); $options->deepmerge({ moods => [ qw(sardonic twisted) ] });
print join(" ", @{$options->{moods}}), "\n";
The above outputs:
happy sad angry sardonic twisted
- fromfile_perl()
-
$options->fromfile_perl("/path/to/optionfile");
This is used to store options in a file. The optionfile is actually a perl program that returns a hash. By default uses option 'optionfile' as filename if none is passed.
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 54:
You forgot a '=back' before '=head1'
- Around line 56:
'=item' outside of any '=over'
=over without closing =back