note
tobyink
<p>Reading between the lines, common.pm doesn't have a <c>package</c> statement at the top?</p>
<p>Perl will only <c>require</c> 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.</p>
<p>What you want to do is make common.pm into a package in its own right, which uses [mod://Exporter] or [mod://Sub::Exporter] or similar to copy its functions into every package that imports it.</p>
<p>Sample common.pm...</p>
<c>
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;
</c>
<p>Then your other modules can just:</p>
<c>
use common;
</c>
<p>And they automatically get <c>do_this</c> and <c>do_that</c> functions.</p>
<div class="pmsig"><div class="pmsig-757127">
<small><small><tt>package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name</tt></small></small>
</div></div>
1017810
1017810