| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "PERLMODSTYLE 1" |
| 58 |
.TH PERLMODSTYLE 1 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
perlmodstyle \- Perl module style guide |
| 65 |
.SH INTRODUCTION |
| 66 |
.IX Header "INTRODUCTION" |
| 67 |
This document attempts to describe the Perl Community's "best practice" |
| 68 |
for writing Perl modules. It extends the recommendations found in |
| 69 |
perlstyle , which should be considered required reading |
| 70 |
before reading this document. |
| 71 |
.PP |
| 72 |
While this document is intended to be useful to all module authors, it is |
| 73 |
particularly aimed at authors who wish to publish their modules on CPAN. |
| 74 |
.PP |
| 75 |
The focus is on elements of style which are visible to the users of a |
| 76 |
module, rather than those parts which are only seen by the module's |
| 77 |
developers. However, many of the guidelines presented in this document |
| 78 |
can be extrapolated and applied successfully to a module's internals. |
| 79 |
.PP |
| 80 |
This document differs from perlnewmod in that it is a style guide |
| 81 |
rather than a tutorial on creating CPAN modules. It provides a |
| 82 |
checklist against which modules can be compared to determine whether |
| 83 |
they conform to best practice, without necessarily describing in detail |
| 84 |
how to achieve this. |
| 85 |
.PP |
| 86 |
All the advice contained in this document has been gleaned from |
| 87 |
extensive conversations with experienced CPAN authors and users. Every |
| 88 |
piece of advice given here is the result of previous mistakes. This |
| 89 |
information is here to help you avoid the same mistakes and the extra |
| 90 |
work that would inevitably be required to fix them. |
| 91 |
.PP |
| 92 |
The first section of this document provides an itemized checklist; |
| 93 |
subsequent sections provide a more detailed discussion of the items on |
| 94 |
the list. The final section, "Common Pitfalls", describes some of the |
| 95 |
most popular mistakes made by CPAN authors. |
| 96 |
.SH "QUICK CHECKLIST" |
| 97 |
.IX Header "QUICK CHECKLIST" |
| 98 |
For more detail on each item in this checklist, see below. |
| 99 |
.SS "Before you start" |
| 100 |
.IX Subsection "Before you start" |
| 101 |
.IP \(bu 4 |
| 102 |
Don't re-invent the wheel |
| 103 |
.IP \(bu 4 |
| 104 |
Patch, extend or subclass an existing module where possible |
| 105 |
.IP \(bu 4 |
| 106 |
Do one thing and do it well |
| 107 |
.IP \(bu 4 |
| 108 |
Choose an appropriate name |
| 109 |
.IP \(bu 4 |
| 110 |
Get feedback before publishing |
| 111 |
.SS "The API" |
| 112 |
.IX Subsection "The API" |
| 113 |
.IP \(bu 4 |
| 114 |
API should be understandable by the average programmer |
| 115 |
.IP \(bu 4 |
| 116 |
Simple methods for simple tasks |
| 117 |
.IP \(bu 4 |
| 118 |
Separate functionality from output |
| 119 |
.IP \(bu 4 |
| 120 |
Consistent naming of subroutines or methods |
| 121 |
.IP \(bu 4 |
| 122 |
Use named parameters (a hash or hashref) when there are more than two |
| 123 |
parameters |
| 124 |
.SS Stability |
| 125 |
.IX Subsection "Stability" |
| 126 |
.IP \(bu 4 |
| 127 |
Ensure your module works under \f(CW\*(C`use strict\*(C'\fR and \f(CW\*(C`\-w\*(C'\fR |
| 128 |
.IP \(bu 4 |
| 129 |
Stable modules should maintain backwards compatibility |
| 130 |
.SS Documentation |
| 131 |
.IX Subsection "Documentation" |
| 132 |
.IP \(bu 4 |
| 133 |
Write documentation in POD |
| 134 |
.IP \(bu 4 |
| 135 |
Document purpose, scope and target applications |
| 136 |
.IP \(bu 4 |
| 137 |
Document each publicly accessible method or subroutine, including params and return values |
| 138 |
.IP \(bu 4 |
| 139 |
Give examples of use in your documentation |
| 140 |
.IP \(bu 4 |
| 141 |
Provide a README file and perhaps also release notes, changelog, etc |
| 142 |
.IP \(bu 4 |
| 143 |
Provide links to further information (URL, email) |
| 144 |
.SS "Release considerations" |
| 145 |
.IX Subsection "Release considerations" |
| 146 |
.IP \(bu 4 |
| 147 |
Specify pre-requisites in Makefile.PL or Build.PL |
| 148 |
.IP \(bu 4 |
| 149 |
Specify Perl version requirements with \f(CW\*(C`use\*(C'\fR |
| 150 |
.IP \(bu 4 |
| 151 |
Include tests with your module |
| 152 |
.IP \(bu 4 |
| 153 |
Choose a sensible and consistent version numbering scheme (X.YY is the common Perl module numbering scheme) |
| 154 |
.IP \(bu 4 |
| 155 |
Increment the version number for every change, no matter how small |
| 156 |
.IP \(bu 4 |
| 157 |
Package the module using "make dist" |
| 158 |
.IP \(bu 4 |
| 159 |
Choose an appropriate license (GPL/Artistic is a good default) |
| 160 |
.SH "BEFORE YOU START WRITING A MODULE" |
| 161 |
.IX Header "BEFORE YOU START WRITING A MODULE" |
| 162 |
Try not to launch headlong into developing your module without spending |
| 163 |
some time thinking first. A little forethought may save you a vast |
| 164 |
amount of effort later on. |
| 165 |
.SS "Has it been done before?" |
| 166 |
.IX Subsection "Has it been done before?" |
| 167 |
You may not even need to write the module. Check whether it's already |
| 168 |
been done in Perl, and avoid re-inventing the wheel unless you have a |
| 169 |
good reason. |
| 170 |
.PP |
| 171 |
Good places to look for pre-existing modules include |
| 172 |
MetaCPAN <https://metacpan.org> and asking on \f(CW\*(C`module\[email protected]\*(C'\fR |
| 173 |
(<https://lists.perl.org/list/module\-authors.html>). |
| 174 |
.PP |
| 175 |
If an existing module \fBalmost\fR does what you want, consider writing a |
| 176 |
patch, writing a subclass, or otherwise extending the existing module |
| 177 |
rather than rewriting it. |
| 178 |
.SS "Do one thing and do it well" |
| 179 |
.IX Subsection "Do one thing and do it well" |
| 180 |
At the risk of stating the obvious, modules are intended to be modular. |
| 181 |
A Perl developer should be able to use modules to put together the |
| 182 |
building blocks of their application. However, it's important that the |
| 183 |
blocks are the right shape, and that the developer shouldn't have to use |
| 184 |
a big block when all they need is a small one. |
| 185 |
.PP |
| 186 |
Your module should have a clearly defined scope which is no longer than |
| 187 |
a single sentence. Can your module be broken down into a family of |
| 188 |
related modules? |
| 189 |
.PP |
| 190 |
Bad example: |
| 191 |
.PP |
| 192 |
"FooBar.pm provides an implementation of the FOO protocol and the |
| 193 |
related BAR standard." |
| 194 |
.PP |
| 195 |
Good example: |
| 196 |
.PP |
| 197 |
"Foo.pm provides an implementation of the FOO protocol. Bar.pm |
| 198 |
implements the related BAR protocol." |
| 199 |
.PP |
| 200 |
This means that if a developer only needs a module for the BAR standard, |
| 201 |
they should not be forced to install libraries for FOO as well. |
| 202 |
.SS "What's in a name?" |
| 203 |
.IX Subsection "What's in a name?" |
| 204 |
Make sure you choose an appropriate name for your module early on. This |
| 205 |
will help people find and remember your module, and make programming |
| 206 |
with your module more intuitive. |
| 207 |
.PP |
| 208 |
When naming your module, consider the following: |
| 209 |
.IP \(bu 4 |
| 210 |
Be descriptive (i.e. accurately describes the purpose of the module). |
| 211 |
.IP \(bu 4 |
| 212 |
Be consistent with existing modules. |
| 213 |
.IP \(bu 4 |
| 214 |
Reflect the functionality of the module, not the implementation. |
| 215 |
.IP \(bu 4 |
| 216 |
Avoid starting a new top-level hierarchy, especially if a suitable |
| 217 |
hierarchy already exists under which you could place your module. |
| 218 |
.SS "Get feedback before publishing" |
| 219 |
.IX Subsection "Get feedback before publishing" |
| 220 |
If you have never uploaded a module to CPAN before (and even if you have), |
| 221 |
you are strongly encouraged to get feedback from people who are already |
| 222 |
familiar with the module's application domain and the CPAN naming system. |
| 223 |
Authors of similar modules, or modules with similar names, may be a good |
| 224 |
place to start, as are community sites like |
| 225 |
Perl Monks <https://www.perlmonks.org>. |
| 226 |
.SH "DESIGNING AND WRITING YOUR MODULE" |
| 227 |
.IX Header "DESIGNING AND WRITING YOUR MODULE" |
| 228 |
Considerations for module design and coding: |
| 229 |
.SS "To OO or not to OO?" |
| 230 |
.IX Subsection "To OO or not to OO?" |
| 231 |
Your module may be object oriented (OO) or not, or it may have both kinds |
| 232 |
of interfaces available. There are pros and cons of each technique, which |
| 233 |
should be considered when you design your API. |
| 234 |
.PP |
| 235 |
In \fIPerl Best Practices\fR (copyright 2004, Published by O'Reilly Media, Inc.), |
| 236 |
Damian Conway provides a list of criteria to use when deciding if OO is the |
| 237 |
right fit for your problem: |
| 238 |
.IP \(bu 4 |
| 239 |
The system being designed is large, or is likely to become large. |
| 240 |
.IP \(bu 4 |
| 241 |
The data can be aggregated into obvious structures, especially if |
| 242 |
there's a large amount of data in each aggregate. |
| 243 |
.IP \(bu 4 |
| 244 |
The various types of data aggregate form a natural hierarchy that |
| 245 |
facilitates the use of inheritance and polymorphism. |
| 246 |
.IP \(bu 4 |
| 247 |
You have a piece of data on which many different operations are |
| 248 |
applied. |
| 249 |
.IP \(bu 4 |
| 250 |
You need to perform the same general operations on related types of |
| 251 |
data, but with slight variations depending on the specific type of data |
| 252 |
the operations are applied to. |
| 253 |
.IP \(bu 4 |
| 254 |
It's likely you'll have to add new data types later. |
| 255 |
.IP \(bu 4 |
| 256 |
The typical interactions between pieces of data are best represented by |
| 257 |
operators. |
| 258 |
.IP \(bu 4 |
| 259 |
The implementation of individual components of the system is likely to |
| 260 |
change over time. |
| 261 |
.IP \(bu 4 |
| 262 |
The system design is already object-oriented. |
| 263 |
.IP \(bu 4 |
| 264 |
Large numbers of other programmers will be using your code modules. |
| 265 |
.PP |
| 266 |
Think carefully about whether OO is appropriate for your module. |
| 267 |
Gratuitous object orientation results in complex APIs which are |
| 268 |
difficult for the average module user to understand or use. |
| 269 |
.SS "Designing your API" |
| 270 |
.IX Subsection "Designing your API" |
| 271 |
Your interfaces should be understandable by an average Perl programmer. |
| 272 |
The following guidelines may help you judge whether your API is |
| 273 |
sufficiently straightforward: |
| 274 |
.IP "Write simple routines to do simple things." 4 |
| 275 |
.IX Item "Write simple routines to do simple things." |
| 276 |
It's better to have numerous simple routines than a few monolithic ones. |
| 277 |
If your routine changes its behaviour significantly based on its |
| 278 |
arguments, it's a sign that you should have two (or more) separate |
| 279 |
routines. |
| 280 |
.IP "Separate functionality from output." 4 |
| 281 |
.IX Item "Separate functionality from output." |
| 282 |
Return your results in the most generic form possible and allow the user |
| 283 |
to choose how to use them. The most generic form possible is usually a |
| 284 |
Perl data structure which can then be used to generate a text report, |
| 285 |
HTML, XML, a database query, or whatever else your users require. |
| 286 |
.Sp |
| 287 |
If your routine iterates through some kind of list (such as a list of |
| 288 |
files, or records in a database) you may consider providing a callback |
| 289 |
so that users can manipulate each element of the list in turn. |
| 290 |
File::Find provides an example of this with its |
| 291 |
\&\f(CW\*(C`find(\e&wanted, $dir)\*(C'\fR syntax. |
| 292 |
.IP "Provide sensible shortcuts and defaults." 4 |
| 293 |
.IX Item "Provide sensible shortcuts and defaults." |
| 294 |
Don't require every module user to jump through the same hoops to achieve a |
| 295 |
simple result. You can always include optional parameters or routines for |
| 296 |
more complex or non-standard behaviour. If most of your users have to |
| 297 |
type a few almost identical lines of code when they start using your |
| 298 |
module, it's a sign that you should have made that behaviour a default. |
| 299 |
Another good indicator that you should use defaults is if most of your |
| 300 |
users call your routines with the same arguments. |
| 301 |
.IP "Naming conventions" 4 |
| 302 |
.IX Item "Naming conventions" |
| 303 |
Your naming should be consistent. For instance, it's better to have: |
| 304 |
.Sp |
| 305 |
.Vb 3 |
| 306 |
\& display_day(); |
| 307 |
\& display_week(); |
| 308 |
\& display_year(); |
| 309 |
.Ve |
| 310 |
.Sp |
| 311 |
than |
| 312 |
.Sp |
| 313 |
.Vb 3 |
| 314 |
\& display_day(); |
| 315 |
\& week_display(); |
| 316 |
\& show_year(); |
| 317 |
.Ve |
| 318 |
.Sp |
| 319 |
This applies equally to method names, parameter names, and anything else |
| 320 |
which is visible to the user (and most things that aren't!) |
| 321 |
.IP "Parameter passing" 4 |
| 322 |
.IX Item "Parameter passing" |
| 323 |
Use named parameters. It's easier to use a hash like this: |
| 324 |
.Sp |
| 325 |
.Vb 5 |
| 326 |
\& $obj\->do_something( |
| 327 |
\& name => "wibble", |
| 328 |
\& type => "text", |
| 329 |
\& size => 1024, |
| 330 |
\& ); |
| 331 |
.Ve |
| 332 |
.Sp |
| 333 |
\&... than to have a long list of unnamed parameters like this: |
| 334 |
.Sp |
| 335 |
.Vb 1 |
| 336 |
\& $obj\->do_something("wibble", "text", 1024); |
| 337 |
.Ve |
| 338 |
.Sp |
| 339 |
While the list of arguments might work fine for one, two or even three |
| 340 |
arguments, any more arguments become hard for the module user to |
| 341 |
remember, and hard for the module author to manage. If you want to add |
| 342 |
a new parameter you will have to add it to the end of the list for |
| 343 |
backward compatibility, and this will probably make your list order |
| 344 |
unintuitive. Also, if many elements may be undefined you may see the |
| 345 |
following unattractive method calls: |
| 346 |
.Sp |
| 347 |
.Vb 1 |
| 348 |
\& $obj\->do_something(undef, undef, undef, undef, undef, 1024); |
| 349 |
.Ve |
| 350 |
.Sp |
| 351 |
Provide sensible defaults for parameters which have them. Don't make |
| 352 |
your users specify parameters which will almost always be the same. |
| 353 |
.Sp |
| 354 |
The issue of whether to pass the arguments in a hash or a hashref is |
| 355 |
largely a matter of personal style. |
| 356 |
.Sp |
| 357 |
The use of hash keys starting with a hyphen (\f(CW\*(C`\-name\*(C'\fR) or entirely in |
| 358 |
upper case (\f(CW\*(C`NAME\*(C'\fR) is a relic of older versions of Perl in which |
| 359 |
ordinary lower case strings were not handled correctly by the \f(CW\*(C`=>\*(C'\fR |
| 360 |
operator. While some modules retain uppercase or hyphenated argument |
| 361 |
keys for historical reasons or as a matter of personal style, most new |
| 362 |
modules should use simple lower case keys. Whatever you choose, be |
| 363 |
consistent! |
| 364 |
.SS "Strictness and warnings" |
| 365 |
.IX Subsection "Strictness and warnings" |
| 366 |
Your module should run successfully under the strict pragma and should |
| 367 |
run without generating any warnings. Your module should also handle |
| 368 |
taint-checking where appropriate, though this can cause difficulties in |
| 369 |
many cases. |
| 370 |
.SS "Backwards compatibility" |
| 371 |
.IX Subsection "Backwards compatibility" |
| 372 |
Modules which are "stable" should not break backwards compatibility |
| 373 |
without at least a long transition phase and a major change in version |
| 374 |
number. |
| 375 |
.SS "Error handling and messages" |
| 376 |
.IX Subsection "Error handling and messages" |
| 377 |
When your module encounters an error it should do one or more of: |
| 378 |
.IP \(bu 4 |
| 379 |
Return an undefined value. |
| 380 |
.IP \(bu 4 |
| 381 |
set \f(CW$Module::errstr\fR or similar (\f(CW\*(C`errstr\*(C'\fR is a common name used by |
| 382 |
DBI and other popular modules; if you choose something else, be sure to |
| 383 |
document it clearly). |
| 384 |
.IP \(bu 4 |
| 385 |
\&\f(CWwarn()\fR or \f(CWcarp()\fR a message to STDERR. |
| 386 |
.IP \(bu 4 |
| 387 |
\&\f(CWcroak()\fR only when your module absolutely cannot figure out what to |
| 388 |
do. (\f(CWcroak()\fR is a better version of \f(CWdie()\fR for use within |
| 389 |
modules, which reports its errors from the perspective of the caller. |
| 390 |
See Carp for details of \f(CWcroak()\fR, \f(CWcarp()\fR and other useful |
| 391 |
routines.) |
| 392 |
.IP \(bu 4 |
| 393 |
As an alternative to the above, you may prefer to throw exceptions using |
| 394 |
the Error module. |
| 395 |
.PP |
| 396 |
Configurable error handling can be very useful to your users. Consider |
| 397 |
offering a choice of levels for warning and debug messages, an option to |
| 398 |
send messages to a separate file, a way to specify an error-handling |
| 399 |
routine, or other such features. Be sure to default all these options |
| 400 |
to the commonest use. |
| 401 |
.SH "DOCUMENTING YOUR MODULE" |
| 402 |
.IX Header "DOCUMENTING YOUR MODULE" |
| 403 |
.SS POD |
| 404 |
.IX Subsection "POD" |
| 405 |
Your module should include documentation aimed at Perl developers. |
| 406 |
You should use Perl's "plain old documentation" (POD) for your general |
| 407 |
technical documentation, though you may wish to write additional |
| 408 |
documentation (white papers, tutorials, etc) in some other format. |
| 409 |
You need to cover the following subjects: |
| 410 |
.IP \(bu 4 |
| 411 |
A synopsis of the common uses of the module |
| 412 |
.IP \(bu 4 |
| 413 |
The purpose, scope and target applications of your module |
| 414 |
.IP \(bu 4 |
| 415 |
Use of each publicly accessible method or subroutine, including |
| 416 |
parameters and return values |
| 417 |
.IP \(bu 4 |
| 418 |
Examples of use |
| 419 |
.IP \(bu 4 |
| 420 |
Sources of further information |
| 421 |
.IP \(bu 4 |
| 422 |
A contact email address for the author/maintainer |
| 423 |
.PP |
| 424 |
The level of detail in Perl module documentation generally goes from |
| 425 |
less detailed to more detailed. Your SYNOPSIS section should contain a |
| 426 |
minimal example of use (perhaps as little as one line of code; skip the |
| 427 |
unusual use cases or anything not needed by most users); the |
| 428 |
DESCRIPTION should describe your module in broad terms, generally in |
| 429 |
just a few paragraphs; more detail of the module's routines or methods, |
| 430 |
lengthy code examples, or other in-depth material should be given in |
| 431 |
subsequent sections. |
| 432 |
.PP |
| 433 |
Ideally, someone who's slightly familiar with your module should be able |
| 434 |
to refresh their memory without hitting "page down". As your reader |
| 435 |
continues through the document, they should receive a progressively |
| 436 |
greater amount of knowledge. |
| 437 |
.PP |
| 438 |
The recommended order of sections in Perl module documentation is: |
| 439 |
.IP \(bu 4 |
| 440 |
NAME |
| 441 |
.IP \(bu 4 |
| 442 |
SYNOPSIS |
| 443 |
.IP \(bu 4 |
| 444 |
DESCRIPTION |
| 445 |
.IP \(bu 4 |
| 446 |
One or more sections or subsections giving greater detail of available |
| 447 |
methods and routines and any other relevant information. |
| 448 |
.IP \(bu 4 |
| 449 |
BUGS/CAVEATS/etc |
| 450 |
.IP \(bu 4 |
| 451 |
AUTHOR |
| 452 |
.IP \(bu 4 |
| 453 |
SEE ALSO |
| 454 |
.IP \(bu 4 |
| 455 |
COPYRIGHT and LICENSE |
| 456 |
.PP |
| 457 |
Keep your documentation near the code it documents ("inline" |
| 458 |
documentation). Include POD for a given method right above that |
| 459 |
method's subroutine. This makes it easier to keep the documentation up |
| 460 |
to date, and avoids having to document each piece of code twice (once in |
| 461 |
POD and once in comments). |
| 462 |
.SS "README, INSTALL, release notes, changelogs" |
| 463 |
.IX Subsection "README, INSTALL, release notes, changelogs" |
| 464 |
Your module should also include a README file describing the module and |
| 465 |
giving pointers to further information (website, author email). |
| 466 |
.PP |
| 467 |
An INSTALL file should be included, and should contain simple installation |
| 468 |
instructions. When using ExtUtils::MakeMaker this will usually be: |
| 469 |
.IP "perl Makefile.PL" 4 |
| 470 |
.IX Item "perl Makefile.PL" |
| 471 |
.PD 0 |
| 472 |
.IP make 4 |
| 473 |
.IX Item "make" |
| 474 |
.IP "make test" 4 |
| 475 |
.IX Item "make test" |
| 476 |
.IP "make install" 4 |
| 477 |
.IX Item "make install" |
| 478 |
.PD |
| 479 |
.PP |
| 480 |
When using Module::Build, this will usually be: |
| 481 |
.IP "perl Build.PL" 4 |
| 482 |
.IX Item "perl Build.PL" |
| 483 |
.PD 0 |
| 484 |
.IP "perl Build" 4 |
| 485 |
.IX Item "perl Build" |
| 486 |
.IP "perl Build test" 4 |
| 487 |
.IX Item "perl Build test" |
| 488 |
.IP "perl Build install" 4 |
| 489 |
.IX Item "perl Build install" |
| 490 |
.PD |
| 491 |
.PP |
| 492 |
Release notes or changelogs should be produced for each release of your |
| 493 |
software describing user-visible changes to your module, in terms |
| 494 |
relevant to the user. |
| 495 |
.PP |
| 496 |
Unless you have good reasons for using some other format |
| 497 |
(for example, a format used within your company), |
| 498 |
the convention is to name your changelog file \f(CW\*(C`Changes\*(C'\fR, |
| 499 |
and to follow the simple format described in CPAN::Changes::Spec. |
| 500 |
.SH "RELEASE CONSIDERATIONS" |
| 501 |
.IX Header "RELEASE CONSIDERATIONS" |
| 502 |
.SS "Version numbering" |
| 503 |
.IX Subsection "Version numbering" |
| 504 |
Version numbers should indicate at least major and minor releases, and |
| 505 |
possibly sub-minor releases. A major release is one in which most of |
| 506 |
the functionality has changed, or in which major new functionality is |
| 507 |
added. A minor release is one in which a small amount of functionality |
| 508 |
has been added or changed. Sub-minor version numbers are usually used |
| 509 |
for changes which do not affect functionality, such as documentation |
| 510 |
patches. |
| 511 |
.PP |
| 512 |
The most common CPAN version numbering scheme looks like this: |
| 513 |
.PP |
| 514 |
.Vb 1 |
| 515 |
\& 1.00, 1.10, 1.11, 1.20, 1.30, 1.31, 1.32 |
| 516 |
.Ve |
| 517 |
.PP |
| 518 |
A correct CPAN version number is a floating point number with at least |
| 519 |
2 digits after the decimal. You can test whether it conforms to CPAN by |
| 520 |
using |
| 521 |
.PP |
| 522 |
.Vb 2 |
| 523 |
\& perl \-MExtUtils::MakeMaker \-le \*(Aqprint MM\->parse_version(shift)\*(Aq \e |
| 524 |
\& \*(AqFoo.pm\*(Aq |
| 525 |
.Ve |
| 526 |
.PP |
| 527 |
If you want to release a 'beta' or 'alpha' version of a module but |
| 528 |
don't want CPAN.pm to list it as most recent use an '_' after the |
| 529 |
regular version number followed by at least 2 digits, eg. 1.20_01. If |
| 530 |
you do this, the following idiom is recommended: |
| 531 |
.PP |
| 532 |
.Vb 5 |
| 533 |
\& our $VERSION = "1.12_01"; # so CPAN distribution will have |
| 534 |
\& # right filename |
| 535 |
\& our $XS_VERSION = $VERSION; # only needed if you have XS code |
| 536 |
\& $VERSION = eval $VERSION; # so "use Module 0.002" won\*(Aqt warn on |
| 537 |
\& # underscore |
| 538 |
.Ve |
| 539 |
.PP |
| 540 |
With that trick MakeMaker will only read the first line and thus read |
| 541 |
the underscore, while the perl interpreter will evaluate the \f(CW$VERSION\fR |
| 542 |
and convert the string into a number. Later operations that treat |
| 543 |
\&\f(CW$VERSION\fR as a number will then be able to do so without provoking a |
| 544 |
warning about \f(CW$VERSION\fR not being a number. |
| 545 |
.PP |
| 546 |
Never release anything (even a one-word documentation patch) without |
| 547 |
incrementing the number. Even a one-word documentation patch should |
| 548 |
result in a change in version at the sub-minor level. |
| 549 |
.PP |
| 550 |
Once picked, it is important to stick to your version scheme, without |
| 551 |
reducing the number of digits. This is because "downstream" packagers, |
| 552 |
such as the FreeBSD ports system, interpret the version numbers in |
| 553 |
various ways. If you change the number of digits in your version scheme, |
| 554 |
you can confuse these systems so they get the versions of your module |
| 555 |
out of order, which is obviously bad. |
| 556 |
.SS Pre-requisites |
| 557 |
.IX Subsection "Pre-requisites" |
| 558 |
Module authors should carefully consider whether to rely on other |
| 559 |
modules, and which modules to rely on. |
| 560 |
.PP |
| 561 |
Most importantly, choose modules which are as stable as possible. In |
| 562 |
order of preference: |
| 563 |
.IP \(bu 4 |
| 564 |
Core Perl modules |
| 565 |
.IP \(bu 4 |
| 566 |
Stable CPAN modules |
| 567 |
.IP \(bu 4 |
| 568 |
Unstable CPAN modules |
| 569 |
.IP \(bu 4 |
| 570 |
Modules not available from CPAN |
| 571 |
.PP |
| 572 |
Specify version requirements for other Perl modules in the |
| 573 |
pre-requisites in your Makefile.PL or Build.PL. |
| 574 |
.PP |
| 575 |
Be sure to specify Perl version requirements both in Makefile.PL or |
| 576 |
Build.PL and with \f(CW\*(C`require 5.6.1\*(C'\fR or similar. See the documentation on |
| 577 |
\&\f(CW\*(C`use VERSION\*(C'\fR for details. |
| 578 |
.SS Testing |
| 579 |
.IX Subsection "Testing" |
| 580 |
All modules should be tested before distribution (using "make disttest"), |
| 581 |
and the tests should also be available to people installing the modules |
| 582 |
(using "make test"). |
| 583 |
For Module::Build you would use the \f(CW\*(C`make test\*(C'\fR equivalent \f(CW\*(C`perl Build test\*(C'\fR. |
| 584 |
.PP |
| 585 |
The importance of these tests is proportional to the alleged stability of a |
| 586 |
module. A module which purports to be |
| 587 |
stable or which hopes to achieve wide |
| 588 |
use should adhere to as strict a testing regime as possible. |
| 589 |
.PP |
| 590 |
Useful modules to help you write tests (with minimum impact on your |
| 591 |
development process or your time) include Test::Simple, Carp::Assert |
| 592 |
and Test::Inline. |
| 593 |
For more sophisticated test suites there are Test::More and Test::MockObject. |
| 594 |
.SS Packaging |
| 595 |
.IX Subsection "Packaging" |
| 596 |
Modules should be packaged using one of the standard packaging tools. |
| 597 |
Currently you have the choice between ExtUtils::MakeMaker and the |
| 598 |
more platform independent Module::Build, allowing modules to be installed in a |
| 599 |
consistent manner. |
| 600 |
When using ExtUtils::MakeMaker, you can use "make dist" to create your |
| 601 |
package. Tools exist to help you to build your module in a |
| 602 |
MakeMaker-friendly style. These include ExtUtils::ModuleMaker and h2xs. |
| 603 |
See also perlnewmod. |
| 604 |
.SS Licensing |
| 605 |
.IX Subsection "Licensing" |
| 606 |
Make sure that your module has a license, and that the full text of it |
| 607 |
is included in the distribution (unless it's a common one and the terms |
| 608 |
of the license don't require you to include it). |
| 609 |
.PP |
| 610 |
If you don't know what license to use, dual licensing under the GPL |
| 611 |
and Artistic licenses (the same as Perl itself) is a good idea. |
| 612 |
See perlgpl and perlartistic. |
| 613 |
.SH "COMMON PITFALLS" |
| 614 |
.IX Header "COMMON PITFALLS" |
| 615 |
.SS "Reinventing the wheel" |
| 616 |
.IX Subsection "Reinventing the wheel" |
| 617 |
There are certain application spaces which are already very, very well |
| 618 |
served by CPAN. One example is templating systems, another is date and |
| 619 |
time modules, and there are many more. While it is a rite of passage to |
| 620 |
write your own version of these things, please consider carefully |
| 621 |
whether the Perl world really needs you to publish it. |
| 622 |
.SS "Trying to do too much" |
| 623 |
.IX Subsection "Trying to do too much" |
| 624 |
Your module will be part of a developer's toolkit. It will not, in |
| 625 |
itself, form the \fBentire\fR toolkit. It's tempting to add extra features |
| 626 |
until your code is a monolithic system rather than a set of modular |
| 627 |
building blocks. |
| 628 |
.SS "Inappropriate documentation" |
| 629 |
.IX Subsection "Inappropriate documentation" |
| 630 |
Don't fall into the trap of writing for the wrong audience. Your |
| 631 |
primary audience is a reasonably experienced developer with at least |
| 632 |
a moderate understanding of your module's application domain, who's just |
| 633 |
downloaded your module and wants to start using it as quickly as possible. |
| 634 |
.PP |
| 635 |
Tutorials, end-user documentation, research papers, FAQs etc are not |
| 636 |
appropriate in a module's main documentation. If you really want to |
| 637 |
write these, include them as sub-documents such as \f(CW\*(C`My::Module::Tutorial\*(C'\fR or |
| 638 |
\&\f(CW\*(C`My::Module::FAQ\*(C'\fR and provide a link in the SEE ALSO section of the |
| 639 |
main documentation. |
| 640 |
.SH "SEE ALSO" |
| 641 |
.IX Header "SEE ALSO" |
| 642 |
.IP perlstyle 4 |
| 643 |
.IX Item "perlstyle" |
| 644 |
General Perl style guide |
| 645 |
.IP perlnewmod 4 |
| 646 |
.IX Item "perlnewmod" |
| 647 |
How to create a new module |
| 648 |
.IP perlpod 4 |
| 649 |
.IX Item "perlpod" |
| 650 |
POD documentation |
| 651 |
.IP podchecker 4 |
| 652 |
.IX Item "podchecker" |
| 653 |
Verifies your POD's correctness |
| 654 |
.IP "Packaging Tools" 4 |
| 655 |
.IX Item "Packaging Tools" |
| 656 |
ExtUtils::MakeMaker, Module::Build |
| 657 |
.IP "Testing tools" 4 |
| 658 |
.IX Item "Testing tools" |
| 659 |
Test::Simple, Test::Inline, Carp::Assert, Test::More, Test::MockObject |
| 660 |
.IP <https://pause.perl.org/> 4 |
| 661 |
.IX Item "<https://pause.perl.org/>" |
| 662 |
Perl Authors Upload Server. Contains links to information for module |
| 663 |
authors. |
| 664 |
.IP "Any good book on software engineering" 4 |
| 665 |
.IX Item "Any good book on software engineering" |
| 666 |
.SH AUTHOR |
| 667 |
.IX Header "AUTHOR" |
| 668 |
Kirrily "Skud" Robert <[email protected]> |