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
23 The parameters to "use lib" are added to the start of the perl search
24 path. Saying
25
26 use lib LIST;
27
28 is almost the same as saying
29
30 BEGIN { unshift(@INC, LIST) }
31
32 For each directory in LIST (called $dir here) the lib module also
33 checks to see if a directory called $dir/$archname/auto exists. If so
34 the $dir/$archname directory is assumed to be a corresponding architec‐
35 ture specific directory and is added to @INC in front of $dir.
36
37 To avoid memory leaks, all trailing duplicate entries in @INC are
38 removed.
39
40 Deleting directories from @INC
41
42 You should normally only add directories to @INC. If you need to
43 delete directories from @INC take care to only delete those which you
44 added yourself or which you are certain are not needed by other modules
45 in your script. Other modules may have added directories which they
46 need for correct operation.
47
48 The "no lib" statement deletes all instances of each named directory
49 from @INC.
50
51 For each directory in LIST (called $dir here) the lib module also
52 checks to see if a directory called $dir/$archname/auto exists. If so
53 the $dir/$archname directory is assumed to be a corresponding architec‐
54 ture specific directory and is also deleted from @INC.
55
56 Restoring original @INC
57
58 When the lib module is first loaded it records the current value of
59 @INC in an array @lib::ORIG_INC. To restore @INC to that value you can
60 say
61
62 @INC = @lib::ORIG_INC;
63
65 In order to keep lib.pm small and simple, it only works with Unix
66 filepaths. This doesn't mean it only works on Unix, but non-Unix users
67 must first translate their file paths to Unix conventions.
68
69 # VMS users wanting to put [.stuff.moo] into
70 # their @INC would write
71 use lib 'stuff/moo';
72
74 In the future, this module will likely use File::Spec for determining
75 paths, as it does now for Mac OS (where Unix-style or Mac-style paths
76 work, and Unix-style paths are converted properly to Mac-style paths
77 before being added to @INC).
78
80 FindBin - optional module which deals with paths relative to the source
81 file.
82
84 Tim Bunce, 2nd June 1995.
85
86
87
88perl v5.8.8 2001-09-21 lib(3pm)