perlhack.html

来自「perl教程」· HTML 代码 · 共 1,154 行 · 第 1/5 页

HTML
1,154
字号
<dt><strong><a name="item_is_the_implementation_robust_3f">Is the implementation robust?</a></strong>

<dd>
<p>Good patches (tight code, complete, correct) stand more chance of
going in.  Sloppy or incorrect patches might be placed on the back
burner until the pumpking has time to fix, or might be discarded
altogether without further notice.</p>
</dd>
</li>
<dt><strong><a name="item_is_the_implementation_generic_enough_to_be_portabl">Is the implementation generic enough to be portable?</a></strong>

<dd>
<p>The worst patches make use of a system-specific features.  It's highly
unlikely that nonportable additions to the Perl language will be
accepted.</p>
</dd>
</li>
<dt><strong><a name="item_is_the_implementation_tested_3f">Is the implementation tested?</a></strong>

<dd>
<p>Patches which change behaviour (fixing bugs or introducing new features)
must include regression tests to verify that everything works as expected.
Without tests provided by the original author, how can anyone else changing
perl in the future be sure that they haven't unwittingly broken the behaviour
the patch implements? And without tests, how can the patch's author be
confident that his/her hard work put into the patch won't be accidentally
thrown away by someone in the future?</p>
</dd>
</li>
<dt><strong><a name="item_is_there_enough_documentation_3f">Is there enough documentation?</a></strong>

<dd>
<p>Patches without documentation are probably ill-thought out or
incomplete.  Nothing can be added without documentation, so submitting
a patch for the appropriate manpages as well as the source code is
always a good idea.</p>
</dd>
</li>
<dt><strong><a name="item_is_there_another_way_to_do_it_3f">Is there another way to do it?</a></strong>

<dd>
<p>Larry said &quot;Although the Perl Slogan is <em>There's More Than One Way
to Do It</em>, I hesitate to make 10 ways to do something&quot;.  This is a
tricky heuristic to navigate, though--one man's essential addition is
another man's pointless cruft.</p>
</dd>
</li>
<dt><strong><a name="item_does_it_create_too_much_work_3f">Does it create too much work?</a></strong>

<dd>
<p>Work for the pumpking, work for Perl programmers, work for module
authors, ...  Perl is supposed to be easy.</p>
</dd>
</li>
<dt><strong><a name="item_patches_speak_louder_than_words">Patches speak louder than words</a></strong>

<dd>
<p>Working code is always preferred to pie-in-the-sky ideas.  A patch to
add a feature stands a much higher chance of making it to the language
than does a random feature request, no matter how fervently argued the
request might be.  This ties into &quot;Will it be useful?&quot;, as the fact
that someone took the time to make the patch demonstrates a strong
desire for the feature.</p>
</dd>
</li>
</dl>
<p>If you're on the list, you might hear the word &quot;core&quot; bandied
around.  It refers to the standard distribution.  &quot;Hacking on the
core&quot; means you're changing the C source code to the Perl
interpreter.  &quot;A core module&quot; is one that ships with Perl.</p>
<p>
</p>
<h2><a name="keeping_in_sync">Keeping in sync</a></h2>
<p>The source code to the Perl interpreter, in its different versions, is
kept in a repository managed by a revision control system ( which is
currently the Perforce program, see <a href="http://perforce.com/">http://perforce.com/</a> ).  The
pumpkings and a few others have access to the repository to check in
changes.  Periodically the pumpking for the development version of Perl
will release a new version, so the rest of the porters can see what's
changed.  The current state of the main trunk of repository, and patches
that describe the individual changes that have happened since the last
public release are available at this location:</p>
<pre>
    <a href="http://public.activestate.com/pub/apc/">http://public.activestate.com/pub/apc/</a>
    <a href="ftp://public.activestate.com/pub/apc/">ftp://public.activestate.com/pub/apc/</a></pre>
<p>If you're looking for a particular change, or a change that affected
a particular set of files, you may find the <strong>Perl Repository Browser</strong>
useful:</p>
<pre>
    <a href="http://public.activestate.com/cgi-bin/perlbrowse">http://public.activestate.com/cgi-bin/perlbrowse</a></pre>
<p>You may also want to subscribe to the perl5-changes mailing list to
receive a copy of each patch that gets submitted to the maintenance
and development &quot;branches&quot; of the perl repository.  See
<a href="http://lists.perl.org/">http://lists.perl.org/</a> for subscription information.</p>
<p>If you are a member of the perl5-porters mailing list, it is a good
thing to keep in touch with the most recent changes. If not only to
verify if what you would have posted as a bug report isn't already
solved in the most recent available perl development branch, also
known as perl-current, bleading edge perl, bleedperl or bleadperl.</p>
<p>Needless to say, the source code in perl-current is usually in a perpetual
state of evolution.  You should expect it to be very buggy.  Do <strong>not</strong> use
it for any purpose other than testing and development.</p>
<p>Keeping in sync with the most recent branch can be done in several ways,
but the most convenient and reliable way is using <strong>rsync</strong>, available at
<a href="ftp://rsync.samba.org/pub/rsync/">ftp://rsync.samba.org/pub/rsync/</a> .  (You can also get the most recent
branch by FTP.)</p>
<p>If you choose to keep in sync using rsync, there are two approaches
to doing so:</p>
<dl>
<dt><strong><a name="item_rsync_27ing_the_source_tree">rsync'ing the source tree</a></strong>

