Gossamer Forum
Home : General : Perl Programming :

Getting the right order

Quote Reply
Getting the right order
For fear of sounding like Andy I won't say "ugh this is really annoying me now".....but it is :)

Like Links SQL I have a cgi script that calls an init() routine. The very first module inclusion in that script (apart from strict and lib) is my main module which loads the base class and my config module which imports $CONF.

The init() routine then assigns the config data to $CFG so that other modules can use my central package to import eg...

use MyPackage qw/$CFG/;

At the end of the init routine I've checked the value of $CFG and it is storing the data properly, however in one of my other modules, $CFG is empty causing an error.

This is getting on my nerves because as far as I can see $CFG is being created properly and also imported into the other module otherwise I'd get an import error.

So to try to make this clearer, here is the top of the cgi script:

Code:
use strict;
use lib '/apache1/cgi-bin/dir';
use MyPackage;

local $SIG{__DIE__} = \&MyPackage::fatal;

MyPackage::init();

.....in MyPackage I have:

Code:
use strict;
use vars qw/$IN $TPL $USER $CFG $DB $LANG_CACHE $DEBUG/;
use Support::Config qw/$CONF/;

....in init() I have (amongst other things):
Code:
# Set the config.
$CFG = $CONF;

Then in the module causing the error:

Code:
use MyPackage qw/$CFG/;

So it _should_ be working. I don't see why it isn't.

The error is being generated by a CFG value being empty so a certain file can't be loaded because the path is wrong...so it is not like an import error meaning that CFG isn't importing properly, CFG is just blank.

The routine is also auto-loaded so hasn't even compiled until it is called, so by then $CFG should be defined.

Sigh.

It was actually working fine before as I was using:

use MyClass::Config qw/$CFG/;

....but stupidly decided to change it. Ugh.

Last edited by:

Paul: Oct 10, 2002, 5:49 AM
Quote Reply
Re: [Paul] Getting the right order In reply to
and $CFG is being exported?

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Getting the right order In reply to
Yeah. In my cgi-script I just tried this:

Code:
use strict;
use lib '/apache1/cgi-bin/dir';
use MyPackage qw/$CFG/;

local $SIG{__DIE__} = \&MyPackage::fatal;

MyPackage::init();

die %$CFG;

....and $CFG is full of my config vars.

Yet in a routine called later on in the other package $CFG is empty. I've traced the steps the script takes and don't see any reason why this should be happening...I'll keep looking...bah!
Quote Reply
Re: [yogi] Getting the right order In reply to
I've solved it "dirtily" by using $MyPackage::CFG->{whatever} in that specific package (only one CFG call thankfully) but I want to know where and why it is blanking out.....grr