in reply to good examples of POD documentation

Asking for good examples of POD is a little like asking for good examples of a web page. What's good depends on the complexity of your module, your development needs, your production environment, and even your personal style. There is a lot of variety in both visible content and internal placement of the POD that creates the content. I'll highlight a few points here, but my recommendation is that you study some CPAN modules and ask yourself "What works (communicates well) and why?" Then develop a style of your own.

There is a basic skeleton that many of the CPAN modules seem to follow. This consists of the following sections:

  1. NAME section - name of function in bold followed by a one line description.
  2. various descriptive sections - often this is divided into two sections. The first is a SYNOPSIS section that gives a quick thumbnail sketch of the module's capabilities, usually via sample code or a list of function/methods. The second is a much longer section titled DESCRIPTION. This covers all the points that may not be obvious from the synopsis. However, the number and organization of the description sections can vary a lot depending on the complexity of the module
  3. CAVEATS (sometimes titled "BUGS AND CAVEATS", "NOTES AND CAVEATS", "NOTES" or "BUGS") - one or more sections listing known bugs, unrealized implementation goals, and general restrictions on use contexts - for example: operating system limitations or whether or not the module plays well with Apache and mod_perl
  4. SEE ALSO - section listing related modules. Modules can be related because they do the same thing a different way, provide helpful background information or because they are a useful complement to module at hand. Sometimes you will also see a brief description explaining why they should be "seen also".
  5. AUTHOR - section listing everyone who wrote or helped with the module.
  6. COPYRIGHT - section listing who holds the copy rights and licensing agreements.

To sort out what information belongs in your description sections is probably the hardest part of writing good POD. A lot depends on the complexity of your module:

If the parameters are simple and the role of each function is pretty obvious from its name, you may be able to get away with documentation that consists of a brief SYNOPSIS section followed by a DESCRIPTION section briefly describing each function and its parameters one by one.

If there are a lot of similarly defined parameters, it is often a good idea to have the synopsis section use consistent variable names for each parameter. Then include a subsection of DESCRIPTION explaining what values parameters $x, $y, $mumblefoo can take. This can save a lot of time for your module user: without users have to scan back and forth between your individual function descriptions to figure out if $x in makeFred($x) has the same meaning as $x in in makeBarney($x). Not fun.

For more complex modules, its hard to come up with rules of thumb, so I refer you back to the original advice: study a variety of CPAN modules and ask yourself - what does and does not get its point across and make the module easier to use?

Once one has figured out what to document, the next question is where to document. There are several styles and I don't know that one is right - they suit different programming styles, maintenence and production needs:

One final issue relating to POD is the role of "hidden POD". POD can be used for many things including in-line test cases, private developer notes, and cook book examples. The normal document generator will quietly ignore =foobar if it doesn't know what foobar is supposed to mean. There are numerous modules on CPAN that take advantage of this feature to embed all sorts of maintenence related information in source code files. For example, see Test::Inline for inline test cases and Test::Cookbook for cookbook examples that double as executable code. (Note: I don't use either of these modules - so I can't vouch for their safety)

Best, beth

Replies are listed 'Best First'.
Re^2: good examples of POD documentation
by JavaFan (Canon) on Mar 06, 2009 at 14:19 UTC
    in the file but out of the way - some people feel that keeping documentation, especially lengthy documentation close to each function makes it difficult for them to get a good birds eye view of a module. This is particularly true if your team has a lot of people that are very fluent in reading code. To get POD out of the way, some people prefer to place all of the POD at the top or the bottom.
    I'm one of the people who puts the POD after the __END__. For the reasons you mention and for an additional reason: I often don't document the code in the same as they appear in the code. In the code, you may want to keep methods accessing the same data close to each other, but for documentation you may have other considerations. I typically use methods I expect to be used often early in the documentation, while lesser used method are documented further down. Sometimes I prefer the documentation to describe the methods sorted lexigraphical. And if the description of method A is build on the description of method B, I like to have in the documentation A right above B. Moving the documentation "out of the way" gives me the freedom of moving documentation (and code) around without changing the order.