<dd>
<p>Presuming you are in the directory where your perl source resides
and you have rsync installed and available, you can &quot;upgrade&quot; to
the bleadperl using:</p>
</dd>
<dd>
<pre>
 <span class="comment"># rsync -avz rsync://public.activestate.com/perl-current/ .</span>
</pre>
</dd>
<dd>
<p>This takes care of updating every single item in the source tree to
the latest applied patch level, creating files that are new (to your
distribution) and setting date/time stamps of existing files to
reflect the bleadperl status.</p>
</dd>
<dd>
<p>Note that this will not delete any files that were in '.' before
the rsync. Once you are sure that the rsync is running correctly,
run it with the --delete and the --dry-run options like this:</p>
</dd>
<dd>
<pre>
 <span class="comment"># rsync -avz --delete --dry-run rsync://public.activestate.com/perl-current/ .</span>
</pre>
</dd>
<dd>
<p>This will <em>simulate</em> an rsync run that also deletes files not
present in the bleadperl master copy. Observe the results from
this run closely. If you are sure that the actual run would delete
no files precious to you, you could remove the '--dry-run' option.</p>
</dd>
<dd>
<p>You can than check what patch was the latest that was applied by
looking in the file <strong>.patch</strong>, which will show the number of the
latest patch.</p>
</dd>
<dd>
<p>If you have more than one machine to keep in sync, and not all of
them have access to the WAN (so you are not able to rsync all the
source trees to the real source), there are some ways to get around
this problem.</p>
</dd>
<dl>
<dt><strong><a name="item_using_rsync_over_the_lan">Using rsync over the LAN</a></strong>

<dd>
<p>Set up a local rsync server which makes the rsynced source tree
available to the LAN and sync the other machines against this
directory.</p>
</dd>
<dd>
<p>From <a href="http://rsync.samba.org/README.html">http://rsync.samba.org/README.html</a> :</p>
</dd>
<dd>
<pre>
   &quot;Rsync uses rsh or ssh for communication. It does not need to be
    setuid and requires no special privileges for installation.  It
    does not require an inetd entry or a daemon.  You must, however,
    have a working rsh or ssh system.  Using ssh is recommended for
    its security features.&quot;</pre>
</dd>
</li>
<dt><strong><a name="item_using_pushing_over_the_nfs">Using pushing over the NFS</a></strong>

<dd>
<p>Having the other systems mounted over the NFS, you can take an
active pushing approach by checking the just updated tree against
the other not-yet synced trees. An example would be</p>
</dd>
<dd>
<pre>
  <span class="comment">#!/usr/bin/perl -w</span>
