Which comes first . . .
hesco
created: 2006-05-01 17:14:47
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/Registration/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

Re: Which comes first . . .
created: 2006-05-01 17:31:52
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::htmlgui;
  require Registration::DB;           # import Registration::DB;
Re: Which comes first . . .
created: 2006-05-01 17:45:12
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 . . .
created: 2006-05-01 18:08:58
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

perlmonks.org content © perlmonks.org and hesco, rhesa, Roy Johnson

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03