webgui/lib/WebGUI/Config.pm
Doug Bell 708b47d73c Merge remote branch 'upstream/WebGUI8' into 8-merge
Conflicts:
	docs/gotcha.txt
	docs/previousVersion.sql
	lib/WebGUI/Asset/Wobject/GalleryAlbum.pm
	lib/WebGUI/Asset/Wobject/Navigation.pm
	lib/WebGUI/AssetLineage.pm
	lib/WebGUI/Config.pm
	lib/WebGUI/Form/Template.pm
	lib/WebGUI/Group.pm
	lib/WebGUI/VersionTag.pm
	lib/WebGUI/Workflow/Activity/TrashExpiredEvents.pm
	t/AdSpace.t
	t/Asset/AssetExportHtml.t
	t/Asset/AssetLineage.t
	t/Asset/Story.t
	t/Asset/Template/HTMLTemplateExpr.t
	t/Asset/Wobject/Gallery/00base.t
	t/Asset/Wobject/GalleryAlbum/00base.t
	t/Asset/Wobject/GalleryAlbum/ajax.t
	t/Asset/Wobject/InOutBoard.t
	t/Asset/Wobject/StoryArchive.t
	t/Asset/Wobject/Survey/ExpressionEngine.t
	t/Asset/Wobject/Survey/Reports.t
	t/AssetAspect/RssFeed.t
	t/Auth/mech.t
	t/Group.t
	t/Mail/Send.t
	t/Operation/AdSpace.t
	t/Session/ErrorHandler.t
	t/Session/Scratch.t
	t/Session/Url.t
	t/Shop/Cart.t
	t/Shop/Pay.t
	t/Shop/Ship.t
	t/Shop/ShipDriver.t
	t/Shop/TaxDriver/Generic.t
	t/Shop/Vendor.t
	t/VersionTag.t
	t/lib/WebGUI/Test.pm
2010-07-14 18:20:00 -05:00

134 lines
3 KiB
Perl

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;
my %config = ();
=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;