1lib(3pm) Perl Programmers Reference Guide lib(3pm)
2
3
4
6 lib - manipulate @INC at compile time
7
9 use lib LIST;
10
11 no lib LIST;
12
14 This is a small simple module which simplifies the manipulation of @INC
15 at compile time.
16
17 It is typically used to add extra directories to perl's search path so
18 that later "use" or "require" statements will find modules which are
19 not located on perl's default search path.
20
21 Adding directories to @INC
22 The parameters to "use lib" are added to the start of the perl search
23 path. Saying
24
25 use lib LIST;
26
27 is almost the same as saying
28
29 BEGIN { unshift(@INC, LIST) }
30
31 For each directory in LIST (called $dir here) the lib module also
32 checks to see if a directory called $dir/$archname/auto exists. If so
33 the $dir/$archname directory is assumed to be a corresponding
34 architecture specific directory and is added to @INC in front of $dir.
35 lib.pm also checks if directories called $dir/$version and
36 $dir/$version/$archname exist and adds these directories to @INC.
37
38 The current value of $archname can be found with this command:
39
40 perl -V:archname
41
42 The corresponding command to get the current value of $version is:
43
44 perl -V:version
45
46 To avoid memory leaks, all trailing duplicate entries in @INC are
47 removed.
48
49 Deleting directories from @INC
50 You should normally only add directories to @INC. If you need to
51 delete directories from @INC take care to only delete those which you
52 added yourself or which you are certain are not needed by other modules
53 in your script. Other modules may have added directories which they
54 need for correct operation.
55
56 The "no lib" statement deletes all instances of each named directory
57 from @INC.
58
59 For each directory in LIST (called $dir here) the lib module also
60 checks to see if a directory called $dir/$archname/auto exists. If so
61 the $dir/$archname directory is assumed to be a corresponding
62 architecture specific directory and is also deleted from @INC. lib.pm
63 also checks if directories called $dir/$version and
64 $dir/$version/$archname exist and deletes these directories from @INC.
65
66 Restoring original @INC
67 When the lib module is first loaded it records the current value of
68 @INC in an array @lib::ORIG_INC. To restore @INC to that value you can
69 say
70
71 @INC = @lib::ORIG_INC;
72
74 In order to keep lib.pm small and simple, it only works with Unix
75 filepaths. This doesn't mean it only works on Unix, but non-Unix users
76 must first translate their file paths to Unix conventions.
77
78 # VMS users wanting to put [.stuff.moo] into
79 # their @INC would write
80 use lib 'stuff/moo';
81
83 In the future, this module will likely use File::Spec for determining
84 paths, as it does now for Mac OS (where Unix-style or Mac-style paths
85 work, and Unix-style paths are converted properly to Mac-style paths
86 before being added to @INC).
87
88 If you try to add a file to @INC as follows:
89
90 use lib 'this_is_a_file.txt';
91
92 "lib" will warn about this. The sole exceptions are files with the
93 ".par" extension which are intended to be used as libraries.
94
96 FindBin - optional module which deals with paths relative to the source
97 file.
98
99 PAR - optional module which can treat ".par" files as Perl libraries.
100
102 Tim Bunce, 2nd June 1995.
103
104 "lib" is maintained by the perl5-porters. Please direct any questions
105 to the canonical mailing list. Anything that is applicable to the CPAN
106 release can be sent to its maintainer, though.
107
108 Maintainer: The Perl5-Porters <perl5-porters@perl.org>
109
110 Maintainer of the CPAN release: Steffen Mueller <smueller@cpan.org>
111
113 This package has been part of the perl core since perl 5.001. It has
114 been released separately to CPAN so older installations can benefit
115 from bug fixes.
116
117 This package has the same copyright and license as the perl core.
118
119
120
121perl v5.32.1 2021-03-31 lib(3pm)