Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

mod_perl and BEGIN blocks

by rruiz (Monk)
on Sep 18, 2005 at 10:37 UTC ( #492996=note: print w/ replies, xml ) Need Help??


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


Comment on mod_perl and BEGIN blocks

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://492996]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2014-09-21 07:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (167 votes), past polls