package WebGUI::Config; =head1 LEGAL ------------------------------------------------------------------- WebGUI is Copyright 2001-2009 Plain Black Corporation. ------------------------------------------------------------------- Please read the legal notices (docs/legal.txt) and the license (docs/license.txt) that came with this distribution before using this software. ------------------------------------------------------------------- http://www.plainblack.com info@plainblack.com ------------------------------------------------------------------- =cut use Moose; extends 'Config::JSON'; use WebGUI::Paths; use Cwd (); use File::Spec; =head1 NAME Package WebGUI::Config =head1 DESCRIPTION This package parses the WebGUI config file. =head1 SYNOPSIS use WebGUI::Config; my $configs = WebGUI::Config->readAllConfigs; my $config = WebGUI::Config->new($configFileName); my $value = $config->get($param); $config->set($param,$value); $config->delete($param); $config->deleteFromHash($name, $key); $config->deleteFromArray($name, $value); $config->addToHash($name, $key, $value); $config->addToArray($name, $value); my $configFileName = $config->getFilename; =head1 ISA Config::JSON =head1 METHODS These subroutines are available from this package: =cut #------------------------------------------------------------------- =head2 getCookieName ( ) Returns the cookie name defined in the config file. Returns "wgSession" if one isn't defined. =cut sub getCookieName { my $self = shift; return $self->get("cookieName") || "wgSession"; } #------------------------------------------------------------------- =head2 getCookieTTL ( ) Returns the cookie time to live defined in the config file. Returns "+10y" if one isn't defined. This may also be "session" to indicate that the cookie should only live for the current browser session. =cut sub getCookieTTL { my $self = shift; my $configTTL = $self->get("cookieTTL"); return defined($configTTL)? $configTTL : "+10y"; } #------------------------------------------------------------------- =head2 new ( configFile ) Returns a hash reference containing the configuration data. It tries to get the data out of the memory cache first, but reads the config file directly if necessary. =head3 configFile The filename of the config file to read. =cut around BUILDARGS => sub { my $orig = shift; my $class = shift; my $filename = shift; $filename = Cwd::realpath(File::Spec->rel2abs($filename, WebGUI::Paths->configBase)); return $class->$orig($filename); }; #------------------------------------------------------------------- =head2 readAllConfigs ( ) Reads all the config file data for all defined sites and returns a hash reference containing WebGUI::Config objects keyed by filename. This is a class method. Example: $configs->{$filename}; =cut sub readAllConfigs { my $class = shift; my @configs = WebGUI::Paths->siteConfigs; my %configs = map { $_ => $class->new($_); } @configs; return \%configs; } 1;