Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How to export a package sitting lower in a module?

by Corion (Pope)
on Apr 22, 2013 at 14:30 UTC ( #1029889=note: print w/ replies, xml ) Need Help??


in reply to How to export a package sitting lower in a module?

You try to export things from pack_A by adding them to @pack_A::EXPORT. But some of these things do not live in pack_A. You will have to export things from their respective packages. In your case, that would be pack_B for third and fourth.


Comment on Re: How to export a package sitting lower in a module?
Select or Download Code
Re^2: How to export a package sitting lower in a module?
by HelenCr (Monk) on Apr 22, 2013 at 14:33 UTC
    Corion: can you please show how to do it?

    (You can't go:
    use pack_B;
    since the interpreter looks for the file specified in "use". In other words, it will look for the module pack_B.pm, which does not exist).

      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.

        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();

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029889]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (20)
As of 2015-07-06 18:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (80 votes), past polls