On Fri, Aug 4, 2017 at 11:52 AM hw <h...@gc-24.de> wrote:

> > Often you will see a module that contains one package statement which
> leads to the confusion.
>
> Huh? How many package statements is a module supposed to contain?
> And doesn´t a package statement turn a module into a package?
>

No, package statements are not required to make a module. All that is
required to make a module is a file that is valid Perl code whose last line
evaluates to true.

It is convention for a module to start with a package statement declaring a
package with the same name as the module, but that is not a requirement.

Package statements just create a namespace.  You don't even really need the
package statement to that though.  This is a module with its own namespace
with no package statements:

use strict;
use warnings;

sub Odd::Module::foo {
    print "this is an odd module with its own namespace\n";
}

1;

The package statement just makes it so all functions and package variables
declared after it don't have to be fully qualified.

A not uncommon pattern is to have a module that has multiple packages
inside it:

package Main::Module;

package Main::Module::Helper;

1;

Reply via email to