1CGI::Application::PlugiUns:e:rCoCnofnitgr:i:bSuitCmeGpdIl:eP:(eA3rp)lplDioccautmieonnt:a:tPiloungin::Config::Simple(3)
2
3
4

NAME

6       CGI::Application::Plugin::Config::Simple - Add Config::Simple support
7       to CGI::Application
8

SYNOPSIS

10       in your CGI::Application based module
11
12               use CGI::Application::Plugin::Config::Simple;
13
14           sub cgiapp_init {
15                 my $self = shift;
16                 #set my config file
17                 $self->config_file('myapp.conf');
18
19                 #
20                 #do other stuff
21                 #
22               }
23
24               #later on in a run mode
25               sub run_mode1 {
26                 my $self = shift;
27
28                 #just get a single parameter from my config file
29                 my $value = $self->config_param('my_param');
30
31                 #get a parameter in a block (if using ini style files)
32                 $value = $self->config_param('my_block.my_param');
33
34                 #the entire config hash reference
35                 my $config_vars = $self->config_param();
36
37                 #get my Config::Simple object for direct access
38                 my $config = $self->config;
39               }
40

DESCRIPTION

42       This module acts as a plugin for Config::Simple to be easily used
43       inside of a CGI::Application module. It does not provide every method
44       available from Config::Simple but rather easy access to your
45       configuration variables. It does however provide direct access to the
46       underlying Config::General object created if you want to use it's full
47       power.
48
49       The module tries to make the getting and setting of configuration
50       variables as easy as possible. Only three methods are exported into
51       your CGI::Application module and they are described below.
52
53       Before I wrote this module sometimes I would put my code that read in
54       the configuration file into the cgiapp_init() or cgiapp_prerun()
55       methods but then if I had a run mode that didn't need those config
56       variables it was run anyway. This module helps to solve this is. The
57       Config::Simple object is not created (and the config file is not read
58       and parsed) until after your first call to config() or config_param()
59       to either retrieve/set values, or get the Config::Simple object. This
60       lazy loading idea came from Cees Hek's
61       CGI::Application::Plugin::Session module.
62

METHODS

64   config_param()
65       This method acts as an accessor/mutator for configuration variables
66       coming from the configuration file.
67
68       This method will behave in three different ways depending on how many
69       parameters it is passed. If 0 parameters are passed then the entire
70       config structure will be returned as a hash ref. If 1 parameters is
71       passed then the value of that parameter in the config file will be
72       returned. If more than 1 parameter is passed then it will treat them as
73       name value pairs and will set the parameters in the config file
74       accordingly. In this case, if we successfully set the parameters then a
75       true value will be returned.
76
77               #get the complete config hash
78               my $config_hash = $self->config_param();
79               #just get one config value
80               my $value = $self->config_param($parameter);
81               #set multiple config values
82               my $success = $self->config_param(param1 => $value1, param2 => $value2);
83
84       This method uses Config::Simple so if you are using ini-files then you
85       can set the values of variables inside blocks as well using the '.'
86       notation. See Config::Simple;
87
88       You must set the name of the configuration file either using the
89       config_file() method or the CGIAPP_CONFIG_FILE environment variable
90       before calling this method or it will 'die'.
91
92   config()
93       This method will return the underlying Config::Simple object for more
94       direct use by your application. You must set the name of the
95       configuration file either using the config_file() method or the
96       CGIAPP_CONFIG_FILE environment variable before calling this method or
97       it will 'die'.
98
99               my $conf = $self->config();
100
101   config_file([$file_name])
102       This method acts as an accessor/mutator to either get the name of the
103       current config file or to change/initialize it. This method must be
104       called to initialize the name of the config file before any call can be
105       made to either config() or config_param() unless the
106       'CGIAPP_CONFIG_FILE' environment variable has been set. If this
107       environment variable is set it will be used as the initial value of the
108       config file. This is useful if we are running in a mod_perl environment
109       when can use a statement like this in your httpd.conf file:
110
111               PerlSetEnv  CGIAPP_CONFIG_FILE  /path/to/my/conf
112
113       It is typical to set the name of the config file in the cgiapp_init()
114       phase of your application.
115
116       If a value is passed as a parameter then the config file with that name
117       is used. It will always return the name of the current config file.
118
119               #get the value of the CGIAPP_CONFIG_FILE environment variable (if there is one)
120               #since we haven't set the config file's name with config_file() yet.
121               my $file_name = $self->config_file();
122
123               #set the config file's name
124               $self->config_file('myapp.conf');
125
126               #get the name of the config file
127               $file_name = $self->config_file();
128

CAVEATS

130       The CGI::Application object is implemented as a hash and we store the
131       variables used by this module's methods inside of it as a hash named
132       __CONFIG_SIMPLE. If you use any other CGI::Application plugins there
133       would be problems if they also used $self->{__CONFIG_SIMPLE} but in
134       practice this should never actually happen.
135

AUTHOR

137       Michael Peters <mpeters@plusthree.com>
138
139       Thanks to Plus Three, LP (http://www.plusthree.com) for sponsoring my
140       work on this module
141

SEE ALSO

143       ·       CGI::Application
144
145       ·       Config::Simple
146

LICENSE

148       This library is free software; you can redistribute it and/or modify it
149       under the same terms as Perl itself.
150
151
152
153perl v5.30.0                      20C1G9I-:0:7A-p2p6lication::Plugin::Config::Simple(3)
Impressum