1CGI::Application::PlugiUns:e:rCoCnofnitgrAiubtuot(e3d)PCeGrIl::DAopcpulmiecnattaitoino:n:Plugin::ConfigAuto(3)
2
3
4

NAME

6       CGI::Application::Plugin::ConfigAuto - Easy config file management for
7       CGI::Application
8

SYNOPSIS

10        use CGI::Application::Plugin::ConfigAuto (qw/cfg/);
11
12       In your instance script:
13
14        my $app = WebApp->new(PARAMS => { cfg_file => 'config.pl' });
15        $app->run();
16
17       In your application module:
18
19        sub my_run_mode {
20           my $self = shift;
21
22           # Access a config hash key directly
23           $self->cfg('field');
24
25           # Return config as hash
26           %CFG = $self->cfg;
27
28        }
29

DESCRIPTION

31       CGI::Application::Plugin::ConfigAuto adds easy access to config file
32       variables to your CGI::Application modules.  Lazy loading is used to
33       prevent the config file from being parsed if no configuration variables
34       are accessed during the request.  In other words, the config file is
35       not parsed until it is actually needed. The Config::Auto package
36       provides the framework for this plugin.
37

RATIONALE

39       "CGI::Application" promotes re-usable applications by moving a maximal
40       amount of code into modules. For an application to be fully re-usable
41       without code changes, it is also necessary to store configuration
42       variables in a separate file.
43
44       This plugin supports multiple config files for a single application,
45       allowing config files to override each other in a particular order.
46       This covers even complex cases, where you have a global config file,
47       and second local config file which overrides a few variables.
48
49       It is recommended that you to declare your config file locations in the
50       instance scripts, where it will have minimum impact on your
51       application. This technique is ideal when you intend to reuse your
52       module to support multiple configuration files. If you have an
53       application with multiple instance scripts which share a single config
54       file, you may prefer to call the plugin from the setup() method.
55

DECLARING CONFIG FILE LOCATIONS

57        # In your instance script
58        # value can also be an arrayref of config files
59        my $app = WebApp->new(PARAMS => { cfg_file => 'config.pl' })
60
61        # OR ...
62
63        # Pass in an array of config files, and they will be processed in order.
64        $app->cfg_file('../../config/config.pl');
65
66       Your config files should be referenced using the syntax example above.
67       Note that the key "config_files" can be used as alternative to
68       cfg_file.
69
70       The format is detected automatically using Config::Auto. It it known to
71       support the following formats: colon separated, space separated, equals
72       separated, XML, Perl code, and Windows INI. See that modules
73       documentation for complete details.
74

METHODS

76   cfg()
77        # Access a config hash key directly
78        $self->cfg('field');
79
80        # Return config as hash
81        my %CFG = $self->cfg;
82
83        # return as hashref
84        my $cfg_href = $self->cfg;
85
86       A method to access project configuration variables. The config file is
87       parsed on the first call with a perl hash representation stored in
88       memory.  Subsequent calls will use this version, rather than re-reading
89       the file.
90
91       In list context, it returns the configuration data as a hash.  In
92       scalar context, it returns the configuration data as a hashref.
93
94   config()
95       "config()" in CGI::Application::Standard::Config is provided as an
96       alias to cfg() for compliance with CGI::Application::Standard::Config.
97       It always exported by default per the standard.
98
99   std_config()
100       "std_config()" in CGI::Application::Standard::Config is implemented to
101       comply with CGI::Application::Standard::Config. It's for developers.
102       Users can ignore it.
103
104   cfg_file()
105        # Usual
106        $self->cfg_file('my_config_file.pl');
107
108        # Supply the first format, guess the second
109        $self->cfg_file('my_config_file.pl',{ format => 'perl' } );
110
111       Supply an array of config files, and they will be processed in order.
112       If a hash reference if found it, will be used to supply the format for
113       the previous file in the array.
114

FILE FORMAT HINTS

116   Perl
117       Here's a simple example of my favorite config file format: Perl.
118       Having the "shebang" line at the top helps "Config::Auto" to identify
119       it as a Perl file. Also, be sure that your last statement returns a
120       hash reference.
121
122           #!/usr/bin/perl
123
124           my %CFG = ();
125
126           # directory path name
127           $CFG{DIR} = '/home/mark/www';
128
129           # website URL
130           $CFG{URL} = 'http://mark.stosberg.com/';
131
132           \%CFG;
133

SEE ALSO

135       CGI::Application CGI::Application::Plugin::ValidateRM
136       CGI::Application::Plugin::DBH CGI::Application::Standard::Config.
137       perl(1)
138

AUTHOR

140       Mark Stosberg "mark@summersault.com"
141

LICENSE

143       Copyright (C) 2004 - 2011 Mark Stosberg "mark@summersault.com"
144
145       This library is free software. You can modify and or distribute it
146       under the same terms as Perl itself.
147
148
149
150perl v5.34.0                      2021-0C7G-I2:2:Application::Plugin::ConfigAuto(3)
Impressum