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

Re: What is cpan (the installer) doing prepending all these directories to the PERL5LIB path?
by Intrepid (Curate) on Feb 23, 2026 at 17:18 UTC

    I'm following up to myself again. I haven't discovered exactly why this is happening but it has inflated greatly.

    Prepending blib/arch and blib/lib of 28 build dirs to PERL5LIB, reaching size 4443; for 'get'
    …
    Prepending blib/arch and blib/lib of 28 build dirs to PERL5LIB, reaching size 4443; for 'prepare'
    …
    Prepending blib/arch and blib/lib of 28 build dirs to PERL5LIB, reaching size 4443; for 'make'
    …
    Prepending blib/arch and blib/lib of 28 build dirs to PERL5LIB, reaching size 4443; for 'test'
    

    I'm doggedly determined to figure this out but others matters have intervened. I know more than a few people would say that the answer is use cpanm and it's not a bad answer; I have been using canpm some of the time. See my previous self-reply above for details on what I've looked at so far.

        – Soren
    Feb 23, 2026 at 17:12 UTC

    I anticipate that some readers will want the entire context. Here it is tucked into READMORE:

      See is_tested:

      is_tested
      List all build directories of distributions that have been tested successfully but have not yet been installed. See also install_tested.

      So it seems you are testing modules without installing them.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        It's the modules that were tested but not installed during a session. At least according to my testing, the list isn't persistent. Exiting the shell resets the list. This also means it doesn't apply to cpan -t MODULE

Re: What is cpan (the installer) doing prepending all these directories to the PERL5LIB path?
by ikegami (Patriarch) on Feb 23, 2026 at 17:47 UTC

    I don't get any instance of that message. (Wasn't using Cygwin, though.)

    Please provide the output of echo 'o conf' | cpan.

      OK, here's the output, ikegami:

      $CPAN::Config options from C:/Users/somia/.cpan/CPAN/MyConfig.pm: commit [Commit changes to disk] defaults [Reload defaults from disk] help [Short help about 'o conf' usage] init [Interactive setting of all options] allow_installing_module_downgrades [ask/no] allow_installing_outdated_dists [ask/no] applypatch [] auto_commit [0] build_cache [1822] build_dir [/cygdrive/C/Users/somia/cygwin-perl-cpan/build +] build_dir_reuse [1] build_requires_install_policy [ask/yes] bzip2 [C:/ix/cygwin/bin/bzip2.exe] cache_metadata [0] check_sigs [0] cleanup_after_install [0] colorize_debug [bold magenta on_black] colorize_output [1] colorize_print [bold magenta] colorize_warn [bold red on_black] commandnumber_in_prompt [0] commands_quote undef connect_to_internet_ok [1] cpan_home [C:/Users/somia/build/strawberry-perl] curl undef dontload_hash undef dontload_list undef ftp undef ftp_passive [1] ftp_proxy [] ftpstats_period undef ftpstats_size undef getcwd [getcwd] gpg [C:/ix/cygwin/bin/gpg.exe] gzip [C:/ix/cygwin/bin/gzip.exe] halt_on_failure [1] histfile [] histsize [699] http_proxy [] inactivity_timeout [0] index_expire [.25] inhibit_startup_message [1] keep_source_where [C:/Users/somia/AppData/strawberry-perl-sourcec +ache] load_module_verbosity [v] lynx undef make [C:/ix/cygwin/bin/make] make_arg [] make_install_arg [UNINST=1] make_install_make_command [C:/ix/cygwin/bin/make.exe] makepl_arg [] mbuild_arg [] mbuild_install_arg [] mbuild_install_build_command [./Build] mbuildpl_arg [] ncftp undef ncftpget undef no_proxy [] pager [C:/ix/cygwin/bin/less.exe] password undef patch [C:/ix/cygwin/usr/local/bin/patch.exe] patches_dir [C:/Users/somia/Documents/Patches/Distroprefs] perl5lib_verbosity [v] plugin_list prefer_external_tar [0] prefer_installer [EUMM] prefs_dir [C:/Users/somia/.cpan/distroprefs_dir] prerequisites_policy [ask] proxy_pass undef proxy_user undef pushy_https [1] randomize_urllist undef recommends_policy [1] scan_cache [atexit] shell [C:/ix/cygwin/bin/bash.exe] show_unparsable_versions [0] show_upload_date [1] show_zero_versions [1] suggests_policy [1] tar [C:/ix/cygwin/bin/tar.exe --force-local] tar_verbosity [v] term_is_latin [0] term_ornaments [1] test_report [1] trust_test_report_history [1] unzip [C:/ix/cygwin/bin/unzip.exe] urllist 0 [http://192.168.1.7/minicpan] 1 [https://www.cpan.org/] 2 [https://cpan.metacpan.org/] urllist_ping_external undef urllist_ping_verbose undef use_prompt_default [0] use_sqlite [0] username undef version_timeout [6] wait_list undef wget [C:/ix/cygwin/bin/wget.exe] yaml_load_code [1] yaml_module [YAML::XS]

      I had to clean up the ANSI escape sequences in that output, which led me to discover ansi2txt, although certainly TIMTOWTDI with this.

      Thanks!

          – Soren
      Feb 28, 2026 at 22:54 UTC