in reply to Re: Re: Re: RFC : Pragma vs. Module
in thread RFC : Pragma vs. Module

Liz,

This makes sense that any of the compilation phases BEGIN, CHECK, INIT etc. would not work 100% as expected when eval-ed. They are for affecting the compilation during compile-time, and eval is a run-time construct.

As for the assertion that this will not work with mod_perl, you are partially right. To start, Apache::Registry and similar CGI-to-mod_perl tools do eval the files as strings in order to run them in the persistant mod_perl environment. But this is only one very small (but very commonly used) aspect of mod_perl. The rest of mod_perl is handlers (for each of the Apache request cycles), and while I have not tested this assertion, I am pretty sure that INIT blocks as well as BEGIN, CHECK & END all run perfectly fine.

-stvn

UPDATE:
Wow, was I wrong. Apparently mod_perl evals everything, handlers and all, see my apology to Liz below.

  • Comment on Re: Re: Re: Re: RFC : Pragma vs. Module

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: RFC : Pragma vs. Module
by ysth (Canon) on Mar 14, 2004 at 23:30 UTC
    BEGIN and END work in eval "". It's just CHECK and INIT that have to be set up before the compile of the main script ends or they are "too late".

      By the way, it looks like perl 5.9.1 (and thus the eventual 5.10.0) will get a UNITCHECK that is defined to run at the end of compliation of that "compilation unit" (string eval, do file, require). That should fix the problem.

        I think that won't be in 5.9.1. It's mentioned in the perl591delta just in the todo-for-5.10 list, and 5.9.1 should be "released" any time now.

        The feature needs more discussion, anyway. As is, it doesn't sound like it would work for a module that wants something to run when the thing using it is done compiling.