<?xml version="1.0" encoding="windows-1252"?>
<node id="1142" title="perlman:lib:lib" created="1999-12-22 19:49:31" updated="2005-08-13 01:12:40">
<type id="119">
perlfunc</type>
<author id="113">
root</author>
<data>
<field name="doctext">
</field>
<field name="name">

&lt;P&gt;
lib - manipulate &lt;CODE&gt;@INC&lt;/CODE&gt; at compile time

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="synopsis">

&lt;P&gt;
&lt;PRE&gt;    use lib LIST;
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;    no lib LIST;
&lt;/PRE&gt;
&lt;P&gt;
&lt;HR&gt;
</field>
<field name="description">

&lt;P&gt;
This is a small simple module which simplifies the manipulation of
&lt;CODE&gt;@INC&lt;/CODE&gt; at compile time.

&lt;P&gt;
It is typically used to add extra directories to perl's search path so that
later [perlfunc:use|use] or [perlfunc:require|require] statements will find modules which are not located on perl's default search
path.

&lt;P&gt;
&lt;HR&gt;
&lt;H2&gt;&lt;A NAME="ADDING_DIRECTORIES_TO_INC"&gt;ADDING DIRECTORIES TO @INC&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;
The parameters to &lt;CODE&gt;use lib&lt;/CODE&gt; are added to the start of the perl search path. Saying

&lt;P&gt;
&lt;PRE&gt;    use lib LIST;
&lt;/PRE&gt;
&lt;P&gt;
is &lt;EM&gt;almost&lt;/EM&gt; the same as saying

&lt;P&gt;
&lt;PRE&gt;    BEGIN { unshift(@INC, LIST) }
&lt;/PRE&gt;
&lt;P&gt;
For each directory in 
&lt;FONT SIZE=-1&gt;LIST&lt;/FONT&gt; (called &lt;CODE&gt;$dir&lt;/CODE&gt; here) the lib module
also checks to see if a directory called $dir/$archname/auto exists. If so
the $dir/$archname directory is assumed to be a corresponding architecture
specific directory and is added to &lt;CODE&gt;@INC&lt;/CODE&gt; in front of $dir.

&lt;P&gt;
If 
&lt;FONT SIZE=-1&gt;LIST&lt;/FONT&gt; includes both &lt;CODE&gt;$dir&lt;/CODE&gt; and
$dir/$archname then $dir/$archname will be added to &lt;CODE&gt;@INC&lt;/CODE&gt; twice
(if $dir/$archname/auto exists).

&lt;P&gt;
&lt;HR&gt;
&lt;H2&gt;&lt;A NAME="DELETING_DIRECTORIES_FROM_INC"&gt;DELETING DIRECTORIES FROM @INC&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;
You should normally only add directories to 
&lt;FONT SIZE=-1&gt;@INC.&lt;/FONT&gt; If you need to delete directories from
&lt;CODE&gt;@INC&lt;/CODE&gt; take care to only delete those which you added yourself
or which you are certain are not needed by other modules in your script.
Other modules may have added directories which they need for correct
operation.

&lt;P&gt;
By default the &lt;CODE&gt;no lib&lt;/CODE&gt; statement deletes the &lt;EM&gt;first&lt;/EM&gt; instance of each named directory from 
&lt;FONT SIZE=-1&gt;@INC.&lt;/FONT&gt; To delete multiple instances of the same name
from &lt;CODE&gt;@INC&lt;/CODE&gt; you can specify the name multiple times.

&lt;P&gt;
To delete &lt;EM&gt;all&lt;/EM&gt; instances of &lt;EM&gt;all&lt;/EM&gt; the specified names from &lt;CODE&gt;@INC&lt;/CODE&gt; you can specify 
&lt;FONT SIZE=-1&gt;':ALL'&lt;/FONT&gt; as the first parameter of &lt;CODE&gt;no lib&lt;/CODE&gt;. For example:

&lt;P&gt;
&lt;PRE&gt;    no lib qw(:ALL .);
&lt;/PRE&gt;
&lt;P&gt;
For each directory in 
&lt;FONT SIZE=-1&gt;LIST&lt;/FONT&gt; (called &lt;CODE&gt;$dir&lt;/CODE&gt; here) the lib module also checks to see if a directory called $dir/$archname/auto exists. If so the $dir/$archname directory is assumed to be a corresponding architecture specific directory and is also deleted from 
&lt;FONT SIZE=-1&gt;@INC.&lt;/FONT&gt;

&lt;P&gt;
If 
&lt;FONT SIZE=-1&gt;LIST&lt;/FONT&gt; includes both &lt;CODE&gt;$dir&lt;/CODE&gt; and
$dir/$archname then $dir/$archname will be deleted from &lt;CODE&gt;@INC&lt;/CODE&gt;
twice (if $dir/$archname/auto exists).

&lt;P&gt;
&lt;HR&gt;
&lt;H2&gt;&lt;A NAME="RESTORING_ORIGINAL_INC"&gt;RESTORING ORIGINAL @INC&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;
When the lib module is first loaded it records the current value of
&lt;CODE&gt;@INC&lt;/CODE&gt; in an array &lt;CODE&gt;@lib::ORIG_INC&lt;/CODE&gt;. To restore &lt;CODE&gt;@INC&lt;/CODE&gt; to that value you can say

&lt;P&gt;
&lt;PRE&gt;    @INC = @lib::ORIG_INC;
&lt;/PRE&gt;
&lt;P&gt;
&lt;HR&gt;
&lt;H1&gt;&lt;A NAME="SEE_ALSO"&gt;SEE ALSO&lt;/A&gt;&lt;/H1&gt;
&lt;P&gt;
FindBin - optional module which deals with paths relative to the source
file.

&lt;P&gt;
&lt;HR&gt;
&lt;H1&gt;&lt;A NAME="AUTHOR"&gt;AUTHOR&lt;/A&gt;&lt;/H1&gt;
&lt;P&gt;
Tim Bunce, 2nd June 1995.

&lt;HR&gt;
</field>
</data>
</node>
