Plan 9 from Bell Labs’s /usr/web/sources/contrib/gabidiaz/root/sys/man/1perl/perlmodstyle

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  | will give a
.\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
.\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
.    de IX
.    tm Index:\\$1\t\\n%\t"\\$2"
..
.    nr % 0
.    rr F
.\}
.\"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "PERLMODSTYLE 1"
.TH PERLMODSTYLE 1 "2002-11-24" "perl v5.8.0" "Perl Programmers Reference Guide"
.SH "NAME"
perlmodstyle \- Perl module style guide
.SH "INTRODUCTION"
.IX Header "INTRODUCTION"
This document attempts to describe the Perl Community's \*(L"best practice\*(R"
for writing Perl modules.  It extends the recommendations found in 
perlstyle , which should be considered required reading
before reading this document.
.PP
While this document is intended to be useful to all module authors, it is
particularly aimed at authors who wish to publish their modules on \s-1CPAN\s0.
.PP
The focus is on elements of style which are visible to the users of a 
module, rather than those parts which are only seen by the module's 
developers.  However, many of the guidelines presented in this document
can be extrapolated and applied successfully to a module's internals.
.PP
This document differs from perlnewmod in that it is a style guide
rather than a tutorial on creating \s-1CPAN\s0 modules.  It provides a
checklist against which modules can be compared to determine whether
they conform to best practice, without necessarily describing in detail
how to achieve this.  
.PP
All the advice contained in this document has been gleaned from
extensive conversations with experienced \s-1CPAN\s0 authors and users.  Every
piece of advice given here is the result of previous mistakes.  This
information is here to help you avoid the same mistakes and the extra
work that would inevitably be required to fix them.
.PP
The first section of this document provides an itemized checklist; 
subsequent sections provide a more detailed discussion of the items on 
the list.  The final section, \*(L"Common Pitfalls\*(R", describes some of the 
most popular mistakes made by \s-1CPAN\s0 authors.
.SH "QUICK CHECKLIST"
.IX Header "QUICK CHECKLIST"
For more detail on each item in this checklist, see below.
.Sh "Before you start"
.IX Subsection "Before you start"
.IP "\(bu" 4
Don't re-invent the wheel
.IP "\(bu" 4
Patch, extend or subclass an existing module where possible
.IP "\(bu" 4
Do one thing and do it well
.IP "\(bu" 4
Choose an appropriate name
.Sh "The \s-1API\s0"
.IX Subsection "The API"
.IP "\(bu" 4
\&\s-1API\s0 should be understandable by the average programmer
.IP "\(bu" 4
Simple methods for simple tasks
.IP "\(bu" 4
Separate functionality from output
.IP "\(bu" 4
Consistent naming of subroutines or methods
.IP "\(bu" 4
Use named parameters (a hash or hashref) when there are more than two
parameters
.Sh "Stability"
.IX Subsection "Stability"
.IP "\(bu" 4
Ensure your module works under \f(CW\*(C`use strict\*(C'\fR and \f(CW\*(C`\-w\*(C'\fR
.IP "\(bu" 4
Stable modules should maintain backwards compatibility
.Sh "Documentation"
.IX Subsection "Documentation"
.IP "\(bu" 4
Write documentation in \s-1POD\s0
.IP "\(bu" 4
Document purpose, scope and target applications
.IP "\(bu" 4
Document each publically accessible method or subroutine, including params and return values
.IP "\(bu" 4
Give examples of use in your documentation
.IP "\(bu" 4
Provide a \s-1README\s0 file and perhaps also release notes, changelog, etc
.IP "\(bu" 4
Provide links to further information (\s-1URL\s0, email)
.Sh "Release considerations"
.IX Subsection "Release considerations"
.IP "\(bu" 4
Specify pre-requisites in Makefile.PL
.IP "\(bu" 4
Specify Perl version requirements with \f(CW\*(C`use\*(C'\fR
.IP "\(bu" 4
Include tests with your module
.IP "\(bu" 4
Choose a sensible and consistent version numbering scheme (X.YY is the common Perl module numbering scheme)
.IP "\(bu" 4
Increment the version number for every change, no matter how small
.IP "\(bu" 4
Package the module using \*(L"make dist\*(R"
.IP "\(bu" 4
Choose an appropriate license (GPL/Artistic is a good default)
.SH "BEFORE YOU START WRITING A MODULE"
.IX Header "BEFORE YOU START WRITING A MODULE"
Try not to launch headlong into developing your module without spending
some time thinking first.  A little forethought may save you a vast
amount of effort later on.
.Sh "Has it been done before?"
.IX Subsection "Has it been done before?"
You may not even need to write the module.  Check whether it's already 
been done in Perl, and avoid re-inventing the wheel unless you have a 
good reason.
.PP
Good places to look for pre-existing modules include
http://search.cpan.org/ and asking on modules@perl.org
.PP
If an existing module \fBalmost\fR does what you want, consider writing a
patch, writing a subclass, or otherwise extending the existing module
rather than rewriting it.
.Sh "Do one thing and do it well"
.IX Subsection "Do one thing and do it well"
At the risk of stating the obvious, modules are intended to be modular.
A Perl developer should be able to use modules to put together the
building blocks of their application.  However, it's important that the
blocks are the right shape, and that the developer shouldn't have to use
a big block when all they need is a small one.
.PP
Your module should have a clearly defined scope which is no longer than
a single sentence.  Can your module be broken down into a family of
related modules?
.PP
Bad example:
.PP
\&\*(L"FooBar.pm provides an implementation of the \s-1FOO\s0 protocol and the
related \s-1BAR\s0 standard.\*(R"
.PP
Good example:
.PP
\&\*(L"Foo.pm provides an implementation of the \s-1FOO\s0 protocol.  Bar.pm
implements the related \s-1BAR\s0 protocol.\*(R"
.PP
This means that if a developer only needs a module for the \s-1BAR\s0 standard,
they should not be forced to install libraries for \s-1FOO\s0 as well.
.Sh "What's in a name?"
.IX Subsection "What's in a name?"
Make sure you choose an appropriate name for your module early on.  This
will help people find and remember your module, and make programming
with your module more intuitive.
.PP
When naming your module, consider the following:
.IP "\(bu" 4
Be descriptive (i.e. accurately describes the purpose of the module).
.IP "\(bu" 4
Be consistent with existing modules.
.IP "\(bu" 4
Reflect the functionality of the module, not the implementation.
.IP "\(bu" 4
Avoid starting a new top-level hierarchy, especially if a suitable
hierarchy already exists under which you could place your module.
.PP
You should contact modules@perl.org to ask them about your module name
before publishing your module.  You should also try to ask people who 
are already familiar with the module's application domain and the \s-1CPAN\s0
naming system.  Authors of similar modules, or modules with similar
names, may be a good place to start.
.SH "DESIGNING AND WRITING YOUR MODULE"
.IX Header "DESIGNING AND WRITING YOUR MODULE"
Considerations for module design and coding:
.Sh "To \s-1OO\s0 or not to \s-1OO\s0?"
.IX Subsection "To OO or not to OO?"
Your module may be object oriented (\s-1OO\s0) or not, or it may have both kinds 
of interfaces available.  There are pros and cons of each technique, which 
should be considered when you design your \s-1API\s0.
.PP
According to Damian Conway, you should consider using \s-1OO:\s0
.IP "\(bu" 4
When the system is large or likely to become so
.IP "\(bu" 4
When the data is aggregated in obvious structures that will become objects 
.IP "\(bu" 4
When the types of data form a natural hierarchy that can make use of inheritance
.IP "\(bu" 4
When operations on data vary according to data type (making
polymorphic invocation of methods feasible)
.IP "\(bu" 4
When it is likely that new data types may be later introduced
into the system, and will need to be handled by existing code
.IP "\(bu" 4
When interactions between data are best represented by
overloaded operators
.IP "\(bu" 4
When the implementation of system components is likely to
change over time (and hence should be encapsulated)
.IP "\(bu" 4
When the system design is itself object-oriented
.IP "\(bu" 4
When large amounts of client code will use the software (and
should be insulated from changes in its implementation)
.IP "\(bu" 4
When many separate operations will need to be applied to the
same set of data
.PP
Think carefully about whether \s-1OO\s0 is appropriate for your module.
Gratuitous object orientation results in complex APIs which are
difficult for the average module user to understand or use.
.Sh "Designing your \s-1API\s0"
.IX Subsection "Designing your API"
Your interfaces should be understandable by an average Perl programmer.  
The following guidelines may help you judge whether your \s-1API\s0 is
sufficiently straightforward:
.IP "Write simple routines to do simple things." 4
.IX Item "Write simple routines to do simple things."
It's better to have numerous simple routines than a few monolithic ones.
If your routine changes its behaviour significantly based on its
arguments, it's a sign that you should have two (or more) separate
routines.
.IP "Separate functionality from output." 4
.IX Item "Separate functionality from output."
Return your results in the most generic form possible and allow the user 
to choose how to use them.  The most generic form possible is usually a
Perl data structure which can then be used to generate a text report,
\&\s-1HTML\s0, \s-1XML\s0, a database query, or whatever else your users require.
.Sp
If your routine iterates through some kind of list (such as a list of
files, or records in a database) you may consider providing a callback
so that users can manipulate each element of the list in turn.
File::Find provides an example of this with its 
\&\f(CW\*(C`find(\e&wanted, $dir)\*(C'\fR syntax.
.IP "Provide sensible shortcuts and defaults." 4
.IX Item "Provide sensible shortcuts and defaults."
Don't require every module user to jump through the same hoops to achieve a
simple result.  You can always include optional parameters or routines for 
more complex or non-standard behaviour.  If most of your users have to
type a few almost identical lines of code when they start using your
module, it's a sign that you should have made that behaviour a default.
Another good indicator that you should use defaults is if most of your 
users call your routines with the same arguments.
.IP "Naming conventions" 4
.IX Item "Naming conventions"
Your naming should be consistent.  For instance, it's better to have:
.Sp
.Vb 3
\&        display_day();
\&        display_week();
\&        display_year();
.Ve
.Sp
than
.Sp
.Vb 3
\&        display_day();
\&        week_display();
\&        show_year();
.Ve
.Sp
This applies equally to method names, parameter names, and anything else
which is visible to the user (and most things that aren't!)
.IP "Parameter passing" 4
.IX Item "Parameter passing"
Use named parameters. It's easier to use a hash like this:
.Sp
.Vb 5
\&    $obj->do_something(
\&            name => "wibble",
\&            type => "text",
\&            size => 1024,
\&    );
.Ve
.Sp
\&... than to have a long list of unnamed parameters like this:
.Sp
.Vb 1
\&    $obj->do_something("wibble", "text", 1024);
.Ve
.Sp
While the list of arguments might work fine for one, two or even three
arguments, any more arguments become hard for the module user to
remember, and hard for the module author to manage.  If you want to add
a new parameter you will have to add it to the end of the list for
backward compatibility, and this will probably make your list order
unintuitive.  Also, if many elements may be undefined you may see the
following unattractive method calls:
.Sp
.Vb 1
\&    $obj->do_something(undef, undef, undef, undef, undef, undef, 1024);
.Ve
.Sp
Provide sensible defaults for parameters which have them.  Don't make
your users specify parameters which will almost always be the same.
.Sp
The issue of whether to pass the arguments in a hash or a hashref is
largely a matter of personal style. 
.Sp
The use of hash keys starting with a hyphen (\f(CW\*(C`\-name\*(C'\fR) or entirely in 
upper case (\f(CW\*(C`NAME\*(C'\fR) is a relic of older versions of Perl in which
ordinary lower case strings were not handled correctly by the \f(CW\*(C`=>\*(C'\fR
operator.  While some modules retain uppercase or hyphenated argument
keys for historical reasons or as a matter of personal style, most new
modules should use simple lower case keys.  Whatever you choose, be
consistent!
.Sh "Strictness and warnings"
.IX Subsection "Strictness and warnings"
Your module should run successfully under the strict pragma and should
run without generating any warnings.  Your module should also handle 
taint-checking where appropriate, though this can cause difficulties in
many cases.
.Sh "Backwards compatibility"
.IX Subsection "Backwards compatibility"
Modules which are \*(L"stable\*(R" should not break backwards compatibility
without at least a long transition phase and a major change in version
number.
.Sh "Error handling and messages"
.IX Subsection "Error handling and messages"
When your module encounters an error it should do one or more of:
.IP "\(bu" 4
Return an undefined value.
.IP "\(bu" 4
set \f(CW$Module::errstr\fR or similar (\f(CW\*(C`errstr\*(C'\fR is a common name used by
\&\s-1DBI\s0 and other popular modules; if you choose something else, be sure to
document it clearly).
.IP "\(bu" 4
\&\f(CW\*(C`warn()\*(C'\fR or \f(CW\*(C`carp()\*(C'\fR a message to \s-1STDERR\s0.  
.IP "\(bu" 4
\&\f(CW\*(C`croak()\*(C'\fR only when your module absolutely cannot figure out what to
do.  (\f(CW\*(C`croak()\*(C'\fR is a better version of \f(CW\*(C`die()\*(C'\fR for use within 
modules, which reports its errors from the perspective of the caller.  
See Carp for details of \f(CW\*(C`croak()\*(C'\fR, \f(CW\*(C`carp()\*(C'\fR and other useful
routines.)
.IP "\(bu" 4
As an alternative to the above, you may prefer to throw exceptions using 
the Error module.
.PP
Configurable error handling can be very useful to your users.  Consider
offering a choice of levels for warning and debug messages, an option to
send messages to a separate file, a way to specify an error-handling
routine, or other such features.  Be sure to default all these options
to the commonest use.
.SH "DOCUMENTING YOUR MODULE"
.IX Header "DOCUMENTING YOUR MODULE"
.Sh "\s-1POD\s0"
.IX Subsection "POD"
Your module should include documentation aimed at Perl developers.
You should use Perl's \*(L"plain old documentation\*(R" (\s-1POD\s0) for your general 
technical documentation, though you may wish to write additional
documentation (white papers, tutorials, etc) in some other format.  
You need to cover the following subjects:
.IP "\(bu" 4
A synopsis of the common uses of the module
.IP "\(bu" 4
The purpose, scope and target applications of your module
.IP "\(bu" 4
Use of each publically accessible method or subroutine, including
parameters and return values
.IP "\(bu" 4
Examples of use
.IP "\(bu" 4
Sources of further information
.IP "\(bu" 4
A contact email address for the author/maintainer
.PP
The level of detail in Perl module documentation generally goes from
less detailed to more detailed.  Your \s-1SYNOPSIS\s0 section should contain a
minimal example of use (perhaps as little as one line of code; skip the
unusual use cases or anything not needed by most users); the
\&\s-1DESCRIPTION\s0 should describe your module in broad terms, generally in
just a few paragraphs; more detail of the module's routines or methods,
lengthy code examples, or other in-depth material should be given in 
subsequent sections.
.PP
Ideally, someone who's slightly familiar with your module should be able
to refresh their memory without hitting \*(L"page down\*(R".  As your reader
continues through the document, they should receive a progressively
greater amount of knowledge.
.PP
The recommended order of sections in Perl module documentation is:
.IP "\(bu" 4
\&\s-1NAME\s0
.IP "\(bu" 4
\&\s-1SYNOPSIS\s0
.IP "\(bu" 4
\&\s-1DESCRIPTION\s0
.IP "\(bu" 4
One or more sections or subsections giving greater detail of available 
methods and routines and any other relevant information.
.IP "\(bu" 4
BUGS/CAVEATS/etc
.IP "\(bu" 4
\&\s-1AUTHOR\s0
.IP "\(bu" 4
\&\s-1SEE\s0 \s-1ALSO\s0
.IP "\(bu" 4
\&\s-1COPYRIGHT\s0 and \s-1LICENSE\s0
.PP
Keep your documentation near the code it documents (\*(L"inline\*(R"
documentation).  Include \s-1POD\s0 for a given method right above that 
method's subroutine.  This makes it easier to keep the documentation up
to date, and avoids having to document each piece of code twice (once in
\&\s-1POD\s0 and once in comments).
.Sh "\s-1README\s0, \s-1INSTALL\s0, release notes, changelogs"
.IX Subsection "README, INSTALL, release notes, changelogs"
Your module should also include a \s-1README\s0 file describing the module and
giving pointers to further information (website, author email).  
.PP
An \s-1INSTALL\s0 file should be included, and should contain simple installation 
instructions (usually \*(L"perl Makefile.PL; make; make install\*(R").
.PP
Release notes or changelogs should be produced for each release of your
software describing user-visible changes to your module, in terms
relevant to the user.
.SH "RELEASE CONSIDERATIONS"
.IX Header "RELEASE CONSIDERATIONS"
.Sh "Version numbering"
.IX Subsection "Version numbering"
Version numbers should indicate at least major and minor releases, and
possibly sub-minor releases.  A major release is one in which most of
the functionality has changed, or in which major new functionality is
added.  A minor release is one in which a small amount of functionality
has been added or changed.  Sub-minor version numbers are usually used
for changes which do not affect functionality, such as documentation
patches.
.PP
The most common \s-1CPAN\s0 version numbering scheme looks like this:
.PP
.Vb 1
\&    1.00, 1.10, 1.11, 1.20, 1.30, 1.31, 1.32
.Ve
.PP
A correct \s-1CPAN\s0 version number is a floating point number with at least 
2 digits after the decimal. You can test whether it conforms to \s-1CPAN\s0 by 
using
.PP
.Vb 1
\&    perl -MExtUtils::MakeMaker -le 'print MM->parse_version(shift)' 'Foo.pm'
.Ve
.PP
If you want to release a 'beta' or 'alpha' version of a module but
don't want \s-1CPAN\s0.pm to list it as most recent use an '_' after the
regular version number followed by at least 2 digits, eg. 1.20_01. If
you do this, the following idiom is recommended:
.PP
.Vb 3
\&  $VERSION = "1.12_01";
\&  $XS_VERSION = $VERSION; # only needed if you have XS code
\&  $VERSION = eval $VERSION;
.Ve
.PP
With that trick MakeMaker will only read the first line and thus read
the underscore, while the perl interpreter will evaluate the \f(CW$VERSION\fR
and convert the string into a number. Later operations that treat
\&\f(CW$VERSION\fR as a number will then be able to do so without provoking a
warning about \f(CW$VERSION\fR not being a number.
.PP
Never release anything (even a one-word documentation patch) without
incrementing the number.  Even a one-word documentation patch should
result in a change in version at the sub-minor level.
.Sh "Pre-requisites"
.IX Subsection "Pre-requisites"
Module authors should carefully consider whether to rely on other
modules, and which modules to rely on.
.PP
Most importantly, choose modules which are as stable as possible.  In
order of preference: 
.IP "\(bu" 4
Core Perl modules
.IP "\(bu" 4
Stable \s-1CPAN\s0 modules
.IP "\(bu" 4
Unstable \s-1CPAN\s0 modules
.IP "\(bu" 4
Modules not available from \s-1CPAN\s0
.PP
Specify version requirements for other Perl modules in the
pre-requisites in your Makefile.PL. 
.PP
Be sure to specify Perl version requirements both in Makefile.PL and 
with \f(CW\*(C`require 5.6.1\*(C'\fR or similar.
.Sh "Testing"
.IX Subsection "Testing"
All modules should be tested before distribution (using \*(L"make disttest\*(R", 
and the tests should also be available to people installing the modules 
(using \*(L"make test\*(R").  
.PP
The importance of these tests is proportional to the alleged stability of a 
module \*(-- a module which purports to be stable or which hopes to achieve wide 
use should adhere to as strict a testing regime as possible.
.PP
Useful modules to help you write tests (with minimum impact on your 
development process or your time) include Test::Simple, Carp::Assert 
and Test::Inline.
.Sh "Packaging"
.IX Subsection "Packaging"
Modules should be packaged using the standard MakeMaker tools, allowing
them to be installed in a consistent manner.  Use \*(L"make dist\*(R" to create 
your package.
.PP
Tools exist to help you build your module in a MakeMaker-friendly style.  
These include ExtUtils::ModuleMaker and h2xs.  See also perlnewmod.
.Sh "Licensing"
.IX Subsection "Licensing"
Make sure that your module has a license, and that the full text of it
is included in the distribution (unless it's a common one and the terms
of the license don't require you to include it).
.PP
If you don't know what license to use, dual licensing under the \s-1GPL\s0
and Artistic licenses (the same as Perl itself) is a good idea.
.SH "COMMON PITFALLS"
.IX Header "COMMON PITFALLS"
.Sh "Reinventing the wheel"
.IX Subsection "Reinventing the wheel"
There are certain application spaces which are already very, very well
served by \s-1CPAN\s0.  One example is templating systems, another is date and
time modules, and there are many more.  While it is a rite of passage to
write your own version of these things, please consider carefully
whether the Perl world really needs you to publish it.
.Sh "Trying to do too much"
.IX Subsection "Trying to do too much"
Your module will be part of a developer's toolkit.  It will not, in
itself, form the \fBentire\fR toolkit.  It's tempting to add extra features
until your code is a monolithic system rather than a set of modular
building blocks.
.Sh "Inappropriate documentation"
.IX Subsection "Inappropriate documentation"
Don't fall into the trap of writing for the wrong audience.  Your
primary audience is a reasonably experienced developer with at least 
a moderate understanding of your module's application domain, who's just 
downloaded your module and wants to start using it as quickly as possible.
.PP
Tutorials, end-user documentation, research papers, FAQs etc are not 
appropriate in a module's main documentation.  If you really want to 
write these, include them as sub-documents such as \f(CW\*(C`My::Module::Tutorial\*(C'\fR or
\&\f(CW\*(C`My::Module::FAQ\*(C'\fR and provide a link in the \s-1SEE\s0 \s-1ALSO\s0 section of the
main documentation.  
.SH "SEE ALSO"
.IX Header "SEE ALSO"
.IP "perlstyle" 4
.IX Item "perlstyle"
General Perl style guide
.IP "perlnewmod" 4
.IX Item "perlnewmod"
How to create a new module
.IP "perlpod" 4
.IX Item "perlpod"
\&\s-1POD\s0 documentation
.IP "podchecker" 4
.IX Item "podchecker"
Verifies your \s-1POD\s0's correctness
.IP "Testing tools" 4
.IX Item "Testing tools"
Test::Simple, Test::Inline, Carp::Assert
.IP "http://pause.perl.org/" 4
.IX Item "http://pause.perl.org/"
Perl Authors Upload Server.  Contains links to information for module
authors.
.IP "Any good book on software engineering" 4
.IX Item "Any good book on software engineering"
.SH "AUTHOR"
.IX Header "AUTHOR"
Kirrily \*(L"Skud\*(R" Robert <skud@cpan.org>

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.