in reply to BEGIN and compile-time

BEGIN { delete $INC{'ModX.pm'}; use lib '../'; } use ModX;
This will execute the BEGIN block before the use.

Replies are listed 'Best First'.
Re^2: BEGIN and compile-time
by ikegami (Patriarch) on Nov 02, 2006 at 16:59 UTC

    You might as well move out the use lib as well.

    BEGIN { delete $INC{'ModX.pm'}; } use lib '../'; use ModX;

    That way, the statements will execute in the same order as they are in the source.

Re^2: BEGIN and compile-time
by jbert (Priest) on Nov 02, 2006 at 11:43 UTC
    Thanks, that looks nicer. Is there a way of capturing and replaying the original list passed to 'use'?

    ah, but...it looks like the top-level use will call import afterwards for us (so we don't need to worry about import...it Just Works with the require). In which case maybe require is more correct, since otherwise we'll call import twice, once when we use it (with no args) and once from the original, script-level use once we finish?

      If you want to use a use without import to be called, just put some parens after the module (and nothing inside the parens):
      use ModX ();