http://www.perlmonks.org?node_id=1029893


in reply to Re^2: How to export a package sitting lower in a module?
in thread How to export a package sitting lower in a module?

I'm not sure how to explain "You will have to export things from their respective packages." in different words, so I'll do it by example:

package pack_B; require Exporter; @ISA = qw {Exporter}; @EXPORT = qw {third fourth}; ...

This is identical to the respective parts of pack_A, except with the obvious changes for pack_B.

Replies are listed 'Best First'.
Re^4: How to export a package sitting lower in a module?
by HelenCr (Monk) on Apr 22, 2013 at 14:53 UTC
    Corion: note that the two packages are sitting in the same module file.
    Like I said, it's not straightforward to export from a package which sits lower in a module. Please try to run this module: it doesn't work - it gives errors:
    # Name of this file: pack_A.pm package pack_A; use strict; require Exporter; @ISA = qw {Exporter}; @EXPORT = qw {first second}; sub first { } sub second { } 1; #end package pack_A; package pack_B; use strict; require Exporter; @ISA = qw {Exporter}; @EXPORT = qw {third fourth}; sub third { } sub fourth { } 1; #end package pack_B; #end of file pack_A.pm
    with the main script:
    use pack_B;
    # or use pack_A; ?
    third();

      That's how use works. It works best if you put separate packages into separate files.

      If you don't want to do that, but still want to use Exporter, you have to call pack_B->import yourself, just like use describes.

      use pack_A; # implicitly calls pack_A->import() pack_B->import(); # explicitly call pack_B->import()

      But maybe you really do not want to have both, pack_A and pack_B in a single file?