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

Hello folks. I am puzzled. I've been noticing a message from cpan that I don't remember seeing before; an example is below. I was seeing 17 build dirs and then I ran install for a couple more today, and it jumped to 19. Why and how is cpan doing this? I know it's necessary when a module being built/tested/installed has prerequisites but they seem to be hanging around long after they are necessary. Anyone? If you're in the know, kindly enlighten me.

Prepending blib/arch and blib/lib of 19 build dirs to PERL5LIB, reaching size 2952; for 'install'

perl is CygwinPerl 5.40.3
CPAN/cpan is v2.38

EDIT

I've attempted to answer the question for myself, see below. Only with partial success.

Nov 25, 2025 at 18:41 UTC

  • Comment on What is cpan (the installer) doing prepending all these directories to the PERL5LIB path?

Replies are listed 'Best First'.
Re: What is cpan (the installer) doing prepending all these directories to the PERL5LIB path?
by ysth (Canon) on Nov 11, 2025 at 22:22 UTC
    Were these built in the same cpan command? Or are you saying it's adding in old builds?

      Hi Yitzchak, good to hear from you. Yes, the message spans runs of cpan, seeming to accumulate. Thanks for asking for clarification, I should have specified how this is happening.

          — Soren

      Nov 12, 2025 at 17:28 UTC

        Weird. Nuke the old directories? I almost always use cpanm.
Re: What is cpan (the installer) doing prepending all these directories to the PERL5LIB path?
by ikegami (Patriarch) on Nov 11, 2025 at 22:46 UTC

    but they seem to be hanging around long after they are necessary.

    That's impossible. A program can't change the environment of another process. It can change its own, and it can set the starting environment of its children. That's it. That means that the cpan process can't modify your shell's environment.

    If you're trying to explain env var found in your shell, start by checking your shell's login and startup scripts (e.g. .profile, .bash_profile, .bashrc).

      He's not saying anything like that. When he's doing an install it is letting him know it is adding other builds to PERL5LIB for that install, and the number is increasing, not that that env var is somehow persisting.

        That's right, ysth. I do understand how env works for the currently-running process, its child processes, its parent process, and so on, ikegami.

        Unrelated to the reported behavior is a spurious error message I'm seeing:

        prerequisite moduleFile::Basename not known
        

        This message also started appearing rather recently and doesn't seem to be connected to any actual failure in cpan. I thought I'd mention it here since it's a "while we're discussing cpan" kind of thing.

            — Soren

        Nov 14, 2025 at 19:44 UTC

        A just machine to make big decisions
        Programmed by fellows (and gals) with compassion and vision
        We'll be clean when their work is done
        We'll be eternally free yes, and eternally young
        Donald Fagen —> I.G.Y.
        (Slightly modified for inclusiveness)

Re: What is cpan (the installer) doing prepending all these directories to the PERL5LIB path?
by Intrepid (Curate) on Nov 25, 2025 at 18:33 UTC

    I've looked for answers for myself, not entirely successfully

    I did some grep-ping through modules and found out where the message in question is being generated. Lines 1496-1502 in CPAN.pm (near the end of the file, in sub set_perl5lib):

    my $cnt = keys %{$self->{is_tested}}; my $newenv = join $Config::Config{path_sep}, @dirs, @env; $CPAN::Frontend->optprint('perl5lib', sprintf ("Prepending bli +b/arch and blib/lib of ". "%d build dirs to PERL5LIB, reaching +size %d; ". "for '%s'\n", $cnt, length($newenv), +$for) ); $ENV{PERL5LIB} = $newenv;

    The code that stores the status of cached builds is this sub (line 1408):

    #-> sub CPAN::is_tested sub is_tested { my($self,$what,$when) = @_; unless ($what) { Carp::cluck("DEBUG: empty what"); return; } $self->{is_tested}{$what} = $when; }

    The code that specifies what to do with the tested modules build dirs, is this:

    sub _list_sorted_descending_is_tested { my($self) = @_; my $foul = 0; my @sorted = sort { ($self->{is_tested}{$b}||0) <=> ($self->{is_tested}{$a}||0) +} grep { if ($foul){ 0 } elsif (-e) { 1 } else { $foul = $_; +0 } } keys %{$self->{is_tested}}; if ($foul) { $CPAN::Frontend->mywarn("Lost build_dir detected ($foul), givi +ng up all cached test results of currently running session.\n"); for my $dbd (sort keys %{$self->{is_tested}}) { # distro-build +-dir SEARCH: for my $d (sort { $a->id cmp $b->id } $CPAN::META->all +_objects("CPAN::Distribution")) { if ($d->{build_dir} && $d->{build_dir} eq $dbd) { $CPAN::Frontend->mywarn(sprintf "Flushing cache fo +r %s\n", $d->pretty_id); $d->fforce(""); last SEARCH; } } delete $self->{is_tested}{$dbd}; } return (); } else { return @sorted; } }

    Finally, the code that would clear the history of tested-but-not-installed modules is this, but grep-ping through CPAN:: I find no place where it's ever called:

    #-> sub CPAN::reset_tested # forget all distributions tested -- resets what gets included in PERL +5LIB sub reset_tested { my ($self) = @_; $self->{is_tested} = {}; }

    I repeat for emphasis, this sub exists but I cannot locate anywhere that it is called from! It would be nice if the CPAN shell had a command to trigger this reset.

    I have not failed to observe that a lot of perlers have switched allegiance from CPAN.pm and CPANPLUS.pm to cpanm (cpan minus/minimal). I still like being able to cope with the older implementations of a CPAN utility, while at the same time I recognize that cpanm has its strong points. So another pair of eyes (or more than one) on this would be welcome! After all, CPAN.pm is the implementation that ships with Perl.

        — Soren
    Nov 25, 2025 at 18:32 UTC