in reply to That solved it!
in thread Apache::Registry losing subs created via globs.

Here is basically what Apache::Registry does to your script, and how to recreate the error:
my $code = <<EOT; sub abc::def { use Dmitri::Test; print <<HTML; Content-type: text/plain HTML use strict; use warnings; Dmitri::Test::say_hi; } EOT eval $code; abc::def();
Your 'INIT' in the module would be a valid label if it ended in a ':', or it would be a valid BEGIN block if it said "BEGIN". I'm not sure what it gets parsed as here or why it works in one situation but not the other.

Update: from perlsyn:

The LABEL is optional, and if present, consists of an identifier followed by a colon.

Update: I now see that INIT is a valid block and is in perlcompile and perlmod, though I still wouldn't know for sure why it behaves the way it does in the above situation.

Replies are listed 'Best First'.
I think I figured it out. [was: Re: Re: That solved it!]
by dmitri (Priest) on Nov 07, 2002 at 15:28 UTC
    After some playing with the code, I think I figured out what is going on. As your reference, open the Camel book, 3rd ed, to page 484.

    The thing with the INIT block is that it is executed _after_ compilation but _before_ the rest of the program is run. Another way to say it is that code in INIT block "runs just before the runtime." Then, if some code that uses INIT blocks is eval'ed, this means that the point in time _before_ runtime has passed, and INIT block does not execute.

    Fine, that answered my first question. Another problem that within eval'ed INIT block,

    sub A::B::c { ... }
    works fine. After thinking about this, it begins to make sense to me. A subroutine definition is _not_ code, but a language construct. While something like *{xyz} = sub {}; is a statement, sub abc {} is not!

    Please correct me if I'm wrong, but I think I figured it out.

And still.. [was: Re: Re: That solved it!]
by dmitri (Priest) on Nov 06, 2002 at 22:51 UTC
    However, this form
    INIT { sub Dmitri::Test::ABC::new { ... } }
    works fine. So 'INIT' _is_ a valid label, no?