in reply to use directives

This sequence is completely fine. Main can "use Common" and MyLib can "use Common" too. No problem. Common.pm will be "used" and say any BEGIN{} statements will be run on first occurrence of "use Common", after that no code in Common.pm is run. Do not put .pm after the name in the "use" statement.

You are doing something with Exporter if you are exporting names from a .pm package module. Package is a name space concept. You don't have to export a name but if you don't, you will have to use the fully qualified package name for it, FOO:some_function_4, etc.

A sort of generic header for a FOO package module in the FOO package name space looks like this...(name this file FOO.pm). It is possible to have multiple "packages" within one Perl file. I strongly recommend against this practice.

use strict; use warnings; package FOO; use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION); use Exporter; our $VERSION=1.0; our @ISA = qw(Exporter); our @EXPORT = qw( some_func_name1 some_func_name2 ); our @EXPORT_OK = qw(some_optional_func_name3);
The "use FOO"; statement does not imply an inheritance hierarchy. Exporter just puts symbols into a symbol table. The form above is more like a 'C' include statement - not exactly, but similar in concept. To fiddle with OO inheritance, I figure that you need to mess with @ISA. This does inherit from Exporter, but that is what you have to do in order for you to export names into from the FOO package name space so that other modules can see them.

Replies are listed 'Best First'.
Re^2: use directives
by dsheroh (Monsignor) on Aug 05, 2009 at 09:11 UTC
    @ISA is only related to OO inheritance. You have its relationship with Exporter reversed: @ISA/inheritance does not depend on Exporter, Exporter uses inheritance ("MyModule is-a Exporter"). Most OO Perl modules do not use Exporter at all, since there's rarely a reason to export symbols into someone else's namespace if they're going to be using an OO interface to talk to you.

    Also, you can do (single) inheritance without (directly) messing with @ISA, thanks to use base. use base 'Exporter'; is equivalent to use Exporter; our @ISA = qw(Exporter);.

    Finally, I just noticed as I was finishing up that last sentence that you're declaring the variables in your example with both use vars and our. One or the other is sufficient, you don't need to do both. (Which of the two is preferred is a matter of taste, but they're functionally equivalent.)