|
NAMEGantry::Conf::Tutorial - Tutorial on how to use Gantry::ConfINTROThis document explains both how to use Gantry::Conf to configure a set of applications and how to extend Gantry::Conf to suit your needs.CONFIGURINGGantry::Conf uses a central config file to control how a set of applications bootstrap their own configuration. By default, this file live in /etc/gantry.conf, but you can control that, see below. That file is parsed by Config::General and looks something like this:<global> database_server_name ourdb.ourcompany.com </global> <shared appearance> background white foreground blue </shared> <instance app1> ConfigureVia FlatFile Config::General /path/to/file use appearance </instance> <instance app2> ConfigureVia HTTP Config::General http://conf.oc.com/conf use appearance </instance> <instance right_here> var value color blue </instance> include /etc/gantry.d/*.conf Then in /etc/gantry.d/app3.conf: <instance app3> ConfigureVia FlatFile Config::Tiny /path/to/conf ConfigureVia HTTP Config::General http://conf.oc.com/conf </instance> Each application instance has a section in this file, unless its instance can be gleaned from /etc/gantry.d. This allows not only multiple apps, but also multiple instances of the same app running in the same server. The instance name must be unique and is what the app uses to find its conf. In the instance block, you may choose to define conf variables and their values directly (as the "right_here" instance does above). Otherwise, the core of any instance's configuration is the ConfigureVia statement(s). The form of these statments vary by the configuration method. The methods supported are:
Any instance can share conf with other instances in three ways:
The precedence is:
Note that you may use "include" at any point passing it a shell style file glob. Any matching files will be included at that point as if typed there. This is highly convenient for separating config information into separate files by app. Then your master config file (/etc/gantry.conf) might be as simple as: include /etc/gantr.d/*.conf USING A CONFIGURATIONOnce you have a configuration for your applications, you can load the conf easily through the "<Gantry::Conf-"retrieve method>>:use Gantry::Conf; my $conf = Gantry::Conf->retrieve( { instance => 'app1', config_file => '/etc/gantry.confs/standard.conf', } ); When using Gantry::Conf with mod_perl you should specify the config file inside of a Perl block or your apache startup file as follows: use Gantry::Conf qw(-Config=/etc/gantry.conf) Failure to do so will cause Gantry::Conf to reload its configuration on each request. When calling retrieve, you must provide the parameters by name in a hash reference. The only required key is "instance". Gantry::Conf will look for the instance in the "config_file". By default the config_file is "/etc/gantry.conf". If your config files use GantryLocation blocks, like this: level_name top all_share 5 reset 5 <GantryLocation /second> level_name second reset 4 </GantryLevel> <GantryLocation /second/nested> level_name second.nested reset 2 </GantryLevel> You can pass "location" to retrieve, then you will get the values for the specified location. Note that parameters are not inherited from "parent" locations. All locations are thought to be independent. Thus, if "/second/nested" above did not define "reset", its value for it would be 5 (inherited from the top level) and not 4 (which "/second" defined). EXTENDING Gantry::ConfYou can implement your own providers for FlatFile and SQL configuration methods. (Note that FlatFile providers are also HTTP providers.)To implement your own FlatFile provider name it like this: package Gantry::Conf::Provider::Module; Then put a method in it called config which is called as a class method taking a single parameter. For example, here is the whole Config::General provider: package Gantry::Conf::Provider::FlatFile::Config::General; use strict; use warnings; use Carp qw(croak); use Config::General; use Gantry::Conf::Provider; use base qw( Gantry::Conf::Provider ); sub config { my $self = shift; my $file = shift; my $config = Config::General->new( $file ) or croak "Unable to create Config::General object: $!"; my %confs = $config->getall; return( \%confs ); } # END config SEE ALSOGantry(3), Gantry::Conf(3), Ganty::Conf::FAQ(3)AUTHORPhil Crow <pcrow@sunflowerbroadband.com>Frank Wiles <frank@revsys.com> COPYRIGHT and LICENSECopyright (c) 2006, Frank Wiles.This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
Visit the GSP FreeBSD Man Page Interface. |