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

Hi all... I have been really stumped with a problem that I am having. I am using Apache 2.0.46 with mod_perl 1.99_09 installed as DSO. I have been able to utilize different libraries from my main script. However, I started to try to utilize a package that I built which requires a library that the main script also requires I get undefined function calls.

main script require block:
BEGIN { use lib "/apache/wiredata/cgi-bin/mod_perl/control_center/library/ +"; use lib "/srccode/wiredata_lib/"; use lib "/apache/wiredata/cgi-bin/mod_perl/Viewer"; use CGI (); use Session (); use IO::ScalarArray (); use strict; use Apache::DBI (); use ReportGenerator(); require "wiredata_mysql_lib.pl"; # library in question require "db_ops.pl"; require "menuDisplay.pl"; require "table_browser.pl"; require "OptionDisplay.pl"; require "Viewer.pl"; }
Package being used require block:
BEGIN { use strict; use Data::Dumper; use Tie::IxHash; use Record; use lib qw(/apache/wiredata_lib); require "report_gen_lib.pl"; require "wiredata_mysql_lib.pl"; # library in question } package ReportGenerator;
I have tried all kinds of combinations to try to remove the conflicts. I have been getting the conflicts on both sides. Once I get the ReportGenerator package to stop complaining, the main script then has the same error. I am completely stumped. I have inspected the @INC and %INC to determine if the path and file occurs in both. I have noticed that I am getting a little inconsistency in the paths in @INC.
If anyone can shed some light on this, maybe I will changed my mind about dropping the mod_perl...however, I am looking to utilize the speed of mod_perl. Thats my driving force for using it...otherwise, I have been just hitting all kind of problems.
Or if this has been covered previously...which i didn't seem to find...please point me to that article.

Thanks
Matt

Replies are listed 'Best First'.
Re: requires in mod_perl
by perrin (Chancellor) on Sep 04, 2003 at 17:49 UTC
    It's all explained here in the mod_perl docs. This is the 1.0 section, but it still applies when using ModPerl::Registry.
Re: requires in mod_perl
by mhorner (Initiate) on Sep 04, 2003 at 22:01 UTC
    Ok, I read through that information and went with Solution #2. I changed my require()'s to state the full path. However, I get a function call undefined in a requirement from the file that was originally at issue. So, as it states in the Solution #2 state the full path. So I repeated that again in the file that is being require()d.

    Fine and dandy...however, when I try to run the program, I get the same error message. I have checked other files that I am require()ing, and updated those to use the full paths.

    I even went as far as putting the problematic require() in a BEGIN block also, and still got the same error.

    Has anybody else try to adapt function libraries primarily used with CGI (not mod_perl) and CLI programming? Are/Did these sort of things cause this much trouble for you also?

    Thanks again... Matt
Re: requires in mod_perl
by Anonymous Monk on Sep 04, 2003 at 17:41 UTC
    Do you have a package declaration in wiredata_mysql_lib.pl?
      Because if you don't, the first file to require the library will put the functions in its package, while the next one will see that it is already loaded and do nothing.
Re: requires in mod_perl
by mhorner (Initiate) on Sep 05, 2003 at 16:01 UTC
    Just a follow up for those looking at this later...

    I made three changes to the code in the initial post
    1. Used the full paths to the library in the require() statement.
    2. Moved the require()s above the use() in the main script.
    3. Also, moved the package statement before the BEGIN block in the package. (don't know why i put it there to begin with.)
    Appears to have cleared up the undefined functions. My conception of what is actually going on now...correct me if I am wrong.

    Compiled the library in the main script which allowed for the propagation of the library down the tree, rather than requiring after it has already been compiled and not loaded into the namespace of the main script.

    Like I said...correct me if I am wrong.

    Thanks for the help again.
    Matt
      Why is all that stuff in BEGIN blocks anyway?