|
From: Chris W. <la...@us...> - 2001-10-17 12:22:21
|
Update of /cvsroot/openinteract/OpenInteract/OpenInteract/Config
In directory usw-pr-cvs1:/tmp/cvs-serv26844
Modified Files:
Ini.pm
Log Message:
add more docs (example); allow get() to contextually return an array
Index: Ini.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/OpenInteract/Config/Ini.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Ini.pm 2001/10/17 04:48:58 1.2
--- Ini.pm 2001/10/17 12:22:19 1.3
***************
*** 21,31 ****
}
sub get {
my ( $self, $section, @p ) = @_;
my ( $sub_section, $param ) = ( $p[1] ) ? ( $p[0], $p[1] ) : ( undef, $p[0] );
! return $self->{ $section }{ $sub_section }{ $param } if ( $sub_section );
! return $self->{ $section }{ $param };
}
sub set {
my ( $self, $section, @p ) = @_;
--- 21,36 ----
}
+
sub get {
my ( $self, $section, @p ) = @_;
my ( $sub_section, $param ) = ( $p[1] ) ? ( $p[0], $p[1] ) : ( undef, $p[0] );
! my $item = ( $sub_section )
! ? $self->{ $section }{ $sub_section }{ $param }
! : $self->{ $section }{ $param };
! return $item unless ( ref $item eq 'ARRAY' );
! return wantarray ? @{ $item } : $item->[0];
}
+
sub set {
my ( $self, $section, @p ) = @_;
***************
*** 35,38 ****
--- 40,44 ----
}
+
sub delete {
my ( $self, $section, @p ) = @_;
***************
*** 235,238 ****
--- 241,324 ----
=back
+
+ =head2 Example
+
+ Given the following configuration in INI-style:
+
+ [datasource]
+ default_connection_db = main
+ db = main
+ db = other
+
+ [db_info main]
+ db_owner =
+ username = captain
+ password = whitman
+ dsn = dbname=usa
+ db_name =
+ driver_name = Pg
+ sql_install =
+ long_read_len = 65536
+ long_trunc_ok = 0
+
+ [db_info other]
+ db_owner =
+ username = tyger
+ password = blake
+ dsn = dbname=britain
+ db_name =
+ driver_name = Pg
+ sql_install =
+ long_read_len = 65536
+ long_trunc_ok = 0
+
+ You would get the following Perl data structure:
+
+ $config = {
+ datasource => {
+ default_connection_db => 'main',
+ db => [ 'main', 'other' ],
+ },
+ db_info => {
+
+ main => {
+ db_owner => undef,
+ username => 'captain',
+ password => 'whitman',
+ dsn => 'dbname=usa',
+ db_name => undef,
+ driver_name => 'Pg',
+ sql_install => undef,
+ long_read_len => '65536',
+ long_trunc_ok => '0',
+ },
+
+ other => {
+ db_owner => undef,
+ username => 'tyger',
+ password => 'blake',
+ dsn => 'dbname=britain',
+ db_name => undef,
+ driver_name => 'Pg',
+ sql_install => undef,
+ long_read_len => '65536',
+ long_trunc_ok => '0',
+ },
+ },
+ };
+
+
+
+ =head2 'Global' Key
+
+ Anything under the 'Global' key in the configuration will be available
+ under the configuration object root. For instance:
+
+ [Global]
+ DEBUG = 1
+
+ will be available as:
+
+ $CONFIG->{DEBUG}
=head1 SEE ALSO
|