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.
63
64 Restoring original @INC
65 When the lib module is first loaded it records the current value of
66 @INC in an array @lib::ORIG_INC. To restore @INC to that value you can
67 say
68
69 @INC = @lib::ORIG_INC;
70
72 In order to keep lib.pm small and simple, it only works with Unix
73 filepaths. This doesn't mean it only works on Unix, but non-Unix users
74 must first translate their file paths to Unix conventions.
75
76 # VMS users wanting to put [.stuff.moo] into
77 # their @INC would write
78 use lib 'stuff/moo';
79
81 In the future, this module will likely use File::Spec for determining
82 paths, as it does now for Mac OS (where Unix-style or Mac-style paths
83 work, and Unix-style paths are converted properly to Mac-style paths
84 before being added to @INC).
85
86 If you try to add a file to @INC as follows:
87
88 use lib 'this_is_a_file.txt';
89
90 "lib" will warn about this. The sole exceptions are files with the
91 ".par" extension which are intended to be used as libraries.
92
94 FindBin - optional module which deals with paths relative to the source
95 file.
96
97 PAR - optional module which can treat ".par" files as Perl libraries.
98
100 Tim Bunce, 2nd June 1995.
101
102 "lib" is maintained by the perl5-porters. Please direct any questions
103 to the canonical mailing list. Anything that is applicable to the CPAN
104 release can be sent to its maintainer, though.
105
106 Maintainer: The Perl5-Porters <perl5-porters@perl.org>
107
108 Maintainer of the CPAN release: Steffen Mueller <smueller@cpan.org>
109
111 This package has been part of the perl core since perl 5.001. It has
112 been released separately to CPAN so older installations can benefit
113 from bug fixes.
114
115 This package has the same copyright and license as the perl core.
116
117
118
119perl v5.28.2 2019-04-23 lib(3pm)