Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

clscott (4354)

clscott
  (email not shown publicly)

Journal of clscott (4354)

Friday June 22, 2007
12:35 AM

Perl too smart require()ing libs

[ #33574 ]
Background

At $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 problem

When 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 Question

How the heck can I work around or overcome this?

Or what's an alternate solution that meets my goals?

Code and discussion on PerlMonks

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.