Install Perl 5.8.8
[msysgit.git] / mingw / html / pod / perlmodstyle.html
blob9fbe1ed28741cae6a1c251aaac948e4c3fab75ba
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>perlmodstyle - Perl module style guide</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;perlmodstyle - Perl module style guide</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#introduction">INTRODUCTION</a></li>
24 <li><a href="#quick_checklist">QUICK CHECKLIST</a></li>
25 <ul>
27 <li><a href="#before_you_start">Before you start</a></li>
28 <li><a href="#the_api">The API</a></li>
29 <li><a href="#stability">Stability</a></li>
30 <li><a href="#documentation">Documentation</a></li>
31 <li><a href="#release_considerations">Release considerations</a></li>
32 </ul>
34 <li><a href="#before_you_start_writing_a_module">BEFORE YOU START WRITING A MODULE</a></li>
35 <ul>
37 <li><a href="#has_it_been_done_before">Has it been done before?</a></li>
38 <li><a href="#do_one_thing_and_do_it_well">Do one thing and do it well</a></li>
39 <li><a href="#what_s_in_a_name">What's in a name?</a></li>
40 </ul>
42 <li><a href="#designing_and_writing_your_module">DESIGNING AND WRITING YOUR MODULE</a></li>
43 <ul>
45 <li><a href="#to_oo_or_not_to_oo">To OO or not to OO?</a></li>
46 <li><a href="#designing_your_api">Designing your API</a></li>
47 <li><a href="#strictness_and_warnings">Strictness and warnings</a></li>
48 <li><a href="#backwards_compatibility">Backwards compatibility</a></li>
49 <li><a href="#error_handling_and_messages">Error handling and messages</a></li>
50 </ul>
52 <li><a href="#documenting_your_module">DOCUMENTING YOUR MODULE</a></li>
53 <ul>
55 <li><a href="#pod">POD</a></li>
56 <li><a href="#readme__install__release_notes__changelogs">README, INSTALL, release notes, changelogs</a></li>
57 </ul>
59 <li><a href="#release_considerations">RELEASE CONSIDERATIONS</a></li>
60 <ul>
62 <li><a href="#version_numbering">Version numbering</a></li>
63 <li><a href="#prerequisites">Pre-requisites</a></li>
64 <li><a href="#testing">Testing</a></li>
65 <li><a href="#packaging">Packaging</a></li>
66 <li><a href="#licensing">Licensing</a></li>
67 </ul>
69 <li><a href="#common_pitfalls">COMMON PITFALLS</a></li>
70 <ul>
72 <li><a href="#reinventing_the_wheel">Reinventing the wheel</a></li>
73 <li><a href="#trying_to_do_too_much">Trying to do too much</a></li>
74 <li><a href="#inappropriate_documentation">Inappropriate documentation</a></li>
75 </ul>
77 <li><a href="#see_also">SEE ALSO</a></li>
78 <li><a href="#author">AUTHOR</a></li>
79 </ul>
80 <!-- INDEX END -->
82 <hr />
83 <p>
84 </p>
85 <h1><a name="name">NAME</a></h1>
86 <p>perlmodstyle - Perl module style guide</p>
87 <p>
88 </p>
89 <hr />
90 <h1><a name="introduction">INTRODUCTION</a></h1>
91 <p>This document attempts to describe the Perl Community's ``best practice''
92 for writing Perl modules. It extends the recommendations found in
93 <a href="file://C|\msysgit\mingw\html/pod/perlstyle.html">the perlstyle manpage</a> , which should be considered required reading
94 before reading this document.</p>
95 <p>While this document is intended to be useful to all module authors, it is
96 particularly aimed at authors who wish to publish their modules on CPAN.</p>
97 <p>The focus is on elements of style which are visible to the users of a
98 module, rather than those parts which are only seen by the module's
99 developers. However, many of the guidelines presented in this document
100 can be extrapolated and applied successfully to a module's internals.</p>
101 <p>This document differs from <a href="file://C|\msysgit\mingw\html/pod/perlnewmod.html">the perlnewmod manpage</a> in that it is a style guide
102 rather than a tutorial on creating CPAN modules. It provides a
103 checklist against which modules can be compared to determine whether
104 they conform to best practice, without necessarily describing in detail
105 how to achieve this.</p>
106 <p>All the advice contained in this document has been gleaned from
107 extensive conversations with experienced CPAN authors and users. Every
108 piece of advice given here is the result of previous mistakes. This
109 information is here to help you avoid the same mistakes and the extra
110 work that would inevitably be required to fix them.</p>
111 <p>The first section of this document provides an itemized checklist;
112 subsequent sections provide a more detailed discussion of the items on
113 the list. The final section, ``Common Pitfalls'', describes some of the
114 most popular mistakes made by CPAN authors.</p>
116 </p>
117 <hr />
118 <h1><a name="quick_checklist">QUICK CHECKLIST</a></h1>
119 <p>For more detail on each item in this checklist, see below.</p>
121 </p>
122 <h2><a name="before_you_start">Before you start</a></h2>
123 <ul>
124 <li>
125 <p>Don't re-invent the wheel</p>
126 </li>
127 <li>
128 <p>Patch, extend or subclass an existing module where possible</p>
129 </li>
130 <li>
131 <p>Do one thing and do it well</p>
132 </li>
133 <li>
134 <p>Choose an appropriate name</p>
135 </li>
136 </ul>
138 </p>
139 <h2><a name="the_api">The API</a></h2>
140 <ul>
141 <li>
142 <p>API should be understandable by the average programmer</p>
143 </li>
144 <li>
145 <p>Simple methods for simple tasks</p>
146 </li>
147 <li>
148 <p>Separate functionality from output</p>
149 </li>
150 <li>
151 <p>Consistent naming of subroutines or methods</p>
152 </li>
153 <li>
154 <p>Use named parameters (a hash or hashref) when there are more than two
155 parameters</p>
156 </li>
157 </ul>
159 </p>
160 <h2><a name="stability">Stability</a></h2>
161 <ul>
162 <li>
163 <p>Ensure your module works under <code>use strict</code> and <code>-w</code></p>
164 </li>
165 <li>
166 <p>Stable modules should maintain backwards compatibility</p>
167 </li>
168 </ul>
170 </p>
171 <h2><a name="documentation">Documentation</a></h2>
172 <ul>
173 <li>
174 <p>Write documentation in POD</p>
175 </li>
176 <li>
177 <p>Document purpose, scope and target applications</p>
178 </li>
179 <li>
180 <p>Document each publically accessible method or subroutine, including params and return values</p>
181 </li>
182 <li>
183 <p>Give examples of use in your documentation</p>
184 </li>
185 <li>
186 <p>Provide a README file and perhaps also release notes, changelog, etc</p>
187 </li>
188 <li>
189 <p>Provide links to further information (URL, email)</p>
190 </li>
191 </ul>
193 </p>
194 <h2><a name="release_considerations">Release considerations</a></h2>
195 <ul>
196 <li>
197 <p>Specify pre-requisites in Makefile.PL or Build.PL</p>
198 </li>
199 <li>
200 <p>Specify Perl version requirements with <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_use"><code>use</code></a></p>
201 </li>
202 <li>
203 <p>Include tests with your module</p>
204 </li>
205 <li>
206 <p>Choose a sensible and consistent version numbering scheme (X.YY is the common Perl module numbering scheme)</p>
207 </li>
208 <li>
209 <p>Increment the version number for every change, no matter how small</p>
210 </li>
211 <li>
212 <p>Package the module using ``make dist''</p>
213 </li>
214 <li>
215 <p>Choose an appropriate license (GPL/Artistic is a good default)</p>
216 </li>
217 </ul>
219 </p>
220 <hr />
221 <h1><a name="before_you_start_writing_a_module">BEFORE YOU START WRITING A MODULE</a></h1>
222 <p>Try not to launch headlong into developing your module without spending
223 some time thinking first. A little forethought may save you a vast
224 amount of effort later on.</p>
226 </p>
227 <h2><a name="has_it_been_done_before">Has it been done before?</a></h2>
228 <p>You may not even need to write the module. Check whether it's already
229 been done in Perl, and avoid re-inventing the wheel unless you have a
230 good reason.</p>
231 <p>Good places to look for pre-existing modules include
232 <a href="http://search.cpan.org/">http://search.cpan.org/</a> and asking on <a href="mailto:modules@perl.org">modules@perl.org</a></p>
233 <p>If an existing module <strong>almost</strong> does what you want, consider writing a
234 patch, writing a subclass, or otherwise extending the existing module
235 rather than rewriting it.</p>
237 </p>
238 <h2><a name="do_one_thing_and_do_it_well">Do one thing and do it well</a></h2>
239 <p>At the risk of stating the obvious, modules are intended to be modular.
240 A Perl developer should be able to use modules to put together the
241 building blocks of their application. However, it's important that the
242 blocks are the right shape, and that the developer shouldn't have to use
243 a big block when all they need is a small one.</p>
244 <p>Your module should have a clearly defined scope which is no longer than
245 a single sentence. Can your module be broken down into a family of
246 related modules?</p>
247 <p>Bad example:</p>
248 <p>``FooBar.pm provides an implementation of the FOO protocol and the
249 related BAR standard.''</p>
250 <p>Good example:</p>
251 <p>``Foo.pm provides an implementation of the FOO protocol. Bar.pm
252 implements the related BAR protocol.''</p>
253 <p>This means that if a developer only needs a module for the BAR standard,
254 they should not be forced to install libraries for FOO as well.</p>
256 </p>
257 <h2><a name="what_s_in_a_name">What's in a name?</a></h2>
258 <p>Make sure you choose an appropriate name for your module early on. This
259 will help people find and remember your module, and make programming
260 with your module more intuitive.</p>
261 <p>When naming your module, consider the following:</p>
262 <ul>
263 <li>
264 <p>Be descriptive (i.e. accurately describes the purpose of the module).</p>
265 </li>
266 <li>
267 <p>Be consistent with existing modules.</p>
268 </li>
269 <li>
270 <p>Reflect the functionality of the module, not the implementation.</p>
271 </li>
272 <li>
273 <p>Avoid starting a new top-level hierarchy, especially if a suitable
274 hierarchy already exists under which you could place your module.</p>
275 </li>
276 </ul>
277 <p>You should contact <a href="mailto:modules@perl.org">modules@perl.org</a> to ask them about your module name
278 before publishing your module. You should also try to ask people who
279 are already familiar with the module's application domain and the CPAN
280 naming system. Authors of similar modules, or modules with similar
281 names, may be a good place to start.</p>
283 </p>
284 <hr />
285 <h1><a name="designing_and_writing_your_module">DESIGNING AND WRITING YOUR MODULE</a></h1>
286 <p>Considerations for module design and coding:</p>
288 </p>
289 <h2><a name="to_oo_or_not_to_oo">To OO or not to OO?</a></h2>
290 <p>Your module may be object oriented (OO) or not, or it may have both kinds
291 of interfaces available. There are pros and cons of each technique, which
292 should be considered when you design your API.</p>
293 <p>According to Damian Conway, you should consider using OO:</p>
294 <ul>
295 <li>
296 <p>When the system is large or likely to become so</p>
297 </li>
298 <li>
299 <p>When the data is aggregated in obvious structures that will become objects</p>
300 </li>
301 <li>
302 <p>When the types of data form a natural hierarchy that can make use of inheritance</p>
303 </li>
304 <li>
305 <p>When operations on data vary according to data type (making
306 polymorphic invocation of methods feasible)</p>
307 </li>
308 <li>
309 <p>When it is likely that new data types may be later introduced
310 into the system, and will need to be handled by existing code</p>
311 </li>
312 <li>
313 <p>When interactions between data are best represented by
314 overloaded operators</p>
315 </li>
316 <li>
317 <p>When the implementation of system components is likely to
318 change over time (and hence should be encapsulated)</p>
319 </li>
320 <li>
321 <p>When the system design is itself object-oriented</p>
322 </li>
323 <li>
324 <p>When large amounts of client code will use the software (and
325 should be insulated from changes in its implementation)</p>
326 </li>
327 <li>
328 <p>When many separate operations will need to be applied to the
329 same set of data</p>
330 </li>
331 </ul>
332 <p>Think carefully about whether OO is appropriate for your module.
333 Gratuitous object orientation results in complex APIs which are
334 difficult for the average module user to understand or use.</p>
336 </p>
337 <h2><a name="designing_your_api">Designing your API</a></h2>
338 <p>Your interfaces should be understandable by an average Perl programmer.
339 The following guidelines may help you judge whether your API is
340 sufficiently straightforward:</p>
341 <dl>
342 <dt><strong><a name="item_write_simple_routines_to_do_simple_things_2e">Write simple routines to do simple things.</a></strong>
344 <dd>
345 <p>It's better to have numerous simple routines than a few monolithic ones.
346 If your routine changes its behaviour significantly based on its
347 arguments, it's a sign that you should have two (or more) separate
348 routines.</p>
349 </dd>
350 </li>
351 <dt><strong><a name="item_separate_functionality_from_output_2e">Separate functionality from output.</a></strong>
353 <dd>
354 <p>Return your results in the most generic form possible and allow the user
355 to choose how to use them. The most generic form possible is usually a
356 Perl data structure which can then be used to generate a text report,
357 HTML, XML, a database query, or whatever else your users require.</p>
358 </dd>
359 <dd>
360 <p>If your routine iterates through some kind of list (such as a list of
361 files, or records in a database) you may consider providing a callback
362 so that users can manipulate each element of the list in turn.
363 File::Find provides an example of this with its
364 <code>find(\&amp;wanted, $dir)</code> syntax.</p>
365 </dd>
366 </li>
367 <dt><strong><a name="item_provide_sensible_shortcuts_and_defaults_2e">Provide sensible shortcuts and defaults.</a></strong>
369 <dd>
370 <p>Don't require every module user to jump through the same hoops to achieve a
371 simple result. You can always include optional parameters or routines for
372 more complex or non-standard behaviour. If most of your users have to
373 type a few almost identical lines of code when they start using your
374 module, it's a sign that you should have made that behaviour a default.
375 Another good indicator that you should use defaults is if most of your
376 users call your routines with the same arguments.</p>
377 </dd>
378 </li>
379 <dt><strong><a name="item_naming_conventions">Naming conventions</a></strong>
381 <dd>
382 <p>Your naming should be consistent. For instance, it's better to have:</p>
383 </dd>
384 <dd>
385 <pre>
386 display_day();
387 display_week();
388 display_year();</pre>
389 </dd>
390 <dd>
391 <p>than</p>
392 </dd>
393 <dd>
394 <pre>
395 display_day();
396 week_display();
397 show_year();</pre>
398 </dd>
399 <dd>
400 <p>This applies equally to method names, parameter names, and anything else
401 which is visible to the user (and most things that aren't!)</p>
402 </dd>
403 </li>
404 <dt><strong><a name="item_parameter_passing">Parameter passing</a></strong>
406 <dd>
407 <p>Use named parameters. It's easier to use a hash like this:</p>
408 </dd>
409 <dd>
410 <pre>
411 $obj-&gt;do_something(
412 name =&gt; &quot;wibble&quot;,
413 type =&gt; &quot;text&quot;,
414 size =&gt; 1024,
415 );</pre>
416 </dd>
417 <dd>
418 <p>... than to have a long list of unnamed parameters like this:</p>
419 </dd>
420 <dd>
421 <pre>
422 $obj-&gt;do_something(&quot;wibble&quot;, &quot;text&quot;, 1024);</pre>
423 </dd>
424 <dd>
425 <p>While the list of arguments might work fine for one, two or even three
426 arguments, any more arguments become hard for the module user to
427 remember, and hard for the module author to manage. If you want to add
428 a new parameter you will have to add it to the end of the list for
429 backward compatibility, and this will probably make your list order
430 unintuitive. Also, if many elements may be undefined you may see the
431 following unattractive method calls:</p>
432 </dd>
433 <dd>
434 <pre>
435 $obj-&gt;do_something(undef, undef, undef, undef, undef, undef, 1024);</pre>
436 </dd>
437 <dd>
438 <p>Provide sensible defaults for parameters which have them. Don't make
439 your users specify parameters which will almost always be the same.</p>
440 </dd>
441 <dd>
442 <p>The issue of whether to pass the arguments in a hash or a hashref is
443 largely a matter of personal style.</p>
444 </dd>
445 <dd>
446 <p>The use of hash keys starting with a hyphen (<code>-name</code>) or entirely in
447 upper case (<a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_name"><code>NAME</code></a>) is a relic of older versions of Perl in which
448 ordinary lower case strings were not handled correctly by the <code>=&gt;</code>
449 operator. While some modules retain uppercase or hyphenated argument
450 keys for historical reasons or as a matter of personal style, most new
451 modules should use simple lower case keys. Whatever you choose, be
452 consistent!</p>
453 </dd>
454 </li>
455 </dl>
457 </p>
458 <h2><a name="strictness_and_warnings">Strictness and warnings</a></h2>
459 <p>Your module should run successfully under the strict pragma and should
460 run without generating any warnings. Your module should also handle
461 taint-checking where appropriate, though this can cause difficulties in
462 many cases.</p>
464 </p>
465 <h2><a name="backwards_compatibility">Backwards compatibility</a></h2>
466 <p>Modules which are ``stable'' should not break backwards compatibility
467 without at least a long transition phase and a major change in version
468 number.</p>
470 </p>
471 <h2><a name="error_handling_and_messages">Error handling and messages</a></h2>
472 <p>When your module encounters an error it should do one or more of:</p>
473 <ul>
474 <li>
475 <p>Return an undefined value.</p>
476 </li>
477 <li>
478 <p>set <code>$Module::errstr</code> or similar (<code>errstr</code> is a common name used by
479 DBI and other popular modules; if you choose something else, be sure to
480 document it clearly).</p>
481 </li>
482 <li>
483 <p><code>warn()</code> or <code>carp()</code> a message to STDERR.</p>
484 </li>
485 <li>
486 <p><code>croak()</code> only when your module absolutely cannot figure out what to
487 do. (<code>croak()</code> is a better version of <code>die()</code> for use within
488 modules, which reports its errors from the perspective of the caller.
489 See <a href="file://C|\msysgit\mingw\html/lib/Carp.html">the Carp manpage</a> for details of <code>croak()</code>, <code>carp()</code> and other useful
490 routines.)</p>
491 </li>
492 <li>
493 <p>As an alternative to the above, you may prefer to throw exceptions using
494 the Error module.</p>
495 </li>
496 </ul>
497 <p>Configurable error handling can be very useful to your users. Consider
498 offering a choice of levels for warning and debug messages, an option to
499 send messages to a separate file, a way to specify an error-handling
500 routine, or other such features. Be sure to default all these options
501 to the commonest use.</p>
503 </p>
504 <hr />
505 <h1><a name="documenting_your_module">DOCUMENTING YOUR MODULE</a></h1>
507 </p>
508 <h2><a name="pod">POD</a></h2>
509 <p>Your module should include documentation aimed at Perl developers.
510 You should use Perl's ``plain old documentation'' (POD) for your general
511 technical documentation, though you may wish to write additional
512 documentation (white papers, tutorials, etc) in some other format.
513 You need to cover the following subjects:</p>
514 <ul>
515 <li>
516 <p>A synopsis of the common uses of the module</p>
517 </li>
518 <li>
519 <p>The purpose, scope and target applications of your module</p>
520 </li>
521 <li>
522 <p>Use of each publically accessible method or subroutine, including
523 parameters and return values</p>
524 </li>
525 <li>
526 <p>Examples of use</p>
527 </li>
528 <li>
529 <p>Sources of further information</p>
530 </li>
531 <li>
532 <p>A contact email address for the author/maintainer</p>
533 </li>
534 </ul>
535 <p>The level of detail in Perl module documentation generally goes from
536 less detailed to more detailed. Your SYNOPSIS section should contain a
537 minimal example of use (perhaps as little as one line of code; skip the
538 unusual use cases or anything not needed by most users); the
539 DESCRIPTION should describe your module in broad terms, generally in
540 just a few paragraphs; more detail of the module's routines or methods,
541 lengthy code examples, or other in-depth material should be given in
542 subsequent sections.</p>
543 <p>Ideally, someone who's slightly familiar with your module should be able
544 to refresh their memory without hitting ``page down''. As your reader
545 continues through the document, they should receive a progressively
546 greater amount of knowledge.</p>
547 <p>The recommended order of sections in Perl module documentation is:</p>
548 <ul>
549 <li>
550 <p>NAME</p>
551 </li>
552 <li>
553 <p>SYNOPSIS</p>
554 </li>
555 <li>
556 <p>DESCRIPTION</p>
557 </li>
558 <li>
559 <p>One or more sections or subsections giving greater detail of available
560 methods and routines and any other relevant information.</p>
561 </li>
562 <li>
563 <p>BUGS/CAVEATS/etc</p>
564 </li>
565 <li>
566 <p>AUTHOR</p>
567 </li>
568 <li>
569 <p>SEE ALSO</p>
570 </li>
571 <li>
572 <p>COPYRIGHT and LICENSE</p>
573 </li>
574 </ul>
575 <p>Keep your documentation near the code it documents (``inline''
576 documentation). Include POD for a given method right above that
577 method's subroutine. This makes it easier to keep the documentation up
578 to date, and avoids having to document each piece of code twice (once in
579 POD and once in comments).</p>
581 </p>
582 <h2><a name="readme__install__release_notes__changelogs">README, INSTALL, release notes, changelogs</a></h2>
583 <p>Your module should also include a README file describing the module and
584 giving pointers to further information (website, author email).</p>
585 <p>An INSTALL file should be included, and should contain simple installation
586 instructions. When using ExtUtils::MakeMaker this will usually be:</p>
587 <dl>
588 <dt><strong><a name="item_perl_makefile_2epl">perl Makefile.PL</a></strong>
590 <dt><strong><a name="item_make">make</a></strong>
592 <dt><strong><a name="item_make_test">make test</a></strong>
594 <dt><strong><a name="item_make_install">make install</a></strong>
596 </dl>
597 <p>When using Module::Build, this will usually be:</p>
598 <dl>
599 <dt><strong><a name="item_perl_build_2epl">perl Build.PL</a></strong>
601 <dt><strong><a name="item_perl_build">perl Build</a></strong>
603 <dt><strong><a name="item_perl_build_test">perl Build test</a></strong>
605 <dt><strong><a name="item_perl_build_install">perl Build install</a></strong>
607 </dl>
608 <p>Release notes or changelogs should be produced for each release of your
609 software describing user-visible changes to your module, in terms
610 relevant to the user.</p>
612 </p>
613 <hr />
614 <h1><a name="release_considerations">RELEASE CONSIDERATIONS</a></h1>
616 </p>
617 <h2><a name="version_numbering">Version numbering</a></h2>
618 <p>Version numbers should indicate at least major and minor releases, and
619 possibly sub-minor releases. A major release is one in which most of
620 the functionality has changed, or in which major new functionality is
621 added. A minor release is one in which a small amount of functionality
622 has been added or changed. Sub-minor version numbers are usually used
623 for changes which do not affect functionality, such as documentation
624 patches.</p>
625 <p>The most common CPAN version numbering scheme looks like this:</p>
626 <pre>
627 1.00, 1.10, 1.11, 1.20, 1.30, 1.31, 1.32</pre>
628 <p>A correct CPAN version number is a floating point number with at least
629 2 digits after the decimal. You can test whether it conforms to CPAN by
630 using</p>
631 <pre>
632 perl -MExtUtils::MakeMaker -le 'print MM-&gt;parse_version(shift)' 'Foo.pm'</pre>
633 <p>If you want to release a 'beta' or 'alpha' version of a module but
634 don't want CPAN.pm to list it as most recent use an '_' after the
635 regular version number followed by at least 2 digits, eg. 1.20_01. If
636 you do this, the following idiom is recommended:</p>
637 <pre>
638 $VERSION = &quot;1.12_01&quot;;
639 $XS_VERSION = $VERSION; # only needed if you have XS code
640 $VERSION = eval $VERSION;</pre>
641 <p>With that trick MakeMaker will only read the first line and thus read
642 the underscore, while the perl interpreter will evaluate the $VERSION
643 and convert the string into a number. Later operations that treat
644 $VERSION as a number will then be able to do so without provoking a
645 warning about $VERSION not being a number.</p>
646 <p>Never release anything (even a one-word documentation patch) without
647 incrementing the number. Even a one-word documentation patch should
648 result in a change in version at the sub-minor level.</p>
650 </p>
651 <h2><a name="prerequisites">Pre-requisites</a></h2>
652 <p>Module authors should carefully consider whether to rely on other
653 modules, and which modules to rely on.</p>
654 <p>Most importantly, choose modules which are as stable as possible. In
655 order of preference:</p>
656 <ul>
657 <li>
658 <p>Core Perl modules</p>
659 </li>
660 <li>
661 <p>Stable CPAN modules</p>
662 </li>
663 <li>
664 <p>Unstable CPAN modules</p>
665 </li>
666 <li>
667 <p>Modules not available from CPAN</p>
668 </li>
669 </ul>
670 <p>Specify version requirements for other Perl modules in the
671 pre-requisites in your Makefile.PL or Build.PL.</p>
672 <p>Be sure to specify Perl version requirements both in Makefile.PL or
673 Build.PL and with <code>require 5.6.1</code> or similar. See the section on
674 <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_use"><code>use VERSION</code></a> of <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_require">require in the perlfunc manpage</a> for details.</p>
676 </p>
677 <h2><a name="testing">Testing</a></h2>
678 <p>All modules should be tested before distribution (using ``make disttest''),
679 and the tests should also be available to people installing the modules
680 (using ``make test'').
681 For Module::Build you would use the <a href="#item_make_test"><code>make test</code></a> equivalent <a href="#item_perl_build_test"><code>perl Build test</code></a>.</p>
682 <p>The importance of these tests is proportional to the alleged stability of a
683 module -- a module which purports to be stable or which hopes to achieve wide
684 use should adhere to as strict a testing regime as possible.</p>
685 <p>Useful modules to help you write tests (with minimum impact on your
686 development process or your time) include Test::Simple, Carp::Assert
687 and Test::Inline.
688 For more sophisticated test suites there are Test::More and Test::MockObject.</p>
690 </p>
691 <h2><a name="packaging">Packaging</a></h2>
692 <p>Modules should be packaged using one of the standard packaging tools.
693 Currently you have the choice between ExtUtils::MakeMaker and the
694 more platform independent Module::Build, allowing modules to be installed in a
695 consistent manner.
696 When using ExtUtils::MakeMaker, you can use ``make dist'' to create your
697 package. Tools exist to help you to build your module in a MakeMaker-friendly
698 style. These include ExtUtils::ModuleMaker and h2xs. See also <a href="file://C|\msysgit\mingw\html/pod/perlnewmod.html">the perlnewmod manpage</a>.</p>
700 </p>
701 <h2><a name="licensing">Licensing</a></h2>
702 <p>Make sure that your module has a license, and that the full text of it
703 is included in the distribution (unless it's a common one and the terms
704 of the license don't require you to include it).</p>
705 <p>If you don't know what license to use, dual licensing under the GPL
706 and Artistic licenses (the same as Perl itself) is a good idea.
707 See <a href="file://C|\msysgit\mingw\html/pod/perlgpl.html">the perlgpl manpage</a> and <a href="file://C|\msysgit\mingw\html/pod/perlartistic.html">the perlartistic manpage</a>.</p>
709 </p>
710 <hr />
711 <h1><a name="common_pitfalls">COMMON PITFALLS</a></h1>
713 </p>
714 <h2><a name="reinventing_the_wheel">Reinventing the wheel</a></h2>
715 <p>There are certain application spaces which are already very, very well
716 served by CPAN. One example is templating systems, another is date and
717 time modules, and there are many more. While it is a rite of passage to
718 write your own version of these things, please consider carefully
719 whether the Perl world really needs you to publish it.</p>
721 </p>
722 <h2><a name="trying_to_do_too_much">Trying to do too much</a></h2>
723 <p>Your module will be part of a developer's toolkit. It will not, in
724 itself, form the <strong>entire</strong> toolkit. It's tempting to add extra features
725 until your code is a monolithic system rather than a set of modular
726 building blocks.</p>
728 </p>
729 <h2><a name="inappropriate_documentation">Inappropriate documentation</a></h2>
730 <p>Don't fall into the trap of writing for the wrong audience. Your
731 primary audience is a reasonably experienced developer with at least
732 a moderate understanding of your module's application domain, who's just
733 downloaded your module and wants to start using it as quickly as possible.</p>
734 <p>Tutorials, end-user documentation, research papers, FAQs etc are not
735 appropriate in a module's main documentation. If you really want to
736 write these, include them as sub-documents such as <code>My::Module::Tutorial</code> or
737 <code>My::Module::FAQ</code> and provide a link in the SEE ALSO section of the
738 main documentation.</p>
740 </p>
741 <hr />
742 <h1><a name="see_also">SEE ALSO</a></h1>
743 <dl>
744 <dt><strong><a name="item_perlstyle"><a href="file://C|\msysgit\mingw\html/pod/perlstyle.html">the perlstyle manpage</a></a></strong>
746 <dd>
747 <p>General Perl style guide</p>
748 </dd>
749 </li>
750 <dt><strong><a name="item_perlnewmod"><a href="file://C|\msysgit\mingw\html/pod/perlnewmod.html">the perlnewmod manpage</a></a></strong>
752 <dd>
753 <p>How to create a new module</p>
754 </dd>
755 </li>
756 <dt><strong><a name="item_perlpod"><a href="file://C|\msysgit\mingw\html/pod/perlpod.html">the perlpod manpage</a></a></strong>
758 <dd>
759 <p>POD documentation</p>
760 </dd>
761 </li>
762 <dt><strong><a name="item_podchecker"><a href="file://C|\msysgit\mingw\html/pod/podchecker.html">the podchecker manpage</a></a></strong>
764 <dd>
765 <p>Verifies your POD's correctness</p>
766 </dd>
767 </li>
768 <dt><strong><a name="item_packaging_tools">Packaging Tools</a></strong>
770 <dd>
771 <p><a href="file://C|\msysgit\mingw\html/lib/ExtUtils/MakeMaker.html">the ExtUtils::MakeMaker manpage</a>, <a href="file://C|\msysgit\mingw\html/Module/Build.html">the Module::Build manpage</a></p>
772 </dd>
773 </li>
774 <dt><strong><a name="item_testing_tools">Testing tools</a></strong>
776 <dd>
777 <p><a href="file://C|\msysgit\mingw\html/lib/Test/Simple.html">the Test::Simple manpage</a>, <a href="file://C|\msysgit\mingw\html/Test/Inline.html">the Test::Inline manpage</a>, <a href="file://C|\msysgit\mingw\html/Carp/Assert.html">the Carp::Assert manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/Test/More.html">the Test::More manpage</a>, <a href="file://C|\msysgit\mingw\html/Test/MockObject.html">the Test::MockObject manpage</a></p>
778 </dd>
779 </li>
780 <dt><strong><a name="item_http_3a_2f_2fpause_2eperl_2eorg_2f"><a href="http://pause.perl.org/">http://pause.perl.org/</a></a></strong>
782 <dd>
783 <p>Perl Authors Upload Server. Contains links to information for module
784 authors.</p>
785 </dd>
786 </li>
787 <dt><strong><a name="item_any_good_book_on_software_engineering">Any good book on software engineering</a></strong>
789 </dl>
791 </p>
792 <hr />
793 <h1><a name="author">AUTHOR</a></h1>
794 <p>Kirrily ``Skud'' Robert &lt;<a href="mailto:skud@cpan.org">skud@cpan.org</a>&gt;</p>
795 <table border="0" width="100%" cellspacing="0" cellpadding="3">
796 <tr><td class="block" style="background-color: #cccccc" valign="middle">
797 <big><strong><span class="block">&nbsp;perlmodstyle - Perl module style guide</span></strong></big>
798 </td></tr>
799 </table>
801 </body>
803 </html>