ric00015 has asked for the wisdom of the Perl Monks concerning the following question:

This is a continuation of a previous node, found here. I am making a new node, rather than continuing the old one, to clarify and simplify. If you haven't read that one, please do; this node might make more sense once you do.

My problem stems from the fact that I recently did a mass upgrade on my CPAN, and subsequently broke something that seems to be important to exporting module functions or loading incomplete modules.

In my other nodes, I talked about my program for work. Here's a basic structure for it. Let's call the main script main.pl, with an explicit package of main. I have several modules: CG::GUI.pm, which holds Tk code, CG::CORE2.pm, which holds most of the logic, and Paths.pm, which was written by a coworker. In main.pl, I use CG::GUI and CG::CORE2. In CG::CORE2 I use Paths and other modules. But Paths is the one I'm having problems with. I have to use lib '/abs/path/to/module'; for each module for specific reasons, which may not be important now. The specific error I am getting, when I run main.pl, is:

Undefined subroutine &Paths::get_config called at /abs/path/to/CG/CORE2.pm line 128, <FILE> line 30.

Line 128 in CG::CORE2 is:

%config = %{Paths::get_config($var1, $var2)};

This is just with a use Paths; statement. When I put a require '/abs/path/to/Paths.pm';, I get 9 warnings such as:

Subroutine sub1 redefined at /abs/path/to/Paths.pm line 68.

(use diagnostics; doesn't help much; it only says how to disable the warnings)

9 subroutines are being redefined, which means Paths.pm is being loaded with only 9 subroutines. However, there are 15 subroutines being exported, and more that aren't. The specific subroutine mentioned above in line 128 is not among the exported.

So the question has gone from "What did I do and how do I fix it?" to "What could possibly cause a module to partially load?" For the sake of completeness, I installed other versions of Perl. The one that got updated and borked was 5.16.0. I installed a fresh instance of the same version, plus 5.18.1. (System Perl is completely separate.) All had the same errors/warnings (with the trivial exception listed in the previous node. I will not go into detail here).

This indicates, to me at least, 2 possibilities. 1) that a common file/setting/env variable was corrupted. This would suck, because I have no idea what all 3 Perls would use. They are all installed separately; they all have their own CPAN/modules; they should all be independent, especially if the script explicitly states which Perl to use.

Or 2) a module that was updated broke something, and the recently installed Perls also have that module. This also sucks, because I have no idea which CPAN module I need to look for. Once I have the (hopefully small) list of modules, I can see which Perl has which version of the modules.

tl;dr: One of my modules doesn't contain all the subroutine it is supposed to at run-time. It's either an export issue, or just an incomplete load. Or something totally different. I don't know yet.

Replies are listed 'Best First'.
Re: Module not loading completely? Part 2
by Corion (Patriarch) on Oct 30, 2013 at 20:33 UTC

    This still sounds as if you are either loading the wrong module (maybe an old(er) version) or loading the same module (or package) twice.

    A potential approach to find out what modules actually get loaded is to make Perl output every file as it loads them:

    #!perl -w use strict; use Data::Dumper; warn "Looking for files in"; warn Dumper \@INC; warn "PERL5LIB=$ENV{PERL5LIB}" if $ENV{ PERL5LIB }; BEGIN { unshift @INC, sub { warn "Loading module from $_[1]"; warn Dum +per \%INC; undef }}; use CG::CORE2; warn "Done.";

    This will show you what modules get loaded in every step, and from what file. Hopefully, an old version of your file will simply present itself there.

      You are my hero! The culprit was PERL5LIB. It was pointing to an old directory containing mostly-unused and way out of date modules. I would never have found that without your code. If I could vote your solution up more than once, I would. And I'll have to wait until tomorrow to do so anyway.

      Now the question (albeit, unimportant) becomes, "Why did upgrading my CPAN modules trigger this change? Why didn't this show up before?" Still not going to mass-upgrade modules again. Ah, well. PERL5LIB is changed, problem solved, another tangentially related problem may also have been solved, this new question is not important. Today has been a good day. Thanks again.

      Oh, and the 9 subroutines that were mentioned in the warnings? They were all of the exported subs from that old version of Paths.pm. Just another tiny piece in this puzzle.

Re: Module not loading completely? Part 2
by MidLifeXis (Monsignor) on Oct 30, 2013 at 20:16 UTC

    Can you create a short, self contained example that you can post here? That would go a long way to help us help you.

    --MidLifeXis