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


in reply to Single module spanning multiple Packages,

Reading between the lines, common.pm doesn't have a package statement at the top?

Perl will only require a file once. So if you do things the way you're doing them, the functions defined in common.pm will end up only in the first package that loads the file.

What you want to do is make common.pm into a package in its own right, which uses Exporter or Sub::Exporter or similar to copy its functions into every package that imports it.

Sample common.pm...

package common; use Exporter 'import'; our @EXPORT = qw( do_this do_that ); sub do_this { print "doing this!\n" } sub do_that { print "doing that!\n" } 1;

Then your other modules can just:

use common;

And they automatically get do_this and do_that functions.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name