Config::Param

All you want to do with parameters for your program (or someone else's)
Download

Config::Param Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Thomas Orgis
  • Publisher web site:
  • http://thomas.orgis.org/

Config::Param Tags


Config::Param Description

The basic task is to take some description of offered parameters and return a hash ref with values for these parameters, influenced by the command line and/or configuration files. The simple loop from many years ago now is about the most comprehensive solution for a program's param space that I am aware of, while still supporting the one-shot usage via a single function call and a flat description of parameters.Config::Param handles command line parameters (somewhat flexible regarding the number of "-", but insisting on the equal sign in --name=value), defining and handling standard parameters for generating helpful usage messages and parses as well as generates configuration files.command line parameter processingProcess command line options/switches/parameters/... , be it short or long style, supporting clustering of short options. Interprets --parm=value / -p=value with the obvious effect; sets option to 1 (which is true) when just --option / -o is given. Also, though somewhat counterintuitive but sort of a standard already and logically following the idea that "-" is true, ++option / +o will set the value to 0 (false). The form "--parm value" is not supported as no simple bullet-proof generic way to do that came across my mind. There is the fundamental problem of deciding if we have a parameter value or some other command line data like a file name to process. Since this problem still persists with the "=" used in assignment when one considers a file with a name like "--i_look_like_an_option", which is perfectly possible, Param also looks out for "--" as a final delimiter for the named parameter part, which is also quite common behaviour. The command line arguments after "--" stay in the input array (usually @ARGV) and can be used by the calling program. The parsed parameters as well as the optional "--" are removed; so, if you want to retain your @ARGV, just provide a copy.You can have scalars, hashes or arrays (references, of course) as values for your parameters. The hash/array type is chosen when you provide an (anonymous) hash/array reference as default value.Hash values are set via prefixing a key with following "=" before the actual value: --hashpar=name=valueA nifty feature is the support of operators. Instead of --parm=value you can do do --parm.=value to append something to the existing value. When -p is the short form of --parm, the same happens through -p.=value or, saving one character, -p.value (but not --parm.value, here the dot would be considered part of the parameter name). So "--parm=a --parm.=b -p.c" results in the value of parm being "abc".SYNOPSISJust use the module, define your parameters use Config::Param; # the definitions in flat array # remember: parameters help / h and config / I are predefined! my @pardef = ( 'parm1', $default1, 'a', 'help text for scalar 1' ,'parm2', $default2, 'b', 'help text for scalar 2' ,'parmA', \@defaultA, 'A', 'help text for array A' ,'parmH', \@defaultH, 'H', 'help text for hash H' ,'parmX', $defaultX, '', 'help text for last one (scalar)' );and call the parser, $parm_ref = Config::Param::get(@pardef); print "Value of parameter 'parm1': $parm_ref->{parm1}\n"; print "Contents of array 'parmA': @{$parm_ref->{parmA}}\n";possibly including some extra configuration, my %config = ( 'info' => 'program info text', 'version' => '1.2.3' # possibly more configuration key/value pairs ); $parm_ref = Config::Param::get(\%config, @pardef);or $parm_ref = Config::Param::get(\%config,\@pardef); or $parm_ref = Config::Param::get(\%config,\@pardef,\@cmdline_args); The most complicated call is this, making only sense when disabling final exit: $config{noexit} = 1; # or nofinals $parm_ref = Config::Param::get(\%config,\@pardef,\@cmdline_args, $errors); This will return a count of errors encountered (bad setup, bad command line args). With default configuration, the routine would not return on error, but end the program. Errors will be mentioned to STDERR in any case.Finally, you can use a Config::Param object to do what Config::Param::get does: # equivalent to # $parm_ref = Config::Param::get(\%config,\@pardef); my $pars = Config::Param->new(\%config, \@pardef); $pars->parse_args(\@ARGV); $pars->use_config_files(); $pars->apply_args(); $pars->final_action(); $parm_ref = $pars->{param};Product's homepage


Config::Param Related Software