Config file bugs fixed, see gotcha.txt for details.

This commit is contained in:
JT Smith 2007-08-14 14:07:46 +00:00
parent 7507816878
commit 5175cceb39
4 changed files with 23 additions and 217 deletions

View file

@ -1,5 +1,6 @@
7.4.3
- Data Forms set reply to to the same as the from field
- Config file bugs fixed, see gotcha.txt for details.
7.4.2

View file

@ -7,6 +7,14 @@ upgrading from one version to the next, or even between multiple
versions. Be sure to heed the warnings contained herein as they will
save you many hours of grief.
7.4.3
--------------------------------------------------------------------
* You must upgrade to Config::JSON 1.1.0 or higher prior to upgrading.
Due to a bug in CPAN you should type "force install Config::JSON" in
order to upgrade to this version.
7.4.0
--------------------------------------------------------------------

View file

@ -15,10 +15,10 @@ package WebGUI::Config;
=cut
use strict;
use JSON;
use WebGUI::Utility;
use Class::InsideOut qw(readonly id register);
use base 'Config::JSON';
our %config;
my %config = ();
=head1 NAME
@ -51,6 +51,10 @@ This package parses the WebGUI config file.
my $configFileName = $config->getFilename;
my $webguiRoot = $config->getWebguiRoot;
=head1 ISA
Config::JSON
=head1 METHODS
These subroutines are available from this package:
@ -58,141 +62,6 @@ These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 addToArray ( property, value )
Adds a value to an array property in the config file.
=head3 property
The name of the array.
=head3 value
The value to add.
=cut
sub addToArray {
my $self = shift;
my $property = shift;
my $value = shift;
my $array = $self->get($property);
return undef if isIn($value,@{$array});
push(@{$array}, $value);
$self->set($property, $array);
}
#-------------------------------------------------------------------
=head2 addToHash ( property, key, value )
Adds a value to a hash property in the config file.
=head3 property
The name of the hash.
=head3 key
The key to add.
=head3 value
The value to add.
=cut
sub addToHash {
my $self = shift;
my $property = shift;
my $key = shift;
my $value = shift;
my $hash = $self->get($property);
$hash->{$key} = $value;
$self->set($property, $hash);
}
#-------------------------------------------------------------------
=head2 delete ( param )
Deletes a key from the config file.
=head3 param
The name of the parameter to delete.
=cut
sub delete {
my $self = shift;
my $param = shift;
delete $self->{_config}{$param};
open(my $FILE,">",$self->getWebguiRoot.'/etc/'.$self->getFilename);
print $FILE "# config-file-type: JSON 1\n".objToJson($self->{_config}, {pretty => 1, indent => 4, autoconv=>0, skipinvalid=>1});
close($FILE);
}
#-------------------------------------------------------------------
=head2 deleteFromArray ( property, value )
Deletes a value from an array property in the config file.
=head3 property
The name of the array.
=head3 value
The value to delete.
=cut
sub deleteFromArray {
my $self = shift;
my $property = shift;
my $value = shift;
my $array = $self->get($property);
for (my $i = 0; $i < scalar(@{$array}); $i++) {
if ($array->[$i] eq $value) {
splice(@{$array}, $i, 1);
last;
}
}
$self->set($property, $array);
}
#-------------------------------------------------------------------
=head2 deleteFromHash ( property, key )
Delete a key from a hash property in the config file.
=head3 property
The name of the hash.
=head3 key
The key to delete.
=cut
sub deleteFromHash {
my $self = shift;
my $property = shift;
my $key = shift;
my $hash = $self->get($property);
delete $hash->{$key};
$self->set($property, $hash);
}
#-------------------------------------------------------------------
=head2 DESTROY ( )
@ -203,29 +72,12 @@ Deconstructor.
sub DESTROY {
my $self = shift;
$self->DEMOLISH;
undef $self;
}
#-------------------------------------------------------------------
=head2 get ( param )
Returns the value of a particular parameter from the config file.
=head3 param
The name of the parameter to return.
=cut
sub get {
my $self = shift;
my $param = shift;
return $self->{_config}{$param};
}
#-------------------------------------------------------------------
=head2 getCookieName ( )
Returns the cookie name defined in the config file. Returns "wgSession" if one isn't defined.
@ -255,29 +107,13 @@ sub getCookieTTL {
#-------------------------------------------------------------------
=head2 getFilename ( )
Returns the filename for this config.
=cut
sub getFilename {
my $self = shift;
return $self->{_configFile};
}
#-------------------------------------------------------------------
=head2 getWebguiRoot ( )
Returns the path to the WebGUI installation.
=cut
sub getWebguiRoot {
my $self = shift;
return $self->{_webguiRoot};
}
readonly getWebguiRoot => my %webguiRoot;
#-------------------------------------------------------------------
@ -334,23 +170,10 @@ sub new {
if (exists $config{$filename}) {
return $config{$filename};
} else {
my $json = "";
if (open(my $FILE,"<",$fullPath)) {
while (my $line = <$FILE>) {
$json .= $line unless ($line =~ /^\s*#/);
}
close($FILE);
my $conf = jsonToObj($json);
die "Couldn't parse JSON in config file '$filename'\n"
unless ref $conf;
my $self = {_webguiRoot=>$webguiPath, _configFile=>$filename, _config=>$conf};
bless $self, $class;
$config{$filename} = $self unless $noCache;
return $self;
} else {
warn "Cannot open config file: ".$fullPath;
return undef;
}
my $self = Config::JSON->new($webguiPath."/etc/".$filename);
register($self, $class);
$config{$filename} = $self unless $noCache;
return $self;
}
}
@ -385,31 +208,5 @@ sub readAllConfigs {
}
#-------------------------------------------------------------------
=head2 set ( param, value )
Creates a new or updates an existing parameter in the config file.
=head3 param
A parameter name.
=head3 value
The value to set the paraemter to. Can be a scalar, hash reference, or array reference.
=cut
sub set {
my $self = shift;
my $param = shift;
my $value = shift;
$self->{_config}{$param} = $value;
open(my $FILE,">",$self->getWebguiRoot.'/etc/'.$self->getFilename);
print $FILE "# config-file-type: JSON 1\n".objToJson($self->{_config}, {pretty => 1, indent => 4, autoconv=>0, skipinvalid=>1});
close($FILE);
}
1;

View file

@ -104,7 +104,7 @@ checkModule("HTML::Template",2.9);
checkModule("HTML::Template::Expr",0.05,2);
checkModule("XML::RSSLite",0.11);
checkModule("JSON",0.991);
checkModule("Config::JSON","1.0.3");
checkModule("Config::JSON","1.1.0");
checkModule("Text::CSV_XS","0.26");
checkModule("Net::Subnets",0.21);
checkModule("Finance::Quote",1.08);