|
From: Chris W. <la...@us...> - 2001-10-17 04:49:01
|
Update of /cvsroot/openinteract/OpenInteract/OpenInteract/Config
In directory usw-pr-cvs1:/tmp/cvs-serv26087
Modified Files:
Ini.pm IniFile.pm
Log Message:
small modifications -- basically working now
Index: Ini.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/OpenInteract/Config/Ini.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Ini.pm 2001/10/17 02:58:22 1.1
--- Ini.pm 2001/10/17 04:48:58 1.2
***************
*** 4,7 ****
--- 4,8 ----
use strict;
+ use OpenInteract::Config qw( _w DEBUG );
# Stuff in metadata (_m):
***************
*** 49,53 ****
my ( $self, $filename ) = @_;
! warn "Trying to read file ($filename)\n";
open( CONF, $filename ) || die "Cannot open ($filename) for reading: $!";
--- 50,54 ----
my ( $self, $filename ) = @_;
! DEBUG && _w( 1, "Trying to read INI file ($filename)" );
open( CONF, $filename ) || die "Cannot open ($filename) for reading: $!";
***************
*** 69,73 ****
}
if ( /^\s*\[\s*(\S|\S.*\S)\s*\]\s*$/) {
! warn "--Found section ($1)\n";
( $section, $sub_section ) = $self->read_section_head( $1, \@comments );
@comments = ();
--- 70,74 ----
}
if ( /^\s*\[\s*(\S|\S.*\S)\s*\]\s*$/) {
! DEBUG && _w( 2, "Found section ($1)" );
( $section, $sub_section ) = $self->read_section_head( $1, \@comments );
@comments = ();
***************
*** 75,79 ****
}
my ( $param, $value ) = /^\s*([^=]+?)\s*=\s*(.*)\s*$/;
! warn "--Setting ($param) to ($value)\n";
$self->read_item( $section, $sub_section, $param, $value );
}
--- 76,80 ----
}
my ( $param, $value ) = /^\s*([^=]+?)\s*=\s*(.*)\s*$/;
! DEBUG && _w( 2, "Setting ($param) to ($value)" );
$self->read_item( $section, $sub_section, $param, $value );
}
***************
*** 100,119 ****
sub read_item {
my ( $self, $section, $sub_section, $param, $value ) = @_;
! my $set_value_in = ( $sub_section )
! ? $self->{ $section }{ $sub_section }
! : $self->{ $section };
! my $existing = $set_value_in->{ $param };
! if ( $existing and ref $set_value_in eq 'ARRAY' ) {
! push @{ $set_value_in->{ $param } }, $value;
}
elsif ( $existing ) {
! push @{ $set_value_in->{ $param } }, $existing, $value
}
else {
! $set_value_in->{ $param } = $value;
}
}
-
########################################
# OUTPUT
--- 101,133 ----
sub read_item {
my ( $self, $section, $sub_section, $param, $value ) = @_;
!
! # Special case -- 'Global' stuff goes in the config object root
!
! if ( $section eq 'Global' ) {
! push @{ $self->{_m}{global} }, $param;
! $self->set_value( $self, $param, $value );
! return;
}
+
+ return ( $sub_section )
+ ? $self->set_value( $self->{ $section }{ $sub_section }, $param, $value )
+ : $self->set_value( $self->{ $section }, $param, $value );
+ }
+
+
+ sub set_value {
+ my ( $self, $set_in, $param, $value ) = @_;
+ my $existing = $set_in->{ $param };
+ if ( $existing and ref $set_in->{ $param } eq 'ARRAY' ) {
+ push @{ $set_in->{ $param } }, $value;
+ }
elsif ( $existing ) {
! push @{ $set_in->{ $param } }, $existing, $value
}
else {
! $set_in->{ $param } = $value;
}
}
########################################
# OUTPUT
***************
*** 128,134 ****
$filename = "$filename.new";
}
! warn "--Writing INI to ($filename) (original: $original_filename)\n";
open( OUT, "> $filename" ) || die "Cannot write configuration to ($filename): $!";
! print OUT "# Written by ", ref $self, " at ", scalar localtime, "\n\n";
foreach my $full_section ( @{ $self->{_m}{order} } ) {
print OUT $self->{_m}{comments}{ $full_section }, "\n",
--- 142,155 ----
$filename = "$filename.new";
}
!
! # Set 'Global' items from the config object root
!
! foreach my $key ( @{ $self->{_m}{global} } ) {
! $self->{Global}{ $key } = $self->{ $key };
! }
!
! DEBUG && _w( 1, "--Writing INI to ($filename) (original: $original_filename)" );
open( OUT, "> $filename" ) || die "Cannot write configuration to ($filename): $!";
! print OUT "# Written by ", ref $self, " at ", scalar localtime, "\n";
foreach my $full_section ( @{ $self->{_m}{order} } ) {
print OUT $self->{_m}{comments}{ $full_section }, "\n",
Index: IniFile.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/OpenInteract/Config/IniFile.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** IniFile.pm 2001/10/17 02:58:22 1.1
--- IniFile.pm 2001/10/17 04:48:58 1.2
***************
*** 4,8 ****
use strict;
- use Data::Dumper qw( Dumper );
use OpenInteract::Config qw( _w DEBUG );
use OpenInteract::Config::Ini;
--- 4,7 ----
***************
*** 22,25 ****
--- 21,26 ----
+ # Cheeseball, but it works
+
sub write_config {
my ( $self ) = @_;
***************
*** 28,32 ****
$backup->write_file;
}
-
--- 29,32 ----
|