Pgreet::Config - Configuration object for Penguin Greetings.
# Bootstrap Initialization: $Pg_config = new Pgreet::Config($config_file); $Pg_config->add_error_obj($Pg_error);
# Normal Initialization: $Pg_config = new Pgreet::Config($config_file, $Pg_error, $Pg_default_config ); # Access methods: $Pg_config->access('config_parameter'); $Pg_config->access('config_parameter', $Value_to_set_parameter_to); $Pg_config->get_hash(); $Pg_config->put_hash($new_hash);
# Other Misc. methods: $Pg_default_config->is_valid_site($site); $Pg_default_config->expand_config_file($site); $card_conf->scalar_to_array(); $results = $Pg_config->chk_params();
The module Pgreet::Config
is the Penguin
Greetings interface to configuration information. It, in turn,
uses the CPAN module the
Config::General manpage to actually access the
configuration files. This module provides methods to maintain
the configuration of the parameters needed to operate the
Penguin Greetings applications, the configuration of primary
and secondary sites and the configuration related to the ecards
themselves. This module can either construct a default object
in a bootstrap mode or create objects for secondary sites that
merge new information into the primary site's setup.
One of the main purposes of these modules was to provide a consistent interface to error handling. However, the error handling module requires configuration information in order to deal with some error conditions. Therefore when when this method is first called, there is no error handling apparatus yet available. To cope with this, the first attempt to construct a Pgreet::Config object simply tries to open a configuration file and read it's contents. If it fails, the constructor returns a false value. If the returned value is false, the calling program must cope as best it can:
unless ($Pg_default_config = new Pgreet::Config($config_file)) { die; }
When bootstrapping, the constructor to Pgreet::Config is given one argument: the complete path to the configuration file. The constructor always needs at least this one argument. If the configuration object is successfully constructed, it can then be used to create a new error object (illustrated for example by the call below:)
$Pg_error = new Pgreet::Error($Pg_default_config, 'CGIApp');
Once this is done, an error object must be immediately added to the configuration object. If an error occurs without an error object attached to the configuration object, it will crash in about as inelegant a manner as is possible.
$Pg_default_config->add_error_obj($Pg_error);
Once this is done, the bootstrapped configuration object may be used in the manner presented below.
Once an Error object is constructed, successive Penguin Greeting configuration objects can be created directly by providing two arguments the complete path to the configuration file, and the error object. For example, creating a configuration object to hold card configuration data would be as follows:
$card_conf = new Pgreet::Config($card_conf_file, $Pg_error);
There is a third possible way to use the constructor object. If one is defining a configuration object that is using an existing object for default information (for example defining a secondary ecard site) then three arguments are expected in constructing the object:
$Pg_config = new Pgreet::Config($config_file, $Pg_error, $Pg_default_config );
When used in this way, the values in the configuration file
are merged with the values already in the default object
$Pg_default_config
via the internal method
_merge_configs
. Note that certain values cannot be
overridden from the default configuration. Those values are:
PID_file
, PID_path
,
batch_pause
, tmpdir
,
today_pause
, data_file_prefix
,
state_file_prefix
, delete_state
,
scheduled_email_queue
, pgreet_uid
,
pgreet_gid
, SMTP_server
,
user_access
, User_Pgreets
and
flush_on_cycle
. Attempting to change these values
will cause an error to be generated via the attached Penguin
Greetings error object, and calling application will be
terminated via the Pgreet::Error
object.
add_error_obj()
$Pg_default_config->add_error_obj($Pg_error);
access()
$Pg_config->access('config_parameter');
The second syntax is use to set a configuration variable. In this case a second parameter is the value that the configuration variable should be set to:
$Pg_config->access('config_parameter', $Value_to_set_parameter_to);
get_hash()
$Pg_config->get_hash();
put_hash()
get_hash
method. It is only
used internally to this object, but could be used for
meatball surgery of the configuration parameters. It requires
one parameter:$Pg_config->put_hash($new_hash);
is_valid_site()
$Pg_default_config->is_valid_site($site);
expand_config_file()
$Pg_default_config->expand_config_file($site);
scalar_to_array()
Force_to_array
. It then looks for all instances
of the listed fields
in that configuration item,
and if it finds one of those fields containing a single
scalar item, it replaces with with an array reference
containing that scalar item. The purpose of this is to
simplify the creation of Embperl
foreach
loops which might otherwise be handed a
scalar instead of an array of one item to loop through. This
method takes no arguments and should only be called on card
configuration information.$card_conf->scalar_to_array();
chk_params()
String::Checker
.The method returns a hash reference. If any errors are
encountered the hash keys will be the configuration
variables that had failed the tests and the hash value will
be a list reference of String::Checker
expectations that failed.
In order to provide meaningful tests, some additional
expectations are defined: is_directory
- is
this an existing directory on system?, num_min
- is this value less than supplied number?,
existing_uid
is this an existing UID on this
system?, and existing_gid
is this an existing
GID on this system? These names are turned in the array
reference. The Penguin Greetings utility
PgreetConfTest
has a translation table of
these expectations to provide ``human-friendly''
diagnostics for administrators.
choose_localized_site()
I18N::AcceptLanguage
to match among the options
provided in the Localize
configuration
parameters which available sites among those sites with
multiple language support best fits the user's language
profile as represented by their
HTTP_ACCEPT_LANGUAGE
environmental string. If no
acceptable match is found, it returns the default site is
specified. If no default is provided, it will create a
warning and return the argument supplied. If there is no
Localize
lookup for the site name it is just
returned assuming that this is a non-localized site.Pgreet::Config
that should never be of interest
to those working on the application layer of Penguin
Greetings. they are listed here for completeness:$self->_read_config_file($config_file); $self->_merge_configs($default_config_hash, $config_hash); $self->_int_scalar_to_array($new_hash); $self->_swap_arrays_for_scalars($config_piece); $self->_chk_params_helper($to_test, \%check_configs, $test_results);
Copyright (c) 2003-2005 Edouard Lagache
This software is released under the GNU General Public License, Version 2. For more information, see the COPYING file included with this software or visit: http://www.gnu.org/copyleft/gpl.html
No known bugs at this time.
Edouard Lagache <pgreetdev@canebas.org>
1.0.0
the Config::General manpage, Pgreet, the Pgreet::Error manpage, the Pgreet::CGIUtils manpage