in reply to repeated use of module and EXPORT

Z uses L, so L is compiled and executed before the body of Z is even parsed. At compilation of L the assignment to @EXPORT in package Z hasn't been executed, so tough noogies - L doesn't get sub zProc, since that isn't there yet... Exporter's import (which is what's executed in Z at Z->import() ) sees an empty @EXPORT.

Use a BEGIN block to execute the assignment before compiling L via use:

package Z; use strict; use Exporter; BEGIN { our (@EXPORT) = qw(zProc subzProc); our (@ISA) = qw(Exporter); } use L; sub zProc { print "I am zProc\n"; } sub subzProc { print "I am subzProc\n"; L::lProc(); L::sublProc(); } 1;

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: repeated use of module and EXPORT
by rpelak (Sexton) on May 23, 2008 at 16:32 UTC
    wow... you are right... that does work...
    I had tried something very similar but I had the use L above the begin... I didn't think the location of the BEGIN would matter...
    So... I am guessing that use statments are just like BEGIN blocks and thus happen in the order they are encoutnered.. is that right?
      actually... how is compilation order determined... or do you have any good links to documentation about compilation order and such... I tried to find it, but most links where about compilers that make exe's out of your perl... Randell

        The basic description is found in perlmod:

        A "BEGIN" code block is executed as soon as possible, that is, the moment it is completely defined, even before the rest of the containing file (or string) is parsed. You may have multiple "BEGIN" blocks within a file (or eval'ed string) -- they will execute in order of definition. Because a "BEGIN" code block executes immediately, it can pull in definitions of subroutines and such from other files in time to be visible to the rest of the compile and run time. Once a "BEGIN" has run, it is immediately undefined and any code it used is returned to Perl's memory pool.

        Also note that use has an implicit BEGIN block around it.