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


In reply to mod_perl and BEGIN blocks by rruiz
in thread Constants imported from other perl scripts doesn't want to exist :( by OnionKnight

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.