⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch12_18.htm

📁 By Tom Christiansen and Nathan Torkington ISBN 1-56592-243-3 First Edition, published August 1998
💻 HTM
字号:
<HTML><HEAD><TITLE>Recipe 12.17. Building and Installing a CPAN Module (Perl Cookbook)</TITLE><METANAME="DC.title"CONTENT="Perl Cookbook"><METANAME="DC.creator"CONTENT="Tom Christiansen &amp; Nathan Torkington"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1999-07-02T01:42:04Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-243-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch12_01.htm"TITLE="12. Packages, Libraries, and Modules"><LINKREL="prev"HREF="ch12_17.htm"TITLE="12.16. Documenting Your Module with Pod"><LINKREL="next"HREF="ch12_19.htm"TITLE="12.18. Example: Module Template"></HEAD><BODYBGCOLOR="#FFFFFF"><img alt="Book Home" border="0" src="gifs/smbanner.gif" usemap="#banner-map" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Perl Cookbook"><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><p><TABLEWIDTH="684"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch12_17.htm"TITLE="12.16. Documenting Your Module with Pod"><IMGSRC="../gifs/txtpreva.gif"ALT="Previous: 12.16. Documenting Your Module with Pod"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="228"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1"><ACLASS="chapter"REL="up"HREF="ch12_01.htm"TITLE="12. Packages, Libraries, and Modules"></A></FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch12_19.htm"TITLE="12.18. Example: Module Template"><IMGSRC="../gifs/txtnexta.gif"ALT="Next: 12.18. Example: Module Template"BORDER="0"></A></TD></TR></TABLE></DIV><DIVCLASS="sect1"><H2CLASS="sect1"><ACLASS="title"NAME="ch12-chap12_building_0">12.17. Building and Installing a CPAN Module</A></H2><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch12-pgfId-1830">Problem<ACLASS="indexterm"NAME="ch12-idx-1000005311-0"></A><ACLASS="indexterm"NAME="ch12-idx-1000005311-1"></A><ACLASS="indexterm"NAME="ch12-idx-1000005311-2"></A><ACLASS="indexterm"NAME="ch12-idx-1000005311-3"></A></A></H3><PCLASS="para">You want to install a module file that you downloaded from CPAN over the Net or obtained from a CD.</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch12-pgfId-1836">Solution</A></H3><PCLASS="para">Type the following commands into your shell. It will build and install version 4.54 of the Some::Module package.</P><PRECLASS="programlisting">% gunzip Some-Module-4.54.tar.gz% tar xf Some-Module-4.54% cd Some-Module-4.54% perl Makefile.PL% make% make test% make install</PRE></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch12-pgfId-1856">Discussion</A></H3><PCLASS="para">Like most programs on the Net, Perl modules are available in source kits stored as <EMCLASS="emphasis">tar</EM> archives in GNU zip format.[<ACLASS="footnote"HREF="#ch12-pgfId-1000000746">2</A>] If <EMCLASS="emphasis">tar</EM> warns of <CODECLASS="literal">&quot;Directory</CODE> <CODECLASS="literal">checksum</CODE> <CODECLASS="literal">errors&quot;</CODE>, then you downloaded the binary file in text format, mutilating it.</P><BLOCKQUOTECLASS="footnote"><DIVCLASS="footnote"><PCLASS="para"><ACLASS="footnote"NAME="ch12-pgfId-1000000746">[2]</A> This is not the same as the zip format common on Windows machines, but newer version of Windows <EMCLASS="emphasis">winzip</EM> will read it. Prior to Perl 5.005, you'll need the standard port of Perl for Win32, not the ActiveState port, to build CPAN modules. Free versions of <EMCLASS="emphasis">tar</EM> and <EMCLASS="emphasis">gnutar</EM> are also available for Microsoft systems.</P></DIV></BLOCKQUOTE><PCLASS="para">You'll probably have to become a privileged user with adequate permissions to install the module in the system directories. Standard modules are installed in a directory like <EMCLASS="emphasis">/usr/lib/perl5</EM> while third-party modules are installed in <EMCLASS="emphasis">/usr/lib/perl5/site_ perl</EM>.</P><PCLASS="para">Here's a sample run, showing the installation of the MD5 module:</P><PRECLASS="programlisting">% gunzip MD5-1.7.tar.gz% tar xf MD5-1.7.tar% cd MD5-1.7% perl Makefile.PL <CODECLASS="userinput"><B><CODECLASS="replaceable"><I>Checking if your kit is complete...</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>Looks good</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>Writing Makefile for MD5</I></CODE></B></CODE>% make<CODECLASS="userinput"><B><CODECLASS="replaceable"><I>mkdir ./blib</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>mkdir ./blib/lib</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>cp MD5.pm ./blib/lib/MD5.pm</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>AutoSplitting MD5 (./blib/lib/auto/MD5)</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>/usr/bin/perl -I/usr/local/lib/perl5/i386 ...</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>...</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>cp MD5.bs ./blib/arch/auto/MD5/MD5.bs</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>chmod 644 ./blib/arch/auto/MD5/MD5.bsmkdir ./blib/man3</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>Manifying ./blib/man3/MD5.3</I></CODE></B></CODE>% make test<CODECLASS="userinput"><B><CODECLASS="replaceable"><I>PERL_DL_NONLAZY=1 /usr/bin/perl -I./blib/arch -I./blib/lib</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>-I/usr/local/lib/perl5/i386-freebsd/5.00404 -I/usr/local/lib/perl5 test.pl</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>1..14</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>ok 1</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>ok 2</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>...</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>ok 13</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>ok 14</I></CODE></B></CODE>% sudo make install<CODECLASS="userinput"><B><CODECLASS="replaceable"><I>Password:</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>Installing /usr/local/lib/perl5/site_perl/i386-freebsd/./auto/MD5/</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>    MD5.so</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>Installing /usr/local/lib/perl5/site_perl/i386-freebsd/./auto/MD5/</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>    MD5.bs</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>Installing /usr/local/lib/perl5/site_perl/./auto/MD5/autosplit.ix</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>Installing /usr/local/lib/perl5/site_perl/./MD5.pm</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>Installing /usr/local/lib/perl5/man/man3/./MD5.3</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>Writing /usr/local/lib/perl5/site_perl/i386-freebsd/auto/MD5/.packlist</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>Appending installation info to /usr/local/lib/perl5/i386-freebsd/</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>5.00404/perllocal.pod</I></CODE></B></CODE></PRE><PCLASS="para">If your system manager isn't around or can't be prevailed upon to run the installation, don't worry. When you use Perl to generate the Makefile from template <EMCLASS="emphasis">Makefile.PL</EM>, you can specify alternate installation directories.</P><PRECLASS="programlisting"># if you just want the modules installed in your own directory% perl Makefile.PL LIB=~/lib# if you have your own a complete distribution% perl Makefile.PL PREFIX=~/perl5-private<ACLASS="indexterm"NAME="ch12-idx-1000005313-0"></A><ACLASS="indexterm"NAME="ch12-idx-1000005313-1"></A><ACLASS="indexterm"NAME="ch12-idx-1000005313-2"></A></PRE></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch12-pgfId-1950">See Also</A></H3><PCLASS="para">The documentation for the standard ExtUtils::MakeMaker module, also in <ACLASS="olink"HREF="../prog/ch07_01.htm">Chapter 7</A> of <ACLASS="citetitle"HREF="../prog/index.htm"TITLE="Programming Perl"><CITECLASS="citetitle">Programming Perl</CITE></A>; the INSTALL file in the Perl source distribution for information on building a staticly linked <ICLASS="filename">perl</I> binary.</P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="684"TITLE="footer"><TABLEWIDTH="684"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch12_17.htm"TITLE="12.16. Documenting Your Module with Pod"><IMGSRC="../gifs/txtpreva.gif"ALT="Previous: 12.16. Documenting Your Module with Pod"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="228"><ACLASS="book"HREF="index.htm"TITLE="Perl Cookbook"><IMGSRC="../gifs/txthome.gif"ALT="Perl Cookbook"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch12_19.htm"TITLE="12.18. Example: Module Template"><IMGSRC="../gifs/txtnexta.gif"ALT="Next: 12.18. Example: Module Template"BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="228">12.16. Documenting Your Module with Pod</TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="228"><ACLASS="index"HREF="index/index.htm"TITLE="Book Index"><IMGSRC="../gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="228">12.18. Example: Module Template</TD></TR></TABLE><HRALIGN="LEFT"WIDTH="684"TITLE="footer"><FONTSIZE="-1"></DIV<!-- LIBRARY NAV BAR --> <img src="../gifs/smnavbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links"><p> <a href="copyrght.htm">Copyright &copy; 2002</a> O'Reilly &amp; Associates. All rights reserved.</font> </p> <map name="library-map"> <area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map> </BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -