What's the best way to document Perl code?
Look inside almost any Perl module and you'll see the Plain Old Documentation (POD) format. On CPAN Search, when looking at a module you have the option of viewing the raw source, so that's one way you can look at the raw pod, but you can also use perldoc from the command line. The -m
switch shows you the file
perldoc -m Foo::Bar
Or, if you want to find the file so you can look at it in your favorite editor, use the -l
switch to find it:
perldoc -l Foo::Bar
Once you start documenting your program, you put the Pod in the file right with the code, either interwoven with the code so the documentation is next to the relevant parts, or at the beginning, middle, or end as one big chunk.
Pod is easily translated to several other formats, such as LaTeX, Postscript, HTML, and so on with translators that come with Perl (pod2latex, pod2ps, pod2html). I even have a pod translator that goes to InDesign. Writing your own Pod translator is easy with Pod::Simple, so if you don't find a translator to your favorite final form, just make it yourself.
There are also several tools that you can add to your test suite to check your Pod. The Test::Pod module checks for format errors, the Test::Pod::Coverage module checks the you've documented each subroutine, and so on. You also might be interested in my Perl documentation documentation.
I definitely recommend POD.
POD can also be used in-line with code but I prefer to put at bottom of program after __END__ (as recommended by Damian Conway in Perl Best Practices).
Look at POD::Server & POD::Webserver, which provides a web front-end to all your PODs.
Perl pod.
This is how Mozilla documents their Perl.