Saying that BEGIN blocks should be re-run on every invocation of the 
script in mod_perl is like saying that you must re-start your car every 
time you stop even though the engine may still be running.  The fact 
that BEGIN blocks only execute once per server instance is expected 
simply by definition of the BEGIN block.  If you wrote a daemon in perl 
that stood waiting for connection, would you expect the BEGIN block to 
execute every time it responded to a request?  I certainly wouldn't.  I 
would only expect it to run only when I fired it up.  This certainly 
does not qualify as being "broken."  It is the way BEGIN blocks work -- 
they are executed at compile time as soon as they are completely defined 
and quite possibly even before other code is parsed from that script.

If I were to say the following:
    ($hour,$min,$sec) = (localtime)[0,1,2];

When the documentation clearly states that the first three elements from 
localtime are seconds, mintutes then hours.  Which would be broken, 
localtime() or my code? The fact is that I must code according to the 
way it is documented, not the way I think it should be.

Please note that what you're experiencing in your initial post is not 
even related to BEGIN block execution.  Please see my previous post in 
this thread for the explanation for your problem regarding Apache::Include.

--
Tim Tompkins



Mike McLagan wrote:

>On Fri, 8 Feb 2002 17:02:20 +0000 (GMT), Ged Haywood wrote:
>
>>>   My message is about data space.  The data space for the modules does not 
>>>seem to be recreated or reinitialized (BEGIN blocks are not rerun) from one 
>>>invocation of a script to another.
>>>
>>Yes, this is well known to mod_perl users and it's in the Guide, in
>>the same chapter that I've already suggested that you read:
>>
>>=head1 BEGIN blocks 
>>
>>Perl executes C<BEGIN> blocks as soon as possible, at the time of
>>compiling the code. The same is true under mod_perl. However, since
>>mod_perl normally only compiles scripts and modules once, either in
>>the parent server or once per-child, C<BEGIN> blocks in that code will
>>only be run once.  As the C<perlmod> manpage explains, once a C<BEGIN>
>>block has run, it is immediately undefined. In the mod_perl
>>environment, this means that C<BEGIN> blocks will not be run during
>>the response to an incoming request unless that request happens to be
>>the one that causes the compilation of the code.
>>
>
>Broken behavior, defined or not, is still broken behavior.  Maybe it's
>up to the CGI.pm author to investigate what he has to do to work around
>this problem, but that's still a work around for broken behavior.
>
>>If you are having trouble coping with mod_perl and CGI.pm perhaps it
>>would better if you tried different approach, Apache::Request for
>>example has some useful features.
>>
>
>Linux Online has been using mod_perl and CGI.pm for over 4 years now,
>I'm not about to change because I've tripped over this bug.  As my 
>original message said, I found a solution, albeit an unreasonable one.
>If Apache::Request was perl only, I might look into it since we only 
>use CGI.pm for it's query parsing abilities but with the need to drag
>along a C library, I'll pass.
>
>   Michael
>
>


Reply via email to