01 Jan 2013 09:21:18 UTC
- Distribution: Config-Cmd
- Module version: 0.002
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (444 / 4 / 0)
- KwaliteeBus factor: 0
- 89.26% Coverage
- License: perl_5
- Perl: v5.6.0
- Activity24 month
- Download (16.46KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionHEIKKI Heikki Lehväslaihoand 1 contributors
- Heikki Lehvaslaiho
- SEE ALSO
- COPYRIGHT AND LICENSE
Config::Cmd - Command line to config file two way interface
# user writes options in a file; configcmd parallel -j 8 --verbose # stored in ./parallel_conf.yaml # same functionality when using the module directly use Config::Cmd; my $conf = Config::Cmd(section => 'parallel'); $conf->set('-j 8 --verbose'); # main application uses the options use Config::Cmd; my $conf = Config::Cmd(section => 'parallel'); my $parallel_opts = $conf->get; # read from ./parallel_conf.yaml # call external program `$exe $parallel_opts @args`;
This module makes it easy to take a set of command line options, store them into a config file, and read them later in for passing to an external program. Part of this distribution is a command line program configcmd for writing these options into a file. The main application can then use this module to automate reading of these options and passing them on.
The options stored by Command::Cmd and its command line tool use single quotes around options with white space, but that can be changed to double quotes if needed by using method quote. Usually you will want stick with single quotes.
The command line program writes into the working directory. The default filename is the section name appended with string '_conf.yaml'. This file can be moved and renamed.
The method filename can be used to set the path where the file is found. This overrides all other potential places. If the filename has not been set, the module uses the section name to find the configuration file from the working directory (./[section]_conf.yaml). If that file is not found, it looks into user's home directory for a file ~/.[section]_conf.yaml.
The obligatory section name for the stored configuration. This string, typically a program name, defines the name of the config file.
Override method that allows user to determine the filename where a config is to be written or read.
Store the command line into a file as YAML. Returns true value on success.
Same as set() but does not report to STDERR.
Get the command line options stored in the file as a string.
The quote character to put around a string with white spaces by method get. Defaults to single quote to make it possible to use double quotes for the whole string. Can be set to any string but you would foolish to set to anything else than single or double quote character.
Heikki Lehvaslaiho <email@example.com>
This software is copyright (c) 2012 by Heikki Lehvaslaiho.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.