Think about Loose Coupling | |
PerlMonks |
Perl too smart require()ing libsby clscott (Friar) |
on Jun 22, 2007 at 05:32 UTC ( [id://622720]=perlquestion: print w/replies, xml ) | Need Help?? |
clscott has asked for the wisdom of the Perl Monks concerning the following question: BackgroundAt $work we have a bunch of perl 4 style libraries that get required into apps when we need their functionality. As they are not packages they automatically pull a whole pile of subroutine and variable definitions into the main:: namespace. I wasn't feeling very happy about that. So in a effort to begin refactoring I wrote packages as wrappers around these libraries. The packages use Exporter and @EXPORT_OK so we could use the package and import only the subroutines our apps actually needed. This allows us to incrementally migrate the code base to the package style as we need to, by keeping the original libraries intact. As these types of things usually do, there are interdependencies between the libraries, for example bar.pl calls a sub defined in foo.pl so the package for bar.pl (BarWrapper.pm) needs to require both bar.pl and foo.pl The problemWhen I "use" two wrapper packages and they both "require" the same lib, the second package gets shafted and doesn't get the subroutines defined and imported into its namespace. The QuestionHow the heck can I work around or overcome this? Code to demonstrate
-- Clayton
Back to
Seekers of Perl Wisdom
|
|