.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "CGI::Application::Plugin::ConfigAuto 3pm" .TH CGI::Application::Plugin::ConfigAuto 3pm "2021-01-05" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" CGI::Application::Plugin::ConfigAuto \- Easy config file management for CGI::Application .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use CGI::Application::Plugin::ConfigAuto (qw/cfg/); .Ve .PP In your instance script: .PP .Vb 2 \& my $app = WebApp\->new(PARAMS => { cfg_file => \*(Aqconfig.pl\*(Aq }); \& $app\->run(); .Ve .PP In your application module: .PP .Vb 2 \& sub my_run_mode { \& my $self = shift; \& \& # Access a config hash key directly \& $self\->cfg(\*(Aqfield\*(Aq); \& \& # Return config as hash \& %CFG = $self\->cfg; \& \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" CGI::Application::Plugin::ConfigAuto adds easy access to config file variables to your CGI::Application modules. Lazy loading is used to prevent the config file from being parsed if no configuration variables are accessed during the request. In other words, the config file is not parsed until it is actually needed. The Config::Auto package provides the framework for this plugin. .SH "RATIONALE" .IX Header "RATIONALE" \&\f(CW\*(C`CGI::Application\*(C'\fR promotes re-usable applications by moving a maximal amount of code into modules. For an application to be fully re-usable without code changes, it is also necessary to store configuration variables in a separate file. .PP This plugin supports multiple config files for a single application, allowing config files to override each other in a particular order. This covers even complex cases, where you have a global config file, and second local config file which overrides a few variables. .PP It is recommended that you to declare your config file locations in the instance scripts, where it will have minimum impact on your application. This technique is ideal when you intend to reuse your module to support multiple configuration files. If you have an application with multiple instance scripts which share a single config file, you may prefer to call the plugin from the \&\fBsetup()\fR method. .SH "DECLARING CONFIG FILE LOCATIONS" .IX Header "DECLARING CONFIG FILE LOCATIONS" .Vb 3 \& # In your instance script \& # value can also be an arrayref of config files \& my $app = WebApp\->new(PARAMS => { cfg_file => \*(Aqconfig.pl\*(Aq }) \& \& # OR ... \& \& # Pass in an array of config files, and they will be processed in order. \& $app\->cfg_file(\*(Aq../../config/config.pl\*(Aq); .Ve .PP Your config files should be referenced using the syntax example above. Note that the key \f(CW\*(C`config_files\*(C'\fR can be used as alternative to cfg_file. .PP The format is detected automatically using Config::Auto. It it known to support the following formats: colon separated, space separated, equals separated, \s-1XML,\s0 Perl code, and Windows \s-1INI.\s0 See that modules documentation for complete details. .SH "METHODS" .IX Header "METHODS" .SS "\fBcfg()\fP" .IX Subsection "cfg()" .Vb 2 \& # Access a config hash key directly \& $self\->cfg(\*(Aqfield\*(Aq); \& \& # Return config as hash \& my %CFG = $self\->cfg; \& \& # return as hashref \& my $cfg_href = $self\->cfg; .Ve .PP A method to access project configuration variables. The config file is parsed on the first call with a perl hash representation stored in memory. Subsequent calls will use this version, rather than re-reading the file. .PP In list context, it returns the configuration data as a hash. In scalar context, it returns the configuration data as a hashref. .SS "\fBconfig()\fP" .IX Subsection "config()" \&\*(L"\fBconfig()\fR\*(R" in CGI::Application::Standard::Config is provided as an alias to \fBcfg()\fR for compliance with CGI::Application::Standard::Config. It always exported by default per the standard. .SS "\fBstd_config()\fP" .IX Subsection "std_config()" \&\*(L"\fBstd_config()\fR\*(R" in CGI::Application::Standard::Config is implemented to comply with CGI::Application::Standard::Config. It's for developers. Users can ignore it. .SS "\fBcfg_file()\fP" .IX Subsection "cfg_file()" .Vb 2 \& # Usual \& $self\->cfg_file(\*(Aqmy_config_file.pl\*(Aq); \& \& # Supply the first format, guess the second \& $self\->cfg_file(\*(Aqmy_config_file.pl\*(Aq,{ format => \*(Aqperl\*(Aq } ); .Ve .PP Supply an array of config files, and they will be processed in order. If a hash reference if found it, will be used to supply the format for the previous file in the array. .SH "FILE FORMAT HINTS" .IX Header "FILE FORMAT HINTS" .SS "Perl" .IX Subsection "Perl" Here's a simple example of my favorite config file format: Perl. Having the \*(L"shebang\*(R" line at the top helps \f(CW\*(C`Config::Auto\*(C'\fR to identify it as a Perl file. Also, be sure that your last statement returns a hash reference. .PP .Vb 1 \& #!/usr/bin/perl \& \& my %CFG = (); \& \& # directory path name \& $CFG{DIR} = \*(Aq/home/mark/www\*(Aq; \& \& # website URL \& $CFG{URL} = \*(Aqhttp://mark.stosberg.com/\*(Aq; \& \& \e%CFG; .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" CGI::Application CGI::Application::Plugin::ValidateRM CGI::Application::Plugin::DBH CGI::Application::Standard::Config. \&\fBperl\fR\|(1) .SH "AUTHOR" .IX Header "AUTHOR" Mark Stosberg \f(CW\*(C`mark@summersault.com\*(C'\fR .SH "LICENSE" .IX Header "LICENSE" Copyright (C) 2004 \- 2011 Mark Stosberg \f(CW\*(C`mark@summersault.com\*(C'\fR .PP This library is free software. You can modify and or distribute it under the same terms as Perl itself.