/usr/share/doc/libapache2-mod-perl2-doc/docs/2.0/devel/core/coding_style.html is in libapache2-mod-perl2-doc 2.0.10-2ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | <?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>
<body>
<ul id="index">
<li><a href="#NAME">NAME</a></li>
<li><a href="#Description">Description</a></li>
<li><a href="#Coding-Style-Guide">Coding Style Guide</a></li>
<li><a href="#Function-and-Variable-Prefixes-Convention">Function and Variable Prefixes Convention</a></li>
<li><a href="#Coding-Guidelines">Coding Guidelines</a>
<ul>
<li><a href="#Global-Variables">Global Variables</a></li>
<li><a href="#Modules">Modules</a></li>
<li><a href="#Methods">Methods</a></li>
<li><a href="#Inheritance">Inheritance</a></li>
<li><a href="#Symbol-tables">Symbol tables</a></li>
<li><a href="#Use-of-_-in-loops">Use of $_ in loops</a></li>
</ul>
</li>
<li><a href="#Maintainers">Maintainers</a></li>
<li><a href="#Authors">Authors</a></li>
</ul>
<h1 id="NAME">NAME</h1>
<p>mod_perl Coding Style Guide</p>
<h1 id="Description">Description</h1>
<p>This document explains the coding style used in the core mod_perl development and which should be followed by all core developers.</p>
<h1 id="Coding-Style-Guide">Coding Style Guide</h1>
<p>We try hard to code mod_perl using an identical style. Because everyone in the team should be able to read and understand the code as quickly and easily as possible. Some will have to adjust their habits for the benefit of all.</p>
<ul>
<li><p>C code</p>
<p>mod_perl's C code follows the Apache style guide: http://dev.apache.org/styleguide.html</p>
</li>
<li><p>XS code</p>
<p>C code inside XS modules also follows the Apache style guide.</p>
</li>
<li><p>Perl code</p>
<p>mod_perl's Perl code also follows the Apache style guide, in terms of indentation, braces, etc. Style issues not covered by Apache style of guide should be looked up in the <i>perlstyle</i> manpage.</p>
</li>
</ul>
<p>Here are the rough guidelines with more stress on the Perl coding style.</p>
<dl>
<dt id="Indentation-and-Tabs">Indentation and Tabs</dt>
<dd>
<p>Do use 4 characters indentation.</p>
<p>Do NOT use tabs.</p>
<p>Here is how to setup your editor to do the right thing:</p>
<ul>
<li><p>x?emacs: cperl-mode</p>
<pre><code> .xemacs/custom.el:
------------------
(custom-set-variables
'(cperl-indent-level 4)
'(cperl-continued-statement-offset 4)
'(cperl-tab-always-indent t)
'(indent-tabs-mode nil)
)</code></pre>
</li>
<li><p>vim</p>
<pre><code> .vimrc:
-------
set expandtab " replaces any tab keypress with the appropriate number of spaces
set tabstop=4 " sets tabs to 4 spaces</code></pre>
</li>
</ul>
</dd>
<dt id="Block-Braces">Block Braces</dt>
<dd>
<p>Do use a style similar to K&R style, not the same. The following example is the best guide:</p>
<p>Do:</p>
<pre><code> sub foo {
my ($self, $cond, $baz, $taz) = @_;
if ($cond) {
bar();
}
else {
$self->foo("one", 2, "...");
}
return $self;
}</code></pre>
<p>Don't:</p>
<pre><code> sub foo
{
my ($self,$bar,$baz,$taz)=@_;
if( $cond )
{
&bar();
} else { $self->foo ("one",2,"..."); }
return $self;
}</code></pre>
</dd>
<dt id="Lists-and-Arrays">Lists and Arrays</dt>
<dd>
<p>Whenever you create a list or an array, always add a comma after the last item. The reason for doing this is that it's highly probable that new items will be appended to the end of the list in the future. If the comma is missing and this isn't noticed, there will be an error.</p>
<p>Do:</p>
<pre><code> my @list = (
"item1",
"item2",
"item3",
);</code></pre>
<p>Don't:</p>
<pre><code> my @list = (
"item1",
"item2",
"item3"
);</code></pre>
</dd>
<dt id="Last-Statement-in-the-Block">Last Statement in the Block</dt>
<dd>
<p>The same goes for <code>;</code> in the last statement of the block. Almost always add it even if it's not required, so when you add a new statement you don't have to remember to add <code>;</code> on a previous line.</p>
<p>Do:</p>
<pre><code> sub foo {
statement1;
statement2;
statement3;
}</code></pre>
<p>Don't:</p>
<pre><code> sub foo {
statement1;
statement2;
statement3
}</code></pre>
</dd>
</dl>
<h1 id="Function-and-Variable-Prefixes-Convention">Function and Variable Prefixes Convention</h1>
<dl>
<dt id="modperl_">modperl_</dt>
<dd>
<p>The prefix for mod_perl C API functions.</p>
</dd>
<dt id="MP_">MP_</dt>
<dd>
<p>The prefix for mod_perl C macros.</p>
</dd>
<dt id="mpxs_">mpxs_</dt>
<dd>
<p>The prefix for mod_perl XS utility functions.</p>
</dd>
<dt id="mp_xs_">mp_xs_</dt>
<dd>
<p>The prefix for mod_perl <i>generated</i> XS utility functions.</p>
</dd>
<dt id="MPXS_">MPXS_</dt>
<dd>
<p>The prefix for mod_perl XSUBs with an XS() prototype.</p>
</dd>
</dl>
<h1 id="Coding-Guidelines">Coding Guidelines</h1>
<p>The following are the Perl coding guidelines:</p>
<h2 id="Global-Variables">Global Variables</h2>
<dl>
<dt id="avoid-globals-in-general">avoid globals in general</dt>
<dd>
</dd>
<dt id="avoid">avoid $&, $', $`</dt>
<dd>
<p>See <code>Devel::SawAmpersand</code>'s <i>README</i> that explains the evilness. Under mod_perl everybody suffers when one is seen anywhere since the interpreter is never shutdown.</p>
</dd>
</dl>
<h2 id="Modules">Modules</h2>
<dl>
<dt id="Exporting-Importing">Exporting/Importing</dt>
<dd>
<p>Avoid too much exporting/importing (glob aliases eat up memory)</p>
<p>When you do wish to import from a module try to use an explicit list or tag whenever possible, e.g.:</p>
<pre><code> use POSIX qw(strftime);</code></pre>
<p>When you do not wish to import from a module, always use an empty list to avoid any import, e.g.:</p>
<pre><code> use IO::File ();</code></pre>
<p>(explain how to use Apache2::Status to find imported/exported functions)</p>
</dd>
</dl>
<h2 id="Methods">Methods</h2>
<dl>
<dt id="indirect-vs-direct-method-calls">indirect vs direct method calls</dt>
<dd>
<p>Avoid indirect method calls, e.g.</p>
<p>Do:</p>
<pre><code> CGI::Cookie->new</code></pre>
<p>Don't:</p>
<pre><code> new CGI::Cookie</code></pre>
</dd>
</dl>
<h2 id="Inheritance">Inheritance</h2>
<dl>
<dt id="Avoid-inheriting-from-certain-modules">Avoid inheriting from certain modules</dt>
<dd>
<p>Exporter. To avoid inheriting <b>AutoLoader::AUTOLOAD</b></p>
<p>Do:</p>
<pre><code> *import = \&Exporter::import;</code></pre>
<p>Don't:</p>
<pre><code> @MyClass::ISA = qw(Exporter);</code></pre>
</dd>
</dl>
<h2 id="Symbol-tables">Symbol tables</h2>
<dl>
<dt id="main">%main::</dt>
<dd>
<p>stay away from <code>main::</code> to avoid namespace clashes</p>
</dd>
</dl>
<h2 id="Use-of-_-in-loops">Use of $_ in loops</h2>
<p>Avoid using <code>$_</code> in loops unless it's a short loop and you don't call any subs from within the loop. If the loop started as short and then started to grow make sure to remove the use of <code>$_</code>:</p>
<p>Do:</p>
<pre><code> for my $idx (1..100) {
....more than few lines...
foo($idx);
....
}</code></pre>
<p>Don't:</p>
<pre><code> for (1..100) {
....more than a few statements...
foo();
....
}</code></pre>
<p>Because foo() might change <code>$_</code> if foo()'s author didn't localize <code>$_</code>.</p>
<p>This is OK:</p>
<pre><code> for (1..100) {
.... a few statements with no subs called
# do something with $_
....
}</code></pre>
<h1 id="Maintainers">Maintainers</h1>
<p>Maintainer is the person(s) you should contact with updates, corrections and patches.</p>
<p>Stas Bekman [http://stason.org/]</p>
<h1 id="Authors">Authors</h1>
<ul>
<li><p>Doug MacEachern<dougm (at) covalent.net></p>
</li>
<li><p>Stas Bekman [http://stason.org/]</p>
</li>
</ul>
<p>Only the major authors are listed above. For contributors see the Changes file.</p>
</body>
</html>
|