in reply to Module forwarding

Have you looked at use? It shows how use works and that should give you enough hints on how to do your "module loader" as well.

Also, maybe you want to look at perlvar regarding @INC instead of doing manual module loading?

Replies are listed 'Best First'.
Re^2: Module forwarding
by Anonymous Monk on Feb 06, 2012 at 15:43 UTC
    As far as using @INC: We want to do that with a single repository... Our format is that each lib lives in its own versioned directory -- and each directory is owned by a team member, and we have about 30 such directories... So having them individually in the path is inconvenient. We could centralize the mechanism to create @INC -- which should reduce headaches when a file upgrade occurs. Indeed, that's the motivation for centralizing them via symlinks. Each module is also run-able to provide self-tests and documentation. I had hope there was a standard CPAN solution for this... at the moment mucking around with require/import/do to see if I can hack it out......

      That concept lacks an installer. Perl has standard mechanisms for installing modules, ExtUtils::MakeMaker is the oldest one, Module::Build is newer, several others attempt to improve various details. But the best: All of these can be used by the various CPAN modules to install modules from a repository into a running system.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      .. this isn't looking very easy... My problem is that it seems to depend on whether the forwarded module uses "export" or not....
        package ForwardSimpleModule; require Exporter; @ISA = qw(Exporter); use constant FORWARDED => 'SimpleModule'; require do { FORWARDED . '.pm' }; warn; sub import { warn; my $exporter = FORWARDED . "->export_to_level(2, @_)"; my $simple = FORWARDED . "->import(@_)"; eval $exporter; eval $simple if $@; }
        The above demonstration seems to work where exporter is used and where it isn't and import doesn't require details about the caller. BUT: I still can't get it so that the forwarders filename is the same as the underlying pm and use "use" -- I think import get overwritten in the package namespace. (hence the introduction of ForwardSimpleModule namespace)