</pre>
</dd>
<dd>
<pre>
  <span class="keyword">use</span> <span class="variable">strict</span><span class="operator">;</span>
  <span class="keyword">use</span> <span class="variable">File::Copy</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<pre>
  <span class="keyword">my</span> <span class="variable">%MF</span> <span class="operator">=</span> <span class="keyword">map</span> <span class="operator">{</span>
      <span class="regex">m/(\S+)/</span><span class="operator">;</span>
      <span class="variable">$1</span> <span class="operator">=&gt;</span> <span class="operator">[</span> <span class="operator">(</span><span class="keyword">stat</span> <span class="variable">$1</span><span class="operator">)</span><span class="operator">[</span><span class="number">2</span><span class="operator">,</span> <span class="number">7</span><span class="operator">,</span> <span class="number">9</span><span class="operator">]</span> <span class="operator">]</span><span class="operator">;</span>     <span class="comment"># mode, size, mtime</span>
      <span class="operator">}</span> <span class="string">`cat MANIFEST`</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<pre>
  <span class="keyword">my</span> <span class="variable">%remote</span> <span class="operator">=</span> <span class="keyword">map</span> <span class="operator">{</span> <span class="variable">$_</span> <span class="operator">=&gt;</span> <span class="string">"/$_/pro/3gl/CPAN/perl-5.7.1"</span> <span class="operator">}</span> <span class="string">qw(host1 host2)</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<pre>
  <span class="keyword">foreach</span> <span class="keyword">my</span> <span class="variable">$host</span> <span class="operator">(</span><span class="keyword">keys</span> <span class="variable">%remote</span><span class="operator">)</span> <span class="operator">{</span>
      <span class="keyword">unless</span> <span class="operator">(</span><span class="keyword">-d</span> <span class="variable">$remote</span><span class="operator">{</span><span class="variable">$host</span><span class="operator">}</span><span class="operator">)</span> <span class="operator">{</span>
          <span class="keyword">print</span> <span class="variable">STDERR</span> <span class="string">"Cannot Xsync for host $host\n"</span><span class="operator">;</span>
          <span class="keyword">next</span><span class="operator">;</span>
          <span class="operator">}</span>
      <span class="keyword">foreach</span> <span class="keyword">my</span> <span class="variable">$file</span> <span class="operator">(</span><span class="keyword">keys</span> <span class="variable">%MF</span><span class="operator">)</span> <span class="operator">{</span>
          <span class="keyword">my</span> <span class="variable">$rfile</span> <span class="operator">=</span> <span class="string">"$remote{$host}/$file"</span><span class="operator">;</span>
          <span class="keyword">my</span> <span class="operator">(</span><span class="variable">$mode</span><span class="operator">,</span> <span class="variable">$size</span><span class="operator">,</span> <span class="variable">$mtime</span><span class="operator">)</span> <span class="operator">=</span> <span class="operator">(</span><span class="keyword">stat</span> <span class="variable">$rfile</span><span class="operator">)</span><span class="operator">[</span><span class="number">2</span><span class="operator">,</span> <span class="number">7</span><span class="operator">,</span> <span class="number">9</span><span class="operator">]</span><span class="operator">;</span>
          <span class="keyword">defined</span> <span class="variable">$size</span> <span class="keyword">or</span> <span class="operator">(</span><span class="variable">$mode</span><span class="operator">,</span> <span class="variable">$size</span><span class="operator">,</span> <span class="variable">$mtime</span><span class="operator">)</span> <span class="operator">=</span> <span class="operator">(</span><span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">);</span>
          <span class="variable">$size</span> <span class="operator">==</span> <span class="variable">$MF</span><span class="operator">{</span><span class="variable">$file</span><span class="operator">}[</span><span class="number">1</span><span class="operator">]</span> <span class="operator">&amp;&amp;</span> <span class="variable">$mtime</span> <span class="operator">==</span> <span class="variable">$MF</span><span class="operator">{</span><span class="variable">$file</span><span class="operator">}[</span><span class="number">2</span><span class="operator">]</span> <span class="keyword">and</span> <span class="keyword">next</span><span class="operator">;</span>
          <span class="keyword">printf</span> <span class="string">"%4s %-34s %8d %9d  %8d %9d\n"</span><span class="operator">,</span>
              <span class="variable">$host</span><span class="operator">,</span> <span class="variable">$file</span><span class="operator">,</span> <span class="variable">$MF</span><span class="operator">{</span><span class="variable">$file</span><span class="operator">}[</span><span class="number">1</span><span class="operator">]</span><span class="operator">,</span> <span class="variable">$MF</span><span class="operator">{</span><span class="variable">$file</span><span class="operator">}[</span><span class="number">2</span><span class="operator">]</span><span class="operator">,</span> <span class="variable">$size</span><span class="operator">,</span> <span class="variable">$mtime</span><span class="operator">;</span>
          <span class="keyword">unlink</span> <span class="variable">$rfile</span><span class="operator">;</span>
          <span class="variable">copy</span> <span class="operator">(</span><span class="variable">$file</span><span class="operator">,</span> <span class="variable">$rfile</span><span class="operator">);</span>
          <span class="keyword">utime</span> <span class="keyword">time</span><span class="operator">,</span> <span class="variable">$MF</span><span class="operator">{</span><span class="variable">$file</span><span class="operator">}[</span><span class="number">2</span><span class="operator">]</span><span class="operator">,</span> <span class="variable">$rfile</span><span class="operator">;</span>
          <span class="keyword">chmod</span> <span class="variable">$MF</span><span class="operator">{</span><span class="variable">$file</span><span class="operator">}[</span><span class="number">0</span><span class="operator">]</span><span class="operator">,</span> <span class="variable">$rfile</span><span class="operator">;</span>
          <span class="operator">}</span>
      <span class="operator">}</span>
</pre>
</dd>
<dd>
<p>though this is not perfect. It could be improved with checking
file checksums before updating. Not all NFS systems support
reliable utime support (when used over the NFS).</p>

⌨️ 快捷键说明

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