I am having trouble defining a few interrelated modules.  I made some
progress based on this advice
(http://readlist.com/lists/perl.org/beginners/0/2844.html) but am now
having another problem

 

Basically, I want to have:

1)       a set of configuration variables stored in the local web space.

2)       a set of centrally defined functions  (such as opening a
database connection) in my main perl tree which makes use of the locally
configured variables.  This file is not included below, since my problem
seems to arise prior to that central modules invocation.

 

Each of the config files (MetaManagerTest in the examples below) need to
have the same name in their local directories.

 

The code I have works fine when there is a single web site on my server
using the modules.  However, when two or more web sites use the set up,
there is bleed through of variables between sites.  I am assuming that
there is some sort of name space collision based on the fact each
package has the same name. I had hoped that the "use lib" statement
would be adequate to ensure that each site would see only it own config
variables.  

 

I would be grateful for any advice on how to achieve my goal of multiple
same-named modules.

 

++++++++++++++

First page code (perl is embedded in HTML via Apache::ASP):

+++++++++++++++

use strict;

use lib "/home/httpd/html-CLAC/admin"; # So that we can see the proper
MetaManagerTest.pm; this line changes depending on which config file I
want to load

use MetaManagerTest; 

my %cfg = %MetaManagerTest::cfg;

 

print "Base URL2: $cfg{baseUrl} <br>";

 

++++++++++++++

Second page code (only change is the use lib path):

+++++++++++++++

use strict;

use lib "/home/httpd/html-CLAC/admin2"; # So that we can see the proper
MetaManagerTest.pm

use MetaManagerTest; 

my %cfg = %MetaManagerTest::cfg;

 

print "Base URL2: $cfg{baseUrl} <br>";

++++++++++++++++++++++
Local Configuration File 1 living at
/home/httpd/html-CLAC/admin/MetaManagerTest.pm
++++++++++++++++++++++

package MetaManagerTest;
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
our (%cfg, $version);
our @EXPORT = qw(%cfg);
our $VERSION = "1.0.1";

# Base URL without path (no trailing /)
$cfg{baseUrl} = "http://test1.server.admin.state.mn.us";;

+++++++++++++
Local Configuration File 2  living at
/home/httpd/html-CLAC/admin2/MetaManagerTest.pm
Note: the only difference is the value of "baseUrl"
+++++++++++++

package MetaManagerTest;
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
our (%cfg, $version);
our @EXPORT = qw(%cfg);
our $VERSION = "1.0.1";

# Base URL without path (no trailing /)
$cfg{baseUrl} = "http://test2.server.admin.state.mn.us";;

++++++++++++++++++++++++++++++++

When I load a either page, it comes up printing the correct baseURL.
However, if I keep reloading the pages, the value of baseUrl will
occassionally toggle between the two values.  Am I correct in assuming
this is a perl namespace issues (as opposed to an Apache::ASP issue?
Any way to ensure that I only read from the proper symbol table?

Andrew Koebrick
Web Coordinator / Librarian

Dept. of Administration
State of Minnesota
658 Cedar St.
St. Paul, MN 55155

651-296-4156
http://server.admin.state.mn.us

 

Reply via email to