NAME CGI::AppBuilder::Config - Configuration initializer SYNOPSIS use CGI::AppBuilder::Config; my $cg = CGI::AppBuilder::Config->new( 'ifn', 'my_init.cfg', 'opt', 'vhS:a:'); my $ar = $cg->get_inputs; DESCRIPTION This class provides methods for reading and parsing configuration files. new (ifn => 'file.cfg', opt => 'hvS:') This is a inherited method from CGI::AppBuilder. See the same method in CGI::AppBuilder for more details. get_inputs($ifn, $opt) Input variables: $ifn - input/initial file name. $opt - options for Getopt::Std, for instance 'vhS:a:' Variables used or routines called: None How to use: my $ar = $self->get_inputs('/tmp/my_init.cfg','vhS:'); Return: ($q, $ar) where $q is the CGI object and $ar is a hash array reference containing parameters from web form, or command line and/or configuration file if specified. This method performs the following tasks: 1) create a CGI object 2) get input from CGI web form or command line 3) read initial file if provided 4) merge the two inputs into one hash array This method uses the following rules: 1) All parameters in the initial file can not be changed through command line or web form; 2) The "-S" option in command line can be used to set non-single char parameters in the format of -S k1=value1:k2=value2 3) Single char parameters are included only if they are listed in $opt input variable. Some parameters are dfined automatically: script_name - $ENV{SCRIPT_NAME} url_dn - $ENV{HTTP_HOST} home_url - http://$ENV{HTTP_HOST} HomeLoc - http://$ENV{HTTP_HOST}/ version - $VERSION action - https://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME} encoding - application/x-www-form-urlencoded method - POST read_init_file($fn) Input variables: $fn - full path to a file name Variables used or routines called: Debug::EchoMessage echoMSG - echo messages How to use: my $ar = $self->read_init_file('crop.ini'); Return: a hash array ref This method reads a configuraton file containing parameters in the format of key=values. Multiple lines is allowed for values as long as the lines after the "key=" line are indented as least with two blanks. For instance: width = 80 desc = This is a long description about the value # you can define perl hash araay as well msg = { 101 => "msg 101", 102 => "msg 102" } # you can use variable as well js_var = /my/js/var_file.js js_src = /my/first/js/prg.js,$js_var This will create a hash array of $ar->{width} = 80 $ar->{desc} = "This is a long description about the value" $ar->{msg} = {101=>"msg 101",102=>"msg 102"} $ar->{js_var}= "/my/js/var_file.js"; $ar->{js_src}= "/my/first/js/prg.js,/my/js/var_file.js"; read_cfg_file($fn,$ot, $fs) Input variables: $fn - full path to a file name $ot - output array type: A(array) or H(hash) $fs - field separator, default to vertical bar (|) Variables used or routines called: Debug::EchoMessage echoMSG - display message How to use: my $arf = $self->read_cfg_file('crop.cfg', 'H'); Return: an array or hash array ref containing (${$arf}[$i]{$itm}, ${$arf}[$i][$j]; This method reads a configuraton file containing delimited fields. It looks a line starting with '#CN:' for column names. If it finds the line, it uses to define the first row in the array or use the column names as keys in the hash array. The default output type is A(array). It will read the field names into the first row ([0][0]~[0][n]). If output array type is hash, then it uses the columns name as keys such as ${$arf}[$i]{key}. If it does not find '#CN:' line, it will use 'FD001' ~ 'FD###' as keys. #Form: fm1 #CN: Step|VarName|DispName|Action|Description 0.0|t1|Title||CROP Worksheet HISTORY * Version 0.10 This version extracts these methods from CGI::Getopt class: get_inputs, read_init_file, and read_cfg_file. * Version 0.11 Inherits the new constructor from CGI::AppBuilder. SEE ALSO (some of docs that I check often) Oracle::Loader, Oracle::Trigger, CGI::AppBuilder, File::Xcopy, Debug::EchoMessage AUTHOR Copyright (c) 2005 Hanming Tu. All rights reserved. This package is free software and is provided "as is" without express or implied warranty. It may be used, redistributed and/or modified under the terms of the Perl Artistic License (see http://www.perl.com/perl/misc/Artistic.html)