"Fossies" - the Fresh Open Source Software Archive

Member "install-tl-20200916/tlpkg/tlperl/lib/lib.pm" (7 Mar 2020, 6136 Bytes) of package /windows/misc/install-tl.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 package lib;
    2 
    3 # THIS FILE IS AUTOMATICALLY GENERATED FROM lib_pm.PL.
    4 # ANY CHANGES TO THIS FILE WILL BE OVERWRITTEN BY THE NEXT PERL BUILD.
    5 
    6 use Config;
    7 
    8 use strict;
    9 
   10 my $archname         = $Config{archname};
   11 my $version          = $Config{version};
   12 my @inc_version_list = reverse split / /, $Config{inc_version_list};
   13 
   14 
   15 our @ORIG_INC = @INC;   # take a handy copy of 'original' value
   16 our $VERSION = '0.65';
   17 
   18 sub import {
   19     shift;
   20 
   21     my %names;
   22     foreach (reverse @_) {
   23     my $path = $_;      # we'll be modifying it, so break the alias
   24     if ($path eq '') {
   25         require Carp;
   26         Carp::carp("Empty compile time value given to use lib");
   27     }
   28 
   29     if ($path !~ /\.par$/i && -e $path && ! -d _) {
   30         require Carp;
   31         Carp::carp("Parameter to use lib must be directory, not file");
   32     }
   33     unshift(@INC, $path);
   34     # Add any previous version directories we found at configure time
   35     foreach my $incver (@inc_version_list)
   36     {
   37         my $dir = "$path/$incver";
   38         unshift(@INC, $dir) if -d $dir;
   39     }
   40     # Put a corresponding archlib directory in front of $path if it
   41     # looks like $path has an archlib directory below it.
   42     my($arch_auto_dir, $arch_dir, $version_dir, $version_arch_dir)
   43         = _get_dirs($path);
   44     unshift(@INC, $arch_dir)         if -d $arch_auto_dir;
   45     unshift(@INC, $version_dir)      if -d $version_dir;
   46     unshift(@INC, $version_arch_dir) if -d $version_arch_dir;
   47     }
   48 
   49     # remove trailing duplicates
   50     @INC = grep { ++$names{$_} == 1 } @INC;
   51     return;
   52 }
   53 
   54 
   55 sub unimport {
   56     shift;
   57 
   58     my %names;
   59     foreach my $path (@_) {
   60     my($arch_auto_dir, $arch_dir, $version_dir, $version_arch_dir)
   61         = _get_dirs($path);
   62     ++$names{$path};
   63     ++$names{$arch_dir}         if -d $arch_auto_dir;
   64     ++$names{$version_dir}      if -d $version_dir;
   65     ++$names{$version_arch_dir} if -d $version_arch_dir;
   66     }
   67 
   68     # Remove ALL instances of each named directory.
   69     @INC = grep { !exists $names{$_} } @INC;
   70     return;
   71 }
   72 
   73 sub _get_dirs {
   74     my($dir) = @_;
   75     my($arch_auto_dir, $arch_dir, $version_dir, $version_arch_dir);
   76 
   77     $arch_auto_dir    = "$dir/$archname/auto";
   78     $arch_dir         = "$dir/$archname";
   79     $version_dir      = "$dir/$version";
   80     $version_arch_dir = "$dir/$version/$archname";
   81 
   82     return($arch_auto_dir, $arch_dir, $version_dir, $version_arch_dir);
   83 }
   84 
   85 1;
   86 __END__
   87 
   88 =head1 NAME
   89 
   90 lib - manipulate @INC at compile time
   91 
   92 =head1 SYNOPSIS
   93 
   94     use lib LIST;
   95 
   96     no lib LIST;
   97 
   98 =head1 DESCRIPTION
   99 
  100 This is a small simple module which simplifies the manipulation of @INC
  101 at compile time.
  102 
  103 It is typically used to add extra directories to perl's search path so
  104 that later C<use> or C<require> statements will find modules which are
  105 not located on perl's default search path.
  106 
  107 =head2 Adding directories to @INC
  108 
  109 The parameters to C<use lib> are added to the start of the perl search
  110 path. Saying
  111 
  112     use lib LIST;
  113 
  114 is I<almost> the same as saying
  115 
  116     BEGIN { unshift(@INC, LIST) }
  117 
  118 For each directory in LIST (called $dir here) the lib module also
  119 checks to see if a directory called $dir/$archname/auto exists.
  120 If so the $dir/$archname directory is assumed to be a corresponding
  121 architecture specific directory and is added to @INC in front of $dir.
  122 lib.pm also checks if directories called $dir/$version and $dir/$version/$archname
  123 exist and adds these directories to @INC.
  124 
  125 The current value of C<$archname> can be found with this command:
  126 
  127     perl -V:archname
  128 
  129 The corresponding command to get the current value of C<$version> is:
  130 
  131     perl -V:version
  132 
  133 To avoid memory leaks, all trailing duplicate entries in @INC are
  134 removed.
  135 
  136 =head2 Deleting directories from @INC
  137 
  138 You should normally only add directories to @INC.  If you need to
  139 delete directories from @INC take care to only delete those which you
  140 added yourself or which you are certain are not needed by other modules
  141 in your script.  Other modules may have added directories which they
  142 need for correct operation.
  143 
  144 The C<no lib> statement deletes all instances of each named directory
  145 from @INC.
  146 
  147 For each directory in LIST (called $dir here) the lib module also
  148 checks to see if a directory called $dir/$archname/auto exists.
  149 If so the $dir/$archname directory is assumed to be a corresponding
  150 architecture specific directory and is also deleted from @INC. lib.pm also
  151 checks if directories called $dir/$version and $dir/$version/$archname
  152 exist and deletes these directories from @INC.
  153 
  154 =head2 Restoring original @INC
  155 
  156 When the lib module is first loaded it records the current value of @INC
  157 in an array C<@lib::ORIG_INC>. To restore @INC to that value you
  158 can say
  159 
  160     @INC = @lib::ORIG_INC;
  161 
  162 =head1 CAVEATS
  163 
  164 In order to keep lib.pm small and simple, it only works with Unix
  165 filepaths.  This doesn't mean it only works on Unix, but non-Unix
  166 users must first translate their file paths to Unix conventions.
  167 
  168     # VMS users wanting to put [.stuff.moo] into 
  169     # their @INC would write
  170     use lib 'stuff/moo';
  171 
  172 =head1 NOTES
  173 
  174 In the future, this module will likely use File::Spec for determining
  175 paths, as it does now for Mac OS (where Unix-style or Mac-style paths
  176 work, and Unix-style paths are converted properly to Mac-style paths
  177 before being added to @INC).
  178 
  179 If you try to add a file to @INC as follows:
  180 
  181   use lib 'this_is_a_file.txt';
  182 
  183 C<lib> will warn about this. The sole exceptions are files with the
  184 C<.par> extension which are intended to be used as libraries.
  185 
  186 =head1 SEE ALSO
  187 
  188 FindBin - optional module which deals with paths relative to the source file.
  189 
  190 PAR - optional module which can treat C<.par> files as Perl libraries.
  191 
  192 =head1 AUTHOR
  193 
  194 Tim Bunce, 2nd June 1995.
  195 
  196 C<lib> is maintained by the perl5-porters. Please direct
  197 any questions to the canonical mailing list. Anything that
  198 is applicable to the CPAN release can be sent to its maintainer,
  199 though.
  200 
  201 Maintainer: The Perl5-Porters <perl5-porters@perl.org>
  202 
  203 Maintainer of the CPAN release: Steffen Mueller <smueller@cpan.org>
  204 
  205 =head1 COPYRIGHT AND LICENSE
  206 
  207 This package has been part of the perl core since perl 5.001.
  208 It has been released separately to CPAN so older installations
  209 can benefit from bug fixes.
  210 
  211 This package has the same copyright and license as the perl core.
  212 
  213 =cut