perlhack.html
来自「perl教程」· HTML 代码 · 共 1,154 行 · 第 1/5 页
HTML
1,154 行
<span class="variable">case</span> <span class="string">`echo $f | sed 's,.orig$,,;s,.*\.,,'`</span> <span class="variable">in</span>
<span class="variable">c</span><span class="operator">)</span> <span class="variable">diffopts</span><span class="operator">=</span><span class="keyword">-p</span> <span class="operator">;;</span>
<span class="variable">pod</span><span class="operator">)</span> <span class="variable">diffopts</span><span class="operator">=</span><span class="string">'-F^='</span> <span class="operator">;;</span>
<span class="operator">*)</span> <span class="variable">diffopts</span><span class="operator">=</span> <span class="operator">;;</span>
<span class="variable">esac</span>
<span class="variable">diff</span> <span class="operator">-</span><span class="variable">du</span> <span class="variable">$diffopts</span> <span class="variable">$f</span> <span class="string">`echo $f | sed 's,.orig$,,'`</span>
<span class="variable">done</span>
<span class="operator">}</span>
</pre>
<p>This function produces patches which include enough context to make
your changes obvious. This makes it easier for the Perl <code>pumpking(s)</code>
to review them when you send them to the perl5-porters list, and that
means they're more likely to get applied.</p>
<p>This function assumed a GNU diff, and may require some tweaking for
other diff variants.</p>
<p>
</p>
<h2><a name="perlbug_administration">Perlbug administration</a></h2>
<p>There is a single remote administrative interface for modifying bug status,
category, open issues etc. using the <strong>RT</strong> <em>bugtracker</em> system, maintained
by <em>Robert Spier</em>. Become an administrator, and close any bugs you can get
your sticky mitts on:</p>
<pre>
<a href="http://rt.perl.org">http://rt.perl.org</a></pre>
<p>The bugtracker mechanism for <strong>perl5</strong> bugs in particular is at:</p>
<pre>
<a href="http://bugs6.perl.org/perlbug">http://bugs6.perl.org/perlbug</a></pre>
<p>To email the bug system administrators:</p>
<pre>
"perlbug-admin" <perlbug-admin@perl.org></pre>
<p>
</p>
<h2><a name="submitting_patches">Submitting patches</a></h2>
<p>Always submit patches to <em><a href="mailto:perl5-porters@perl.org">perl5-porters@perl.org</a></em>. If you're
patching a core module and there's an author listed, send the author a
copy (see <a href="#patching_a_core_module">Patching a core module</a>). This lets other porters review
your patch, which catches a surprising number of errors in patches.
Either use the diff program (available in source code form from
<a href="ftp://ftp.gnu.org/pub/gnu/">ftp://ftp.gnu.org/pub/gnu/</a> , or use Johan Vromans' <em>makepatch</em>
(available from <em>CPAN/authors/id/JV/</em>). Unified diffs are preferred,
but context diffs are accepted. Do not send RCS-style diffs or diffs
without context lines. More information is given in the
<em>Porting/patching.pod</em> file in the Perl source distribution. Please
patch against the latest <strong>development</strong> version (e.g., if you're
fixing a bug in the 5.005 track, patch against the latest 5.005_5x
version). Only patches that survive the heat of the development
branch get applied to maintenance versions.</p>
<p>Your patch should update the documentation and test suite. See
<a href="#writing_a_test">Writing a test</a>.</p>
<p>To report a bug in Perl, use the program <em>perlbug</em> which comes with
Perl (if you can't get Perl to work, send mail to the address
<em><a href="mailto:perlbug@perl.org">perlbug@perl.org</a></em> or <em><a href="mailto:perlbug@perl.com">perlbug@perl.com</a></em>). Reporting bugs through
<em>perlbug</em> feeds into the automated bug-tracking system, access to
which is provided through the web at <a href="http://bugs.perl.org/">http://bugs.perl.org/</a> . It
often pays to check the archives of the perl5-porters mailing list to
see whether the bug you're reporting has been reported before, and if
so whether it was considered a bug. See above for the location of
the searchable archives.</p>
<p>The CPAN testers ( <a href="http://testers.cpan.org/">http://testers.cpan.org/</a> ) are a group of
volunteers who test CPAN modules on a variety of platforms. Perl
Smokers ( <a href="http://archives.develooper.com/daily-build@perl.org/">http://archives.develooper.com/daily-build@perl.org/</a> )
automatically tests Perl source releases on platforms with various
configurations. Both efforts welcome volunteers.</p>
<p>It's a good idea to read and lurk for a while before chipping in.
That way you'll get to see the dynamic of the conversations, learn the
personalities of the players, and hopefully be better prepared to make
a useful contribution when do you speak up.</p>
<p>If after all this you still think you want to join the perl5-porters
mailing list, send mail to <em><a href="mailto:perl5-porters-subscribe@perl.org">perl5-porters-subscribe@perl.org</a></em>. To
unsubscribe, send mail to <em><a href="mailto:perl5-porters-unsubscribe@perl.org">perl5-porters-unsubscribe@perl.org</a></em>.</p>
<p>To hack on the Perl guts, you'll need to read the following things:</p>
<dl>
<dt><strong><a name="item_perlguts"><a href="../../lib/Pod/perlguts.html">the perlguts manpage</a></a></strong>
<dd>
<p>This is of paramount importance, since it's the documentation of what
goes where in the Perl source. Read it over a couple of times and it
might start to make sense - don't worry if it doesn't yet, because the
best way to study it is to read it in conjunction with poking at Perl
source, and we'll do that later on.</p>
</dd>
<dd>
<p>You might also want to look at Gisle Aas's illustrated perlguts -
there's no guarantee that this will be absolutely up-to-date with the
latest documentation in the Perl core, but the fundamentals will be
right. ( <a href="http://gisle.aas.no/perl/illguts/">http://gisle.aas.no/perl/illguts/</a> )</p>
</dd>
</li>
<dt><strong><a name="item_perlxstut_and_perlxs"><a href="../../lib/Pod/perlxstut.html">the perlxstut manpage</a> and <a href="../../lib/Pod/perlxs.html">the perlxs manpage</a></a></strong>
<dd>
<p>A working knowledge of XSUB programming is incredibly useful for core
hacking; XSUBs use techniques drawn from the PP code, the portion of the
guts that actually executes a Perl program. It's a lot gentler to learn
those techniques from simple examples and explanation than from the core
itself.</p>
</dd>
</li>
<dt><strong><a name="item_perlapi"><a href="../../lib/Pod/perlapi.html">the perlapi manpage</a></a></strong>
<dd>
<p>The documentation for the Perl API explains what some of the internal
functions do, as well as the many macros used in the source.</p>
</dd>
</li>
<dt><strong><a name="item_porting_2fpumpkin_2epod"><em>Porting/pumpkin.pod</em></a></strong>
<dd>
<p>This is a collection of words of wisdom for a Perl porter; some of it is
only useful to the pumpkin holder, but most of it applies to anyone
wanting to go about Perl development.</p>
</dd>
</li>
<dt><strong><a name="item_the_perl5_2dporters_faq">The perl5-porters FAQ</a></strong>
<dd>
<p>This should be available from <a href="http://simon-cozens.org/writings/p5p-faq">http://simon-cozens.org/writings/p5p-faq</a> ;
alternatively, you can get the FAQ emailed to you by sending mail to
<code>perl5-porters-faq@perl.org</code>. It contains hints on reading perl5-porters,
information on how perl5-porters works and how Perl development in general
works.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="finding_your_way_around">Finding Your Way Around</a></h2>
<p>Perl maintenance can be split into a number of areas, and certain people
(pumpkins) will have responsibility for each area. These areas sometimes
correspond to files or directories in the source kit. Among the areas are:</p>
<dl>
<dt><strong><a name="item_core_modules">Core modules</a></strong>
<dd>
<p>Modules shipped as part of the Perl core live in the <em>lib/</em> and <em>ext/</em>
subdirectories: <em>lib/</em> is for the pure-Perl modules, and <em>ext/</em>
contains the core XS modules.</p>
</dd>
</li>
<dt><strong><a name="item_tests">Tests</a></strong>
<dd>
<p>There are tests for nearly all the modules, built-ins and major bits
of functionality. Test files all have a .t suffix. Module tests live
in the <em>lib/</em> and <em>ext/</em> directories next to the module being
tested. Others live in <em>t/</em>. See <a href="#writing_a_test">Writing a test</a></p>
</dd>
</li>
<dt><strong><a name="item_documentation">Documentation</a></strong>
<dd>
<p>Documentation maintenance includes looking after everything in the
<em>pod/</em> directory, (as well as contributing new documentation) and
the documentation to the modules in core.</p>
</dd>
</li>
<dt><strong><a name="item_configure">Configure</a></strong>
<dd>
<p>The configure process is the way we make Perl portable across the
myriad of operating systems it supports. Responsibility for the
configure, build and installation process, as well as the overall
portability of the core code rests with the configure pumpkin - others
help out with individual operating systems.</p>
</dd>
<dd>
<p>The files involved are the operating system directories, (<em>win32/</em>,
<em>os2/</em>, <em>vms/</em> and so on) the shell scripts which generate <em>config.h</em>
and <em>Makefile</em>, as well as the metaconfig files which generate
<em>Configure</em>. (metaconfig isn't included in the core distribution.)</p>
</dd>
</li>
<dt><strong><a name="item_interpreter">Interpreter</a></strong>
<dd>
<p>And of course, there's the core of the Perl interpreter itself. Let's
have a look at that in a little more detail.</p>
</dd>
</li>
</dl>
<p>Before we leave looking at the layout, though, don't forget that
<em>MANIFEST</em> contains not only the file names in the Perl distribution,
but short descriptions of what's in them, too. For an overview of the
important files, try this:</p>
<pre>
perl -lne 'print if /^[^\/]+\.[ch]\s+/' MANIFEST</pre>
<p>
</p>
<h2><a name="elements_of_the_interpreter">Elements of the interpreter</a></h2>
<p>The work of the interpreter has two main stages: compiling the code
into the internal representation, or bytecode, and then executing it.
<a href="../../lib/Pod/perlguts.html#compiled_code">Compiled code in the perlguts manpage</a> explains exactly how the compilation stage
happens.</p>
<p>Here is a short breakdown of perl's operation:</p>
<dl>
<dt><strong><a name="item_startup">Startup</a></strong>
<dd>
<p>The action begins in <em>perlmain.c</em>. (or <em>miniperlmain.c</em> for miniperl)
This is very high-level code, enough to fit on a single screen, and it
resembles the code found in <a href="../../lib/Pod/perlembed.html">the perlembed manpage</a>; most of the real action takes
place in <em>perl.c</em></p>
</dd>
<dd>
<p>First, <em>perlmain.c</em> allocates some memory and constructs a Perl
interpreter:</p>
</dd>
<dd>
<pre>
<span class="number">1</span> <span class="variable">PERL_SYS_INIT3</span><span class="operator">(&</span><span class="variable">argc</span><span class="operator">,&</span><span class="variable">argv</span><span class="operator">,&</span><span class="variable">env</span><span class="operator">);</span>
<span class="number">2</span>
<span class="number">3</span> <span class="keyword">if</span> <span class="operator">(!</span><span class="variable">PL_do_undump</span><span class="operator">)</span> <span class="operator">{</span>
<span class="number">4</span> <span class="variable">my_perl</span> <span class="operator">=</span> <span class="variable">perl_alloc</span><span class="operator">();</span>
<span class="number">5</span> <span class="keyword">if</span> <span class="operator">(!</span><span class="variable">my_perl</span><span class="operator">)</span>
<span class="number">6</span> <span class="keyword">exit</span><span class="operator">(</span><span class="number">1</span><span class="operator">);</span>
<span class="number">7</span> <span class="variable">perl_construct</span><span class="operator">(</span><span class="variable">my_perl</span><span class="operator">);</span>
<span class="number">8</span> <span class="variable">PL_perl_destruct_level</span> <span class="operator">=</span> <span class="number">0</span><span class="operator">;</span>
<span class="number">9</span> <span class="operator">}</span>
</pre>
</dd>
<dd>
<p>Line 1 is a macro, and its definition is dependent on your operating
system. Line 3 references <code>PL_do_undump</code>, a global variable - all
global variables in Perl start with <code>PL_</code>. This tells you whether the
current running program was created with the <a href="../../lib/Pod/perlrun.html#item__2du"><code>-u</code></a> flag to perl and then
<em>undump</em>, which means it's going to be false in any sane context.</p>
</dd>
<dd>
<p>Line 4 calls a function in <em>perl.c</em> to allocate memory for a Perl
interpreter. It's quite a simple function, and the guts of it looks like
this:</p>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?