progress and WebGUI::Paths conversion

This commit is contained in:
Graham Knop 2010-02-23 10:06:50 -06:00
parent 90d63c6713
commit 29df110409
23 changed files with 63 additions and 333 deletions

View file

@ -15,8 +15,9 @@ package WebGUI::Config;
=cut
use strict;
use Class::InsideOut qw(readonly id register);
use WebGUI::Paths;
use Cwd ();
use File::Spec;
use base 'Config::JSON';
my %config = ();
@ -50,7 +51,6 @@ This package parses the WebGUI config file.
$config->addToArray($name, $value);
my $configFileName = $config->getFilename;
my $webguiRoot = $config->getWebguiRoot;
=head1 ISA
@ -109,17 +109,6 @@ sub getCookieTTL {
return defined($configTTL)? $configTTL : "+10y";
}
#-------------------------------------------------------------------
=head2 getWebguiRoot ( )
Returns the path to the WebGUI installation.
=cut
readonly getWebguiRoot => my %webguiRoot;
#-------------------------------------------------------------------
=head2 loadAllConfigs ( webguiRoot )
@ -166,57 +155,39 @@ A boolean value that when set to true tells the config system not to store the c
=cut
sub new {
my $class = shift;
my $webguiPath = Cwd::realpath(shift);
my $filename = shift;
my $noCache = shift;
my $fullPath = Cwd::realpath($webguiPath.'/etc/'.$filename);
if (exists $config{$fullPath}) {
return $config{$fullPath};
} else {
my $self = Config::JSON->new($fullPath);
register($self, $class);
$webguiRoot{id $self} = $webguiPath;
$config{$filename} = $self unless $noCache;
return $self;
}
my $class = shift;
my $filename = shift;
my $noCache = shift;
if (!File::Spec->file_name_is_absolute($filename)) {
Cwd::realpath($filename = File::Spec->catfile(WebGUI::Paths->configBase, $filename));
}
if (exists $config{$filename}) {
return $config{$filename};
}
else {
my $self = $class->SUPER::new($fullPath);
$config{$filename} = $self unless $noCache;
return $self;
}
}
#-------------------------------------------------------------------
=head2 readAllConfigs ( webguiRoot )
=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};
=head3 webguiRoot
The path to the WebGUI installation.
=cut
sub readAllConfigs {
my $class = shift;
my $webguiPath = shift;
opendir my $dh, $webguiPath."/etc";
my @files = readdir $dh;
closedir $dh;
my %configs;
foreach my $file (@files) {
next
if $file !~ /\.conf$/
|| $file =~ /^\./
|| $file eq 'log.conf'
|| $file eq 'spectre.conf';
eval {
$configs{$file} = WebGUI::Config->new($webguiPath,$file)
};
if ($@) {
warn "Config file ".$file." looks to be corrupt or have a syntax error.";
}
}
my @configs = WebGUI::Paths->siteConfigs;
my %configs = map {
$_ => $class->new($_);
} @configs
return \%configs;
}