hesco has asked for the wisdom of the Perl Monks concerning the following question:

I'm working with my coding partner remotely on a module we're developing. Its a CGI::App based web interface.

We're using CGI::Application::Plugin::Config::Simple to read in configuration data, including a definition for library, where our respective sandboxes are stored.

Its loading the cpan installed modules already in @INC, just fine. But its tripping up on this piece of it:

# cgiapp_init(); sub cgiapp_init { my $self = shift; $self->config_file('/var/lib/cf/tbd/regform/Registration.ini'); my $lib = $self->config_param('library'); use lib qw/$lib/; use Registration::WWW::htmlgui; use Registration::DB; my $dbh = Registration::DB->connect($self->config_param('db_engine') +,$self->config_param('host_name'),$self- >config_param('db_name'),$self->config_param('db_user'),$self->config_ +param('db_pw')); my $result = auth_config($dbh); }
At which point it throws these ugly errors, reading:

Use of uninitialized value in string at Registration/lib/Registration/ +WWW/RegForm.pm line 46. Empty compile time value given to use lib at Registration/lib/Registra +tion/WWW/RegForm.pm line 46
Apparently it wants to be able to do its use lib piece at compile time, but it doesn't get populated from the configuration until run time. Can anyone here suggest a work-around, please?

All help appreciated.

-- Hugh

Replies are listed 'Best First'.
Re: Which comes first . . .
by rhesa (Vicar) on May 01, 2006 at 21:31 UTC
    All calls to "use" are done at compile time, so in your case you need "require" (and "import") to do it at runtime. Instead of "use lib", you'll need to push @INC, $lib;.

    To summarize:

    my $lib = $self->config_param('library'); push @INC, $lib; # uncomment the calls to import if needed require Registration::WWW::htmlgui; # import Registration::WWW::html +gui; require Registration::DB; # import Registration::DB;
Re: Which comes first . . .
by Roy Johnson (Monsignor) on May 01, 2006 at 21:45 UTC
    I'm pretty sure that qw/$lib/ is not what you think it is. It's literally the four-character string you see there, starting with a $.

    Caution: Contents may have been coded under pressure.
Re: Which comes first . . .
by hesco (Deacon) on May 01, 2006 at 22:08 UTC
    Thank you Rhesa and Roy_Johnson. Rhesa's advice was precisely what the doctor ordered and allowed me to delete the hard coded path I had put in there. Its now pulling this information out of the config file as it should. Now I can focus on testing my db connection. Thanks again, -- Hugh