You can place a copy of your perl's lib.pm into the directory where your debug versions of modules live. Then edit that lib.pm to remember the first path actually passed to use lib:

my $sticky_dir; # EDIT sub import { shift; my %names; foreach (reverse @_) { my $path = $_; # we'll be modifying it, so break the +alias $sticky_dir = $path unless $sticky_dir; # EDIT if ($path eq '') { ... # remove trailing duplicates @INC = grep { ++$names{$_} == 1 } @INC; # put sticky dir up front # EDIT @INC = ($sticky_dir, grep { ! m{^$sticky_dir$} } @INC); # EDIT return; }

See the lines marked with # EDIT. Make sure your directory is the first which gets into the private $sticky_dir variable. All subsequent calls to use lib will result in the directories being placed after the sticky directory:

#!/usr/bin/perl BEGIN{ # necessary unshift @INC,'/home/shmem/tmp/foo'; # so 'use lib' } # gets my version use lib "/home/shmem/tmp/foo"; # this dir is now sticky BEGIN { print "lib is ",$INC{"lib.pm"},$/; } use lib "/some/path"; BEGIN { print "\@INC after 'use lib \"/some/path\":\n"; print "$_\n" for @INC; } use lib "/another/path"; BEGIN { print "\@INC after 'use lib \"/another/path\":\n"; print "$_\n" for @INC; } __END__ lib is /home/shmem/tmp/foo/lib.pm @INC after 'use lib "/some/path": /home/shmem/tmp/foo /some/path /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl . @INC after 'use lib "/another/path": /home/shmem/tmp/foo /another/path /some/path /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .

update: Instead of the first BEGIN block, invoking a script like this

perl -I/my/debug/directory script

prepends /my/debug/directory to @INC to have /my/debug/directory/lib.pm loaded at the first call to use lib inside the script - so you can switch on debugging without modifying the script at all.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

In reply to Re: Containing 'use lib' statements in modules to their own namespace by shmem
in thread Containing 'use lib' statements in modules to their own namespace by lgp171188

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.