Commit | Line | Data |
---|---|---|
f67486be KR |
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 | ||
114 | Document purpose, scope and target applications | |
115 | ||
116 | =item * | |
117 | ||
118 | Document each publically accessible method or subroutine, including params and return values | |
119 | ||
120 | =item * | |
121 | ||
122 | Give examples of use in your documentation | |
123 | ||
124 | =item * | |
125 | ||
126 | Provide a README file and perhaps also release notes, changelog, etc | |
127 | ||
128 | =item * | |
129 | ||
130 | Provide links to further information (URL, email) | |
131 | ||
132 | =back | |
133 | ||
134 | =head2 Release considerations | |
135 | ||
136 | =over 4 | |
137 | ||
138 | =item * | |
139 | ||
ff23347e | 140 | Specify pre-requisites in Makefile.PL or Build.PL |
f67486be KR |
141 | |
142 | =item * | |
143 | ||
144 | Specify Perl version requirements with C<use> | |
145 | ||
146 | =item * | |
147 | ||
148 | Include tests with your module | |
149 | ||
150 | =item * | |
151 | ||
152 | Choose a sensible and consistent version numbering scheme (X.YY is the common Perl module numbering scheme) | |
153 | ||
154 | =item * | |
155 | ||
156 | Increment the version number for every change, no matter how small | |
157 | ||
158 | =item * | |
159 | ||
160 | Package the module using "make dist" | |
161 | ||
162 | =item * | |
163 | ||
164 | Choose an appropriate license (GPL/Artistic is a good default) | |
165 | ||
166 | =back | |
167 | ||
168 | =head1 BEFORE YOU START WRITING A MODULE | |
169 | ||
170 | Try not to launch headlong into developing your module without spending | |
171 | some time thinking first. A little forethought may save you a vast | |
172 | amount of effort later on. | |
173 | ||
174 | =head2 Has it been done before? | |
175 | ||
176 | You may not even need to write the module. Check whether it's already | |
177 | been done in Perl, and avoid re-inventing the wheel unless you have a | |
178 | good reason. | |
179 | ||
ccbb3b41 IT |
180 | Good places to look for pre-existing modules include |
181 | http://search.cpan.org/ and asking on modules@perl.org | |
182 | ||
f67486be KR |
183 | If an existing module B<almost> does what you want, consider writing a |
184 | patch, writing a subclass, or otherwise extending the existing module | |
185 | rather than rewriting it. | |
186 | ||
187 | =head2 Do one thing and do it well | |
188 | ||
189 | At the risk of stating the obvious, modules are intended to be modular. | |
190 | A Perl developer should be able to use modules to put together the | |
191 | building blocks of their application. However, it's important that the | |
192 | blocks are the right shape, and that the developer shouldn't have to use | |
193 | a big block when all they need is a small one. | |
194 | ||
195 | Your module should have a clearly defined scope which is no longer than | |
196 | a single sentence. Can your module be broken down into a family of | |
197 | related modules? | |
198 | ||
199 | Bad example: | |
200 | ||
201 | "FooBar.pm provides an implementation of the FOO protocol and the | |
202 | related BAR standard." | |
203 | ||
204 | Good example: | |
205 | ||
206 | "Foo.pm provides an implementation of the FOO protocol. Bar.pm | |
207 | implements the related BAR protocol." | |
208 | ||
209 | This means that if a developer only needs a module for the BAR standard, | |
210 | they should not be forced to install libraries for FOO as well. | |
211 | ||
212 | =head2 What's in a name? | |
213 | ||
214 | Make sure you choose an appropriate name for your module early on. This | |
215 | will help people find and remember your module, and make programming | |
216 | with your module more intuitive. | |
217 | ||
218 | When naming your module, consider the following: | |
219 | ||
220 | =over 4 | |
221 | ||
222 | =item * | |
223 | ||
224 | Be descriptive (i.e. accurately describes the purpose of the module). | |
225 | ||
226 | =item * | |
227 | ||
228 | Be consistent with existing modules. | |
229 | ||
230 | =item * | |
231 | ||
232 | Reflect the functionality of the module, not the implementation. | |
233 | ||
234 | =item * | |
235 | ||
236 | Avoid starting a new top-level hierarchy, especially if a suitable | |
237 | hierarchy already exists under which you could place your module. | |
238 | ||
239 | =back | |
240 | ||
241 | You should contact modules@perl.org to ask them about your module name | |
242 | before publishing your module. You should also try to ask people who | |
243 | are already familiar with the module's application domain and the CPAN | |
244 | naming system. Authors of similar modules, or modules with similar | |
245 | names, may be a good place to start. | |
246 | ||
247 | =head1 DESIGNING AND WRITING YOUR MODULE | |
248 | ||
249 | Considerations for module design and coding: | |
250 | ||
251 | =head2 To OO or not to OO? | |
252 | ||
253 | Your module may be object oriented (OO) or not, or it may have both kinds | |
254 | of interfaces available. There are pros and cons of each technique, which | |
255 | should be considered when you design your API. | |
256 | ||
325c7616 DR |
257 | In I<Perl Best Practices> (copyright 2004, Published by O'Reilly Media, Inc.), |
258 | Damian Conway provides a list of criteria to use when deciding if OO is the | |
259 | right fit for your problem: | |
f67486be KR |
260 | |
261 | =over 4 | |
262 | ||
995ab4ef | 263 | =item * |
f67486be | 264 | |
325c7616 | 265 | The system being designed is large, or is likely to become large. |
f67486be | 266 | |
995ab4ef | 267 | =item * |
f67486be | 268 | |
325c7616 DR |
269 | The data can be aggregated into obvious structures, especially if |
270 | there's a large amount of data in each aggregate. | |
f67486be | 271 | |
995ab4ef | 272 | =item * |
f67486be | 273 | |
325c7616 DR |
274 | The various types of data aggregate form a natural hierarchy that |
275 | facilitates the use of inheritance and polymorphism. | |
f67486be | 276 | |
995ab4ef | 277 | =item * |
f67486be | 278 | |
325c7616 DR |
279 | You have a piece of data on which many different operations are |
280 | applied. | |
f67486be | 281 | |
995ab4ef | 282 | =item * |
f67486be | 283 | |
325c7616 DR |
284 | You need to perform the same general operations on related types of |
285 | data, but with slight variations depending on the specific type of data | |
286 | the operations are applied to. | |
f67486be | 287 | |
995ab4ef | 288 | =item * |
f67486be | 289 | |
325c7616 | 290 | It's likely you'll have to add new data types later. |
f67486be | 291 | |
995ab4ef | 292 | =item * |
f67486be | 293 | |
325c7616 DR |
294 | The typical interactions between pieces of data are best represented by |
295 | operators. | |
f67486be | 296 | |
995ab4ef | 297 | =item * |
f67486be | 298 | |
325c7616 DR |
299 | The implementation of individual components of the system is likely to |
300 | change over time. | |
f67486be | 301 | |
995ab4ef | 302 | =item * |
f67486be | 303 | |
325c7616 | 304 | The system design is already object-oriented. |
f67486be | 305 | |
995ab4ef | 306 | =item * |
f67486be | 307 | |
325c7616 | 308 | Large numbers of other programmers will be using your code modules. |
f67486be KR |
309 | |
310 | =back | |
311 | ||
312 | Think carefully about whether OO is appropriate for your module. | |
313 | Gratuitous object orientation results in complex APIs which are | |
314 | difficult for the average module user to understand or use. | |
315 | ||
316 | =head2 Designing your API | |
317 | ||
318 | Your interfaces should be understandable by an average Perl programmer. | |
319 | The following guidelines may help you judge whether your API is | |
320 | sufficiently straightforward: | |
321 | ||
322 | =over 4 | |
323 | ||
324 | =item Write simple routines to do simple things. | |
325 | ||
326 | It's better to have numerous simple routines than a few monolithic ones. | |
327 | If your routine changes its behaviour significantly based on its | |
328 | arguments, it's a sign that you should have two (or more) separate | |
329 | routines. | |
330 | ||
331 | =item Separate functionality from output. | |
332 | ||
333 | Return your results in the most generic form possible and allow the user | |
334 | to choose how to use them. The most generic form possible is usually a | |
335 | Perl data structure which can then be used to generate a text report, | |
336 | HTML, XML, a database query, or whatever else your users require. | |
337 | ||
338 | If your routine iterates through some kind of list (such as a list of | |
339 | files, or records in a database) you may consider providing a callback | |
340 | so that users can manipulate each element of the list in turn. | |
341 | File::Find provides an example of this with its | |
342 | C<find(\&wanted, $dir)> syntax. | |
343 | ||
344 | =item Provide sensible shortcuts and defaults. | |
345 | ||
346 | Don't require every module user to jump through the same hoops to achieve a | |
347 | simple result. You can always include optional parameters or routines for | |
348 | more complex or non-standard behaviour. If most of your users have to | |
349 | type a few almost identical lines of code when they start using your | |
350 | module, it's a sign that you should have made that behaviour a default. | |
351 | Another good indicator that you should use defaults is if most of your | |
352 | users call your routines with the same arguments. | |
353 | ||
354 | =item Naming conventions | |
355 | ||
356 | Your naming should be consistent. For instance, it's better to have: | |
357 | ||
358 | display_day(); | |
359 | display_week(); | |
360 | display_year(); | |
361 | ||
362 | than | |
363 | ||
364 | display_day(); | |
365 | week_display(); | |
366 | show_year(); | |
367 | ||
368 | This applies equally to method names, parameter names, and anything else | |
369 | which is visible to the user (and most things that aren't!) | |
370 | ||
371 | =item Parameter passing | |
372 | ||
373 | Use named parameters. It's easier to use a hash like this: | |
374 | ||
375 | $obj->do_something( | |
376 | name => "wibble", | |
377 | type => "text", | |
378 | size => 1024, | |
379 | ); | |
380 | ||
381 | ... than to have a long list of unnamed parameters like this: | |
382 | ||
383 | $obj->do_something("wibble", "text", 1024); | |
384 | ||
385 | While the list of arguments might work fine for one, two or even three | |
386 | arguments, any more arguments become hard for the module user to | |
387 | remember, and hard for the module author to manage. If you want to add | |
388 | a new parameter you will have to add it to the end of the list for | |
389 | backward compatibility, and this will probably make your list order | |
390 | unintuitive. Also, if many elements may be undefined you may see the | |
391 | following unattractive method calls: | |
392 | ||
555bd962 | 393 | $obj->do_something(undef, undef, undef, undef, undef, 1024); |
f67486be KR |
394 | |
395 | Provide sensible defaults for parameters which have them. Don't make | |
396 | your users specify parameters which will almost always be the same. | |
397 | ||
398 | The issue of whether to pass the arguments in a hash or a hashref is | |
399 | largely a matter of personal style. | |
400 | ||
401 | The use of hash keys starting with a hyphen (C<-name>) or entirely in | |
402 | upper case (C<NAME>) is a relic of older versions of Perl in which | |
403 | ordinary lower case strings were not handled correctly by the C<=E<gt>> | |
404 | operator. While some modules retain uppercase or hyphenated argument | |
405 | keys for historical reasons or as a matter of personal style, most new | |
406 | modules should use simple lower case keys. Whatever you choose, be | |
407 | consistent! | |
408 | ||
409 | =back | |
410 | ||
411 | =head2 Strictness and warnings | |
412 | ||
413 | Your module should run successfully under the strict pragma and should | |
414 | run without generating any warnings. Your module should also handle | |
415 | taint-checking where appropriate, though this can cause difficulties in | |
416 | many cases. | |
417 | ||
418 | =head2 Backwards compatibility | |
419 | ||
420 | Modules which are "stable" should not break backwards compatibility | |
421 | without at least a long transition phase and a major change in version | |
422 | number. | |
423 | ||
424 | =head2 Error handling and messages | |
425 | ||
426 | When your module encounters an error it should do one or more of: | |
427 | ||
428 | =over 4 | |
429 | ||
430 | =item * | |
431 | ||
432 | Return an undefined value. | |
433 | ||
434 | =item * | |
435 | ||
436 | set C<$Module::errstr> or similar (C<errstr> is a common name used by | |
437 | DBI and other popular modules; if you choose something else, be sure to | |
438 | document it clearly). | |
439 | ||
440 | =item * | |
441 | ||
442 | C<warn()> or C<carp()> a message to STDERR. | |
443 | ||
444 | =item * | |
445 | ||
446 | C<croak()> only when your module absolutely cannot figure out what to | |
447 | do. (C<croak()> is a better version of C<die()> for use within | |
448 | modules, which reports its errors from the perspective of the caller. | |
449 | See L<Carp> for details of C<croak()>, C<carp()> and other useful | |
450 | routines.) | |
451 | ||
452 | =item * | |
453 | ||
454 | As an alternative to the above, you may prefer to throw exceptions using | |
455 | the Error module. | |
456 | ||
457 | =back | |
458 | ||
459 | Configurable error handling can be very useful to your users. Consider | |
460 | offering a choice of levels for warning and debug messages, an option to | |
461 | send messages to a separate file, a way to specify an error-handling | |
462 | routine, or other such features. Be sure to default all these options | |
463 | to the commonest use. | |
464 | ||
465 | =head1 DOCUMENTING YOUR MODULE | |
466 | ||
467 | =head2 POD | |
468 | ||
469 | Your module should include documentation aimed at Perl developers. | |
470 | You should use Perl's "plain old documentation" (POD) for your general | |
471 | technical documentation, though you may wish to write additional | |
472 | documentation (white papers, tutorials, etc) in some other format. | |
473 | You need to cover the following subjects: | |
474 | ||
475 | =over 4 | |
476 | ||
477 | =item * | |
478 | ||
479 | A synopsis of the common uses of the module | |
480 | ||
481 | =item * | |
482 | ||
483 | The purpose, scope and target applications of your module | |
484 | ||
485 | =item * | |
486 | ||
487 | Use of each publically accessible method or subroutine, including | |
488 | parameters and return values | |
489 | ||
490 | =item * | |
491 | ||
492 | Examples of use | |
493 | ||
494 | =item * | |
495 | ||
496 | Sources of further information | |
497 | ||
498 | =item * | |
499 | ||
500 | A contact email address for the author/maintainer | |
501 | ||
502 | =back | |
503 | ||
504 | The level of detail in Perl module documentation generally goes from | |
505 | less detailed to more detailed. Your SYNOPSIS section should contain a | |
506 | minimal example of use (perhaps as little as one line of code; skip the | |
da75cd15 | 507 | unusual use cases or anything not needed by most users); the |
f67486be KR |
508 | DESCRIPTION should describe your module in broad terms, generally in |
509 | just a few paragraphs; more detail of the module's routines or methods, | |
510 | lengthy code examples, or other in-depth material should be given in | |
511 | subsequent sections. | |
512 | ||
513 | Ideally, someone who's slightly familiar with your module should be able | |
514 | to refresh their memory without hitting "page down". As your reader | |
515 | continues through the document, they should receive a progressively | |
516 | greater amount of knowledge. | |
517 | ||
518 | The recommended order of sections in Perl module documentation is: | |
519 | ||
520 | =over 4 | |
521 | ||
522 | =item * | |
523 | ||
524 | NAME | |
525 | ||
526 | =item * | |
527 | ||
528 | SYNOPSIS | |
529 | ||
530 | =item * | |
531 | ||
532 | DESCRIPTION | |
533 | ||
534 | =item * | |
535 | ||
536 | One or more sections or subsections giving greater detail of available | |
537 | methods and routines and any other relevant information. | |
538 | ||
539 | =item * | |
540 | ||
541 | BUGS/CAVEATS/etc | |
542 | ||
543 | =item * | |
544 | ||
545 | AUTHOR | |
546 | ||
547 | =item * | |
548 | ||
549 | SEE ALSO | |
550 | ||
551 | =item * | |
552 | ||
553 | COPYRIGHT and LICENSE | |
554 | ||
555 | =back | |
556 | ||
557 | Keep your documentation near the code it documents ("inline" | |
558 | documentation). Include POD for a given method right above that | |
559 | method's subroutine. This makes it easier to keep the documentation up | |
560 | to date, and avoids having to document each piece of code twice (once in | |
561 | POD and once in comments). | |
562 | ||
563 | =head2 README, INSTALL, release notes, changelogs | |
564 | ||
565 | Your module should also include a README file describing the module and | |
566 | giving pointers to further information (website, author email). | |
567 | ||
568 | An INSTALL file should be included, and should contain simple installation | |
ff23347e JB |
569 | instructions. When using ExtUtils::MakeMaker this will usually be: |
570 | ||
571 | =over 4 | |
572 | ||
573 | =item perl Makefile.PL | |
574 | ||
575 | =item make | |
576 | ||
577 | =item make test | |
578 | ||
579 | =item make install | |
580 | ||
581 | =back | |
582 | ||
583 | When using Module::Build, this will usually be: | |
584 | ||
585 | =over 4 | |
586 | ||
587 | =item perl Build.PL | |
588 | ||
589 | =item perl Build | |
590 | ||
591 | =item perl Build test | |
592 | ||
593 | =item perl Build install | |
594 | ||
595 | =back | |
f67486be KR |
596 | |
597 | Release notes or changelogs should be produced for each release of your | |
598 | software describing user-visible changes to your module, in terms | |
599 | relevant to the user. | |
600 | ||
4a8dd740 NB |
601 | Unless you have good reasons for using some other format |
602 | (for example, a format used within your company), | |
603 | the convention is to name your changelog file C<Changes>, | |
604 | and to follow the simple format described in L<CPAN::Changes::Spec>. | |
605 | ||
f67486be KR |
606 | =head1 RELEASE CONSIDERATIONS |
607 | ||
608 | =head2 Version numbering | |
609 | ||
610 | Version numbers should indicate at least major and minor releases, and | |
611 | possibly sub-minor releases. A major release is one in which most of | |
612 | the functionality has changed, or in which major new functionality is | |
613 | added. A minor release is one in which a small amount of functionality | |
614 | has been added or changed. Sub-minor version numbers are usually used | |
615 | for changes which do not affect functionality, such as documentation | |
616 | patches. | |
617 | ||
618 | The most common CPAN version numbering scheme looks like this: | |
619 | ||
620 | 1.00, 1.10, 1.11, 1.20, 1.30, 1.31, 1.32 | |
621 | ||
622 | A correct CPAN version number is a floating point number with at least | |
623 | 2 digits after the decimal. You can test whether it conforms to CPAN by | |
624 | using | |
625 | ||
626 | perl -MExtUtils::MakeMaker -le 'print MM->parse_version(shift)' 'Foo.pm' | |
627 | ||
4398853c A |
628 | If you want to release a 'beta' or 'alpha' version of a module but |
629 | don't want CPAN.pm to list it as most recent use an '_' after the | |
630 | regular version number followed by at least 2 digits, eg. 1.20_01. If | |
631 | you do this, the following idiom is recommended: | |
632 | ||
633 | $VERSION = "1.12_01"; | |
634 | $XS_VERSION = $VERSION; # only needed if you have XS code | |
635 | $VERSION = eval $VERSION; | |
636 | ||
637 | With that trick MakeMaker will only read the first line and thus read | |
638 | the underscore, while the perl interpreter will evaluate the $VERSION | |
639 | and convert the string into a number. Later operations that treat | |
640 | $VERSION as a number will then be able to do so without provoking a | |
641 | warning about $VERSION not being a number. | |
f67486be KR |
642 | |
643 | Never release anything (even a one-word documentation patch) without | |
644 | incrementing the number. Even a one-word documentation patch should | |
645 | result in a change in version at the sub-minor level. | |
646 | ||
647 | =head2 Pre-requisites | |
648 | ||
649 | Module authors should carefully consider whether to rely on other | |
650 | modules, and which modules to rely on. | |
651 | ||
652 | Most importantly, choose modules which are as stable as possible. In | |
653 | order of preference: | |
654 | ||
655 | =over 4 | |
656 | ||
657 | =item * | |
658 | ||
659 | Core Perl modules | |
660 | ||
661 | =item * | |
662 | ||
663 | Stable CPAN modules | |
664 | ||
665 | =item * | |
666 | ||
667 | Unstable CPAN modules | |
668 | ||
669 | =item * | |
670 | ||
671 | Modules not available from CPAN | |
672 | ||
673 | =back | |
674 | ||
675 | Specify version requirements for other Perl modules in the | |
ff23347e | 676 | pre-requisites in your Makefile.PL or Build.PL. |
f67486be | 677 | |
ff23347e JB |
678 | Be sure to specify Perl version requirements both in Makefile.PL or |
679 | Build.PL and with C<require 5.6.1> or similar. See the section on | |
680 | C<use VERSION> of L<perlfunc/require> for details. | |
f67486be KR |
681 | |
682 | =head2 Testing | |
683 | ||
ff23347e | 684 | All modules should be tested before distribution (using "make disttest"), |
f67486be KR |
685 | and the tests should also be available to people installing the modules |
686 | (using "make test"). | |
ff23347e | 687 | For Module::Build you would use the C<make test> equivalent C<perl Build test>. |
f67486be KR |
688 | |
689 | The importance of these tests is proportional to the alleged stability of a | |
ac036724 | 690 | module. A module which purports to be stable or which hopes to achieve wide |
f67486be KR |
691 | use should adhere to as strict a testing regime as possible. |
692 | ||
693 | Useful modules to help you write tests (with minimum impact on your | |
694 | development process or your time) include Test::Simple, Carp::Assert | |
695 | and Test::Inline. | |
ff23347e | 696 | For more sophisticated test suites there are Test::More and Test::MockObject. |
f67486be KR |
697 | |
698 | =head2 Packaging | |
699 | ||
ff23347e JB |
700 | Modules should be packaged using one of the standard packaging tools. |
701 | Currently you have the choice between ExtUtils::MakeMaker and the | |
702 | more platform independent Module::Build, allowing modules to be installed in a | |
703 | consistent manner. | |
704 | When using ExtUtils::MakeMaker, you can use "make dist" to create your | |
705 | package. Tools exist to help you to build your module in a MakeMaker-friendly | |
706 | style. These include ExtUtils::ModuleMaker and h2xs. See also L<perlnewmod>. | |
f67486be KR |
707 | |
708 | =head2 Licensing | |
709 | ||
710 | Make sure that your module has a license, and that the full text of it | |
711 | is included in the distribution (unless it's a common one and the terms | |
712 | of the license don't require you to include it). | |
713 | ||
714 | If you don't know what license to use, dual licensing under the GPL | |
715 | and Artistic licenses (the same as Perl itself) is a good idea. | |
2a551100 | 716 | See L<perlgpl> and L<perlartistic>. |
f67486be KR |
717 | |
718 | =head1 COMMON PITFALLS | |
719 | ||
720 | =head2 Reinventing the wheel | |
721 | ||
722 | There are certain application spaces which are already very, very well | |
723 | served by CPAN. One example is templating systems, another is date and | |
724 | time modules, and there are many more. While it is a rite of passage to | |
725 | write your own version of these things, please consider carefully | |
726 | whether the Perl world really needs you to publish it. | |
727 | ||
728 | =head2 Trying to do too much | |
729 | ||
730 | Your module will be part of a developer's toolkit. It will not, in | |
731 | itself, form the B<entire> toolkit. It's tempting to add extra features | |
732 | until your code is a monolithic system rather than a set of modular | |
733 | building blocks. | |
734 | ||
735 | =head2 Inappropriate documentation | |
736 | ||
737 | Don't fall into the trap of writing for the wrong audience. Your | |
738 | primary audience is a reasonably experienced developer with at least | |
739 | a moderate understanding of your module's application domain, who's just | |
740 | downloaded your module and wants to start using it as quickly as possible. | |
741 | ||
742 | Tutorials, end-user documentation, research papers, FAQs etc are not | |
743 | appropriate in a module's main documentation. If you really want to | |
744 | write these, include them as sub-documents such as C<My::Module::Tutorial> or | |
745 | C<My::Module::FAQ> and provide a link in the SEE ALSO section of the | |
746 | main documentation. | |
747 | ||
748 | =head1 SEE ALSO | |
749 | ||
750 | =over 4 | |
751 | ||
752 | =item L<perlstyle> | |
753 | ||
754 | General Perl style guide | |
755 | ||
756 | =item L<perlnewmod> | |
757 | ||
758 | How to create a new module | |
759 | ||
760 | =item L<perlpod> | |
761 | ||
762 | POD documentation | |
763 | ||
764 | =item L<podchecker> | |
765 | ||
766 | Verifies your POD's correctness | |
767 | ||
ff23347e JB |
768 | =item Packaging Tools |
769 | ||
770 | L<ExtUtils::MakeMaker>, L<Module::Build> | |
771 | ||
f67486be KR |
772 | =item Testing tools |
773 | ||
ff23347e | 774 | L<Test::Simple>, L<Test::Inline>, L<Carp::Assert>, L<Test::More>, L<Test::MockObject> |
f67486be KR |
775 | |
776 | =item http://pause.perl.org/ | |
777 | ||
778 | Perl Authors Upload Server. Contains links to information for module | |
779 | authors. | |
780 | ||
781 | =item Any good book on software engineering | |
782 | ||
783 | =back | |
784 | ||
785 | =head1 AUTHOR | |
786 | ||
787 | Kirrily "Skud" Robert <skud@cpan.org> | |
788 |