prhodes has asked for the wisdom of the Perl Monks concerning the following question:
I have alot of code, but I've stripped out as much content as possible in order to make my question simple and non-ambiguous.
Both pkga.pm and pkgb.pm are packages in their own right (in fact they are OO packages containing methods), and start with the Package keyword in order to define them as such.
In each package there is just one constructor function which works absolutely fine.
This is where the trouble starts ....
I have common.pm which is full of lots of useful functions that we use across our site, and I want it to be accessible from everywhere !
So I've placed use common within script.pl, pkga.pm, and pkg.pm.
However, when I proceed I get an error like this :
Undefined subroutine &pkga::doit called at pkga.pm line 10.
doit is the function within common.pm that I am calling from within the constructor method in pkga.pm - although it could be any method.
It's clear that perl doesnt like to load the same module within each package - most likely related to the symbol table and keeping namespaces clean.
I have discovered a fix - by simply creating another module file as a symbolic link e.g.
ln -s common.pm common_for_pkga.pm and then
use common_for_pkga; within the pkga.pm package file.
However, this seems like a crude fix, and I feel like my understanding of this entire is unsatisfactory.
I've done alot of google and monks searches but haven't been able to find a deeper exaplanation, FIX, or workaround.
This perl disciple/fan would appeciate any help or pointers.
Thanks in advance. Peter.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Single module spanning multiple Packages,
by tobyink (Canon) on Feb 08, 2013 at 13:18 UTC | |
by prhodes (Novice) on Feb 08, 2013 at 14:37 UTC | |
Re: Single module spanning multiple Packages,
by daxim (Curate) on Feb 08, 2013 at 13:18 UTC |