| 1 | =head1 NAME
|
|---|
| 2 |
|
|---|
| 3 | perlmodstyle - Perl module style guide
|
|---|
| 4 |
|
|---|
| 5 | =head1 INTRODUCTION
|
|---|
| 6 |
|
|---|
| 7 | This document attempts to describe the Perl Community's "best practice"
|
|---|
| 8 | for writing Perl modules. It extends the recommendations found in
|
|---|
| 9 | L<perlstyle> , which should be considered required reading
|
|---|
| 10 | before reading this document.
|
|---|
| 11 |
|
|---|
| 12 | While this document is intended to be useful to all module authors, it is
|
|---|
| 13 | particularly aimed at authors who wish to publish their modules on CPAN.
|
|---|
| 14 |
|
|---|
| 15 | The focus is on elements of style which are visible to the users of a
|
|---|
| 16 | module, rather than those parts which are only seen by the module's
|
|---|
| 17 | developers. However, many of the guidelines presented in this document
|
|---|
| 18 | can be extrapolated and applied successfully to a module's internals.
|
|---|
| 19 |
|
|---|
| 20 | This document differs from L<perlnewmod> in that it is a style guide
|
|---|
| 21 | rather than a tutorial on creating CPAN modules. It provides a
|
|---|
| 22 | checklist against which modules can be compared to determine whether
|
|---|
| 23 | they conform to best practice, without necessarily describing in detail
|
|---|
| 24 | how to achieve this.
|
|---|
| 25 |
|
|---|
| 26 | All the advice contained in this document has been gleaned from
|
|---|
| 27 | extensive conversations with experienced CPAN authors and users. Every
|
|---|
| 28 | piece of advice given here is the result of previous mistakes. This
|
|---|
| 29 | information is here to help you avoid the same mistakes and the extra
|
|---|
| 30 | work that would inevitably be required to fix them.
|
|---|
| 31 |
|
|---|
| 32 | The first section of this document provides an itemized checklist;
|
|---|
| 33 | subsequent sections provide a more detailed discussion of the items on
|
|---|
| 34 | the list. The final section, "Common Pitfalls", describes some of the
|
|---|
| 35 | most popular mistakes made by CPAN authors.
|
|---|
| 36 |
|
|---|
| 37 | =head1 QUICK CHECKLIST
|
|---|
| 38 |
|
|---|
| 39 | For more detail on each item in this checklist, see below.
|
|---|
| 40 |
|
|---|
| 41 | =head2 Before you start
|
|---|
| 42 |
|
|---|
| 43 | =over 4
|
|---|
| 44 |
|
|---|
| 45 | =item *
|
|---|
| 46 |
|
|---|
| 47 | Don't re-invent the wheel
|
|---|
| 48 |
|
|---|
| 49 | =item *
|
|---|
| 50 |
|
|---|
| 51 | Patch, extend or subclass an existing module where possible
|
|---|
| 52 |
|
|---|
| 53 | =item *
|
|---|
| 54 |
|
|---|
| 55 | Do one thing and do it well
|
|---|
| 56 |
|
|---|
| 57 | =item *
|
|---|
| 58 |
|
|---|
| 59 | Choose an appropriate name
|
|---|
| 60 |
|
|---|
| 61 | =back
|
|---|
| 62 |
|
|---|
| 63 | =head2 The API
|
|---|
| 64 |
|
|---|
| 65 | =over 4
|
|---|
| 66 |
|
|---|
| 67 | =item *
|
|---|
| 68 |
|
|---|
| 69 | API should be understandable by the average programmer
|
|---|
| 70 |
|
|---|
| 71 | =item *
|
|---|
| 72 |
|
|---|
| 73 | Simple methods for simple tasks
|
|---|
| 74 |
|
|---|
| 75 | =item *
|
|---|
| 76 |
|
|---|
| 77 | Separate functionality from output
|
|---|
| 78 |
|
|---|
| 79 | =item *
|
|---|
| 80 |
|
|---|
| 81 | Consistent naming of subroutines or methods
|
|---|
| 82 |
|
|---|
| 83 | =item *
|
|---|
| 84 |
|
|---|
| 85 | Use named parameters (a hash or hashref) when there are more than two
|
|---|
| 86 | parameters
|
|---|
| 87 |
|
|---|
| 88 | =back
|
|---|
| 89 |
|
|---|
| 90 | =head2 Stability
|
|---|
| 91 |
|
|---|
| 92 | =over 4
|
|---|
| 93 |
|
|---|
| 94 | =item *
|
|---|
| 95 |
|
|---|
| 96 | Ensure your module works under C<use strict> and C<-w>
|
|---|
| 97 |
|
|---|
| 98 | =item *
|
|---|
| 99 |
|
|---|
| 100 | Stable modules should maintain backwards compatibility
|
|---|
| 101 |
|
|---|
| 102 | =back
|
|---|
| 103 |
|
|---|
| 104 | =head2 Documentation
|
|---|
| 105 |
|
|---|
| 106 | =over 4
|
|---|
| 107 |
|
|---|
| 108 | =item *
|
|---|
| 109 |
|
|---|
| 110 | Write documentation in POD
|
|---|
| 111 |
|
|---|
| 112 | =item *
|
|---|
| 113 |
|
|---|
|
|---|