[svn:p5ee] r6852 - p5ee/trunk/App-Repository/lib/App/Repository

[email protected]
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
Author: spadkins
Date: Mon Sep  4 18:10:37 2006
New Revision: 6852

Modified:
   p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm

Log:
can now configure multiple databases (App::Repository::DBI) from app.conf (xyz_dbhost, xyz_dbname, ... for rep "xyz")

Modified: p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm	(original)
+++ p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm	Mon Sep  4 18:10:37 2006
@@ -340,17 +340,29 @@
         my $options = $self->{context}{options} || {};
 
         my $config_from_options = 1;
+        my $config_from_ext_options = 0;
         foreach my $var qw(dbdsn dbdriver dbhost dbport dbname dbuser dbpass dbschema dbioptions) {
             if ($self->{$var}) {
                 $config_from_options = 0;
-                last;
+            }
+            if ($options->{"${name}_${var}"}) {
+                $config_from_ext_options = 1;
             }
         }
 
         if ($config_from_options) {
-            foreach my $var qw(dbdsn dbdriver dbhost dbport dbname dbuser dbpass dbschema dbioptions) {
-                if (defined $options->{$var}) {
-                    $self->{$var} = $options->{$var};
+            if ($config_from_ext_options) {
+                foreach my $var qw(dbdsn dbdriver dbhost dbport dbname dbuser dbpass dbschema dbioptions) {
+                    if (defined $options->{"${name}_${var}"}) {
+                        $self->{$var} = $options->{"${name}_${var}"};
+                    }
+                }
+            }
+            else {
+                foreach my $var qw(dbdsn dbdriver dbhost dbport dbname dbuser dbpass dbschema dbioptions) {
+                    if (defined $options->{$var}) {
+                        $self->{$var} = $options->{$var};
+                    }
                 }
             }
         }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.