http://www.perlmonks.org?node_id=492996


in reply to Re^4: Constants imported from other perl scripts doesn't want to exist :(
in thread Constants imported from other perl scripts doesn't want to exist :(

If you are requiring the module in a BEGIN block in a mod_perl environment, then your BEGIN block may not be compiled/runned in every request (ie. when your script run).

Check the docs in http://perl.apache.org, especially the BEGIN blocks part in the porting section of the guide (this is from the mod_perl 1 guide, but I don't think this changed in mod_perl 2).

Using mod_perl could be triky if you came from CGI (I was bitted by some differences of running under Apache::Registry vs. CGI recently). The main difference is that the compilation of your script is done only once, and BEGIN blocks AFAIK, are only called at compile time and then discarded.

If you are comming from CGI as me, I strongly recommend to read the full porting section of the mod_perl guide, it will save you a lot of troubles. Also reading the Perl Reference in the mod_perl documentation may be usefull (I know it was for me ;),

Also note the difference between require vs. use. require's work at runtime and use's at compile time. Putting a require module; inside a BEGIN block is like doing use module (); (so it don't import any symbol into your main namespace).

Seeing what you are doing, I think you may want the code on your config.pl to be executed at runtime, so just remove the BEGIN { } construct around your require and it should work. If you do this, make sure the configuration file is in a path in you @INC or your script will die by not finding it.

So, as borisz suggest, this is more a mod_perl issue, you may consider editting your node title to reflect it, so monks with more knowledge in mod_perl can see it, and help you.

HTH, God bless you
rruiz