Compiling a package into a namespace

Uri Guttman uri at
Fri Apr 11 20:50:54 BST 2008

>>>>> "SW" == Simon Wistow <simon at> writes:

  SW> On Fri, Apr 11, 2008 at 08:03:30PM +0100, Dave Cantrell said:
  >> which is Just Fine.  Or are you worried about, eg, both of them defining
  >> a subroutine with the same name?

  SW> Unfortunately it's not only probably but guaranteed that they'll both 
  SW> have the subroutines named the same.

here are a couple of other thoughts. first off, the slurp in source/modify
package/eval isn't so bad. it is pretty much what require does other
than the package change.

another idea is to just load one module with require into the shared
namespace and then move either the entire namespace or selected subs
into the desired space. this is not hard when accessing the stash with
%::foo (assuming foo is the space). you can even make a sub that does
this and it takes the expected space, the file/module to load and the
desired space as args.

you may want to look at Sub::Installer. if you can load the modules and
get code refs from the subs you want, that module will allow you to
install them in other packages. you can do the same load as above and
get the sub refs you want and reinstall them in another package. this
isn't that different but saves you some work and ugly symref code.

finally i have to ask, how did you get so entangled that you NEED to
load two modules with the same packages and sub names? is there any way
to rename them with different parent namespaces so you don't have the


Uri Guttman  ------  uri at  -------- --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- ---------
---------  Gourmet Hot Cocoa Mix  ---- ---------

More information about the mailing list